5e4e716320c21decfbe2877ed6d1543bb9c00ae1.svn-base 27 KB

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