271057d3a18c5e5a3104cd5c6c6e73817d44aa1a.svn-base 14 KB

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