b2d1da2dcb942e21ec9c5757b742d04d11570c78.svn-base 16 KB

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