a103dbde9c14af925cfe90b1febfcf298a7e9e54.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. <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 } 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. activeName: 'first',
  166. tab1: {
  167. getdataListParm: {
  168. name: 'getPreMixStorageLsit',
  169. page: 1,
  170. offset: 1,
  171. pagecount: '',
  172. returntype: 'Map',
  173. parammaps: {
  174. pastureid: Cookies.get('pastureid')
  175. }
  176. },
  177. tableKey: 0,
  178. list: [],
  179. total: 0,
  180. listLoading: true
  181. },
  182. table: {
  183. getdataListParm: {
  184. name: 'getFsWarnList',
  185. page: 1,
  186. offset: 1,
  187. pagecount: '',
  188. returntype: 'Map',
  189. parammaps: {
  190. pastureid: Cookies.get('pastureid')
  191. }
  192. },
  193. tableKey: 0,
  194. list: [],
  195. total: 0,
  196. listLoading: true
  197. },
  198. textMap: {
  199. see: '库存预警记录'
  200. },
  201. see: {
  202. dialogFormVisible: false,
  203. dialogStatus: '',
  204. temp: {},
  205. rules: {},
  206. getdataListParm: {
  207. name: 'getFsWarnListdate',
  208. page: 1,
  209. offset: 1,
  210. pagecount: 10,
  211. returntype: 'Map',
  212. parammaps: {
  213. pastureid: Cookies.get('pastureid'),
  214. feedid: ''
  215. }
  216. },
  217. tableKey: 0,
  218. list: [],
  219. total: 0,
  220. listLoading: true
  221. },
  222. download: {
  223. getdataListParm: {
  224. name: '',
  225. page: 1,
  226. offset: 1,
  227. pagecount: 0,
  228. returntype: 'Map',
  229. parammaps: {
  230. pastureid: Cookies.get('pastureid')
  231. }
  232. },
  233. list: []
  234. },
  235. requestParam: {},
  236. isokDisable: false,
  237. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  238. cellStyle: { padding: 0 + 'px' }
  239. }
  240. },
  241. created() {
  242. if (this.$route.params.jmp == undefined) {
  243. this.getTab1List()
  244. } else {
  245. this.activeName = 'second'
  246. this.getTab2List()
  247. }
  248. },
  249. methods: {
  250. handleClick(item) {
  251. console.log(item)
  252. if (item == 'first') {
  253. this.getTab1List()
  254. } else {
  255. this.getTab2List()
  256. }
  257. },
  258. getTab1List() {
  259. this.tab1.listLoading = true
  260. GetDataByName(this.tab1.getdataListParm).then(response => {
  261. console.log('table数据', response.data.list)
  262. if (response.data.list !== null) {
  263. for (let i = 0; i < response.data.list.length; i++) {
  264. this.$set(response.data.list[i], 'Edit', false) // 编辑
  265. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  266. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  267. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  268. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  269. }
  270. this.tab1.list = response.data.list
  271. this.tab1.pageNum = response.data.pageNum
  272. this.tab1.pageSize = response.data.pageSize
  273. this.tab1.total = response.data.total
  274. } else {
  275. this.tab1.list = []
  276. }
  277. setTimeout(() => {
  278. this.tab1.listLoading = false
  279. }, 100)
  280. })
  281. },
  282. handleUpdate(row) {
  283. for (let i = 0; i < this.table.list.length; i++) {
  284. if (this.table.list[i].Edit == true) {
  285. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  286. return false
  287. }
  288. }
  289. // 编辑true,不可编辑false
  290. row.Edit = true
  291. row.NoEdit = false
  292. // 新增false,编辑false,编辑保存true
  293. row.isCreate = false
  294. row.isUpdate = false
  295. row.isUpdateSave = true
  296. },
  297. updateData(row) {
  298. this.isokDisable = true
  299. setTimeout(() => {
  300. this.isokDisable = false
  301. }, 1000)
  302. if (row.stockweight == '') {
  303. this.$message({ type: 'error', message: '当前配方剩余重量不能为空', duration: 2000 })
  304. return false
  305. }
  306. const keepTwoNum = /^\d+(\.\d{1,2})?$/
  307. // 当前配方剩余重量
  308. if (!keepTwoNum.test(parseFloat(row.stockweight))) {
  309. this.$message({ type: 'error', message: '当前配方剩余重量请输入自然数并保留两位小数', duration: 2000 })
  310. return false
  311. }
  312. this.requestParam.name = 'updatePreMixStorage'
  313. this.requestParam.parammaps = {}
  314. this.requestParam.parammaps.pastureid = row.pastureid
  315. this.requestParam.parammaps.id = row.id
  316. this.requestParam.parammaps.stockweight = row.stockweight
  317. PostDataByName(this.requestParam).then(response => {
  318. console.log('编辑保存发送参数', this.requestParam)
  319. if (response.msg !== 'fail') {
  320. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  321. this.getTab1List()
  322. } else {
  323. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  324. }
  325. })
  326. },
  327. updateCancel(row) {
  328. console.log('点击了编辑取消')
  329. // 编辑false,不可编辑true
  330. row.Edit = false
  331. row.NoEdit = true
  332. // 新增false,编辑true,编辑保存false
  333. row.isCreate = false
  334. row.isUpdate = true
  335. row.isUpdateSave = false
  336. this.getTab1List()
  337. },
  338. getTab2List() {
  339. this.table.listLoading = true
  340. GetDataByName(this.table.getdataListParm).then(response => {
  341. console.log('table数据', response.data.list)
  342. if (response.data.list !== null) {
  343. this.table.list = response.data.list
  344. // this.table.pageNum = response.data.pageNum
  345. // this.table.pageSize = response.data.pageSize
  346. this.table.total = response.data.total
  347. } else {
  348. this.table.list = []
  349. }
  350. setTimeout(() => {
  351. this.table.listLoading = false
  352. }, 100)
  353. })
  354. },
  355. handleSee(row) {
  356. this.see.dialogStatus = 'see'
  357. this.see.dialogFormVisible = true
  358. this.see.temp = Object.assign({}, row)
  359. this.see.list = []
  360. this.see.getdataListParm.offset = 1
  361. this.see.getdataListParm.parammaps.feedid = row.feedid
  362. this.getSeeList()
  363. },
  364. getSeeList() {
  365. this.see.listLoading = true
  366. GetDataByName(this.see.getdataListParm).then(response => {
  367. console.log('table数据', response.data.list)
  368. if (response.data.list !== null) {
  369. this.see.list = response.data.list
  370. this.see.pageNum = response.data.pageNum
  371. this.see.pageSize = response.data.pageSize
  372. this.see.total = response.data.total
  373. } else {
  374. this.see.list = []
  375. }
  376. setTimeout(() => {
  377. this.see.listLoading = false
  378. }, 100)
  379. })
  380. },
  381. handleExport(item) {
  382. console.log('导出')
  383. if (item == 'tab1') {
  384. var excelDatas = [
  385. {
  386. tHeader: ['预混配方', '当前剩余量', '预计使用天数'],
  387. filterVal: ['pftname', 'stockweight', 'days'],
  388. tableDatas: this.tab1.list,
  389. sheetName: 'Sheet1'
  390. }
  391. ]
  392. json2excel(excelDatas, '预混记录', true, 'xlsx')
  393. } else {
  394. this.download.getdataListParm.name = 'getFsWarnList'
  395. GetDataByName(this.download.getdataListParm).then(response => {
  396. if (response.data.list !== null) {
  397. this.download.list = response.data.list
  398. } else {
  399. this.download.list = []
  400. }
  401. var excelDatas = [
  402. {
  403. tHeader: ['饲料名称', '库存量(kg)', '近七天平均计划量(kg)', '剩余使用天数', '最新预警日期'],
  404. filterVal: ['feedname', 'stockweight', 'avgweight', 'ldays', 'lastdate'],
  405. tableDatas: this.download.list,
  406. sheetName: 'Sheet1'
  407. }
  408. ]
  409. json2excel(excelDatas, '库存预警', true, 'xlsx')
  410. })
  411. }
  412. }
  413. }
  414. }
  415. </script>