<template> <div> <div class="table"> <el-table :key="table.tableKey" v-loading="table.listLoading" element-loading-text="给我一点时间" :data="table.list" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable" :span-method="objectSpanMethod" > <el-table-column :key="1" label="序号" align="center" type="index" width="50px" class-name="small-padding fixed-width" fixed="left"> <template slot-scope="scope"> <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span> </template> </el-table-column> <el-table-column :key="2" label="栏舍名称" prop="barname" min-width="90px" align="center" class-name="small-padding fixed-width" fixed="left" /> <el-table-column :key="3" label="班次" prop="times" min-width="90px" align="center" class-name="small-padding fixed-width" fixed="left" /> <el-table-column :key="4" label="软件牛头数" prop="softccount" min-width="70px" align="center" /> <el-table-column :key="5" label="实际牛头数" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.ccount }}</span> <el-input v-if="scope.row.Edit" v-model="scope.row.ccount" step="0.01" type="number" style="width:95%;padding:10px 0;" @blur="blurCcount(scope.row)" /> </template> </el-table-column> <el-table-column :key="6" label="系数(%)" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.ratio }}</span> <el-input v-if="scope.row.Edit" v-model="scope.row.ratio" step="0.01" type="number" style="width:95%;padding:10px 0;" @blur="blurRatio(scope.row)" /> </template> </el-table-column> <el-table-column :key="7" label="系数头数" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.ccountratio }}</span> <el-input v-if="scope.row.Edit" v-model="scope.row.ccountratio" step="0.01" type="number" style="width:95%;padding:10px 0;" @blur="blurCcountratio(scope.row)" /> </template> </el-table-column> <el-table-column :key="8" label="配方模板" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.ptname }}</span> <el-select v-if="scope.row.Edit" v-model="scope.row.ptid" filterable placeholder="配方模板" class="filter-item" style="width:99%;" @change="(value)=> {changeRecipeTemplate(value, scope.row)}"> <el-option v-for="item in recipeTemplateList" :key="item.id" :label="item.tname" :value="item.id" /> </el-select> </template> </el-table-column> <el-table-column v-if="table.isPtsfname" :key="9" label="补料配方" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.ptsname }}</span> <el-select v-if="scope.row.Edit" v-model="scope.row.ptsid" clearable filterable placeholder="补料配方" class="filter-item" style="width:95%;padding:10px 0;" @change="(value)=> {changeFeedingFormula(value, scope.row)}"> <el-option v-for="item in feedingFormulaList" :key="item.id" :label="item.tname" :value="item.id" /> </el-select> </template> </el-table-column> <el-table-column :key="10" label="班次比例(%)" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.tratio }}</span> <el-input v-if="scope.row.Edit" v-model="scope.row.tratio" :disabled="scope.row.isOneWeight" step="0.01" type="number" style="width:95%;padding:10px 0;" @blur="blurTratio(scope.row)" /> </template> </el-table-column> <el-table-column :key="11" label="班次重量" min-width="100px" align="center"> <template slot-scope="scope"> <span v-if="scope.row.NoEdit">{{ scope.row.weight }}</span> <el-input v-if="scope.row.Edit" v-model="scope.row.weight" :disabled="scope.row.isOneWeight" step="0.01" type="number" style="width:95%;padding:10px 0;" @blur="blurWeight(scope.row)" /> </template> </el-table-column> <el-table-column :key="12" label="配方重量" prop="pweight" min-width="85px" align="center" /> <el-table-column v-if="table.isPtsfname" :key="13" label="补料重量" prop="ptweight" min-width="85px" align="center" /> <el-table-column :key="14" label="配方干物质量" prop="dryweight" min-width="85px" align="center" /> <el-table-column :key="15" label="饲喂干物质量" prop="swdryw" min-width="85px" align="center" /> <el-table-column :key="16" label="采样干物质量" prop="cydryw" min-width="85px" align="center" /> <el-table-column :key="17" label="日投喂量" prop="sumweight" min-width="85px" align="center" /> <el-table-column label="操作" align="center" width="100" class-name="small-padding fixed-width" fixed="right"> <template slot-scope="{row}"> <!-- 编辑 --> <el-button v-if="row.isUpdate" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" /> <!-- 编辑保存 --> <el-button v-if="row.isUpdateSave" class="miniSuccess" :disabled="isokDisable" icon="el-icon-folder-checked" @click="updateData(row)" /> <el-button v-if="row.isUpdateSave" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" /> </template> </el-table-column> </el-table> <pagination2 v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" /> </div> </div> </template> <script> import { GetDataByName, GETNurJudge, GetDataByNames, compareSort, ExecDataByConfig, failproccess, PostDataByName, formatNum } from '@/api/common' import Pagination2 from '@/components/Pagination2' import { parseTime, json2excel, handleTableSpan, handleObjectSpanMethod } from '@/utils/index.js' import { MessageBox } from 'element-ui' import Cookies from 'js-cookie' import { getToken } from '@/utils/auth' export default { name: 'DhedFormula', inject: ['reload'], components: { Pagination2 }, props: { show: { type: Boolean, default: false }, parentDate: { type: String, defalut: '' } }, data() { return { date: '', requestParams: [ { name: 'getFTSWList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}, { name: 'getFTBLList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}, { name: 'getCowclassListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }} ], recipeTemplateList: [], // 配方模板 feedingFormulaList: [], // 补料配方 livestockTypeList: [], // 类别 rules: { cowclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }] }, table: { getdataListParm: { name: 'getPlanModifyFPlist', page: 1, offset: 1, pagecount: 12, returntype: 'Map', parammaps: { pastureid: Cookies.get('pastureid') } }, tableKey: 0, list: [], total: 0, listLoading: true, temp: {}, rwList: [], isPtsfname: false, // 补料配方/补料重量 getdataListParm2: { name: 'getSysoptEnable', page: 1, offset: 1, pagecount: 1, returntype: 'Map', parammaps: { pastureid: Cookies.get('pastureid'), inforname: 'isEnableSupplyFeed' } } }, requestParam: {}, spanObj: {}, mergekeys: ['barname', 'sumweight'], isokDisable: false, rowStyle: { maxHeight: 50 + 'px', height: 35 + 'px' }, cellStyle: { padding: 0 + 'px' } } }, watch: { show: { immediate: true, handler(show) { this.visible = show } }, parentDate: { immediate: true, handler(newVal, oldVal) { console.log(newVal, oldVal, 'newVal,oldVal') this.date = newVal } } }, created() { this.getIsDisplay() this.getDownList() }, methods: { // 下拉 getDownList() { GetDataByNames(this.requestParams).then(response => { this.recipeTemplateList = response.data.getFTSWList.list this.feedingFormulaList = response.data.getFTBLList.list this.livestockTypeList = response.data.getCowclassListEnable.list }) }, // 补料是否显示 getIsDisplay() { GetDataByName(this.table.getdataListParm2).then(response => { console.log(response.data.list[0].inforvalue) if (response.data.list !== null) { if (response.data.list[0].inforvalue == 0) { this.table.isPtsfname = false } else { this.table.isPtsfname = true } } }) this.getList() }, getList() { this.table.listLoading = true this.table.getdataListParm.parammaps.date = this.date GetDataByName(this.table.getdataListParm).then(response => { console.log('table数据', response.data.list) if (response.data.list !== null) { for (let i = 0; i < response.data.list.length; i++) { this.$set(response.data.list[i], 'Edit', false) // 编辑 this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入 this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作 this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存 if (response.data.list[i].ptid == undefined || response.data.list[i].ptname == '') { this.$set(response.data.list[i], 'ptid', '') this.$set(response.data.list[i], 'ptname', '') } if (response.data.list[i].ratio == undefined) { this.$set(response.data.list[i], 'ratio', '') } if (response.data.list[i].ccount == undefined) { this.$set(response.data.list[i], 'ccount', '') } if (response.data.list[i].ccountratio == undefined) { this.$set(response.data.list[i], 'ccountratio', '') } } this.table.list = response.data.list console.log(this.table.list, 'this.table.list') this.table.pageNum = response.data.pageNum this.table.pageSize = response.data.pageSize this.table.total = response.data.total this.handleSpan() } else { this.table.list = [] } setTimeout(() => { this.table.listLoading = false }, 100) }) }, handleSpan() { this.mergekeys.forEach(key => { this.spanObj[key] = [] let position = 0 this.table.list.forEach((item, index) => { if (index === 0) { this.spanObj[key].push(1) position = 0 } else { if (key == 'sumweight') { if (this.table.list[index][key] === this.table.list[index - 1][key] && this.table.list[index]['barname'] === this.table.list[index - 1]['barname']) { this.spanObj[key][position] += 1 this.spanObj[key].push(0) } else { this.spanObj[key].push(1) position = index } } else { if (this.table.list[index][key] === this.table.list[index - 1][key]) { this.spanObj[key][position] += 1 this.spanObj[key].push(0) } else { this.spanObj[key].push(1) position = index } } } }) }) }, objectSpanMethod({ row, column, rowIndex, columnIndex }) { for (let i = 0; i < this.mergekeys.length; i++) { if (column.property === this.mergekeys[i]) { const _row = this.spanObj[this.mergekeys[i]][rowIndex] const _col = _row > 0 ? 1 : 0 return { rowspan: _row, colspan: _col } } } }, handleUpdate(row) { console.log(row) for (let i = 0; i < this.table.list.length; i++) { if (this.table.list[i].Edit == true) { this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 }) return false } } // 编辑true,不可编辑false row.Edit = true row.NoEdit = false // 编辑false,编辑保存true row.isUpdate = false row.isUpdateSave = true if (row.ptsfid == '-1') { row.ptsfid = '' } row.ptsfid = String(row.ptsfid) this.table.temp.ptid = row.ptid this.table.temp.ptname = row.ptname this.table.temp.ptsfid = row.ptsfid this.table.temp.ptsfname = row.ptsfname // row.sumweight = '' row.Sfweight = this.recipeTemplateList.find(obj => obj.id == row.ptid).Sfweight// Sfweight // SfweightLock row.SfweightLock = this.recipeTemplateList.find(obj => obj.id == row.ptid).SfweightLock }, // 实际牛头数 blurCcount(row) { if (row.ccount !== '' && row.ratio !== '') { row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2) } else if (row.ratio !== '' && row.ccountratio !== '') { row.ccount = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ratio) / 100, 2) } else if (row.ccount !== '' || row.ratio !== '') { row.ccountratio = '' } if (this.table.isPtsfname == false) { if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // 软件牛头数softccount实际牛头数ccount系数(%)ratio系数头数ccountratio // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) // row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } else { if (row.supplyweight == 'NaN') { row.supplyweight = 0 } if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) // row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } this.getSumWeight(row) }, // 系数 blurRatio(row) { if (row.ccount !== '' && row.ratio !== '') { row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2) } else if (row.ccount !== '' && row.ccountratio !== '') { row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2) } else if (row.ccount !== '' || row.ccountratio !== '') { row.ratio = '' } if (this.table.isPtsfname == false) { if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } else { if (row.supplyweight == 'NaN') { row.supplyweight = 0 } if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } this.getSumWeight(row) }, // 系数头数 // 系数头数=实际牛头数*系数*100%; blurCcountratio(row) { if (row.ccountratio !== '' && row.ccount !== '' && row.ratio !== '') { row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2) } else if (row.ccount !== '' && row.ratio !== '') { row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2) } else if (row.ccountratio !== '' && row.ccount !== '') { row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2) } else if (row.ccountratio !== '' && row.ratio !== '') { row.ccount = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ratio) / 100, 2) } if (this.table.isPtsfname == false) { if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } else { if (row.supplyweight == 'NaN') { row.supplyweight = 0 } if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } this.getSumWeight(row) }, getSumWeight(row) { var barArr = [] for (let i = 0; i < this.table.list.length; i++) { if (row.barid == this.table.list[i].barid) { barArr.push(this.table.list[i].weight) } } // console.log(barArr, 'barArr') var sumw = 0 for (let i = 0; i < barArr.length; i++) { sumw += parseFloat(barArr[i]) } // console.log(sumw, 'sumw') for (let i = 0; i < this.table.list.length; i++) { if (row.barid == this.table.list[i].barid) { this.table.list[i].sumweight = formatNum(sumw, 2) } } }, // 配方模板 changeRecipeTemplate(item, row) { row.ptname = this.recipeTemplateList.find(obj => obj.id == item).tname // Sfweight row.Sfweight = this.recipeTemplateList.find(obj => obj.id == item).Sfweight// Sfweight // SfweightLock row.SfweightLock = this.recipeTemplateList.find(obj => obj.id == item).SfweightLock// SfweightLock console.log('Sfweight', row.Sfweight) console.log('SfweightLock', row.SfweightLock) if (this.table.isPtsfname == false) { if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } else { if (row.supplyweight == 'NaN') { row.supplyweight = 0 } if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) { // row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccount) * parseFloat(row.ratio) / 100 + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2) row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2) } else { row.pweight = 0 row.weight = 0 } } this.getSumWeight(row) }, // 班次比例 blurTratio(row) { if (row.pweight !== '' && row.tratio !== '') { row.weight = formatNum(parseFloat(row.pweight) * parseFloat(row.tratio) / 100, 2) } else { row.weight = 0 } this.getSumWeight(row) }, // 班次重量 blurWeight(row) { if (row.weight !== '' && row.pweight !== '' && row.ratio !== '') { // row.tratio = formatNum(parseFloat(row.weight) / parseFloat(row.pweight) * parseFloat(row.ratio), 0) // row.tratio = formatNum(parseFloat(row.pweight) / parseFloat(row.weight), 0) row.tratio = formatNum(parseFloat(row.weight) / parseFloat(row.pweight) * 100, 0) } else { row.tratio = 0 } }, updateData(row) { console.log(row, '编辑保存') this.isokDisable = true setTimeout(() => { this.isokDisable = false }, 5000) const positiveInteger = /^[1-9]\d*$/ if (row.ccount !== '') { if (!positiveInteger.test(parseFloat(row.ccount))) { this.$message({ type: 'error', message: '实际牛头数请输入正整数', duration: 2000 }) return false } } else { this.$message({ type: 'error', message: '实际牛头数不能为空', duration: 2000 }) } const positiveNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/ if (row.ratio !== '') { if (!positiveNumber.test(parseFloat(row.ratio))) { this.$message({ type: 'error', message: '系数请输入正数', duration: 2000 }) return false } } else { this.$message({ type: 'error', message: '系数不能为空', duration: 2000 }) } if (row.ccountratio !== '') { if (!positiveNumber.test(parseFloat(row.ccountratio))) { this.$message({ type: 'error', message: '系数头数请输入正数', duration: 2000 }) return false } } else { this.$message({ type: 'error', message: '系数头数不能为空', duration: 2000 }) } this.requestParam = {} this.requestParam.common = { 'returnmap': '0' } this.requestParam.data = [] this.requestParam.data[0] = { 'name': 'updatePlanModifyFPlist', 'type': 'e', 'parammaps': { pastureid: row.pastureid, date: this.date, id: row.id, ptweight: row.ptweight, pweight: row.pweight, weight: row.weight, tratio: row.tratio, cowcount: row.ccount, ccountradio: row.ratio, ptid: row.ptid, ptsid: row.ptsid }} this.requestParam.data[1] = { 'name': 'updateLPPbyFPChangedate', 'type': 'e', 'parammaps': { pastureid: row.pastureid, fpid: row.fpid, date: this.date, timesin: row.timesin }} ExecDataByConfig(this.requestParam).then(response => { if (response.msg === 'fail') { this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 }) } else { this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 }) this.getList() } }) }, updateCancel(row) { console.log('点击了编辑取消') // 编辑false,不可编辑true row.Edit = false row.NoEdit = true // 编辑true,编辑保存false row.isUpdate = true row.isUpdateSave = false console.log(this.table.getdataListParm.offset) this.table.getdataListParm.offset = this.table.getdataListParm.offset this.getList() } } } </script> <style>