608bd8c4e070de87c63bd3555ea9a28f02d1535b.svn-base 28 KB

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