index改.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  5. <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
  6. <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
  7. <el-select v-model="table.getdataListParm.parammaps.cowclassid" placeholder="牲畜类别" class="filter-item" style="width: 150px;" clearable>
  8. <el-option v-for="item in livestockTypeList" :key="item.value" :label="item.label" :value="item.value" />
  9. </el-select>
  10. <el-select v-model="table.getdataListParm.parammaps.feedid" placeholder="饲料名称" class="filter-item" style="width: 150px;" filterable clearable>
  11. <el-option v-for="item in feedNameList" :key="item.id" :label="item.fname" :value="item.id" />
  12. </el-select>
  13. <el-select v-model="table.getdataListParm.parammaps.ischarge" placeholder="是否预混料" class="filter-item" style="width: 150px;" clearable>
  14. <el-option v-for="item in isPremixList" :key="item.id" :label="item.name" :value="item.id" />
  15. </el-select>
  16. <el-select v-model="table.getdataListParm.parammaps.ischarge" placeholder="是否审核" class="filter-item" style="width: 150px;" clearable>
  17. <el-option v-for="item in isAuditList" :key="item.id" :label="item.name" :value="item.id" />
  18. </el-select>
  19. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  20. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  21. </div>
  22. <div class="operation">
  23. <el-button v-if="isRoleEdit" class="success" icon="el-icon-document-checked" @click="handleExamine">审核</el-button>
  24. <el-button class="export" icon="el-icon-upload2" style="float: right;margin-right: 10px;" @click="handleExport">导出</el-button>
  25. </div>
  26. <div class="table">
  27. <el-table
  28. :key="table.tableKey"
  29. v-loading="table.listLoading"
  30. element-loading-text="给我一点时间"
  31. :data="table.list"
  32. border
  33. fit
  34. highlight-current-row
  35. style="width: 100%;"
  36. :row-style="rowStyle"
  37. :cell-style="cellStyle"
  38. class="elTable table-fixed"
  39. @selection-change="handleSelectionChange"
  40. >
  41. <el-table-column type="selection" align="center" width="50" />
  42. <el-table-column label="序号" align="center" type="index" width="50px">
  43. <template slot-scope="scope">
  44. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="业务日期" min-width="100px" align="center">
  48. <template slot-scope="scope">
  49. <span>{{ scope.row.usedate }}</span>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="牲畜类别" min-width="100px" align="center">
  53. <template slot-scope="scope">
  54. <span>{{ scope.row.cowclass }}</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="饲料名称" min-width="100px" align="center">
  58. <template slot-scope="scope">
  59. <span>{{ scope.row.feedname }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="是否预混料" min-width="60px" align="center">
  63. <template slot-scope="scope">
  64. <span v-if="scope.row.premix == 0">否</span>
  65. <span v-else>是</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="库存重量(kg)" min-width="100px" align="center">
  69. <template slot-scope="scope">
  70. <span>{{ scope.row.repertoryweight }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="计划重量(kg)" min-width="100px" align="center">
  74. <template slot-scope="scope">
  75. <span>{{ scope.row.planweight }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="设备实测重量(kg)" min-width="150px" align="center">
  79. <template slot-scope="scope">
  80. <span>{{ scope.row.actweight }}</span>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="出库重量(kg)" min-width="130px" align="center">
  84. <template slot-scope="scope">
  85. <span v-if="scope.row.NoEdit">{{ scope.row.operateweight }}</span>
  86. <el-input v-if="scope.row.Edit" v-model="scope.row.operateweight" placeholder="最多保留两位小数" type="number" :step="0.01" style="width:95%;padding:10px 0;" />
  87. </template>
  88. </el-table-column>
  89. <el-table-column label="备注" min-width="70px" align="center">
  90. <template slot-scope="scope">
  91. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  92. <el-input v-if="scope.row.Edit" v-model="scope.row.remark" placeholder="1-32个字符" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="是否审核" min-width="70px" align="center">
  96. <template slot-scope="scope">
  97. <span v-if="scope.row.ischarge == 1">是</span>
  98. <span v-else>否</span>
  99. </template>
  100. </el-table-column>
  101. <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
  102. <template slot-scope="{row}">
  103. <el-button v-if="row.isUpdate && row.ischarge !== 1 && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
  104. <el-button v-if="row.isUpdateSave" :disabled="isokDisable" class="miniSuccess" icon="el-icon-folder-checked" @click="updateData(row)" />
  105. <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />
  106. <el-button v-if="row.ischarge == 1 && isRoleEdit" class="miniSuccess" icon="el-icon-refresh-left" @click="handleRevoke(row)" />
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  111. </div>
  112. </div>
  113. </template>
  114. <script>
  115. import { GetDataByName, GetDataByNames, checkButtons, PostDataByName, failproccess, ExecDataByConfig } from '@/api/common'
  116. import Pagination from '@/components/Pagination'
  117. import { MessageBox } from 'element-ui'
  118. import Cookies from 'js-cookie'
  119. import { parseTime, json2excel } from '@/utils/index.js'
  120. export default {
  121. name: 'SystemConsumption',
  122. components: { Pagination },
  123. data() {
  124. return {
  125. isPremixList:[{ id: '1', name: '是' }, { id: '0', name: '否' }],//是否预混料
  126. livestockTypeList: [], // 牲畜类别
  127. feedNameList: [{ id: 0, name: '羊草' }, { id: 1, name: '小苏打' }], // 饲料名称
  128. isAuditList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否审核
  129. requestParams: [
  130. { name: 'getFeedListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  131. { name: 'getDictByName', offset: 0, pagecount: 0, params: ['牲畜父类'] }
  132. ],
  133. table: {
  134. getdataListParm: {
  135. name: 'getFeeduseList',
  136. page: 1,
  137. offset: 1,
  138. pagecount: parseInt(Cookies.get('pageCount')),
  139. returntype: 'Map',
  140. parammaps: {
  141. inputDatetime: '',
  142. pastureid: Cookies.get('pastureid'),
  143. startTime: '',
  144. stopTime: '',
  145. usetype: '系统用量',
  146. feedid: '',
  147. cowclassid: '',
  148. ischarge: ''
  149. }
  150. },
  151. tableKey: 0,
  152. list: [],
  153. total: 0,
  154. listLoading: true
  155. },
  156. selectList: [],
  157. requestParam: {},
  158. download: {
  159. getdataListParm: {
  160. name: 'getFeeduseList',
  161. page: 1,
  162. offset: 1,
  163. pagecount: 0,
  164. returntype: 'Map',
  165. parammaps: {
  166. inputDatetime: '',
  167. pastureid: Cookies.get('pastureid'),
  168. startTime: '',
  169. stopTime: '',
  170. usetype: '系统用量',
  171. feedid: '',
  172. cowclassid: '',
  173. ischarge: ''
  174. }
  175. },
  176. list: []
  177. },
  178. isokDisable: false,
  179. isRoleEdit: [],
  180. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  181. cellStyle: { padding: 0 + 'px' }
  182. }
  183. },
  184. created() {
  185. this.getButtons()
  186. this.getDownList()
  187. this.getList()
  188. },
  189. methods: {
  190. getButtons() {
  191. const Edit = 'SystemConsumption'
  192. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  193. this.isRoleEdit = isRoleEdit
  194. },
  195. getDownList() {
  196. GetDataByNames(this.requestParams).then(response => {
  197. this.feedNameList = response.data.getFeedListEnable.list
  198. this.livestockTypeList = response.data.getDictByName.list
  199. })
  200. },
  201. handleBefore() {
  202. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  203. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
  204. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
  205. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  206. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  207. this.$forceUpdate()
  208. }
  209. },
  210. handleNext() {
  211. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  212. var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
  213. var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
  214. this.table.getdataListParm.parammaps.inputDatetime.length = 0
  215. this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
  216. this.$forceUpdate()
  217. }
  218. },
  219. getList() {
  220. this.table.listLoading = true
  221. GetDataByName(this.table.getdataListParm).then(response => {
  222. console.log('table数据', response.data.list)
  223. if (response.data.list !== null) {
  224. for (let i = 0; i < response.data.list.length; i++) {
  225. this.$set(response.data.list[i], 'Edit', false) // 编辑
  226. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  227. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  228. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  229. }
  230. this.table.list = response.data.list
  231. this.table.pageNum = response.data.pageNum
  232. this.table.pageSize = response.data.pageSize
  233. this.table.total = response.data.total
  234. } else {
  235. this.table.list = []
  236. }
  237. setTimeout(() => {
  238. this.table.listLoading = false
  239. }, 100)
  240. })
  241. },
  242. handleSearch() {
  243. console.log('点击了查询')
  244. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  245. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  246. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  247. } else {
  248. this.table.getdataListParm.parammaps.inputDatetime = ''
  249. this.table.getdataListParm.parammaps.startTime = ''
  250. this.table.getdataListParm.parammaps.stopTime = ''
  251. }
  252. this.table.getdataListParm.offset = 1
  253. this.getList()
  254. },
  255. handleRefresh() {
  256. console.log('点击了重置')
  257. this.table.getdataListParm.parammaps.inputDatetime = ''
  258. this.table.getdataListParm.parammaps.startTime = ''
  259. this.table.getdataListParm.parammaps.stopTime = ''
  260. this.table.getdataListParm.parammaps.feedid = ''
  261. this.table.getdataListParm.parammaps.cowclassid = ''
  262. this.table.getdataListParm.parammaps.ischarge = ''
  263. this.table.getdataListParm.offset = 1
  264. this.getList()
  265. },
  266. handleUpdate(row) {
  267. for (let i = 0; i < this.table.list.length; i++) {
  268. if (this.table.list[i].Edit == true) {
  269. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  270. return false
  271. }
  272. }
  273. // 编辑true,不可编辑false
  274. row.Edit = true
  275. row.NoEdit = false
  276. // 编辑false,编辑保存true
  277. row.isUpdate = false
  278. row.isUpdateSave = true
  279. },
  280. updateData(row) {
  281. console.log('点击了编辑保存', row)
  282. this.isokDisable = true
  283. setTimeout(() => {
  284. this.isokDisable = false
  285. }, 1000)
  286. this.requestParam.name = 'updateFeeduse'
  287. this.requestParam.parammaps = {}
  288. this.requestParam.parammaps.pastureid = row.pastureid
  289. this.requestParam.parammaps.id = row.id
  290. this.requestParam.parammaps.remark = row.remark
  291. this.requestParam.parammaps.operateweight = row.operateweight
  292. PostDataByName(this.requestParam).then(response => {
  293. console.log('新增保存发送参数', this.requestParam)
  294. if (response.msg !== 'fail') {
  295. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  296. this.getList()
  297. } else {
  298. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  299. }
  300. })
  301. },
  302. updateCancel(row) {
  303. console.log('点击了编辑取消')
  304. // 编辑false,不可编辑true
  305. row.Edit = false
  306. row.NoEdit = true
  307. // 编辑true,编辑保存false
  308. row.isUpdate = true
  309. row.isUpdateSave = false
  310. this.getList()
  311. },
  312. handleRevoke(row){
  313. MessageBox.confirm('请确认是否要撤销审核结果?', '提示', {
  314. confirmButtonText: '是', cancelButtonText: '否', type: 'warning'
  315. }).then(() => {
  316. console.log('点击了撤销')
  317. })
  318. },
  319. handleSelectionChange(val) {
  320. console.log('勾选数据', val)
  321. this.selectList = val
  322. },
  323. handleExamine() {
  324. if (this.selectList.length == 0) {
  325. this.$message({ type: 'error', message: '请选择需要审核的单据', duration: 2000 })
  326. } else {
  327. for (let i = 0; i < this.selectList.length; i++) {
  328. if (this.selectList[i].ischarge == 1) {
  329. this.$message({ type: 'error', message: '单据不可重复审核,请重新选择', duration: 2000 })
  330. return
  331. }
  332. }
  333. MessageBox.confirm('是否确认审核系统用量?', '提示', {
  334. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  335. }).then(() => {
  336. this.requestParam.common = { 'returnmap': '0' }
  337. this.requestParam.data = []
  338. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  339. this.requestParam.data[0].children = []
  340. this.requestParam.data[0].children[0] = { 'name': 'insertFeedstorageUse', 'type': 'e', 'parammaps': {
  341. snowid: '@insertSpotList.snowid',
  342. pastureid: '@insertSpotList.pastureid',
  343. feedid: '@insertSpotList.feedid',
  344. fname: '@insertSpotList.fname',
  345. pcpde: '@insertSpotList.pcpde',
  346. operateweight: '@insertSpotList.operateweight',
  347. price: '@insertSpotList.price'
  348. }}
  349. this.requestParam.data[0].children[1] = { 'name': 'chargeFeedstorageuse', 'type': 'e', 'parammaps': {
  350. id: '@insertSpotList.id',
  351. pastureid: '@insertSpotList.pastureid',
  352. operateweight: '@insertSpotList.operateweight'
  353. }}
  354. ExecDataByConfig(this.requestParam).then(response => {
  355. console.log('审核保存发送参数', this.requestParam)
  356. if (response.msg === 'fail') {
  357. this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
  358. } else {
  359. this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
  360. this.getList()
  361. }
  362. })
  363. })
  364. }
  365. },
  366. handleExport() {
  367. console.log('点击了导出')
  368. this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
  369. if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
  370. this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  371. this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  372. } else {
  373. this.download.getdataListParm.parammaps.inputDatetime = ''
  374. this.download.getdataListParm.parammaps.startTime = ''
  375. this.download.getdataListParm.parammaps.stopTime = ''
  376. }
  377. GetDataByName(this.download.getdataListParm).then(response => {
  378. if (response.data.list !== null) {
  379. for (let i = 0; i < response.data.list.length; i++) {
  380. if (response.data.list[i].ischarge == 1) {
  381. response.data.list[i].ischarge = '是'
  382. } else {
  383. response.data.list[i].ischarge = '否'
  384. }
  385. }
  386. this.download.list = response.data.list
  387. } else {
  388. this.download.list = []
  389. }
  390. var excelDatas = [
  391. {
  392. tHeader: ['业务日期', '牲畜类别', '饲料名称', '库存重量(kg)', '计划重量(kg)', '设备实测重量(kg)', '出库重量(kg)', '备注', '是否审核'],
  393. filterVal: ['usedate', 'cowclass', 'feedname', 'repertoryweight', 'planweight', 'actweight', 'operateweight', 'remark', 'ischarge'],
  394. tableDatas: this.download.list,
  395. sheetName: 'Sheet1'
  396. }
  397. ]
  398. json2excel(excelDatas, '系统用量', true, 'xlsx')
  399. })
  400. }
  401. }
  402. }
  403. </script>
  404. <style lang="scss" scoped>
  405. .operation{margin-top:10px;}
  406. .search{margin-top:10px;}
  407. .table{margin-top:10px;}
  408. </style>