index改.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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="100" 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-edit-outline" class="miniSuccess" @click="handleUpdate(scope.row)" />
  71. <span v-if="scope.$index + (table.pageNum-1) * table.pageSize + 1 == 1 && isRoleEdit" class="centerSpan">|</span>
  72. <el-button v-if="scope.$index + (table.pageNum-1) * table.pageSize + 1 == 1 && isRoleEdit" icon="el-icon-delete" class="miniDanger" @click="handleRowDelete(scope.row)" />
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  77. </div>
  78. <!-- 新增盘点单 -->
  79. <el-dialog :fullscreen="dialogFull" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  80. <template slot="title">
  81. <div class="avue-crud__dialog__header">
  82. <span class="el-dialog__title">
  83. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  84. {{ textMap[create.dialogStatus] }}
  85. </span>
  86. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  87. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  88. <svg-icon v-else icon-class="fullscreen" />
  89. </div>
  90. </div>
  91. </template>
  92. <div class="app-add">
  93. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 90%;margin:0 auto">
  94. <el-row>
  95. <el-col :span="8">
  96. <el-form-item label="盘点日期:" prop="inventorydate">
  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' || create.dialogStatus=='update'" 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' || create.dialogStatus=='update'" class="cancelClose" @click="create.dialogFormVisible = false; ">关闭</el-button>
  151. <el-button v-if="create.dialogStatus =='create' || create.dialogStatus=='update'" class="save" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</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. update:'编辑'
  194. },
  195. create: {
  196. pickerOptions1: {
  197. disabledDate: this.disabledDate
  198. },
  199. dialogFormVisible: false,
  200. dialogStatus: '',
  201. createTemp: {
  202. pastureid: Cookies.get('pastureid'),
  203. remark: '',
  204. inventorydate: parseTime(new Date(), '{y}-{m}-{d}'),
  205. createuser: Cookies.get('employename')
  206. },
  207. rules: {},
  208. getdataListParm: {
  209. name: 'getFeedstorageWeightList',
  210. page: 1,
  211. offset: 1,
  212. pagecount: '',
  213. returntype: 'Map',
  214. parammaps: {
  215. pastureid: Cookies.get('pastureid'),
  216. emp: Cookies.get('employename')
  217. }
  218. },
  219. tableKey: 0,
  220. list: [],
  221. total: 0,
  222. listLoading: true,
  223. getMaxdataParm: {
  224. name: 'getInventoryMaxdate',
  225. page: 1,
  226. offset: 1,
  227. pagecount: '',
  228. returntype: 'Map',
  229. parammaps: {
  230. pastureid: Cookies.get('pastureid')
  231. }
  232. },
  233. maxDate: ''
  234. },
  235. see: {
  236. getdataListParm: {
  237. name: 'getInventoryList',
  238. page: 1,
  239. offset: 1,
  240. pagecount: '',
  241. returntype: 'Map',
  242. parammaps: {}
  243. }
  244. },
  245. requestParam: {},
  246. download: {
  247. getdataListParm: {
  248. name: 'getBigInventoryList',
  249. page: 1,
  250. offset: 1,
  251. pagecount: 0,
  252. returntype: 'Map',
  253. parammaps: {
  254. pastureid: Cookies.get('pastureid'),
  255. startTime: '',
  256. stopTime: '',
  257. inputDatetime: ''
  258. }
  259. },
  260. list: []
  261. },
  262. isokDisable: false,
  263. isRoleEdit: [],
  264. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  265. cellStyle: { padding: 0 + 'px' }
  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. } 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. 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. handleUpdate(row){
  509. console.log('点击了编辑')
  510. this.dialogFull = false
  511. this.create.dialogStatus = 'update'
  512. this.create.dialogFormVisible = true
  513. this.create.createTemp = Object.assign({}, row)
  514. this.see.getdataListParm.parammaps.pastureid = row.pastureid
  515. this.see.getdataListParm.parammaps.id = row.id
  516. this.getSeeList()
  517. },
  518. updateData(){
  519. console.log('点击了编辑保存')
  520. },
  521. handleInventoryList() {
  522. this.download.getdataListParm.name = 'getFeedstorageWeightList'
  523. this.download.getdataListParm.parammaps = {}
  524. this.download.getdataListParm.parammaps.pastureid = Cookies.get('pastureid')
  525. this.download.getdataListParm.parammaps.emp = Cookies.get('employename')
  526. GetDataByName(this.download.getdataListParm).then(response => {
  527. if (response.data.list !== null) {
  528. this.download.list = response.data.list
  529. } else {
  530. this.download.list = []
  531. }
  532. var downloadList = [
  533. { 'obj1': '1、文件类型为xlsx类型,对应表格文件名格式为:文件名称.xlsx;' },
  534. { 'obj1': '2、底部工作表名称不可更改,默认为:Sheet1;' },
  535. { 'obj1': '3、盘点日期,饲料名称为必填;' },
  536. { 'obj1': '4、饲料名称必须与系统基础数据-饲料表中匹配;' },
  537. { 'obj1': '5、实际重量为非负数,至多保留俩位小数;' },
  538. { 'obj1': '6、盘点日期为文本格式的年-月-日,例:2020-10-10,盘点日期不可与系统已存在日期重复;盘点日期需保持一致' },
  539. { 'obj1': '7、库存重量仅做参考,不与系统现有库存做校验;' },
  540. { 'obj1': '8、实际重量可仅填写部分,导入已填写实际重量的饲料生成盘点单。' },
  541. { 'obj1': '9、若有备注则填写在表格内容中第一个饲料行内即可;' }
  542. ]
  543. var excelDatas = [
  544. {
  545. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)'],
  546. filterVal: ['nowdate', 'emp', '', 'feedname', 'stockweight', ''],
  547. tableDatas: this.download.list,
  548. sheetName: 'Sheet1'
  549. }, {
  550. tHeader: ['填写规范:'],
  551. filterVal: ['obj1'],
  552. tableDatas: downloadList,
  553. sheetName: 'Sheet2'
  554. }
  555. ]
  556. json2excel(excelDatas, '盘点单导入模板', true, 'xlsx')
  557. })
  558. },
  559. handleExport(item) {
  560. if (item == 1) {
  561. this.download.getdataListParm.parammaps.inputDatetime = this.table.getdataListParm.parammaps.inputDatetime
  562. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  563. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  564. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  565. } else {
  566. this.download.getdataListParm.parammaps.inputDatetime = ''
  567. this.download.getdataListParm.parammaps.startTime = ''
  568. this.download.getdataListParm.parammaps.stopTime = ''
  569. }
  570. this.download.getdataListParm.name = 'getBigInventoryList'
  571. GetDataByName(this.download.getdataListParm).then(response => {
  572. if (response.data.list !== null) {
  573. this.download.list = response.data.list
  574. } else {
  575. this.download.list = []
  576. }
  577. var excelDatas = [
  578. {
  579. tHeader: ['盘点日期', '盘点人', '盘盈库存(kg)', '盘亏库存(kg)', '盈亏净值(kg)', '备注'],
  580. filterVal: ['inventorydate', 'createuser', 'moreWeight', 'lessWeight', 'differWeight', 'remark'],
  581. tableDatas: this.download.list,
  582. sheetName: 'Sheet1'
  583. }
  584. ]
  585. json2excel(excelDatas, '盘点单', true, 'xlsx')
  586. })
  587. } else {
  588. this.download.getdataListParm.name = 'getInventoryList'
  589. this.download.getdataListParm.parammaps = this.see.getdataListParm.parammaps
  590. GetDataByName(this.download.getdataListParm).then(response => {
  591. for (let i = 0; i < response.data.list.length; i++) {
  592. this.$set(response.data.list[i], 'inventorydate', this.create.createTemp.inventorydate)
  593. this.$set(response.data.list[i], 'createuser', this.create.createTemp.createuser)
  594. this.$set(response.data.list[i], 'remark', this.create.createTemp.remark)
  595. }
  596. if (response.data.list !== null) {
  597. this.download.list = response.data.list
  598. } else {
  599. this.download.list = []
  600. }
  601. var excelDatas = [
  602. {
  603. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '差值(kg)'],
  604. filterVal: ['inventorydate', 'createuser', 'remark', 'feedname', 'stockweight', 'factweight', 'differ'],
  605. tableDatas: this.download.list,
  606. sheetName: 'Sheet1'
  607. }
  608. ]
  609. json2excel(excelDatas, '盘点-查看', true, 'xlsx')
  610. })
  611. }
  612. },
  613. beforeImport(file) {
  614. const isLt2M = file.size / 1024 / 1024 < 2
  615. if (!isLt2M) {
  616. this.$message.error('上传文件大小不能超过 2MB!')
  617. }
  618. return isLt2M
  619. },
  620. handleImportSuccess(res, file) {
  621. this.getList()
  622. if (res.msg === 'ok') {
  623. this.$message({ title: '成功', message: '导入成功:' + res.data.success + '条!', type: 'success', duration: 2000 })
  624. if (res.data.err_count > 0) {
  625. this.$notify({ title: '失败', message: '导入失败:' + res.data.err_count + '条!', type: 'danger', duration: 2000 })
  626. import('@/vendor/Export2Excel').then(excel => {
  627. const list1 = res.data.result
  628. const tHeader = [
  629. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '错误信息'
  630. ]
  631. const filterVal = [
  632. '盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', 'error_msg'
  633. ]
  634. const data1 = this.formatJson(filterVal, list1)
  635. excel.export_json_to_excel({ header: tHeader, data: data1, filename: '盘点单报错信息', autoWidth: true, bookType: 'xlsx' })
  636. })
  637. }
  638. } else {
  639. this.$notify({ title: '失败', message: '上传失败', type: 'danger', duration: 2000 })
  640. }
  641. },
  642. formatJson(filterVal, jsonData) {
  643. return jsonData.map(v =>
  644. filterVal.map(j => {
  645. if (j === 'timestamp') {
  646. return parseTime(v[j])
  647. } else {
  648. return v[j]
  649. }
  650. })
  651. )
  652. }
  653. }
  654. }
  655. </script>
  656. <style lang="scss" scoped>
  657. .search{margin-top:10px;}
  658. </style>
  659. <style>
  660. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  661. </style>