3bc67610ba3b5a189aa6d80033158437c6ab24d2.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div class="app-container" style="position: relative;">
  3. <div v-if="activeName=='first'" class="operation" style="position: absolute;top: -5px;right: 10px;z-index:1;">
  4. <el-button class="import" icon="el-icon-upload2" @click="handleExport('tab1')">导出</el-button>
  5. </div>
  6. <div v-if="activeName=='second'" class="operation" style="position: absolute;top: -5px;right: 10px;z-index:1;">
  7. <el-button class="import" icon="el-icon-upload2" @click="handleExport('tab2')">导出</el-button>
  8. </div>
  9. <el-tabs v-model="activeName" @tab-click="handleClick">
  10. <el-tab-pane label="预混记录" name="first">
  11. <div class="table">
  12. <el-table
  13. :key="tab1.tableKey"
  14. v-loading="tab1.listLoading"
  15. element-loading-text="给我一点时间"
  16. :data="tab1.list"
  17. border
  18. fit
  19. highlight-current-row
  20. style="width: 100%;"
  21. :row-style="rowStyle"
  22. :cell-style="cellStyle"
  23. class="elTable table-fixed"
  24. >
  25. <el-table-column label="序号" align="center" type="index" width="50px" />
  26. <el-table-column label="预混配方" min-width="130px" align="center" prop="pftname" />
  27. <el-table-column label="当前剩余量" min-width="110px" align="center">
  28. <template slot-scope="scope">
  29. <span v-if="scope.row.NoEdit">{{ scope.row.stockweight }}</span>
  30. <el-input v-if="scope.row.Edit" v-model="scope.row.stockweight" type="number" style="width:95%;padding:10px 0;" />
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="预计使用天数" min-width="130px" align="center" prop="days" />
  34. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  35. <template slot-scope="{row}">
  36. <a v-if="row.isUpdate && isRoleEdit" class="correcting" @click="handleUpdate(row)">校正</a>
  37. <el-button v-if="row.isUpdateSave && isRoleEdit" :disabled="isokDisable" class="miniSuccess" icon="el-icon-folder-checked" @click="updateData(row)" />
  38. <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
  39. <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <span v-if="tab1.listLoading == false" style="margin-right: 30px;margin-top: 10px;font-size: 14px;">共{{ tab1.total }}条</span>
  44. </div>
  45. </el-tab-pane>
  46. <el-tab-pane label="库存预警" name="second">
  47. <div class="table">
  48. <el-table
  49. :key="table.tableKey"
  50. v-loading="table.listLoading"
  51. element-loading-text="给我一点时间"
  52. :data="table.list"
  53. border
  54. fit
  55. highlight-current-row
  56. style="width: 100%;"
  57. :cell-style="cellStyle"
  58. class="elTable table-fixed"
  59. :row-style="rowStyle"
  60. >
  61. <el-table-column label="序号" align="center" type="index" width="50px" />
  62. <el-table-column label="饲料名称" min-width="130px" align="center">
  63. <template slot-scope="scope">
  64. <span>{{ scope.row.feedname }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="库存量(kg)" min-width="130px" align="center">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.stockweight }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="近七天平均计划量(kg)" min-width="110px" align="center">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.avgweight }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="剩余使用天数" min-width="110px" align="center">
  78. <template slot-scope="scope">
  79. <span>{{ scope.row.ldays }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="最近预警日期" min-width="110px" align="center">
  83. <template slot-scope="scope">
  84. <span>{{ scope.row.lastdate }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" align="center" width="50" class-name="small-padding fixed-width" fixed="right">
  88. <template slot-scope="{row}">
  89. <el-button class="miniSuccess" :disabled="isokDisable" icon="el-icon-search" @click="handleSee(row)" />
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <span v-if="table.listLoading == false" style="margin-right: 30px;margin-top: 10px;font-size: 14px;">共{{ table.total }}条</span>
  94. </div>
  95. </el-tab-pane>
  96. </el-tabs>
  97. <el-dialog :fullscreen="dialogFull" :visible.sync="see.dialogFormVisible" :close-on-click-modal="false" width="90%">
  98. <template slot="title">
  99. <div class="avue-crud__dialog__header">
  100. <span class="el-dialog__title">
  101. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  102. {{ textMap[see.dialogStatus] }}
  103. </span>
  104. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  105. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  106. <svg-icon v-else icon-class="fullscreen" />
  107. </div>
  108. </div>
  109. </template>
  110. <div class="app-see">
  111. <el-form ref="temp" :rules="see.rules" :model="see.temp" label-position="right" label-width="110px" style="width: 100%;margin:0 auto">
  112. <el-row>
  113. <el-col :span="8">
  114. <el-form-item label="饲料名称:" prop="feedname">
  115. <span> {{ see.temp.feedname }}</span>
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. </el-form>
  120. <el-table
  121. :key="see.tableKey"
  122. v-loading="see.listLoading"
  123. element-loading-text="给我一点时间"
  124. :data="see.list"
  125. border
  126. fit
  127. highlight-current-row
  128. style="width: 100%;"
  129. :row-style="rowStyle"
  130. :cell-style="cellStyle"
  131. class="elTable table-fixed"
  132. >
  133. <el-table-column label="序号" align="center" type="index" width="50px">
  134. <template slot-scope="scope">
  135. <span>{{ scope.$index + (see.pageNum-1) * see.pageSize + 1 }}</span>
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="库存量" min-width="130px" align="center">
  139. <template slot-scope="scope">
  140. <span>{{ scope.row.stockweight }}</span>
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="近七天平均计划量(kg)" min-width="130px" align="center">
  144. <template slot-scope="scope">
  145. <span>{{ scope.row.avgweight }}</span>
  146. </template>
  147. </el-table-column>
  148. <el-table-column label="剩余使用天数" min-width="110px" align="center">
  149. <template slot-scope="scope">
  150. <span> {{ scope.row.ldays }}</span>
  151. </template>
  152. </el-table-column>
  153. <el-table-column label="预警日期" min-width="110px" align="center">
  154. <template slot-scope="scope">
  155. <span>{{ scope.row.date }}</span>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <pagination v-show="see.total>=0" style="margin-bottom: 50px;" :total="see.total" :page.sync="see.getdataListParm.offset" :limit.sync="see.getdataListParm.pagecount" @pagination="getSeeList" />
  160. <div slot="footer" class="dialog-footer">
  161. <el-button class="cancelClose cancelClose1" @click="see.dialogFormVisible = false; ">关闭</el-button>
  162. </div>
  163. </div>
  164. </el-dialog>
  165. </div>
  166. </template>
  167. <script>
  168. import { GetDataByName, PostDataByName, failproccess, checkButtons } from '@/api/common'
  169. import Pagination from '@/components/Pagination'
  170. import Cookies from 'js-cookie'
  171. import { json2excel } from '@/utils/index.js'
  172. export default {
  173. name: 'Warning',
  174. components: { Pagination },
  175. data() {
  176. return {
  177. dialogFull: false,
  178. isRoleEdit: [],
  179. activeName: 'first',
  180. tab1: {
  181. getdataListParm: {
  182. name: 'getPreMixStorageLsit',
  183. page: 1,
  184. offset: 1,
  185. pagecount: '',
  186. returntype: 'Map',
  187. parammaps: {
  188. pastureid: Cookies.get('pastureid')
  189. }
  190. },
  191. tableKey: 0,
  192. list: [],
  193. total: 0,
  194. listLoading: true
  195. },
  196. table: {
  197. getdataListParm: {
  198. name: 'getFsWarnList',
  199. page: 1,
  200. offset: 1,
  201. pagecount: '',
  202. returntype: 'Map',
  203. parammaps: {
  204. pastureid: Cookies.get('pastureid')
  205. }
  206. },
  207. tableKey: 0,
  208. list: [],
  209. total: 0,
  210. listLoading: true
  211. },
  212. textMap: {
  213. see: '库存预警记录'
  214. },
  215. see: {
  216. dialogFormVisible: false,
  217. dialogStatus: '',
  218. temp: {},
  219. rules: {},
  220. getdataListParm: {
  221. name: 'getFsWarnListdate',
  222. page: 1,
  223. offset: 1,
  224. pagecount: 10,
  225. returntype: 'Map',
  226. parammaps: {
  227. pastureid: Cookies.get('pastureid'),
  228. feedid: ''
  229. }
  230. },
  231. tableKey: 0,
  232. list: [],
  233. total: 0,
  234. listLoading: true
  235. },
  236. download: {
  237. getdataListParm: {
  238. name: '',
  239. page: 1,
  240. offset: 1,
  241. pagecount: 0,
  242. returntype: 'Map',
  243. parammaps: {
  244. pastureid: Cookies.get('pastureid')
  245. }
  246. },
  247. list: []
  248. },
  249. requestParam: {},
  250. isokDisable: false,
  251. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  252. cellStyle: { padding: 0 + 'px' }
  253. }
  254. },
  255. created() {
  256. this.getButtons()
  257. if (this.$route.params.jmp == undefined) {
  258. this.getTab1List()
  259. } else {
  260. this.activeName = 'second'
  261. this.getTab2List()
  262. }
  263. },
  264. methods: {
  265. getButtons() {
  266. const Edit = 'Warning'
  267. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  268. this.isRoleEdit = isRoleEdit
  269. },
  270. handleClick(item) {
  271. console.log(item)
  272. if (item.name == 'first') {
  273. this.getTab1List()
  274. } else {
  275. this.getTab2List()
  276. }
  277. },
  278. getTab1List() {
  279. this.tab1.listLoading = true
  280. GetDataByName(this.tab1.getdataListParm).then(response => {
  281. if (response.data.list !== null) {
  282. console.log('table数据111', response.data.list)
  283. for (let i = 0; i < response.data.list.length; i++) {
  284. this.$set(response.data.list[i], 'Edit', false) // 编辑
  285. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  286. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  287. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  288. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  289. }
  290. this.tab1.list = response.data.list
  291. this.tab1.pageNum = response.data.pageNum
  292. this.tab1.pageSize = response.data.pageSize
  293. this.tab1.total = response.data.total
  294. } else {
  295. this.tab1.list = []
  296. }
  297. setTimeout(() => {
  298. this.tab1.listLoading = false
  299. }, 100)
  300. })
  301. },
  302. handleUpdate(row) {
  303. for (let i = 0; i < this.table.list.length; i++) {
  304. if (this.table.list[i].Edit == true) {
  305. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  306. return false
  307. }
  308. }
  309. // 编辑true,不可编辑false
  310. row.Edit = true
  311. row.NoEdit = false
  312. // 新增false,编辑false,编辑保存true
  313. row.isCreate = false
  314. row.isUpdate = false
  315. row.isUpdateSave = true
  316. },
  317. updateData(row) {
  318. this.isokDisable = true
  319. setTimeout(() => {
  320. this.isokDisable = false
  321. }, 1000)
  322. if (row.stockweight == '') {
  323. this.$message({ type: 'error', message: '当前配方剩余重量不能为空', duration: 2000 })
  324. return false
  325. }
  326. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  327. // 当前配方剩余重量
  328. if (!keepTwoNum.test(parseFloat(row.stockweight))) {
  329. this.$message({ type: 'error', message: '当前配方剩余重量请输入自然数并保留两位小数', duration: 2000 })
  330. return false
  331. }
  332. this.requestParam.name = 'updatePreMixStorage'
  333. this.requestParam.parammaps = {}
  334. this.requestParam.parammaps.pastureid = row.pastureid
  335. this.requestParam.parammaps.id = row.id
  336. this.requestParam.parammaps.stockweight = row.stockweight
  337. PostDataByName(this.requestParam).then(response => {
  338. console.log('编辑保存发送参数', this.requestParam)
  339. if (response.msg !== 'fail') {
  340. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  341. this.getTab1List()
  342. } else {
  343. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  344. }
  345. })
  346. },
  347. updateCancel(row) {
  348. console.log('点击了编辑取消')
  349. // 编辑false,不可编辑true
  350. row.Edit = false
  351. row.NoEdit = true
  352. // 新增false,编辑true,编辑保存false
  353. row.isCreate = false
  354. row.isUpdate = true
  355. row.isUpdateSave = false
  356. this.getTab1List()
  357. },
  358. getTab2List() {
  359. this.table.listLoading = true
  360. GetDataByName(this.table.getdataListParm).then(response => {
  361. if (response.data.list !== null) {
  362. console.log('table数据22', response.data.list)
  363. this.table.list = response.data.list
  364. // this.table.pageNum = response.data.pageNum
  365. // this.table.pageSize = response.data.pageSize
  366. this.table.total = response.data.total
  367. } else {
  368. this.table.list = []
  369. }
  370. setTimeout(() => {
  371. this.table.listLoading = false
  372. }, 100)
  373. })
  374. },
  375. handleSee(row) {
  376. this.see.dialogStatus = 'see'
  377. this.dialogFull = false
  378. this.see.dialogFormVisible = true
  379. this.see.temp = Object.assign({}, row)
  380. this.see.list = []
  381. this.see.getdataListParm.offset = 1
  382. this.see.getdataListParm.parammaps.feedid = row.feedid
  383. this.getSeeList()
  384. },
  385. getSeeList() {
  386. this.see.listLoading = true
  387. GetDataByName(this.see.getdataListParm).then(response => {
  388. if (response.data.list !== null) {
  389. console.log('table数据', response.data.list)
  390. this.see.list = response.data.list
  391. this.see.pageNum = response.data.pageNum
  392. this.see.pageSize = response.data.pageSize
  393. this.see.total = response.data.total
  394. } else {
  395. this.see.list = []
  396. }
  397. setTimeout(() => {
  398. this.see.listLoading = false
  399. }, 100)
  400. })
  401. },
  402. handleExport(item) {
  403. console.log('导出')
  404. if (item == 'tab1') {
  405. var excelDatas = [
  406. {
  407. tHeader: ['预混配方', '当前剩余量', '预计使用天数'],
  408. filterVal: ['pftname', 'stockweight', 'days'],
  409. tableDatas: this.tab1.list,
  410. sheetName: 'Sheet1'
  411. }
  412. ]
  413. json2excel(excelDatas, '预混记录', true, 'xlsx')
  414. } else {
  415. this.download.getdataListParm.name = 'getFsWarnList'
  416. GetDataByName(this.download.getdataListParm).then(response => {
  417. if (response.data.list !== null) {
  418. this.download.list = response.data.list
  419. } else {
  420. this.download.list = []
  421. }
  422. var excelDatas = [
  423. {
  424. tHeader: ['饲料名称', '库存量(kg)', '近七天平均计划量(kg)', '剩余使用天数', '最新预警日期'],
  425. filterVal: ['feedname', 'stockweight', 'avgweight', 'ldays', 'lastdate'],
  426. tableDatas: this.download.list,
  427. sheetName: 'Sheet1'
  428. }
  429. ]
  430. json2excel(excelDatas, '库存预警', true, 'xlsx')
  431. })
  432. }
  433. }
  434. }
  435. }
  436. </script>