index.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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="$t('common.to')" :start-placeholder="$t('common.startTime')" :end-placeholder="$t('common.endTime')" 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="form_search">{{$t('common.query')}}</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;">{{$t('formulationEvaluation.enter')}}</el-button>
  14. </el-upload>
  15. <el-button class="import" icon="el-icon-upload2" style="float: right;margin-right: 10px;" @click="handleExport(1)">{{$t('formulationEvaluation.out')}}</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. :element-loading-text="$t('common.tableMsg')"
  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="$t('formulationEvaluation.xh')" 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="$t('formulationEvaluation.remark')" 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="$t('errorAnalysis.cz')" 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="form_see(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="$t('common.tableMsg')"
  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="$t('InventoryManagement.silc')" 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)">{{$t('formulationEvaluation.out')}}</el-button>
  149. <el-button v-if="create.dialogStatus==='see'" class="cancelClose cancelClose1" @click="create.dialogFormVisible = false; ">{{$t('common.closed')}}</el-button>
  150. <el-button v-if="create.dialogStatus==='create'" class="cancelClose" @click="create.dialogFormVisible = false; ">{{$t('common.closed')}}</el-button>
  151. <el-button v-if="create.dialogStatus==='create'" class="save" :disabled="isokDisable" @click="createData()">{{$t('errorAnalysis.confirm')}}</el-button>
  152. </div>
  153. </div>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script>
  158. import { GetDataByName, ExecDataByConfig, failproccess, checkButtons, PostDataByName,postJson } 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 Cookies.get('url') + '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. form_search() {
  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. } else {
  349. this.table.list = []
  350. }
  351. this.table.total = response.data.total
  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. let url = 'authdata/biginventory'
  445. postJson(url,this.requestParam).then(response => {
  446. if (response.msg === 'fail') {
  447. const inventorydate = new RegExp("key 'inventorydate'")
  448. if (inventorydate.test(response.data)) {
  449. this.$message({ type: 'error', message: '当前日期已盘点,不可重复录入', duration: 2000 })
  450. } else {
  451. this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
  452. }
  453. } else {
  454. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  455. this.create.dialogFormVisible = false
  456. this.getList()
  457. }
  458. })
  459. }
  460. })
  461. },
  462. form_see(row) {
  463. console.log('点击了查看')
  464. this.dialogFull = false
  465. this.create.dialogStatus = 'see'
  466. this.create.dialogFormVisible = true
  467. this.create.createTemp = Object.assign({}, row)
  468. this.see.getdataListParm.parammaps.pastureid = row.pastureid
  469. this.see.getdataListParm.parammaps.id = row.id
  470. this.getSeeList()
  471. },
  472. getSeeList() {
  473. this.create.listLoading = true
  474. GetDataByName(this.see.getdataListParm).then(response => {
  475. console.log('table数据', response.data.list)
  476. if (response.data.list !== null) {
  477. this.create.list = response.data.list
  478. this.create.pageNum = response.data.pageNum
  479. this.create.pageSize = response.data.pageSize
  480. this.create.total = response.data.total
  481. } else {
  482. this.create.list = []
  483. }
  484. setTimeout(() => {
  485. this.create.listLoading = false
  486. }, 100)
  487. })
  488. },
  489. handleRowDelete(row) {
  490. MessageBox.confirm( this.$t('common.delMsg'), {
  491. confirmButtonText: this.$t('common.confirm'), confirmButtonText: this.$t('common.cancel'), type: 'warning'
  492. }).then(() => {
  493. this.requestParam.name = 'deleteBigInventory'
  494. this.requestParam.parammaps = {}
  495. this.requestParam.parammaps.pastureid = row.pastureid
  496. this.requestParam.parammaps.id = row.id
  497. PostDataByName(this.requestParam).then(response => {
  498. if (response.msg === 'fail') {
  499. this.$notify({ title: this.$t('common.delfail'), message: response.data, type: 'warning', duration: 2000 })
  500. } else {
  501. this.$notify({ title: this.$t('common.succes'),message: this.$t('common.delSuccess'), type: 'success', duration: 2000 })
  502. this.getList()
  503. }
  504. })
  505. }).catch(() => {
  506. this.$message({ type: 'info', message: this.$t('common.cancelMsg') })
  507. })
  508. },
  509. handleInventoryList() {
  510. this.download.getdataListParm.name = 'getFeedstorageWeightList'
  511. this.download.getdataListParm.parammaps = {}
  512. this.download.getdataListParm.parammaps.pastureid = Cookies.get('pastureid')
  513. this.download.getdataListParm.parammaps.emp = Cookies.get('employename')
  514. GetDataByName(this.download.getdataListParm).then(response => {
  515. if (response.data.list !== null) {
  516. this.download.list = response.data.list
  517. } else {
  518. this.download.list = []
  519. }
  520. var downloadList = [
  521. { 'obj1': '1、文件类型为xlsx类型,对应表格文件名格式为:文件名称.xlsx;' },
  522. { 'obj1': '2、底部工作表名称不可更改,默认为:Sheet1;' },
  523. { 'obj1': '3、盘点日期,饲料名称为必填;' },
  524. { 'obj1': '4、饲料名称必须与系统基础数据-饲料表中匹配;' },
  525. { 'obj1': '5、实际重量为非负数,至多保留俩位小数;' },
  526. { 'obj1': '6、盘点日期为文本格式的年-月-日,例:2020-10-10,盘点日期不可与系统已存在日期重复;盘点日期需保持一致' },
  527. { 'obj1': '7、库存重量仅做参考,不与系统现有库存做校验;' },
  528. { 'obj1': '8、实际重量可仅填写部分,导入已填写实际重量的饲料生成盘点单。' },
  529. { 'obj1': '9、若有备注则填写在表格内容中第一个饲料行内即可;' }
  530. ]
  531. var excelDatas = [
  532. {
  533. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)'],
  534. filterVal: ['nowdate', 'emp', '', 'feedname', 'stockweight', ''],
  535. tableDatas: this.download.list,
  536. sheetName: 'Sheet1'
  537. }, {
  538. tHeader: ['填写规范:'],
  539. filterVal: ['obj1'],
  540. tableDatas: downloadList,
  541. sheetName: 'Sheet2'
  542. }
  543. ]
  544. json2excel(excelDatas, '盘点单导入模板', true, 'xlsx')
  545. })
  546. },
  547. handleExport(item) {
  548. if (item == 1) {
  549. this.download.getdataListParm.parammaps.inputDatetime = this.table.getdataListParm.parammaps.inputDatetime
  550. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  551. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  552. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  553. } else {
  554. this.download.getdataListParm.parammaps.inputDatetime = ''
  555. this.download.getdataListParm.parammaps.startTime = ''
  556. this.download.getdataListParm.parammaps.stopTime = ''
  557. }
  558. this.download.getdataListParm.name = 'getBigInventoryList'
  559. GetDataByName(this.download.getdataListParm).then(response => {
  560. if (response.data.list !== null) {
  561. this.download.list = response.data.list
  562. } else {
  563. this.download.list = []
  564. }
  565. var excelDatas = [
  566. {
  567. tHeader: ['盘点日期', '盘点人', '盘盈库存(kg)', '盘亏库存(kg)', '盈亏净值(kg)', '备注'],
  568. filterVal: ['inventorydate', 'createuser', 'moreWeight', 'lessWeight', 'differWeight', 'remark'],
  569. tableDatas: this.download.list,
  570. sheetName: 'Sheet1'
  571. }
  572. ]
  573. json2excel(excelDatas, '盘点单', true, 'xlsx')
  574. })
  575. } else {
  576. this.download.getdataListParm.name = 'getInventoryList'
  577. this.download.getdataListParm.parammaps = this.see.getdataListParm.parammaps
  578. GetDataByName(this.download.getdataListParm).then(response => {
  579. for (let i = 0; i < response.data.list.length; i++) {
  580. this.$set(response.data.list[i], 'inventorydate', this.create.createTemp.inventorydate)
  581. this.$set(response.data.list[i], 'createuser', this.create.createTemp.createuser)
  582. this.$set(response.data.list[i], 'remark', this.create.createTemp.remark)
  583. }
  584. if (response.data.list !== null) {
  585. this.download.list = response.data.list
  586. } else {
  587. this.download.list = []
  588. }
  589. var excelDatas = [
  590. {
  591. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '差值(kg)'],
  592. filterVal: ['inventorydate', 'createuser', 'remark', 'feedname', 'stockweight', 'factweight', 'differ'],
  593. tableDatas: this.download.list,
  594. sheetName: 'Sheet1'
  595. }
  596. ]
  597. json2excel(excelDatas, '盘点-查看', true, 'xlsx')
  598. })
  599. }
  600. },
  601. beforeImport(file) {
  602. const isLt2M = file.size / 1024 / 1024 < 2
  603. if (!isLt2M) {
  604. this.$message.error('上传文件大小不能超过 2MB!')
  605. }
  606. return isLt2M
  607. },
  608. handleImportSuccess(res, file) {
  609. this.getList()
  610. if (res.msg === 'ok') {
  611. this.$message({ title: this.$t('common.succes'), message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  612. if (res.data.err_count > 0) {
  613. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  614. import('@/vendor/Export2Excel').then(excel => {
  615. const list1 = res.data.result
  616. const tHeader = [
  617. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '错误信息'
  618. ]
  619. const filterVal = [
  620. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', 'error_msg'
  621. ]
  622. const data1 = this.formatJson(filterVal, list1)
  623. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '盘点单报错信息', autoWidth: true, bookType: 'xlsx' })
  624. })
  625. }
  626. } else {
  627. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  628. }
  629. },
  630. formatJson(filterVal, jsonData) {
  631. return jsonData.map(v =>
  632. filterVal.map(j => {
  633. if (j === 'timestamp') {
  634. return parseTime(v[j])
  635. } else {
  636. return v[j]
  637. }
  638. })
  639. )
  640. }
  641. }
  642. }
  643. </script>
  644. <style lang="scss" scoped>
  645. .search{margin-top:10px;}
  646. </style>
  647. <style>
  648. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  649. </style>