620160561597313fd80b3e5cbe9f104cccdd9f50.svn-base 27 KB

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