b615d4fc074a660af04eae43b8dd9333be1584ed.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" @click="handleCreate">新增盘点单</el-button>
  5. <el-button class="success" @click="handleInventoryList">下载盘点单</el-button>
  6. <el-button class="import" style="float: right;" @click="handleExport(1)">导出</el-button>
  7. </div>
  8. <div class="search">
  9. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  10. <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
  11. <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
  12. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  13. </div>
  14. <div class="table">
  15. <el-table
  16. :key="table.tableKey"
  17. v-loading="table.listLoading"
  18. element-loading-text="给我一点时间"
  19. :data="table.list"
  20. border
  21. fit
  22. highlight-current-row
  23. style="width: 100%;"
  24. :row-style="rowStyle"
  25. :cell-style="cellStyle"
  26. class="elTable table-fixed"
  27. >
  28. <el-table-column label="序号" align="center" type="index" width="50px">
  29. <template slot-scope="scope">
  30. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="盘点日期" min-width="130px" align="center">
  34. <template slot-scope="scope">
  35. <span>{{ scope.row.inventorydate }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="盘点人" min-width="130px" align="center">
  39. <template slot-scope="scope">
  40. <span>{{ scope.row.createuser }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="盘盈库存(kg)" min-width="110px" align="center">
  44. <template slot-scope="scope">
  45. <span>{{ scope.row.moreWeight }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="盘亏库存(kg)" min-width="110px" align="center">
  49. <template slot-scope="scope">
  50. <span>{{ scope.row.lessWeight }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="盈亏净值(kg)" min-width="110px" align="center">
  54. <template slot-scope="scope">
  55. <span>{{ scope.row.differWeight }}</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="备注" min-width="110px" align="center">
  59. <template slot-scope="scope">
  60. <span>{{ scope.row.remark }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" align="center" width="320" class-name="small-padding fixed-width" fixed="right">
  64. <template slot-scope="scope">
  65. <el-button class="miniPrimary" :disabled="isokDisable" @click="handleSee(scope.row)">查看</el-button>
  66. <el-button v-if="scope.$index + (table.pageNum-1) * table.pageSize + 1 == 1" class="miniDanger" @click="handleRowDelete(scope.row)">删除</el-button>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  71. </div>
  72. <!-- 新增盘点单 -->
  73. <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
  74. <div class="app-add">
  75. <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 90%;margin:0 auto">
  76. <el-row>
  77. <el-col :span="8">
  78. <el-form-item label="盘点日期:" prop="inventorydate">
  79. <!-- :picker-options="create.pickerOptions2" -->
  80. <el-date-picker v-model="create.createTemp.inventorydate" class="filter-item" type="date" placeholder="盘点日期" :disabled="create.dialogStatus==='see'" :picker-options="create.pickerOptions1" :clearable="false" />
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="8">
  84. <el-form-item label="盘点人:" prop="createuser">
  85. <el-input ref="createuser" v-model="create.createTemp.createuser" class="filter-item" placeholder="盘点人" type="text" disabled />
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="8">
  89. <el-form-item label="备注:" prop="remark">
  90. <el-input ref="remark" v-model="create.createTemp.remark" class="filter-item" placeholder="备注" type="text" :disabled="create.dialogStatus==='see'" />
  91. </el-form-item>
  92. </el-col>
  93. </el-row>
  94. </el-form>
  95. <el-table
  96. :key="create.tableKey"
  97. v-loading="create.listLoading"
  98. element-loading-text="给我一点时间"
  99. :data="create.list"
  100. border
  101. fit
  102. highlight-current-row
  103. style="width: 100%;margin-bottom: 50px;"
  104. :row-style="rowStyle"
  105. :cell-style="cellStyle"
  106. class="elTable table-fixed"
  107. >
  108. <el-table-column label="饲料名称" min-width="130px" align="center">
  109. <template slot-scope="scope">
  110. <span>{{ scope.row.feedname }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="库存重量(kg)" min-width="130px" align="center">
  114. <template slot-scope="scope">
  115. <span>{{ scope.row.stockweight }}</span>
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="实际重量(kg)" min-width="110px" align="center">
  119. <template slot-scope="scope">
  120. <el-input v-if="create.dialogStatus==='create'" ref="input" v-model="scope.row.factweight" style="width:80%;padding:10px 0;" @blur="blurFactweight(scope.row)" />
  121. <span v-else> {{ scope.row.factweight }}</span>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="差值(kg)" min-width="110px" align="center">
  125. <template slot-scope="scope">
  126. <span>{{ scope.row.differ }}</span>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. <div slot="footer" class="dialog-footer">
  131. <el-button v-if="create.dialogStatus==='see'" class="success" :disabled="isokDisable" @click="handleExport(2)">导出</el-button>
  132. <el-button class="cancelClose" @click="create.dialogFormVisible = false; ">关闭</el-button>
  133. <el-button v-if="create.dialogStatus==='create'" class="success" :disabled="isokDisable" @click="createData()">确认</el-button>
  134. </div>
  135. </div>
  136. </el-dialog>
  137. </div>
  138. </template>
  139. <script>
  140. import { GetDataByName, ExecDataByConfig, failproccess, PostDataByName } from '@/api/common'
  141. import Pagination from '@/components/Pagination'
  142. import { parseTime, json2excel } from '@/utils/index.js'
  143. import { MessageBox } from 'element-ui'
  144. import Cookies from 'js-cookie'
  145. export default {
  146. name: 'InventoryList',
  147. components: { Pagination },
  148. data() {
  149. return {
  150. table: {
  151. getdataListParm: {
  152. name: 'getBigInventoryList',
  153. page: 1,
  154. offset: 1,
  155. pagecount: 10,
  156. returntype: 'Map',
  157. parammaps: {
  158. pastureid: Cookies.get('pastureid'),
  159. startTime: '',
  160. stopTime: '',
  161. inputDatetime: ''
  162. }
  163. },
  164. tableKey: 0,
  165. list: [],
  166. total: 0,
  167. listLoading: true
  168. },
  169. textMap: {
  170. create: '新增',
  171. see: '查看盘点单'
  172. },
  173. create: {
  174. pickerOptions1: {
  175. disabledDate: this.disabledDate
  176. },
  177. dialogFormVisible: false,
  178. dialogStatus: '',
  179. createTemp: {
  180. pastureid: Cookies.get('pastureid'),
  181. remark: '',
  182. inventorydate: parseTime(new Date(), '{y}-{m}-{d}'),
  183. createuser: Cookies.get('employename')
  184. },
  185. rules: {},
  186. getdataListParm: {
  187. name: 'getFeedstorageWeightList',
  188. page: 1,
  189. offset: 1,
  190. pagecount: '',
  191. returntype: 'Map',
  192. parammaps: {
  193. pastureid: Cookies.get('pastureid'),
  194. emp: Cookies.get('employename')
  195. }
  196. },
  197. tableKey: 0,
  198. list: [],
  199. total: 0,
  200. listLoading: true,
  201. getMaxdataParm: {
  202. name: 'getInventoryMaxdate',
  203. page: 1,
  204. offset: 1,
  205. pagecount: '',
  206. returntype: 'Map',
  207. parammaps: {
  208. pastureid: Cookies.get('pastureid')
  209. }
  210. },
  211. maxDate: ''
  212. },
  213. see: {
  214. getdataListParm: {
  215. name: 'getInventoryList',
  216. page: 1,
  217. offset: 1,
  218. pagecount: 10,
  219. returntype: 'Map',
  220. parammaps: {}
  221. }
  222. },
  223. requestParam: {},
  224. download: {
  225. getdataListParm: {
  226. name: 'getBigInventoryList',
  227. page: 1,
  228. offset: 1,
  229. pagecount: 0,
  230. returntype: 'Map',
  231. parammaps: {
  232. pastureid: Cookies.get('pastureid'),
  233. startTime: '',
  234. stopTime: '',
  235. inputDatetime: ''
  236. }
  237. },
  238. list: []
  239. },
  240. isokDisable: false,
  241. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  242. cellStyle: { padding: 0 + 'px' }
  243. }
  244. },
  245. created() {
  246. this.getList()
  247. },
  248. methods: {
  249. handleBefore() {
  250. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  251. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  252. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  253. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  254. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  255. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  256. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  257. this.$forceUpdate()
  258. }
  259. },
  260. handleNext() {
  261. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  262. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  263. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  264. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  265. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  266. this.table.getdataListParm.parammaps.startTime = parseTime(start, '{y}-{m}-{d}')
  267. this.table.getdataListParm.parammaps.stopTime = parseTime(stop, '{y}-{m}-{d}')
  268. this.$forceUpdate()
  269. }
  270. },
  271. handleSearch() {
  272. console.log('点击了查询')
  273. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  274. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  275. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  276. } else {
  277. this.table.getdataListParm.parammaps.inputDatetime = ''
  278. this.table.getdataListParm.parammaps.startTime = ''
  279. this.table.getdataListParm.parammaps.stopTime = ''
  280. }
  281. this.table.getdataListParm.offset = 1
  282. this.getList()
  283. },
  284. getList() {
  285. this.table.listLoading = true
  286. GetDataByName(this.table.getdataListParm).then(response => {
  287. console.log('table数据', response.data.list)
  288. if (response.data.list !== null) {
  289. this.table.list = response.data.list
  290. this.table.pageNum = response.data.pageNum
  291. this.table.pageSize = response.data.pageSize
  292. this.table.total = response.data.total
  293. } else {
  294. this.table.list = []
  295. }
  296. setTimeout(() => {
  297. this.table.listLoading = false
  298. }, 100)
  299. })
  300. },
  301. resetCreateTemp() {
  302. this.create.createTemp = { pastureid: Cookies.get('pastureid'), remark: '', inventorydate: parseTime(new Date(), '{y}-{m}-{d}'), createuser: Cookies.get('employename') }
  303. },
  304. handleCreate() {
  305. console.log('点击了新增盘点单')
  306. this.resetCreateTemp()
  307. this.create.dialogStatus = 'create'
  308. this.create.dialogFormVisible = true
  309. this.getMaxDate()
  310. this.getCreateList()
  311. },
  312. disabledDate(time) {
  313. return time.getTime() < new Date(this.create.maxDate) || time.getTime() > Date.now()
  314. },
  315. getMaxDate() {
  316. GetDataByName(this.create.getMaxdataParm).then(response => {
  317. this.create.maxDate = response.data.list[0].maxdate
  318. console.log(response.data.list[0])
  319. })
  320. },
  321. getCreateList() {
  322. this.create.listLoading = true
  323. GetDataByName(this.create.getdataListParm).then(response => {
  324. console.log('table数据', response.data.list)
  325. if (response.data.list !== null) {
  326. for (let i = 0; i < response.data.list.length; i++) {
  327. this.$set(response.data.list[i], 'factweight', '')
  328. this.$set(response.data.list[i], 'differ', '')
  329. }
  330. this.create.list = response.data.list
  331. this.create.pageNum = response.data.pageNum
  332. this.create.pageSize = response.data.pageSize
  333. this.create.total = response.data.total
  334. } else {
  335. this.create.list = []
  336. }
  337. setTimeout(() => {
  338. this.create.listLoading = false
  339. }, 100)
  340. })
  341. },
  342. // 实际重量
  343. blurFactweight(row) {
  344. if (row.factweight !== '' && row.stockweight !== '') {
  345. row.differ = parseFloat(row.factweight) - parseFloat(row.stockweight)
  346. }
  347. },
  348. createData() {
  349. this.$refs['createTemp'].validate(valid => {
  350. if (valid) {
  351. this.isokDisable = true
  352. setTimeout(() => {
  353. this.isokDisable = false
  354. }, 1000)
  355. var createList = []
  356. for (let i = 0; i < this.create.list.length; i++) {
  357. if (this.create.list[i].factweight !== '') {
  358. createList.push(this.create.list[i])
  359. }
  360. }
  361. for (let i = 0; i < createList.length; i++) {
  362. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  363. // 实际重量
  364. if (!keepTwoNum.test(parseFloat(createList[i].factweight))) {
  365. this.$message({ type: 'error', message: '实际重量请输入自然数并保留两位小数', duration: 2000 })
  366. return false
  367. }
  368. }
  369. this.requestParam.common = { 'returnmap': '0' }
  370. this.requestParam.data = []
  371. this.requestParam.data[0] = { 'name': 'insertBigInventory', 'type': 'e', 'parammaps': {
  372. 'pastureid': this.create.createTemp.pastureid,
  373. 'inventorydate': parseTime(this.create.createTemp.inventorydate, '{y}-{m}-{d}'),
  374. 'createuser': this.create.createTemp.createuser,
  375. 'remark': this.create.createTemp.remark
  376. }}
  377. this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': createList }}
  378. this.requestParam.data[1].children = []
  379. this.requestParam.data[1].children[0] = { 'name': 'insertInventory', 'type': 'e', 'parammaps': {
  380. invid: '@insertBigInventory.LastInsertId',
  381. pastureid: '@insertSpotList.pastureid',
  382. feedname: '@insertSpotList.feedname',
  383. feedid: '@insertSpotList.feedid',
  384. stockweight: '@insertSpotList.stockweight',
  385. factweight: '@insertSpotList.factweight'
  386. }}
  387. ExecDataByConfig(this.requestParam).then(response => {
  388. if (response.msg === 'fail') {
  389. const inventorydate = new RegExp("key 'inventorydate'")
  390. if (inventorydate.test(response.data)) {
  391. this.$message({ type: 'error', message: '当前日期已盘点,不可重复录入', duration: 2000 })
  392. } else {
  393. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  394. }
  395. } else {
  396. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  397. this.create.dialogFormVisible = false
  398. this.getList()
  399. }
  400. })
  401. }
  402. })
  403. },
  404. handleInventoryList() {
  405. console.log('点击了下载盘点单')
  406. },
  407. handleSee(row) {
  408. console.log('点击了查看')
  409. this.create.dialogStatus = 'see'
  410. this.create.dialogFormVisible = true
  411. this.create.createTemp = Object.assign({}, row)
  412. this.see.getdataListParm.parammaps.pastureid = row.pastureid
  413. this.see.getdataListParm.parammaps.id = row.id
  414. this.getSeeList()
  415. },
  416. getSeeList() {
  417. this.create.listLoading = true
  418. GetDataByName(this.see.getdataListParm).then(response => {
  419. console.log('table数据', response.data.list)
  420. if (response.data.list !== null) {
  421. this.create.list = response.data.list
  422. this.create.pageNum = response.data.pageNum
  423. this.create.pageSize = response.data.pageSize
  424. this.create.total = response.data.total
  425. } else {
  426. this.create.list = []
  427. }
  428. setTimeout(() => {
  429. this.create.listLoading = false
  430. }, 100)
  431. })
  432. },
  433. handleRowDelete(row) {
  434. MessageBox.confirm('是否确认删除此信息?', {
  435. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  436. }).then(() => {
  437. this.requestParam.name = 'deleteBigInventory'
  438. this.requestParam.parammaps = {}
  439. this.requestParam.parammaps.pastureid = row.pastureid
  440. this.requestParam.parammaps.id = row.id
  441. PostDataByName(this.requestParam).then(response => {
  442. if (response.msg === 'fail') {
  443. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  444. } else {
  445. this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
  446. this.getList()
  447. }
  448. })
  449. }).catch(() => {
  450. this.$message({ type: 'info', message: '已取消删除' })
  451. })
  452. },
  453. handleExport(item) {
  454. if (item == 1) {
  455. this.download.getdataListParm.parammaps.inputDatetime = this.table.getdataListParm.parammaps.inputDatetime
  456. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  457. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  458. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  459. } else {
  460. this.download.getdataListParm.parammaps.inputDatetime = ''
  461. this.download.getdataListParm.parammaps.startTime = ''
  462. this.download.getdataListParm.parammaps.stopTime = ''
  463. }
  464. this.download.getdataListParm.name = 'getBigInventoryList'
  465. GetDataByName(this.download.getdataListParm).then(response => {
  466. if (response.data.list !== null) {
  467. this.download.list = response.data.list
  468. } else {
  469. this.download.list = []
  470. }
  471. var excelDatas = [
  472. {
  473. tHeader: ['盘点日期', '盘点人', '盘盈库存(kg)', '盘亏库存(kg)', '盈亏净值(kg)', '备注'],
  474. filterVal: ['inventorydate', 'createuser', 'moreWeight', 'lessWeight', 'differWeight', 'remark'],
  475. tableDatas: this.download.list,
  476. sheetName: 'Sheet1'
  477. }
  478. ]
  479. json2excel(excelDatas, '盘点单', true, 'xlsx')
  480. })
  481. } else {
  482. this.download.getdataListParm.name = 'getInventoryList'
  483. this.download.getdataListParm.parammaps = this.see.getdataListParm.parammaps
  484. GetDataByName(this.download.getdataListParm).then(response => {
  485. for (let i = 0; i < response.data.list.length; i++) {
  486. this.$set(response.data.list[i], 'inventorydate', this.create.createTemp.inventorydate)
  487. this.$set(response.data.list[i], 'createuser', this.create.createTemp.createuser)
  488. this.$set(response.data.list[i], 'remark', this.create.createTemp.remark)
  489. }
  490. if (response.data.list !== null) {
  491. this.download.list = response.data.list
  492. } else {
  493. this.download.list = []
  494. }
  495. var excelDatas = [
  496. {
  497. tHeader: ['盘点日期', '盘点人', '备注', '饲料名称', '库存重量(kg)', '实际重量(kg)', '差值(kg)'],
  498. filterVal: ['inventorydate', 'createuser', 'remark', 'feedname', 'stockweight', 'factweight', 'differ'],
  499. tableDatas: this.download.list,
  500. sheetName: 'Sheet1'
  501. }
  502. ]
  503. json2excel(excelDatas, '盘点-查看', true, 'xlsx')
  504. })
  505. }
  506. }
  507. }
  508. }
  509. </script>
  510. <style lang="scss" scoped>
  511. .search{margin-top:10px;}
  512. .table{margin-top:10px;}
  513. </style>
  514. <style>
  515. .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
  516. </style>