86fd7b9d5549317ef2726274d5043111cb347818.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <div>
  3. <div class="table">
  4. <el-table
  5. :key="table.tableKey"
  6. v-loading="table.listLoading"
  7. element-loading-text="给我一点时间"
  8. :data="table.list"
  9. border
  10. fit
  11. highlight-current-row
  12. style="width: 100%;"
  13. :row-style="rowStyle"
  14. :cell-style="cellStyle"
  15. class="elTable table-fixed"
  16. :span-method="objectSpanMethod"
  17. >
  18. <el-table-column :key="1" label="序号" align="center" type="index" width="50px" class-name="small-padding fixed-width" fixed="left">
  19. <template slot-scope="scope">
  20. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column :key="2" label="栏舍名称" prop="barname" min-width="90px" align="center" />
  24. <el-table-column :key="3" label="班次" prop="times" min-width="90px" align="center" />
  25. <el-table-column :key="4" label="软件牛头数" prop="softccount" min-width="70px" align="center" />
  26. <el-table-column :key="5" label="实际牛头数" min-width="100px" align="center">
  27. <template slot-scope="scope">
  28. <span v-if="scope.row.NoEdit">{{ scope.row.ccount }}</span>
  29. <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)" />
  30. </template>
  31. </el-table-column>
  32. <el-table-column :key="6" label="系数" min-width="100px" align="center">
  33. <template slot-scope="scope">
  34. <span v-if="scope.row.NoEdit">{{ scope.row.ratio }}</span>
  35. <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)" />
  36. </template>
  37. </el-table-column>
  38. <el-table-column :key="7" label="系数头数(%)" min-width="100px" align="center">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.NoEdit">{{ scope.row.ccountratio }}</span>
  41. <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)" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column :key="8" label="配方模板" min-width="100px" align="center">
  45. <template slot-scope="scope">
  46. <span v-if="scope.row.NoEdit">{{ scope.row.ptname }}</span>
  47. <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)}">
  48. <el-option v-for="item in recipeTemplateList" :key="item.id" :label="item.tname" :value="item.id" />
  49. </el-select>
  50. </template>
  51. </el-table-column>
  52. <el-table-column v-if="table.isPtsfname" :key="9" label="补料配方" min-width="100px" align="center">
  53. <template slot-scope="scope">
  54. <span v-if="scope.row.NoEdit">{{ scope.row.ptsname }}</span>
  55. <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)}">
  56. <el-option v-for="item in feedingFormulaList" :key="item.id" :label="item.tname" :value="item.id" />
  57. </el-select>
  58. </template>
  59. </el-table-column>
  60. <el-table-column :key="10" label="班次比例" min-width="100px" align="center">
  61. <template slot-scope="scope">
  62. <span v-if="scope.row.NoEdit">{{ scope.row.tratio }}</span>
  63. <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)" />
  64. </template>
  65. </el-table-column>
  66. <el-table-column :key="11" label="班次重量" min-width="100px" align="center">
  67. <template slot-scope="scope">
  68. <span v-if="scope.row.NoEdit">{{ scope.row.weight }}</span>
  69. <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)" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column :key="12" label="配方重量" prop="pweight" min-width="85px" align="center" />
  73. <el-table-column v-if="table.isPtsfname" :key="13" label="补料重量" prop="ptweight" min-width="85px" align="center" />
  74. <el-table-column :key="14" label="配方干物质量" prop="dryweight" min-width="85px" align="center" />
  75. <el-table-column :key="15" label="饲喂干物质量" prop="swdryw" min-width="85px" align="center" />
  76. <el-table-column :key="16" label="采样干物质量" prop="cydryw" min-width="85px" align="center" />
  77. <el-table-column :key="17" label="日投喂量" prop="sumWeight" min-width="85px" align="center" />
  78. <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width" fixed="right">
  79. <template slot-scope="{row}">
  80. <!-- 编辑 -->
  81. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  82. <!-- 编辑保存 -->
  83. <el-button v-if="row.isUpdateSave" class="miniSuccess" :disabled="isokDisable" @click="updateData(row)">保存</el-button>
  84. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import { GetDataByName, GETNurJudge, GetDataByNames, compareSort, ExecDataByConfig, failproccess, PostDataByName, formatNum } from '@/api/common'
  94. import Pagination from '@/components/Pagination'
  95. import { parseTime, json2excel, handleTableSpan, handleObjectSpanMethod } from '@/utils/index.js'
  96. import { MessageBox } from 'element-ui'
  97. import Cookies from 'js-cookie'
  98. import { getToken } from '@/utils/auth'
  99. export default {
  100. name: 'DhedFormula',
  101. inject: ['reload'],
  102. components: { Pagination },
  103. props: {
  104. show: { type: Boolean, default: false },
  105. parentDate: {
  106. type: String,
  107. defalut: ''
  108. }
  109. },
  110. data() {
  111. return {
  112. date: '',
  113. requestParams: [
  114. { name: 'getFTSWList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  115. { name: 'getFTBLList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
  116. { name: 'getCowclassListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
  117. ],
  118. recipeTemplateList: [], // 配方模板
  119. feedingFormulaList: [], // 补料配方
  120. livestockTypeList: [], // 类别
  121. rules: {
  122. cowclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
  123. },
  124. table: {
  125. getdataListParm: {
  126. name: 'getPlanModifyFPlist',
  127. page: 1,
  128. offset: 1,
  129. pagecount: 10,
  130. returntype: 'Map',
  131. parammaps: {
  132. pastureid: Cookies.get('pastureid')
  133. }
  134. },
  135. tableKey: 0,
  136. list: [],
  137. total: 0,
  138. listLoading: true,
  139. temp: {},
  140. rwList: [],
  141. isPtsfname: false, // 补料配方/补料重量
  142. getdataListParm2: {
  143. name: 'getSysoptEnable',
  144. page: 1,
  145. offset: 1,
  146. pagecount: 1,
  147. returntype: 'Map',
  148. parammaps: {
  149. pastureid: Cookies.get('pastureid'),
  150. inforname: 'isEnableSupplyFeed'
  151. }
  152. }
  153. },
  154. requestParam: {},
  155. spanObj: {},
  156. mergekeys: ['barname', 'sumWeight'],
  157. isokDisable: false,
  158. rowStyle: { maxHeight: 50 + 'px', height: 35 + 'px' },
  159. cellStyle: { padding: 0 + 'px' }
  160. }
  161. },
  162. watch: {
  163. show: {
  164. immediate: true,
  165. handler(show) {
  166. this.visible = show
  167. }
  168. },
  169. parentDate: {
  170. immediate: true,
  171. handler(newVal, oldVal) {
  172. this.date = newVal
  173. }
  174. }
  175. },
  176. created() {
  177. this.getIsDisplay()
  178. this.getDownList()
  179. },
  180. methods: {
  181. // 下拉
  182. getDownList() {
  183. GetDataByNames(this.requestParams).then(response => {
  184. this.recipeTemplateList = response.data.getFTSWList.list
  185. this.feedingFormulaList = response.data.getFTBLList.list
  186. this.livestockTypeList = response.data.getCowclassListEnable.list
  187. })
  188. },
  189. // 补料是否显示
  190. getIsDisplay() {
  191. GetDataByName(this.table.getdataListParm2).then(response => {
  192. console.log(response.data.list[0].inforvalue)
  193. if (response.data.list !== null) {
  194. if (response.data.list[0].inforvalue == 0) {
  195. this.table.isPtsfname = false
  196. } else {
  197. this.table.isPtsfname = true
  198. }
  199. }
  200. })
  201. this.getList()
  202. },
  203. getList() {
  204. this.table.listLoading = true
  205. this.table.getdataListParm.parammaps.date = this.date
  206. GetDataByName(this.table.getdataListParm).then(response => {
  207. console.log('table数据', response.data.list)
  208. if (response.data.list !== null) {
  209. for (let i = 0; i < response.data.list.length; i++) {
  210. this.$set(response.data.list[i], 'Edit', false) // 编辑
  211. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  212. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  213. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  214. if (response.data.list[i].ptid == undefined || response.data.list[i].ptname == '') {
  215. this.$set(response.data.list[i], 'ptid', '')
  216. this.$set(response.data.list[i], 'ptname', '')
  217. }
  218. response.data.list[0].sumWeight = 2000
  219. response.data.list[1].sumWeight = 2000
  220. response.data.list[2].sumWeight = 2000
  221. response.data.list[3].sumWeight = 2000
  222. }
  223. this.table.list = response.data.list
  224. console.log(this.table.list, 'this.table.list')
  225. this.table.pageNum = response.data.pageNum
  226. this.table.pageSize = response.data.pageSize
  227. this.table.total = response.data.total
  228. this.handleSpan()
  229. } else {
  230. this.table.list = []
  231. }
  232. setTimeout(() => {
  233. this.table.listLoading = false
  234. }, 100)
  235. })
  236. },
  237. handleSpan() {
  238. this.mergekeys.forEach(key => {
  239. this.spanObj[key] = []
  240. let position = 0
  241. this.table.list.forEach((item, index) => {
  242. if (index === 0) {
  243. this.spanObj[key].push(1)
  244. position = 0
  245. } else {
  246. if (key == 'sumWeight') {
  247. if (this.table.list[index][key] === this.table.list[index - 1][key] && this.table.list[index]['barname'] === this.table.list[index - 1]['barname']) {
  248. this.spanObj[key][position] += 1
  249. this.spanObj[key].push(0)
  250. } else {
  251. this.spanObj[key].push(1)
  252. position = index
  253. }
  254. } else {
  255. if (this.table.list[index][key] === this.table.list[index - 1][key]) {
  256. this.spanObj[key][position] += 1
  257. this.spanObj[key].push(0)
  258. } else {
  259. this.spanObj[key].push(1)
  260. position = index
  261. }
  262. }
  263. }
  264. })
  265. })
  266. },
  267. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  268. for (let i = 0; i < this.mergekeys.length; i++) {
  269. if (column.property === this.mergekeys[i]) {
  270. const _row = this.spanObj[this.mergekeys[i]][rowIndex]
  271. const _col = _row > 0 ? 1 : 0
  272. return {
  273. rowspan: _row,
  274. colspan: _col
  275. }
  276. }
  277. }
  278. },
  279. handleUpdate(row) {
  280. console.log(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,编辑保存true
  291. row.isUpdate = false
  292. row.isUpdateSave = true
  293. if (row.ptsfid == '-1') {
  294. row.ptsfid = ''
  295. }
  296. row.ptsfid = String(row.ptsfid)
  297. this.table.temp.ptid = row.ptid
  298. this.table.temp.ptname = row.ptname
  299. this.table.temp.ptsfid = row.ptsfid
  300. this.table.temp.ptsfname = row.ptsfname
  301. row.sumWeight = ''
  302. row.Sfweight = this.recipeTemplateList.find(obj => obj.id == row.ptid).Sfweight// Sfweight
  303. // SfweightLock
  304. row.SfweightLock = this.recipeTemplateList.find(obj => obj.id == row.ptid).SfweightLock
  305. },
  306. // 实际牛头数
  307. blurCcount(row) {
  308. if (row.ccount !== '' && row.ratio !== '') {
  309. row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2)
  310. } else if (row.ratio !== '' && row.ccountratio !== '') {
  311. row.ccount = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ratio) / 100, 2)
  312. } else if (row.ccount !== '' || row.ratio !== '') {
  313. row.ccountratio = ''
  314. }
  315. if (this.table.isPtsfname == false) {
  316. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  317. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  318. row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2)
  319. } else {
  320. row.pweight = 0
  321. row.weight = 0
  322. }
  323. } else {
  324. if (row.supplyweight == 'NaN') {
  325. row.supplyweight = 0
  326. }
  327. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  328. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  329. row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2)
  330. } else {
  331. row.pweight = 0
  332. row.weight = 0
  333. }
  334. }
  335. },
  336. // 系数
  337. blurRatio(row) {
  338. if (row.ccount !== '' && row.ratio !== '' && row.ccountratio !== '') {
  339. row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2)
  340. } else if (row.ccount !== '' && row.ccountratio !== '') {
  341. row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2)
  342. } else if (row.ccount !== '' || row.ccountratio !== '') {
  343. row.ratio = ''
  344. }
  345. if (this.table.isPtsfname == false) {
  346. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  347. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  348. row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2)
  349. } else {
  350. row.pweight = 0
  351. row.weight = 0
  352. }
  353. } else {
  354. if (row.supplyweight == 'NaN') {
  355. row.supplyweight = 0
  356. }
  357. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  358. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  359. row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2)
  360. } else {
  361. row.pweight = 0
  362. row.weight = 0
  363. }
  364. }
  365. },
  366. // 系数头数
  367. // 系数头数=实际牛头数*系数*100%;
  368. blurCcountratio(row) {
  369. if (row.ccountratio !== '' && row.ccount !== '' && row.ratio !== '') {
  370. row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2)
  371. } else if (row.ccount !== '' && row.ratio !== '') {
  372. row.ccountratio = formatNum(parseFloat(row.ccount) * parseFloat(row.ratio) / 100, 2)
  373. } else if (row.ccountratio !== '' && row.ccount !== '') {
  374. row.ratio = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ccount), 2)
  375. } else if (row.ccountratio !== '' && row.ratio !== '') {
  376. row.ccount = formatNum(parseFloat(row.ccountratio) * 100 / parseFloat(row.ratio) / 100, 2)
  377. }
  378. if (this.table.isPtsfname == false) {
  379. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  380. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  381. row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2)
  382. } else {
  383. row.pweight = 0
  384. row.weight = 0
  385. }
  386. } else {
  387. if (row.supplyweight == 'NaN') {
  388. row.supplyweight = 0
  389. }
  390. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  391. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  392. row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2)
  393. } else {
  394. row.pweight = 0
  395. row.weight = 0
  396. }
  397. }
  398. },
  399. // 配方模板
  400. changeRecipeTemplate(item, row) {
  401. row.ptname = this.recipeTemplateList.find(obj => obj.id == item).tname
  402. // Sfweight
  403. row.Sfweight = this.recipeTemplateList.find(obj => obj.id == item).Sfweight// Sfweight
  404. // SfweightLock
  405. row.SfweightLock = this.recipeTemplateList.find(obj => obj.id == item).SfweightLock// SfweightLock
  406. console.log('Sfweight', row.Sfweight)
  407. console.log('SfweightLock', row.SfweightLock)
  408. if (this.table.isPtsfname == false) {
  409. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  410. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  411. row.weight = formatNum(parseFloat(row.pweight) * (parseFloat(row.tratio) / 100), 2)
  412. } else {
  413. row.pweight = 0
  414. row.weight = 0
  415. }
  416. } else {
  417. if (row.supplyweight == 'NaN') {
  418. row.supplyweight = 0
  419. }
  420. if (row.Sfweight !== '' && row.ccountratio !== '' && row.SfweightLock !== '' && row.ccount) {
  421. row.pweight = formatNum(parseFloat(row.Sfweight) * parseFloat(row.ccountratio) + parseFloat(row.SfweightLock) * parseFloat(row.ccount), 2)
  422. row.weight = formatNum((parseFloat(row.pweight) + parseFloat(row.supplyweight)) * (parseFloat(row.tratio) / 100), 2)
  423. } else {
  424. row.pweight = 0
  425. row.weight = 0
  426. }
  427. }
  428. },
  429. // 班次比例
  430. blurTratio(row) {
  431. if (row.pweight !== '' && row.ratio !== '' && row.tratio !== '') {
  432. row.weight = formatNum(parseFloat(row.pweight) * parseFloat(row.ratio) / 100 * parseFloat(row.tratio) / 100, 2)
  433. } else {
  434. row.weight = 0
  435. }
  436. },
  437. // 班次重量
  438. blurWeight(row) {
  439. if (row.weight !== '' && row.pweight !== '' && row.ratio !== '') {
  440. row.tratio = formatNum(parseFloat(row.weight) / parseFloat(row.pweight) * parseFloat(row.ratio), 2)
  441. } else {
  442. row.tratio = 0
  443. }
  444. },
  445. updateData(row) {
  446. console.log(row, '编辑保存')
  447. },
  448. updateCancel(row) {
  449. console.log('点击了编辑取消')
  450. // 编辑false,不可编辑true
  451. row.Edit = false
  452. row.NoEdit = true
  453. // 编辑true,编辑保存false
  454. row.isUpdate = true
  455. row.isUpdateSave = false
  456. console.log(this.table.getdataListParm.offset)
  457. this.table.getdataListParm.offset = this.table.getdataListParm.offset
  458. this.getList()
  459. }
  460. }
  461. }
  462. </script>
  463. <style>