4c919020c102df01b3c09bcc13c3f75e4bd5aead.svn-base 28 KB

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