f91bcdabe2d871613623afe57d395fe5b4645e62.svn-base 16 KB

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