index.vue 28 KB

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