index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div class="app-container">
  3. <div class="table1">
  4. <div class="search">
  5. <el-select v-model="table1.parammaps.pastureid" filterable placeholder="全部牧场" class="filter-item" style="width: 150px;" clearable>
  6. <el-option v-for="item in table1.pastureList" :key="item.pastureid" :label="item.pasturename" :value="item.pastureid" />
  7. </el-select>
  8. <el-date-picker v-model="table1.parammaps.inputDatetime" type="daterange" class="filter-item" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
  9. <el-select v-model="table1.parammaps.genre" filterable placeholder="类型" class="filter-item" style="float: left;width: 150px;" clearable>
  10. <el-option v-for="item in table1.typeList" :key="item.id" :label="item.name" :value="item.id" />
  11. </el-select>
  12. <el-button class="successBorder" @click="handleSearch1">查询</el-button>
  13. <el-button class="successBorder" @click="handleRefresh1">重置</el-button>
  14. <el-button class="filter-item import" style="display:inline-block;" icon="el-icon-download" @click="handleImport">导入</el-button>
  15. <el-button class="filter-item export" icon="el-icon-upload2" @click="handleDownload()" style="display:inline-block;">导出</el-button>
  16. <el-button class="filter-item export" icon="el-icon-upload2" @click="handleDownloadTemp()" style="display:inline-block;">导入模板下载</el-button>
  17. </div>
  18. <div class="table">
  19. <el-table
  20. :key="table1.tableKey"
  21. v-loading="table1.listLoading"
  22. element-loading-text="给我一点时间"
  23. :data="table1.list"
  24. border
  25. fit
  26. highlight-current-row
  27. style="width: 100%;"
  28. :row-style="rowStyle"
  29. :cell-style="cellStyle"
  30. class="elTable table-fixed"
  31. >
  32. <el-table-column label="序号" align="center" type="index" width="50px">
  33. <template slot-scope="scope">
  34. <span v-if="table1.pageNum">{{ scope.$index + (table1.pageNum-1) * table1.pageSize + 1 }}</span>
  35. <span v-else>1</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="牧场名称" min-width="60px" align="center" prop="pasturename" />
  39. <el-table-column label="数量" min-width="60px" align="center" prop="count">
  40. <template slot-scope="{row}">
  41. <a @click="clickQuantity(row)" style="text-decoration: underline;color: #0000FF;">{{row.count}}</a>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="类型" min-width="60px" align="center">
  45. <template slot-scope="{row}">
  46. <span v-if="row.genre == 0">售卖</span>
  47. <span v-else-if="row.genre == 1">返厂</span>
  48. <span v-else>置换</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="导入时间" min-width="60px" align="center" prop="importdate" />
  52. </el-table>
  53. <pagination v-show="table1.total>0" :total="table1.total" :page.sync="table1.offset" :limit.sync="table1.pagecount" @pagination="getList1" />
  54. </div>
  55. </div>
  56. <el-dialog :title="textMap[importPasture.dialogStatus]" :visible.sync="importPasture.dialogFormVisible" :close-on-click-modal="false" width="50%">
  57. <div class="import1" style="height: 300px;">
  58. <el-form ref="temp" :model="importPasture.temp" label-position="right" label-width="150px" style="width: 100%;margin:0 auto 50px">
  59. <el-row>
  60. <el-col :span="16">
  61. <el-form-item label="牧场:" prop="pastureid">
  62. <el-select v-model="importPasture.temp.pastureid" filterable placeholder="牧场名称" class="filter-item" style="width: 100%;" @change="changePasture">
  63. <el-option v-for="item in table1.pastureList" :key="item.pastureid" :label="item.pasturename" :value="item.pastureid" />
  64. </el-select>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. </el-form>
  69. <div style="display: flex;justify-content: center;margin-top: 20px;height: 100px;" >
  70. <el-upload v-if="importPasture.temp.pastureid !== ''" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  71. <el-button class="save" :disabled="importPasture.temp.pastureid==''">选择导入文件</el-button>
  72. </el-upload>
  73. <el-button class="save" v-else @click="clickImpotFile()">选择导入文件</el-button>
  74. </div>
  75. </div>
  76. <div slot="footer" class="dialog-footer" style="bottom: 10px;">
  77. <el-button class="cancelClose1" @click="importPasture.dialogFormVisible = false;">关闭</el-button>
  78. </div>
  79. </el-dialog>
  80. <!-- 数量 -->
  81. <el-dialog :visible.sync="quantity.dialogFormVisible" :close-on-click-modal="false" width="50%">
  82. <template slot="title">
  83. <div class="avue-crud__dialog__header">
  84. <span class="el-dialog__title">
  85. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  86. {{ textMap[quantity.dialogStatus] }}
  87. </span>
  88. <span style="margin-right: 100px;">导入时间:{{quantity.temp.importdate}}</span>
  89. </div>
  90. </template>
  91. <div class="quantity">
  92. <el-table
  93. :key="quantity.table1.tableKey"
  94. v-loading="quantity.table1.listLoading"
  95. element-loading-text="给我一点时间"
  96. :data="quantity.table1.list"
  97. border
  98. fit
  99. highlight-current-row
  100. style="width: 100%;"
  101. :row-style="rowStyle"
  102. :cell-style="cellStyle"
  103. class="elTable table-fixed"
  104. >
  105. <el-table-column label="序号" align="center" type="index" width="50px">
  106. <template slot-scope="scope">
  107. <span v-if="quantity.table1.pageNum">{{ scope.$index + (quantity.table1.pageNum-1) * quantity.table1.pageSize + 1 }}</span>
  108. <span v-else>1</span>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="脖环号" min-width="60px" align="center" prop="code" />
  112. <el-table-column label="日期" min-width="60px" align="center" prop="date" />
  113. </el-table>
  114. <pagination v-show="table1.total>0" :total="table1.total" :page.sync="table1.offset" :limit.sync="table1.pagecount" @pagination="getList1" />
  115. </div>
  116. <div slot="footer" class="dialog-footer" style="bottom: 10px;">
  117. <el-button class="cancelClose1" @click="quantity.dialogFormVisible = false; ">关闭</el-button>
  118. </div>
  119. </el-dialog>
  120. </div>
  121. </template>
  122. <script>
  123. import Pagination from '@/components/Pagination'
  124. import { postJson,getJson } from '@/api/common'
  125. import { parseTime,json2excel } from '@/utils/index.js'
  126. import Cookies from 'js-cookie'
  127. import axios from 'axios'
  128. import { getToken } from '@/utils/auth'
  129. import xlsx from 'xlsx'
  130. import { upload } from '@/utils/index.js'
  131. export default {
  132. name: 'NeckRing',
  133. components: { Pagination },
  134. data() {
  135. return {
  136. table1:{
  137. pastureList:[],
  138. typeList:[{id:0,name:'售卖'},{id:1,name:'返厂'},{id:2,name:'置换'}],
  139. page: 1, offset: 1, pagecount: parseInt(Cookies.get('pageCount')),
  140. parammaps: { pastureid: '', genre:'',inputDatetime:'' },
  141. tableKey: 0, list: [], total: 0, listLoading: true
  142. },
  143. // 数量
  144. quantity:{
  145. dialogStatus: '',
  146. dialogFormVisible: false,
  147. rules:{},
  148. temp:{},
  149. table1:{
  150. page: 1, offset: 1, pagecount: parseInt(Cookies.get('pageCount')),
  151. parammaps: { pastureid: '', date:'' },
  152. tableKey: 0, list: [], total: 0, listLoading: true
  153. }
  154. },
  155. importPasture:{
  156. dialogStatus: '',
  157. dialogFormVisible: false,
  158. temp:{
  159. pastureid:''
  160. }
  161. },
  162. isokDisable:false,
  163. textMap: {
  164. quantityTxt: '数量',
  165. importTxt:'选择牧场'
  166. },
  167. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  168. cellStyle: { padding: 0 + 'px' }
  169. }
  170. },
  171. computed: {
  172. // 设置请求头
  173. headers() {
  174. return {
  175. token: getToken()
  176. }
  177. },
  178. uploadData() {
  179. return {}
  180. },
  181. // 设置上传地址
  182. uploadExcelUrl() {
  183. return process.env.VUE_APP_BASE_API + 'management/add'
  184. }
  185. },
  186. created() {
  187. this.getList1()
  188. this.getPastureList()
  189. },
  190. methods: {
  191. getPastureList(){
  192. let data = 'index=' + 1
  193. + '&pagesize=' + ''
  194. let url = 'public/pasture?'
  195. getJson(url,data).then(response => {
  196. if (response.code == 200) {
  197. this.table1.pastureList = response.data.list
  198. } else {
  199. this.table1.pastureList = []
  200. }
  201. })
  202. },
  203. getList1() {
  204. this.table1.listLoading = true
  205. let genre = ''
  206. if(this.table1.parammaps.genre == '' || this.table1.parammaps.genre == null){
  207. genre = -1
  208. }else{
  209. genre = this.table1.parammaps.genre
  210. }
  211. let startdate = ''
  212. let enddate = ''
  213. if(this.table1.parammaps.inputDatetime !== '' && this.table1.parammaps.inputDatetime !== null){
  214. startdate = parseTime(this.table1.parammaps.inputDatetime[0],'{y}-{m}-{d}')
  215. enddate = parseTime(this.table1.parammaps.inputDatetime[1],'{y}-{m}-{d}')
  216. }else{
  217. startdate = ''
  218. enddate = ''
  219. }
  220. let data = 'index=' + this.table1.offset
  221. + '&pagesize=' + this.table1.pagecount
  222. + '&genre=' + genre
  223. + '&pastureid=' + this.table1.parammaps.pastureid
  224. + '&startdate=' + startdate
  225. + '&enddate=' + enddate
  226. let url = 'management/list?'
  227. getJson(url,data).then(response => {
  228. if (response.code == 200) {
  229. this.table1.list = response.data.list
  230. this.table1.pageNum = this.table1.offset
  231. this.table1.pageSize = this.table1.pagecount
  232. } else {
  233. this.table1.list = []
  234. }
  235. this.table1.total = response.data.total
  236. setTimeout(() => {
  237. this.table1.listLoading = false
  238. }, 100)
  239. })
  240. },
  241. handleSearch1(){
  242. this.table1.offset = 1
  243. this.getList1()
  244. },
  245. handleRefresh1(){
  246. this.table1.offset = 1
  247. this.table1.parammaps.pastureid = ''
  248. this.table1.parammaps.inputDatetime = ''
  249. this.table1.parammaps.genre = ''
  250. this.getList1()
  251. },
  252. clickQuantity(row){
  253. console.log('数量')
  254. this.quantity.temp = Object.assign({}, row)
  255. this.quantity.dialogFormVisible = true
  256. this.quantity.dialogStatus = 'quantityTxt'
  257. this.getQuantityList1()
  258. },
  259. getQuantityList1() {
  260. this.quantity.table1.listLoading = true
  261. let data = 'index=' + this.quantity.table1.offset
  262. + '&pagesize=' + this.quantity.table1.pagecount
  263. + '&managementid=' + this.quantity.temp.id
  264. let url = 'managementbh/list?'
  265. getJson(url,data).then(response => {
  266. if (response.code == 200) {
  267. this.quantity.table1.list = response.data.list
  268. this.quantity.table1.pageNum = this.quantity.table1.offset
  269. this.quantity.table1.pageSize = this.quantity.table1.pagecount
  270. } else {
  271. this.quantity.table1.list = []
  272. }
  273. this.quantity.table1.total = response.data.total
  274. setTimeout(() => {
  275. this.quantity.table1.listLoading = false
  276. }, 100)
  277. })
  278. },
  279. clickhandleData(){
  280. console.log('处理确认')
  281. },
  282. handleDownload(){
  283. console.log('导出')
  284. let genre = ''
  285. if(this.table1.parammaps.genre == '' || this.table1.parammaps.genre == null){
  286. genre = -1
  287. }else{
  288. genre = this.table1.parammaps.genre
  289. }
  290. let startdate = ''
  291. let enddate = ''
  292. if(this.table1.parammaps.inputDatetime !== '' && this.table1.parammaps.inputDatetime !== null){
  293. startdate = parseTime(this.table1.parammaps.inputDatetime[0],'{y}-{m}-{d}')
  294. enddate = parseTime(this.table1.parammaps.inputDatetime[1],'{y}-{m}-{d}')
  295. }else{
  296. startdate = ''
  297. enddate = ''
  298. }
  299. let data = 'index=' + 1
  300. + '&pagesize=' + ''
  301. + '&genre=' + genre
  302. + '&pastureid=' + this.table1.parammaps.pastureid
  303. + '&startdate=' + startdate
  304. + '&enddate=' + enddate
  305. let url = 'management/list?'
  306. var downList = []
  307. getJson(url,data).then(response => {
  308. if (response.code == 200) {
  309. response.data.list.forEach((ele)=> {
  310. if(ele.genre == 0){
  311. ele.genre = '售卖'
  312. }else if(ele.genre == 1){
  313. ele.genre = '返厂'
  314. }else{
  315. ele.genre = '置换'
  316. }
  317. });
  318. downList = response.data.list
  319. } else {
  320. downList = []
  321. }
  322. var excelDatas = [{
  323. tHeader: ['牧场名称','数量','类型','导入时间'],
  324. filterVal: ['pasturename','count','genre','importdate'],
  325. tableDatas: downList,
  326. sheetName: 'sheet'
  327. }]
  328. json2excel(excelDatas, '脖环管理', true, 'xlsx')
  329. })
  330. },
  331. handleDownloadTemp(){
  332. const requestParam = {}
  333. const url = process.env.VUE_APP_BASE_API + 'download?filename=脖环管理.xlsx' // 请求下载文件的地址
  334. console.log(url)
  335. axios({
  336. method: 'GET',
  337. url: url,
  338. data: requestParam,
  339. headers: { token: getToken(), optname: 'insertcustomdoc' },
  340. responseType: 'blob'
  341. }).then(res => {
  342. if (!res) return
  343. this.percentage = 99
  344. setTimeout(() => {
  345. this.isPercentage = false
  346. }, 2000)
  347. const blob = new Blob([res.data], {
  348. type: 'application/octet-stream;charset=utf-8'
  349. })
  350. const url = window.URL.createObjectURL(blob)
  351. const aLink = document.createElement('a')
  352. aLink.style.display = 'none'
  353. aLink.href = url
  354. const docname = '脖环管理导入模板下载.xlsx'
  355. aLink.setAttribute('download', docname) // 下载的文件
  356. document.body.appendChild(aLink)
  357. aLink.click()
  358. document.body.removeChild(aLink)
  359. window.URL.revokeObjectURL(url)
  360. })
  361. },
  362. handleImport(){
  363. this.importPasture.dialogFormVisible = true
  364. this.importPasture.dialogStatus = 'importTxt'
  365. this.importPasture.temp.pastureid = ''
  366. },
  367. clickImpotFile(){
  368. this.$message.warning('请选择牧场')
  369. },
  370. changePasture(item){
  371. this.uploadData.pastureid = item
  372. },
  373. beforeImport(file) {
  374. const isLt2M = file.size / 1024 / 1024 < 2
  375. if (!isLt2M) {
  376. this.$message.error('上传文件大小不能超过 2MB!')
  377. }
  378. return isLt2M
  379. },
  380. handleImportSuccess(res, file) {
  381. if (res.msg === 'ok') {
  382. this.$message({ title: '成功', message: '导入成功', type: 'success', duration: 2000 })
  383. this.importPasture.dialogFormVisible = false
  384. this.getList1()
  385. } else {
  386. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  387. }
  388. },
  389. formatJson(filterVal, jsonData) {
  390. return jsonData.map(v =>
  391. filterVal.map(j => {
  392. if (j === 'timestamp') {
  393. return parseTime(v[j])
  394. } else {
  395. return v[j]
  396. }
  397. })
  398. )
  399. }
  400. }
  401. }
  402. </script>
  403. <style>
  404. </style>