index.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. <template>
  2. <div class="app-container">
  3. <div class="table1">
  4. <div class="search">
  5. <el-input v-model="table1.parammaps.batch" placeholder="召回批次号" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table1.parammaps.pastureid" filterable placeholder="牧场" class="filter-item" style="width: 150px;" clearable>
  7. <el-option v-for="item in table1.pastureList" :key="item.pastureid" :label="item.pasturename" :value="item.pastureid" />
  8. </el-select>
  9. <el-input-number v-model="table1.parammaps.startcount" class="filter-item" :controls="false" placeholder="召回数量" />
  10. <span>-</span>
  11. <el-input-number v-model="table1.parammaps.endcount" class="filter-item" :controls="false" placeholder="召回数量" />
  12. <el-input v-model="table1.parammaps.createname" placeholder="登记人" style="width: 180px;" class="filter-item" clearable />
  13. <el-date-picker v-model="table1.parammaps.inputDatetime" type="daterange" class="filter-item" range-separator="至" start-placeholder="登记开始日期" end-placeholder="登记结束日期" />
  14. <el-button class="successBorder" @click="handleSearch1">查询</el-button>
  15. <el-button class="successBorder" @click="handleRefresh1">重置</el-button>
  16. </div>
  17. <div class="operation">
  18. <el-button class="success" icon="el-icon-plus" @click="clickCreate">新增</el-button>
  19. <el-button class="import" icon="el-icon-download" @click="handleExportTemp1()">导入模板下载</el-button>
  20. <el-button class="export" icon="el-icon-upload2" @click="handleExport1()">导出</el-button>
  21. </div>
  22. <div class="table">
  23. <el-table
  24. :key="table1.tableKey"
  25. v-loading="table1.listLoading"
  26. element-loading-text="给我一点时间"
  27. :data="table1.list"
  28. border
  29. fit
  30. highlight-current-row
  31. style="width: 100%;"
  32. :row-style="rowStyle"
  33. :cell-style="cellStyle"
  34. class="elTable table-fixed"
  35. >
  36. <el-table-column label="序号" align="center" type="index" width="50px">
  37. <template slot-scope="scope">
  38. <span v-if="table1.pageNum">{{ scope.$index + (table1.pageNum-1) * table1.pageSize + 1 }}</span>
  39. <span v-else>1</span>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="召回批次号" min-width="60px" align="center" prop="batch" />
  43. <el-table-column label="牧场" min-width="60px" align="center" prop="pasturename" />
  44. <el-table-column label="召回数量" min-width="60px" align="center" prop="count">
  45. <template slot-scope="{row}">
  46. <a @click="clickQuantity(row)" style="text-decoration: underline;color: #0000FF;">{{row.count}}</a>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="关联出厂批次数" min-width="60px" align="center" prop="recall">
  50. <template slot-scope="{row}">
  51. <a @click="clickRecall(row)" style="text-decoration: underline;color: #0000FF;">{{row.recall}}</a>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="登记人" min-width="60px" align="center" prop="createname" />
  55. <el-table-column label="登记日期" min-width="60px" align="center" prop="createtime" />
  56. </el-table>
  57. <pagination v-show="table1.total>0" :total="table1.total" :page.sync="table1.offset" :limit.sync="table1.pagecount" @pagination="getList1" />
  58. </div>
  59. </div>
  60. <!-- 召回数量 -->
  61. <el-dialog :title="textMap[quantity.dialogStatus]" :visible.sync="quantity.dialogFormVisible" :close-on-click-modal="false" width="50%">
  62. <div class="quantity">
  63. <el-table
  64. :key="quantity.table1.tableKey"
  65. v-loading="quantity.table1.listLoading"
  66. element-loading-text="给我一点时间"
  67. :data="quantity.table1.list"
  68. border
  69. fit
  70. highlight-current-row
  71. style="width: 100%;"
  72. :row-style="rowStyle"
  73. :cell-style="cellStyle"
  74. class="elTable table-fixed"
  75. >
  76. <el-table-column label="序号" align="center" type="index" width="50px">
  77. <template slot-scope="scope">
  78. <span v-if="table1.pageNum">{{ scope.$index + (quantity.table1.pageNum-1) * quantity.table1.pageSize + 1 }}</span>
  79. <span v-else>1</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="脖环号" min-width="60px" align="center" prop="code" />
  83. <el-table-column label="出厂批次号" min-width="60px" align="center" prop="batch" />
  84. </el-table>
  85. <pagination v-show="quantity.table1.total>0" :total="quantity.table1.total" :page.sync="quantity.table1.offset" :limit.sync="quantity.table1.pagecount" @pagination="getQuantityList" />
  86. </div>
  87. <div slot="footer" class="dialog-footer" style="bottom: 10px;">
  88. <el-button class="cancelClose1" @click="quantity.dialogFormVisible = false; ">关闭</el-button>
  89. </div>
  90. </el-dialog>
  91. <!-- 关联召回批次数 -->
  92. <el-dialog :title="textMap[recall.dialogStatus]" :visible.sync="recall.dialogFormVisible" :close-on-click-modal="false" width="50%">
  93. <div class="recall">
  94. <el-table
  95. :key="recall.table1.tableKey"
  96. v-loading="recall.table1.listLoading"
  97. element-loading-text="给我一点时间"
  98. :data="recall.table1.list"
  99. border
  100. fit
  101. highlight-current-row
  102. style="width: 100%;"
  103. :row-style="rowStyle"
  104. :cell-style="cellStyle"
  105. class="elTable table-fixed"
  106. >
  107. <el-table-column label="序号" align="center" type="index" width="50px">
  108. <template slot-scope="scope">
  109. <span v-if="table1.pageNum">{{ scope.$index + (recall.table1.pageNum-1) * recall.table1.pageSize + 1 }}</span>
  110. <span v-else>1</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="出厂批次号" min-width="60px" align="center" prop="batch" />
  114. <el-table-column label="出厂数量" min-width="60px" align="center" prop="count" />
  115. <el-table-column label="登记人" min-width="60px" align="center" prop="createname" />
  116. <el-table-column label="登记日期" min-width="60px" align="center" prop="createtime" />
  117. </el-table>
  118. <pagination v-show="recall.table1.total>0" :total="recall.table1.total" :page.sync="recall.table1.offset" :limit.sync="recall.table1.pagecount" @pagination="getRecallList" />
  119. </div>
  120. <div slot="footer" class="dialog-footer" style="bottom: 10px;">
  121. <el-button class="cancelClose1" @click="recall.dialogFormVisible = false; ">关闭</el-button>
  122. </div>
  123. </el-dialog>
  124. <!-- 新增 -->
  125. <el-dialog :title="textMap[edit.dialogStatus]" :visible.sync="edit.dialogFormVisible" :close-on-click-modal="false" @close="close" width="70%">
  126. <div class="edit">
  127. <el-form ref="editTemp" :rules="edit.rules" :model="edit.temp" label-position="right" label-width="150px" style="width: 100%;margin:0 auto 50px;">
  128. <el-row>
  129. <el-col :span="16">
  130. <el-form-item label="牧场:" prop="pastureid">
  131. <el-select v-model="edit.temp.pastureid" filterable placeholder="牧场" class="filter-item" style="width: 100%;" @change="changePasture">
  132. <el-option v-for="item in table1.pastureList" :key="item.pastureid" :label="item.pasturename" :value="item.pastureid" />
  133. </el-select>
  134. </el-form-item>
  135. </el-col>
  136. </el-row>
  137. </el-form>
  138. <div class="batch" style="border-top: 1px solid #000;border-bottom: 1px solid #000;">
  139. <h5>关联到出厂批次:</h5>
  140. <div class="search">
  141. <el-input v-model="edit.batch.parammaps.batch" placeholder="出厂批次号" style="width: 180px;" class="filter-item" clearable />
  142. <el-input-number v-model="edit.batch.parammaps.startcount" class="filter-item" :controls="false" placeholder="出厂数量" />
  143. <span style="margin-right: 5px;">-</span>
  144. <el-input-number v-model="edit.batch.parammaps.endcount" class="filter-item" :controls="false" placeholder="出厂数量" />
  145. <el-input v-model="edit.batch.parammaps.createname" placeholder="登记人" style="width: 180px;" class="filter-item" clearable />
  146. <el-date-picker v-model="edit.batch.parammaps.inputDatetime" type="daterange" class="filter-item" range-separator="至" start-placeholder="登记开始日期" end-placeholder="登记结束日期" />
  147. <el-button class="successBorder" @click="handleBatchSearch">查询</el-button>
  148. <el-button class="successBorder" @click="handleBatchRefresh">重置</el-button>
  149. </div>
  150. <div class="table" style="margin-bottom: 10px;">
  151. <el-table
  152. :key="edit.batch.tableKey"
  153. v-loading="edit.batch.listLoading"
  154. element-loading-text="给我一点时间"
  155. :data="edit.batch.list"
  156. border
  157. fit
  158. highlight-current-row
  159. style="width: 100%;"
  160. :row-style="rowStyle"
  161. :cell-style="cellStyle"
  162. :height="300"
  163. class="elTable table-fixed"
  164. @selection-change="handleSelectionChange">
  165. >
  166. <el-table-column type="selection" width="55" />
  167. <el-table-column label="序号" align="center" type="index" width="50px" />
  168. <el-table-column label="出厂批次号" min-width="60px" align="center" prop="batch" />
  169. <el-table-column label="出厂数量" min-width="60px" align="center" prop="count" />
  170. <el-table-column label="登记人" min-width="60px" align="center" prop="createname" />
  171. <el-table-column label="登记日期" min-width="60px" align="center" prop="createtime" />
  172. </el-table>
  173. </div>
  174. </div>
  175. <div style="display: flex;justify-content: center;margin-top: 20px;" >
  176. <el-upload v-if="edit.batch.selectList.length>0" :headers="headers2" :data="uploadData2" :action="uploadExcelUrl2" :show-file-list="false" :before-upload="beforeImport2" :on-success="handleImportSuccess2">
  177. <el-button class="save" :disabled="edit.batch.selectList.length==0">选择导入文件</el-button>
  178. </el-upload>
  179. <el-button class="save" v-else disabled>选择导入文件</el-button>
  180. </div>
  181. </div>
  182. <div slot="footer" class="dialog-footer" style="bottom: 10px;">
  183. <!-- <el-button class="save" :disabled="isokDisable" @click="createData()">确认</el-button> -->
  184. <el-button class="cancelClose1" @click="close()">取消</el-button>
  185. </div>
  186. </el-dialog>
  187. </div>
  188. </template>
  189. <script>
  190. import Pagination from '@/components/Pagination'
  191. import { postJson,getJson } from '@/api/common'
  192. import Cookies from 'js-cookie'
  193. import { parseTime,json2excel } from '@/utils/index.js'
  194. import { getToken } from '@/utils/auth'
  195. import axios from 'axios'
  196. import xlsx from 'xlsx'
  197. export default {
  198. name: 'FactoryRegistration',
  199. components: { Pagination },
  200. data() {
  201. return {
  202. table1:{
  203. typeList:[{id:0,name:'购买'},{id:1,name:'置换'}],
  204. pastureList:[],
  205. page: 1, offset: 1, pagecount: parseInt(Cookies.get('pageCount')),
  206. parammaps: { batch:'',pastureid:'',startcount:undefined,endcount:undefined,createname:'',inputDatetime:'',startdate:'',enddate:'' },
  207. tableKey: 0, list: [], total: 0, listLoading: false
  208. },
  209. // 出厂数量
  210. quantity:{
  211. dialogStatus: '',
  212. dialogFormVisible: false,
  213. temp:{},
  214. table1:{
  215. page: 1, offset: 1, pagecount: parseInt(Cookies.get('pageCount')),
  216. parammaps: { batch:'',genre:'',startcount:undefined,endcount:undefined,createname:'',inputDatetime:'',startdate:'',enddate:'' },
  217. tableKey: 0, list: [], total: 0, listLoading: false
  218. },
  219. },
  220. // 关联召回批次数
  221. recall:{
  222. dialogStatus: '',
  223. dialogFormVisible: false,
  224. temp:{},
  225. table1:{
  226. page: 1, offset: 1, pagecount: parseInt(Cookies.get('pageCount')),
  227. parammaps: { batch:'',genre:'',startcount:undefined,endcount:undefined,createname:'',inputDatetime:'',startdate:'',enddate:'' },
  228. tableKey: 0, list: [], total: 0, listLoading: false
  229. },
  230. },
  231. // 新增
  232. edit:{
  233. dialogStatus: '',
  234. dialogFormVisible: false,
  235. rules:{
  236. pastureid: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  237. count: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  238. genre: [{ type: 'number', required: true, message: '必填', trigger: 'change' }]
  239. },
  240. temp:{},
  241. batch:{
  242. page: 1, offset: 1, pagecount: '',
  243. parammaps: { batch:'',startcount:undefined,endcount:undefined,createname:'',inputDatetime:'',startdate:'',enddate:'' },
  244. tableKey: 0, list: [], total: 0, listLoading: false,
  245. selectList:[],
  246. sumCount:''
  247. },
  248. },
  249. isokDisable:false,
  250. textMap: {
  251. revokeTxt: '撤销',
  252. quantityTxt: '',
  253. recallTxt:'',
  254. createTxt:'召回登记',
  255. batchTxt:'选择批次'
  256. },
  257. uploadData2:'',
  258. downParam:{},
  259. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  260. cellStyle: { padding: 0 + 'px' }
  261. }
  262. },
  263. computed: {
  264. // 设置请求头
  265. headers2() {
  266. return {
  267. token: getToken()
  268. }
  269. },
  270. // uploadData2() {
  271. // return {
  272. // // data:edit.batch.selectList
  273. // }
  274. // },
  275. // 设置上传地址
  276. uploadExcelUrl2() {
  277. return process.env.VUE_APP_BASE_API + 'recall/add'
  278. },
  279. },
  280. created() {
  281. this.getList1()
  282. this.getPastureList()
  283. },
  284. methods: {
  285. getPastureList(){
  286. let data = 'index=' + 1
  287. + '&pagesize=' + ''
  288. let url = 'public/pasture?'
  289. getJson(url,data).then(response => {
  290. if (response.code == 200) {
  291. this.table1.pastureList = response.data.list
  292. } else {
  293. this.table1.pastureList = []
  294. }
  295. })
  296. },
  297. getList1() {
  298. this.table1.listLoading = true
  299. let genre = ''
  300. if(this.table1.parammaps.genre == '' || this.table1.parammaps.genre == null){
  301. genre = -1
  302. }else{
  303. genre = this.table1.parammaps.genre
  304. }
  305. let startdate = ''
  306. let enddate = ''
  307. if(this.table1.parammaps.inputDatetime !== '' && this.table1.parammaps.inputDatetime !== null){
  308. startdate = parseTime(this.table1.parammaps.inputDatetime[0],'{y}-{m}-{d}')
  309. enddate = parseTime(this.table1.parammaps.inputDatetime[1],'{y}-{m}-{d}')
  310. }else{
  311. startdate = ''
  312. enddate = ''
  313. }
  314. let startcount = ''
  315. let endcount = ''
  316. if(this.table1.parammaps.startcount == undefined){
  317. startcount = ''
  318. }else{
  319. startcount = this.table1.parammaps.startcount
  320. }
  321. if(this.table1.parammaps.endcount == undefined){
  322. endcount = ''
  323. }else{
  324. endcount = this.table1.parammaps.endcount
  325. }
  326. let data = 'index=' + this.table1.offset
  327. + '&pagesize=' + this.table1.pagecount
  328. + '&batch=' + this.table1.parammaps.batch
  329. + '&pastureid=' + this.table1.parammaps.pastureid
  330. + '&startcount=' + startcount
  331. + '&endcount=' + endcount
  332. + '&createname=' + this.table1.parammaps.createname
  333. + '&startdate=' + startdate
  334. + '&enddate=' + enddate
  335. let url = 'recall/list?'
  336. getJson(url,data).then(response => {
  337. if (response.code == 200) {
  338. this.table1.list = response.data.list
  339. this.table1.pageNum = this.table1.offset
  340. this.table1.pageSize = this.table1.pagecount
  341. } else {
  342. this.table1.list = []
  343. }
  344. this.table1.total = response.data.total
  345. setTimeout(() => {
  346. this.table1.listLoading = false
  347. }, 100)
  348. })
  349. },
  350. handleSearch1(){
  351. this.table1.offset = 1
  352. this.getList1()
  353. },
  354. handleRefresh1(){
  355. this.table1.offset = 1
  356. this.table1.parammaps = {
  357. batch:'',
  358. pastureid:'',
  359. startcount:undefined,
  360. endcount:undefined,
  361. createname:'',
  362. inputDatetime:'',
  363. startdate:'',
  364. enddate:''
  365. },
  366. this.getList1()
  367. },
  368. clickQuantity(row){
  369. console.log('出厂数量')
  370. this.quantity.dialogFormVisible = true
  371. if(row.genre == 0){
  372. this.textMap.quantityTxt = '脖环列表'+'——类型:'+ '购买'
  373. }else{
  374. this.textMap.quantityTxt = '脖环列表'+'——类型:'+ '置换'
  375. }
  376. this.quantity.dialogStatus = 'quantityTxt'
  377. this.quantity.temp = Object.assign({}, row)
  378. this.quantity.table1.offset = 1
  379. this.getQuantityList()
  380. },
  381. getQuantityList() {
  382. this.quantity.table1.listLoading = true
  383. let data = 'index=' + this.quantity.table1.offset
  384. + '&pagesize=' + this.quantity.table1.pagecount
  385. + '&recallid=' + this.quantity.temp.id
  386. let url = 'ring/listing?'
  387. getJson(url,data).then(response => {
  388. if (response.code == 200) {
  389. this.quantity.table1.list = response.data.list
  390. this.quantity.table1.pageNum = this.quantity.table1.offset
  391. this.quantity.table1.pageSize = this.quantity.table1.pagecount
  392. } else {
  393. this.quantity.table1.list = []
  394. }
  395. this.quantity.table1.total = response.data.total
  396. setTimeout(() => {
  397. this.quantity.table1.listLoading = false
  398. }, 100)
  399. })
  400. },
  401. clickRecall(row){
  402. console.log('关联召回批次数')
  403. this.recall.dialogFormVisible = true
  404. this.recall.dialogStatus = 'recallTxt'
  405. this.recall.temp = Object.assign({}, row)
  406. this.recall.table1.offset = 1
  407. this.getRecallList()
  408. },
  409. getRecallList() {
  410. this.recall.table1.listLoading = true
  411. let data = 'index=' + this.recall.table1.offset
  412. + '&pagesize=' + this.recall.table1.pagecount
  413. + '&recallid=' + this.recall.temp.id
  414. let url = 'factory/list?'
  415. getJson(url,data).then(response => {
  416. if (response.code == 200) {
  417. this.recall.table1.list = response.data.list
  418. this.recall.table1.pageNum = this.recall.table1.offset
  419. this.recall.table1.pageSize = this.recall.table1.pagecount
  420. } else {
  421. this.recall.table1.list = []
  422. }
  423. this.recall.table1.total = response.data.total
  424. setTimeout(() => {
  425. this.recall.table1.listLoading = false
  426. }, 100)
  427. })
  428. },
  429. clickCreate(){
  430. this.edit.dialogFormVisible = true
  431. this.edit.dialogStatus = 'createTxt'
  432. this.edit.temp = {
  433. pastureid:'',
  434. }
  435. this.edit.batch.selectList = []
  436. this.edit.batch.list = []
  437. },
  438. createData(){
  439. this.isokDisable = true
  440. setTimeout(() => {
  441. this.isokDisable = false
  442. }, 3000)
  443. this.$refs['editTemp'].validate(valid => {
  444. if (valid) {
  445. console.log(this.edit.temp,'this.edit.temp')
  446. let data = {
  447. count:this.edit.temp.count,
  448. genre:this.edit.temp.genre,
  449. pastureid:this.edit.temp.pastureid,
  450. recall:this.edit.batch.sumCount,
  451. recallid:this.edit.batch.selectList
  452. }
  453. if(this.edit.temp.genre == 1){
  454. if(this.edit.batch.selectList.length == 0 ){
  455. this.$message({ type: 'warning', message: '请选择召回批次' })
  456. return
  457. }
  458. }
  459. let url = 'factory/add'
  460. postJson(url,data).then(response => {
  461. if (response.code == 200) {
  462. this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
  463. this.$refs.editTemp.resetFields();
  464. this.edit.dialogFormVisible = false
  465. this.getList1()
  466. }else{
  467. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  468. }
  469. })
  470. }
  471. })
  472. },
  473. close(){
  474. this.$refs['editTemp'].resetFields()
  475. this.edit.dialogFormVisible = false
  476. this.getList1()
  477. },
  478. changePasture(){
  479. this.getBatchList()
  480. },
  481. getBatchList() {
  482. this.table1.listLoading = true
  483. let startdate = ''
  484. let enddate = ''
  485. if(this.edit.batch.parammaps.inputDatetime !== '' && this.edit.batch.parammaps.inputDatetime !== null){
  486. startdate = parseTime(this.edit.batch.parammaps.inputDatetime[0],'{y}-{m}-{d}')
  487. enddate = parseTime(this.edit.batch.parammaps.inputDatetime[1],'{y}-{m}-{d}')
  488. }else{
  489. startdate = ''
  490. enddate = ''
  491. }
  492. let startcount = ''
  493. let endcount = ''
  494. if(this.edit.batch.parammaps.startcount == undefined){
  495. startcount = ''
  496. }else{
  497. startcount = this.edit.batch.parammaps.startcount
  498. }
  499. if(this.edit.batch.parammaps.endcount == undefined){
  500. endcount = ''
  501. }else{
  502. endcount = this.edit.batch.parammaps.endcount
  503. }
  504. let data = 'index=' + this.edit.batch.offset
  505. + '&pagesize=' + this.edit.batch.pagecount
  506. + '&genre=' + 0
  507. + '&pastureid=' + this.edit.temp.pastureid
  508. + '&batch=' + this.edit.batch.parammaps.batch
  509. + '&startcount=' + startcount
  510. + '&endcount=' + endcount
  511. + '&createname=' + this.edit.batch.parammaps.createname
  512. + '&startdate=' + startdate
  513. + '&enddate=' + enddate
  514. let url = 'factory/list?'
  515. getJson(url,data).then(response => {
  516. if (response.code == 200) {
  517. this.edit.batch.list = response.data.list
  518. } else {
  519. this.edit.batch.list = []
  520. }
  521. this.edit.batch.total = response.data.total
  522. setTimeout(() => {
  523. this.edit.batch.listLoading = false
  524. }, 100)
  525. })
  526. },
  527. handleSelectionChange(val){
  528. this.edit.batch.selectList = []
  529. this.uploadData2 = {}
  530. this.uploadData2.pastureid = this.edit.temp.pastureid
  531. let factoryidList = []
  532. // this.edit.batch.sumCount = 0
  533. val.forEach((ele)=> {
  534. factoryidList.push(ele.id)
  535. this.edit.batch.selectList.push(ele.id)
  536. });
  537. this.uploadData2.factoryid = '['+factoryidList+']'
  538. },
  539. handleBatchSearch(){
  540. this.edit.batch.offset = 1
  541. this.getBatchList()
  542. },
  543. handleBatchRefresh(){
  544. this.edit.batch.offset = 1
  545. this.edit.batch.parammaps = {
  546. batch:'',
  547. batch:'',
  548. startcount:undefined,
  549. endcount:undefined,
  550. createname:'',
  551. inputDatetime:''
  552. }
  553. this.getBatchList()
  554. },
  555. beforeImport2(file) {
  556. const isLt2M = file.size / 1024 / 1024 < 2
  557. if (!isLt2M) {
  558. this.$message.error('上传文件大小不能超过 2MB!')
  559. }
  560. return isLt2M
  561. },
  562. handleImportSuccess2(res, file) {
  563. if (res.msg === 'ok') {
  564. console.log(res,'res===')
  565. this.$message({ title: '成功', message: '导入成功', type: 'success', duration: 2000 })
  566. this.edit.dialogFormVisible = false
  567. this.getList1()
  568. } else if(res.msg === 'recall'){
  569. import('@/vendor/Export2Excel').then(excel => {
  570. console.log(res.data,'res.data')
  571. const list1 = res.data
  572. const tHeader = [
  573. '脖环号', '错误信息'
  574. ]
  575. const filterVal = [
  576. 'a1', 'a2'
  577. ]
  578. const data1 = this.formatJson2(filterVal, list1)
  579. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '脖环召回记录导入报错信息', autoWidth: true, bookType: 'xlsx' })
  580. })
  581. this.edit.dialogFormVisible = false
  582. this.getList1()
  583. } else {
  584. this.$notify({ title: '失败', message: res.data, type: 'danger', duration: 2000 })
  585. }
  586. },
  587. formatJson2(filterVal, jsonData) {
  588. return jsonData.map(v =>
  589. filterVal.map(j => {
  590. if (j === 'timestamp') {
  591. return parseTime(v[j])
  592. } else {
  593. return v[j]
  594. }
  595. })
  596. )
  597. },
  598. handleExport1(){
  599. let genre = ''
  600. if(this.table1.parammaps.genre == '' || this.table1.parammaps.genre == null){
  601. genre = -1
  602. }else{
  603. genre = this.table1.parammaps.genre
  604. }
  605. let startdate = ''
  606. let enddate = ''
  607. if(this.table1.parammaps.inputDatetime !== '' && this.table1.parammaps.inputDatetime !== null){
  608. startdate = parseTime(this.table1.parammaps.inputDatetime[0],'{y}-{m}-{d}')
  609. enddate = parseTime(this.table1.parammaps.inputDatetime[1],'{y}-{m}-{d}')
  610. }else{
  611. startdate = ''
  612. enddate = ''
  613. }
  614. let startcount = ''
  615. let endcount = ''
  616. if(this.table1.parammaps.startcount == undefined){
  617. startcount = ''
  618. }else{
  619. startcount = this.table1.parammaps.startcount
  620. }
  621. if(this.table1.parammaps.endcount == undefined){
  622. endcount = ''
  623. }else{
  624. endcount = this.table1.parammaps.endcount
  625. }
  626. let data = 'index=' + 1
  627. + '&pagesize=' + ''
  628. + '&batch=' + this.table1.parammaps.batch
  629. + '&pastureid=' + this.table1.parammaps.pastureid
  630. + '&startcount=' + startcount
  631. + '&endcount=' + endcount
  632. + '&createname=' + this.table1.parammaps.createname
  633. + '&startdate=' + startdate
  634. + '&enddate=' + enddate
  635. let url = 'recall/list?'
  636. var downList = []
  637. getJson(url,data).then(response => {
  638. if (response.code == 200) {
  639. downList = response.data.list
  640. } else {
  641. downList = []
  642. }
  643. var excelDatas = [{
  644. tHeader: ['召回批次号','牧场','召回数量','关联出厂批次数','登记人','登记日期'],
  645. filterVal: ['batch','pasturename','count','recall','createname','createtime'],
  646. tableDatas: downList,
  647. sheetName: 'sheet'
  648. }]
  649. json2excel(excelDatas, '脖环召回记录', true, 'xlsx')
  650. })
  651. },
  652. handleExportTemp1(){
  653. const requestParam = {}
  654. const url = process.env.VUE_APP_BASE_API + 'download?filename=脖环召回.xlsx' // 请求下载文件的地址
  655. console.log(url)
  656. axios({
  657. method: 'GET',
  658. url: url,
  659. data: requestParam,
  660. headers: { token: getToken(), optname: 'insertcustomdoc' },
  661. responseType: 'blob'
  662. }).then(res => {
  663. if (!res) return
  664. this.percentage = 99
  665. setTimeout(() => {
  666. this.isPercentage = false
  667. }, 2000)
  668. const blob = new Blob([res.data], {
  669. type: 'application/octet-stream;charset=utf-8'
  670. })
  671. const url = window.URL.createObjectURL(blob)
  672. const aLink = document.createElement('a')
  673. aLink.style.display = 'none'
  674. aLink.href = url
  675. const docname = '脖环召回记录导入模板下载.xlsx'
  676. aLink.setAttribute('download', docname) // 下载的文件
  677. document.body.appendChild(aLink)
  678. aLink.click()
  679. document.body.removeChild(aLink)
  680. window.URL.revokeObjectURL(url)
  681. })
  682. }
  683. }
  684. }
  685. </script>
  686. <style>
  687. </style>