9f417f711cf091f3c2c44569656816197661935b.svn-base 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  5. <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
  6. <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
  7. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  8. </div>
  9. <div class="operation">
  10. <el-button class="success" icon="el-icon-plus" @click="handleCreate">新增盘点单</el-button>
  11. <el-button class="success" icon="el-icon-upload2" @click="handleInventoryList">下载盘点单</el-button>
  12. <el-upload style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
  13. <el-button class="import" icon="el-icon-download" style="float: right;">导入</el-button>
  14. </el-upload>
  15. <el-button class="import" icon="el-icon-upload2" style="float: right;margin-right: 10px;" @click="handleExport(1)">导出</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. >
  31. <el-table-column label="序号" align="center" type="index" width="50px">
  32. <template slot-scope="scope">
  33. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="盘点日期" min-width="130px" align="center">
  37. <template slot-scope="scope">
  38. <span>{{ scope.row.inventorydate }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="盘点人" min-width="130px" align="center">
  42. <template slot-scope="scope">
  43. <span>{{ scope.row.createuser }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="盘盈库存(kg)" min-width="110px" align="center">
  47. <template slot-scope="scope">
  48. <span>{{ scope.row.moreWeight }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="盘亏库存(kg)" min-width="110px" align="center">
  52. <template slot-scope="scope">
  53. <span>{{ scope.row.lessWeight }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="盈亏净值(kg)" min-width="110px" align="center">
  57. <template slot-scope="scope">
  58. <span>{{ scope.row.differWeight }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="备注" min-width="110px" align="center">
  62. <template slot-scope="scope">
  63. <span>{{ scope.row.remark }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  67. <template slot-scope="scope">
  68. <el-button class="miniSuccess" :disabled="isokDisable" icon="el-icon-search" @click="handleSee(scope.row)" />
  69. <span v-if="scope.$index + (table.pageNum-1) * table.pageSize + 1 == 1" class="centerSpan">|</span>
  70. <el-button v-if="scope.$index + (table.pageNum-1) * table.pageSize + 1 == 1" icon="el-icon-delete" class="miniDanger" @click="handleRowDelete(scope.row)" />
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  75. </div>
  76. <!-- 新增盘点单 -->
  77. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  78. <div class="app-add">
  79. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 90%;margin:0 auto">
  80. <el-row>
  81. <el-col :span="8">
  82. <el-form-item label="盘点日期:" prop="inventorydate">
  83. <!-- :picker-options="create.pickerOptions2" -->
  84. <el-date-picker v-model="create.createTemp.inventorydate" class="filter-item" type="date" placeholder="盘点日期" :disabled="create.dialogStatus==='see'" :picker-options="create.pickerOptions1" :clearable="false" />
  85. </el-form-item>
  86. </el-col>
  87. <el-col :span="8">
  88. <el-form-item label="盘点人:" prop="createuser">
  89. <el-input ref="createuser" v-model="create.createTemp.createuser" class="filter-item" placeholder="盘点人" type="text" disabled />
  90. </el-form-item>
  91. </el-col>
  92. <el-col :span="8">
  93. <el-form-item label="备注:" prop="remark">
  94. <el-input ref="remark" v-model="create.createTemp.remark" class="filter-item" placeholder="备注" type="text" :disabled="create.dialogStatus==='see'" />
  95. </el-form-item>
  96. </el-col>
  97. </el-row>
  98. </el-form>
  99. <el-table
  100. :key="create.tableKey"
  101. v-loading="create.listLoading"
  102. element-loading-text="给我一点时间"
  103. :data="create.list"
  104. border
  105. fit
  106. highlight-current-row
  107. style="width: 100%;margin-bottom: 50px;"
  108. :row-style="rowStyle"
  109. :cell-style="cellStyle"
  110. class="elTable table-fixed"
  111. >
  112. <el-table-column label="饲料名称" min-width="130px" align="center">
  113. <template slot-scope="scope">
  114. <span>{{ scope.row.feedname }}</span>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="库存重量(kg)" min-width="130px" align="center">
  118. <template slot-scope="scope">
  119. <span>{{ scope.row.stockweight }}</span>
  120. </template>
  121. </el-table-column>
  122. <el-table-column label="实际重量(kg)" min-width="110px" align="center">
  123. <template slot-scope="scope">
  124. <el-input v-if="create.dialogStatus==='create'" ref="input" v-model="scope.row.factweight" style="width:80%;padding:10px 0;" @blur="blurFactweight(scope.row)" />
  125. <span v-else> {{ scope.row.factweight }}</span>
  126. </template>
  127. </el-table-column>
  128. <el-table-column label="差值(kg)" min-width="110px" align="center">
  129. <template slot-scope="scope">
  130. <span>{{ scope.row.differ }}</span>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <div slot="footer" class="dialog-footer">
  135. <el-button v-if="create.dialogStatus==='see'" class="import" icon="el-icon-upload2" :disabled="isokDisable" @click="handleExport(2)">导出</el-button>
  136. <el-button class="cancelClose" @click="create.dialogFormVisible = false; ">关闭</el-button>
  137. <el-button v-if="create.dialogStatus==='create'" class="save" :disabled="isokDisable" @click="createData()">确认</el-button>
  138. </div>
  139. </div>
  140. </el-dialog>
  141. </div>
  142. </template>
  143. <script>
  144. import { GetDataByName, ExecDataByConfig, failproccess, PostDataByName } from '@/api/common'
  145. import Pagination from '@/components/Pagination'
  146. import { parseTime, json2excel } from '@/utils/index.js'
  147. import { MessageBox } from 'element-ui'
  148. import Cookies from 'js-cookie'
  149. import axios from 'axios'
  150. import { getToken } from '@/utils/auth'
  151. export default {
  152. name: 'InventoryList',
  153. components: { Pagination },
  154. data() {
  155. return {
  156. table: {
  157. getdataListParm: {
  158. name: 'getBigInventoryList',
  159. page: 1,
  160. offset: 1,
  161. pagecount: 10,
  162. returntype: 'Map',
  163. parammaps: {
  164. pastureid: Cookies.get('pastureid'),
  165. startTime: '',
  166. stopTime: '',
  167. inputDatetime: ''
  168. }
  169. },
  170. tableKey: 0,
  171. list: [],
  172. total: 0,
  173. listLoading: true
  174. },
  175. textMap: {
  176. create: '新增',
  177. see: '查看盘点单'
  178. },
  179. create: {
  180. pickerOptions1: {
  181. disabledDate: this.disabledDate
  182. },
  183. dialogFormVisible: false,
  184. dialogStatus: '',
  185. createTemp: {
  186. pastureid: Cookies.get('pastureid'),
  187. remark: '',
  188. inventorydate: parseTime(new Date(), '{y}-{m}-{d}'),
  189. createuser: Cookies.get('employename')
  190. },
  191. rules: {},
  192. getdataListParm: {
  193. name: 'getFeedstorageWeightList',
  194. page: 1,
  195. offset: 1,
  196. pagecount: '',
  197. returntype: 'Map',
  198. parammaps: {
  199. pastureid: Cookies.get('pastureid'),
  200. emp: Cookies.get('employename')
  201. }
  202. },
  203. tableKey: 0,
  204. list: [],
  205. total: 0,
  206. listLoading: true,
  207. getMaxdataParm: {
  208. name: 'getInventoryMaxdate',
  209. page: 1,
  210. offset: 1,
  211. pagecount: '',
  212. returntype: 'Map',
  213. parammaps: {
  214. pastureid: Cookies.get('pastureid')
  215. }
  216. },
  217. maxDate: ''
  218. },
  219. see: {
  220. getdataListParm: {
  221. name: 'getInventoryList',
  222. page: 1,
  223. offset: 1,
  224. pagecount: 10,
  225. returntype: 'Map',
  226. parammaps: {}
  227. }
  228. },
  229. requestParam: {},
  230. download: {
  231. getdataListParm: {
  232. name: 'getBigInventoryList',
  233. page: 1,
  234. offset: 1,
  235. pagecount: 0,
  236. returntype: 'Map',
  237. parammaps: {
  238. pastureid: Cookies.get('pastureid'),
  239. startTime: '',
  240. stopTime: '',
  241. inputDatetime: ''
  242. }
  243. },
  244. list: []
  245. },
  246. isokDisable: false,
  247. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  248. cellStyle: { padding: 0 + 'px' }
  249. }
  250. },
  251. computed: {
  252. // 设置请求头
  253. headers() {
  254. return {
  255. token: getToken()
  256. }
  257. },
  258. uploadData() {
  259. return {
  260. name: 'checkFeed,insertBigInventoryUpload,insertInventoryUpload',
  261. importParams: '盘点日期,盘点人,备注,饲料名称,库存重量(kg),实际重量(kg)',
  262. sheetname: 'Sheet1',
  263. // 登录牧场
  264. pastureid: Cookies.get('pastureid'),
  265. // 日期参数
  266. dateParams: '盘点日期',
  267. // 必填参数
  268. requiredParams: '盘点日期,饲料名称,库存重量(kg),实际重量(kg)',
  269. // 为数值的参数
  270. numParams: '实际重量(kg)'
  271. }
  272. },
  273. // 设置上传地址
  274. uploadExcelUrl() {
  275. return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
  276. }
  277. },
  278. created() {
  279. this.getList()
  280. },
  281. methods: {
  282. handleBefore() {
  283. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  284. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  285. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  286. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  287. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  288. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  289. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  290. this.$forceUpdate()
  291. }
  292. },
  293. handleNext() {
  294. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  295. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  296. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  297. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  298. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  299. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  300. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  301. this.$forceUpdate()
  302. }
  303. },
  304. handleSearch() {
  305. console.log('点击了查询')
  306. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  307. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  308. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  309. } else {
  310. this.table.getdataListParm.parammaps.inputDatetime = ''
  311. this.table.getdataListParm.parammaps.startTime = ''
  312. this.table.getdataListParm.parammaps.stopTime = ''
  313. }
  314. this.table.getdataListParm.offset = 1
  315. this.getList()
  316. },
  317. getList() {
  318. this.table.listLoading = true
  319. GetDataByName(this.table.getdataListParm).then(response => {
  320. console.log('table数据', response.data.list)
  321. if (response.data.list !== null) {
  322. this.table.list = response.data.list
  323. this.table.pageNum = response.data.pageNum
  324. this.table.pageSize = response.data.pageSize
  325. this.table.total = response.data.total
  326. } else {
  327. this.table.list = []
  328. }
  329. setTimeout(() => {
  330. this.table.listLoading = false
  331. }, 100)
  332. })
  333. },
  334. resetCreateTemp() {
  335. this.create.createTemp = { pastureid: Cookies.get('pastureid'), remark: '', inventorydate: parseTime(new Date(), '{y}-{m}-{d}'), createuser: Cookies.get('employename') }
  336. },
  337. handleCreate() {
  338. console.log('点击了新增盘点单')
  339. this.resetCreateTemp()
  340. this.create.dialogStatus = 'create'
  341. this.create.dialogFormVisible = true
  342. this.getMaxDate()
  343. this.getCreateList()
  344. },
  345. disabledDate(time) {
  346. return time.getTime() < new Date(this.create.maxDate) || time.getTime() > Date.now()
  347. },
  348. getMaxDate() {
  349. GetDataByName(this.create.getMaxdataParm).then(response => {
  350. this.create.maxDate = response.data.list[0].maxdate
  351. console.log(response.data.list[0])
  352. })
  353. },
  354. getCreateList() {
  355. this.create.listLoading = true
  356. GetDataByName(this.create.getdataListParm).then(response => {
  357. console.log('table数据', response.data.list)
  358. if (response.data.list !== null) {
  359. for (let i = 0; i < response.data.list.length; i++) {
  360. this.$set(response.data.list[i], 'factweight', '')
  361. this.$set(response.data.list[i], 'differ', '')
  362. }
  363. this.create.list = response.data.list
  364. this.create.pageNum = response.data.pageNum
  365. this.create.pageSize = response.data.pageSize
  366. this.create.total = response.data.total
  367. } else {
  368. this.create.list = []
  369. }
  370. setTimeout(() => {
  371. this.create.listLoading = false
  372. }, 100)
  373. })
  374. },
  375. // 实际重量
  376. blurFactweight(row) {
  377. if (row.factweight !== '' && row.stockweight !== '') {
  378. row.differ = parseFloat(row.factweight) - parseFloat(row.stockweight)
  379. }
  380. },
  381. createData() {
  382. this.$refs['createTemp'].validate(valid => {
  383. if (valid) {
  384. this.isokDisable = true
  385. setTimeout(() => {
  386. this.isokDisable = false
  387. }, 1000)
  388. var createList = []
  389. for (let i = 0; i < this.create.list.length; i++) {
  390. if (this.create.list[i].factweight !== '') {
  391. createList.push(this.create.list[i])
  392. }
  393. }
  394. for (let i = 0; i < createList.length; i++) {
  395. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  396. // 实际重量
  397. if (!keepTwoNum.test(parseFloat(createList[i].factweight))) {
  398. this.$message({ type: 'error', message: '实际重量请输入自然数并保留两位小数', duration: 2000 })
  399. return false
  400. }
  401. }
  402. this.requestParam.common = { 'returnmap': '0' }
  403. this.requestParam.data = []
  404. this.requestParam.data[0] = { 'name': 'insertBigInventory', 'type': 'e', 'parammaps': {
  405. 'pastureid': this.create.createTemp.pastureid,
  406. 'inventorydate': parseTime(this.create.createTemp.inventorydate, '{y}-{m}-{d}'),
  407. 'createuser': this.create.createTemp.createuser,
  408. 'remark': this.create.createTemp.remark
  409. }}
  410. this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': createList }}
  411. this.requestParam.data[1].children = []
  412. this.requestParam.data[1].children[0] = { 'name': 'insertInventory', 'type': 'e', 'parammaps': {
  413. invid: '@insertBigInventory.LastInsertId',
  414. pastureid: '@insertSpotList.pastureid',
  415. feedname: '@insertSpotList.feedname',
  416. feedid: '@insertSpotList.feedid',
  417. stockweight: '@insertSpotList.stockweight',
  418. factweight: '@insertSpotList.factweight'
  419. }}
  420. ExecDataByConfig(this.requestParam).then(response => {
  421. if (response.msg === 'fail') {
  422. const inventorydate = new RegExp("key 'inventorydate'")
  423. if (inventorydate.test(response.data)) {
  424. this.$message({ type: 'error', message: '当前日期已盘点,不可重复录入', duration: 2000 })
  425. } else {
  426. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  427. }
  428. } else {
  429. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  430. this.create.dialogFormVisible = false
  431. this.getList()
  432. }
  433. })
  434. }
  435. })
  436. },
  437. handleSee(row) {
  438. console.log('点击了查看')
  439. this.create.dialogStatus = 'see'
  440. this.create.dialogFormVisible = true
  441. this.create.createTemp = Object.assign({}, row)
  442. this.see.getdataListParm.parammaps.pastureid = row.pastureid
  443. this.see.getdataListParm.parammaps.id = row.id
  444. this.getSeeList()
  445. },
  446. getSeeList() {
  447. this.create.listLoading = true
  448. GetDataByName(this.see.getdataListParm).then(response => {
  449. console.log('table数据', response.data.list)
  450. if (response.data.list !== null) {
  451. this.create.list = response.data.list
  452. this.create.pageNum = response.data.pageNum
  453. this.create.pageSize = response.data.pageSize
  454. this.create.total = response.data.total
  455. } else {
  456. this.create.list = []
  457. }
  458. setTimeout(() => {
  459. this.create.listLoading = false
  460. }, 100)
  461. })
  462. },
  463. handleRowDelete(row) {
  464. MessageBox.confirm('是否确认删除此信息?', {
  465. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  466. }).then(() => {
  467. this.requestParam.name = 'deleteBigInventory'
  468. this.requestParam.parammaps = {}
  469. this.requestParam.parammaps.pastureid = row.pastureid
  470. this.requestParam.parammaps.id = row.id
  471. PostDataByName(this.requestParam).then(response => {
  472. if (response.msg === 'fail') {
  473. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  474. } else {
  475. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  476. this.getList()
  477. }
  478. })
  479. }).catch(() => {
  480. this.$message({ type: 'info', message: '已取消删除' })
  481. })
  482. },
  483. handleInventoryList() {
  484. this.download.getdataListParm.name = 'getFeedstorageWeightList'
  485. this.download.getdataListParm.parammaps = {}
  486. this.download.getdataListParm.parammaps.pastureid = Cookies.get('pastureid')
  487. this.download.getdataListParm.parammaps.emp = Cookies.get('employename')
  488. GetDataByName(this.download.getdataListParm).then(response => {
  489. if (response.data.list !== null) {
  490. this.download.list = response.data.list
  491. } else {
  492. this.download.list = []
  493. }
  494. var downloadList = [
  495. { 'obj1': '1、文件类型为xlsx类型,对应表格文件名格式为:文件名称.xlsx;' },
  496. { 'obj1': '2、底部工作表名称不可更改,默认为:Sheet1;' },
  497. { 'obj1': '3、盘点日期,饲料名称为必填;' },
  498. { 'obj1': '4、饲料名称必须与系统基础数据-饲料表中匹配;' },
  499. { 'obj1': '5、实际重量为非负数,至多保留俩位小数;' },
  500. { 'obj1': '6、盘点日期为文本格式的年-月-日,例:2020-10-10,盘点日期不可与系统已存在日期重复;盘点日期需保持一致' },
  501. { 'obj1': '7、库存重量仅做参考,不与系统现有库存做校验;' },
  502. { 'obj1': '8、实际重量可仅填写部分,导入已填写实际重量的饲料生成盘点单。' },
  503. { 'obj1': '9、若有备注则填写在表格内容中第一个饲料行内即可;' }
  504. ]
  505. var excelDatas = [
  506. {
  507. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)'],
  508. filterVal: ['nowdate', 'emp', '', 'feedname', 'stockweight', ''],
  509. tableDatas: this.download.list,
  510. sheetName: 'Sheet1'
  511. }, {
  512. tHeader: ['填写规范:'],
  513. filterVal: ['obj1'],
  514. tableDatas: downloadList,
  515. sheetName: 'Sheet2'
  516. }
  517. ]
  518. json2excel(excelDatas, '盘点单导入模板', true, 'xlsx')
  519. })
  520. },
  521. handleExport(item) {
  522. if (item == 1) {
  523. this.download.getdataListParm.parammaps.inputDatetime = this.table.getdataListParm.parammaps.inputDatetime
  524. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  525. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  526. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  527. } else {
  528. this.download.getdataListParm.parammaps.inputDatetime = ''
  529. this.download.getdataListParm.parammaps.startTime = ''
  530. this.download.getdataListParm.parammaps.stopTime = ''
  531. }
  532. this.download.getdataListParm.name = 'getBigInventoryList'
  533. GetDataByName(this.download.getdataListParm).then(response => {
  534. if (response.data.list !== null) {
  535. this.download.list = response.data.list
  536. } else {
  537. this.download.list = []
  538. }
  539. var excelDatas = [
  540. {
  541. tHeader: ['盘点日期', '盘点人', '盘盈库存(kg)', '盘亏库存(kg)', '盈亏净值(kg)', '备注'],
  542. filterVal: ['inventorydate', 'createuser', 'moreWeight', 'lessWeight', 'differWeight', 'remark'],
  543. tableDatas: this.download.list,
  544. sheetName: 'Sheet1'
  545. }
  546. ]
  547. json2excel(excelDatas, '盘点单', true, 'xlsx')
  548. })
  549. } else {
  550. this.download.getdataListParm.name = 'getInventoryList'
  551. this.download.getdataListParm.parammaps = this.see.getdataListParm.parammaps
  552. GetDataByName(this.download.getdataListParm).then(response => {
  553. for (let i = 0; i < response.data.list.length; i++) {
  554. this.$set(response.data.list[i], 'inventorydate', this.create.createTemp.inventorydate)
  555. this.$set(response.data.list[i], 'createuser', this.create.createTemp.createuser)
  556. this.$set(response.data.list[i], 'remark', this.create.createTemp.remark)
  557. }
  558. if (response.data.list !== null) {
  559. this.download.list = response.data.list
  560. } else {
  561. this.download.list = []
  562. }
  563. var excelDatas = [
  564. {
  565. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '差值(kg)'],
  566. filterVal: ['inventorydate', 'createuser', 'remark', 'feedname', 'stockweight', 'factweight', 'differ'],
  567. tableDatas: this.download.list,
  568. sheetName: 'Sheet1'
  569. }
  570. ]
  571. json2excel(excelDatas, '盘点-查看', true, 'xlsx')
  572. })
  573. }
  574. },
  575. beforeImport(file) {
  576. const isLt2M = file.size / 1024 / 1024 < 2
  577. if (!isLt2M) {
  578. this.$message.error('上传文件大小不能超过 2MB!')
  579. }
  580. return isLt2M
  581. },
  582. handleImportSuccess(res, file) {
  583. this.getList()
  584. if (res.msg === 'ok') {
  585. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  586. if (res.data.err_count > 0) {
  587. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  588. import('@/vendor/Export2Excel').then(excel => {
  589. const list1 = res.data.result
  590. const tHeader = [
  591. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '错误信息'
  592. ]
  593. const filterVal = [
  594. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', 'error_msg'
  595. ]
  596. const data1 = this.formatJson(filterVal, list1)
  597. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '盘点单报错信息', autoWidth: true, bookType: 'xlsx' })
  598. })
  599. }
  600. } else {
  601. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  602. }
  603. },
  604. formatJson(filterVal, jsonData) {
  605. return jsonData.map(v =>
  606. filterVal.map(j => {
  607. if (j === 'timestamp') {
  608. return parseTime(v[j])
  609. } else {
  610. return v[j]
  611. }
  612. })
  613. )
  614. }
  615. }
  616. }
  617. </script>
  618. <style lang="scss" scoped>
  619. .search{margin-top:10px;}
  620. .table{margin-top:10px;}
  621. </style>
  622. <style>
  623. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  624. </style>