plantTable.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div>
  3. <el-table
  4. :data="tableData"
  5. class="plant-table"
  6. border>
  7. >
  8. <el-table-column
  9. v-for="item in tableColums"
  10. :key="item.label"
  11. :label="item.label"
  12. :width="item.widthsty"
  13. :min-width="item.minwidthsty"
  14. align="center"
  15. >
  16. <template #header>
  17. <span>
  18. {{item.label}}
  19. <el-tooltip :content="item.tip" placement="top">
  20. <i class="el-icon-warning" v-if="item.tip"></i>
  21. </el-tooltip>
  22. </span>
  23. </template>
  24. <template slot-scope="{row}">
  25. <template v-if="$route.query.type!=='look'">
  26. <!-- 地点 -->
  27. <span v-if="item.key==='address'">
  28. <v-distpicker
  29. :province="row.Province"
  30. :city="row.City"
  31. :province-source="province_sorce"
  32. :city-source="city_sorce"
  33. hide-area
  34. @selected="changeArea($event,row)"
  35. />
  36. </span>
  37. <!-- 工厂 -->
  38. <span v-else-if="item.key==='FactoryName'">
  39. <el-input
  40. v-model="row.FactoryName"
  41. class="large-sty"
  42. placeholder="请输入工厂"
  43. @change="saveHandle(row)"
  44. />
  45. </span>
  46. <!-- 装置 -->
  47. <span v-else-if="item.key==='PlantName'">
  48. <el-input
  49. v-model="row.PlantName"
  50. class="large-sty"
  51. placeholder="请输入装置/产线"
  52. @change="saveHandle(row)"
  53. />
  54. </span>
  55. <!-- 年产能 -->
  56. <span v-else-if="item.key==='AnnualCapacity'">
  57. <el-input
  58. v-model="row.AnnualCapacity"
  59. type="number"
  60. class="large-sty"
  61. placeholder="请输入年产能"
  62. @change="changeParams(row)"
  63. />
  64. </span>
  65. <!-- 检修日期 -->
  66. <span v-else-if="item.key==='MaintenanceDate'">
  67. <el-date-picker
  68. v-model="row.MaintenanceDate"
  69. type="date"
  70. value-format="yyyy-MM-dd"
  71. placeholder="检修日期"
  72. @change="changeDate(row)"
  73. style="width: 140px"
  74. />
  75. </span>
  76. <!-- 复产日期 -->
  77. <span v-else-if="item.key==='ResumptionDate'">
  78. <el-date-picker
  79. v-model="row.ResumptionDate"
  80. type="date"
  81. value-format="yyyy-MM-dd"
  82. placeholder="复产日期"
  83. style="width: 140px"
  84. @change="() => {row.IsStop=0;changeDate(row)} "
  85. />
  86. <el-checkbox v-model="row.IsStop" @change="changeStopStatus($event,row)" :true-label="1" :false-label="0">退市</el-checkbox>
  87. </span>
  88. <!-- 降负系数 -->
  89. <span v-else-if="item.key==='Coefficient'">
  90. <el-input
  91. v-model="row.Coefficient"
  92. type="number"
  93. placeholder="请输入降负系数"
  94. class="large-sty"
  95. @change="changeParams(row)"
  96. />
  97. </span>
  98. <!-- 日均产量 -->
  99. <span v-else-if="item.key==='AverageDailyCapacityReductionTon'">
  100. <el-input
  101. v-model="row.AverageDailyCapacityReductionTon"
  102. type="number"
  103. class="large-sty"
  104. placeholder="请输入日均产量减量"
  105. @change="()=> { row.AverageDailyCapacityReduction=row.AverageDailyCapacityReductionTon/10000;saveHandle(row)}"
  106. />
  107. </span>
  108. <span v-else-if="['Day','CapacityReduction'].includes(item.key)">
  109. {{(row.MaintenanceDate&&row.ResumptionDate&&!row.IsStop)?row[item.key]:'--'}}
  110. </span>
  111. <span v-else>{{row[item.key]}}</span>
  112. </template>
  113. <!-- 查看 -->
  114. <template v-else>
  115. <span v-if="item.key==='address'">{{row.Province===row.City?row.City:row.Province+row.City}}</span>
  116. <span v-else-if="item.key==='ResumptionDate'">{{row.IsStop?'停产':row.ResumptionDate}}</span>
  117. <span v-else-if="['Day','CapacityReduction'].includes(item.key)">
  118. {{(row.MaintenanceDate&&row.ResumptionDate&&!row.IsStop)?row[item.key] :'--'}}
  119. </span>
  120. <span v-else>{{row[item.key]}}</span>
  121. </template>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="操作" align="center" v-if="$route.query.type!=='look'" width="200">
  125. <template slot-scope="scope">
  126. <el-button type="text" @click="addRow(scope,'copy')">复制</el-button>
  127. <el-button type="text" @click="addRow(scope,'prev')">向上添加</el-button>
  128. <el-button type="text" @click="addRow(scope,'next')">向下添加</el-button>
  129. <span @click="delPlant(scope.row,scope.$index)" class="deletesty">删除</span>
  130. <el-button type="text" @click="addOtherPlantHandle(scope.row.VarietyPlantId)">添加其他装置</el-button>
  131. </template>
  132. </el-table-column>
  133. <div slot="empty" style="padding: 20px 0">
  134. <tableNoData text="暂无信息" size="mini"/>
  135. </div>
  136. </el-table>
  137. <!-- 添加其他装置 -->
  138. <addOtherPlantDia
  139. :isShow.sync="isAddOtherPlantDialog"
  140. :plantId="plantId"
  141. @success="$emit('getData')"
  142. />
  143. </div>
  144. </template>
  145. <script>
  146. import{province_sorce,city_sorce} from '@/utils/distpicker';
  147. import * as supplyApi from '@/api/modules/supplyApi.js';
  148. import addOtherPlantDia from './addOtherPlantDia.vue';
  149. import * as $calculate from '@/utils/calculate.js'
  150. export default {
  151. props: {
  152. data: Array
  153. },
  154. components: {addOtherPlantDia},
  155. watch: {
  156. data(nval) {
  157. this.tableData = nval.length ? nval : this.initTable;
  158. }
  159. },
  160. data() {
  161. return {
  162. province_sorce,
  163. city_sorce,
  164. tableData: this.data,
  165. tableColums: [
  166. {
  167. label: '地点',
  168. key: 'address',
  169. minwidthsty: '120px'
  170. },
  171. {
  172. label: '工厂',
  173. key: 'FactoryName'
  174. },
  175. {
  176. label: '装置/产线',
  177. key: 'PlantName'
  178. },
  179. {
  180. label: '年产能(万吨)',
  181. key: 'AnnualCapacity'
  182. },
  183. {
  184. label: '检修日期',
  185. key: 'MaintenanceDate',
  186. widthsty: '150px'
  187. },
  188. {
  189. label: '复产日期',
  190. key: 'ResumptionDate',
  191. tip: '默认检修结束日期为复产日期',
  192. widthsty: '220px'
  193. },
  194. {
  195. label: '降负系数',
  196. key: 'Coefficient',
  197. widthsty: '80px',
  198. tip: '1表示停产,0.1表示降负10%'
  199. },
  200. {
  201. label: '日均产量减量(吨)',
  202. key: 'AverageDailyCapacityReductionTon',
  203. widthsty: '100px',
  204. },
  205. {
  206. label: '时长',
  207. key: 'Day',
  208. widthsty: '80px',
  209. },
  210. {
  211. label: '期间减量(万吨)',
  212. key: 'CapacityReduction',
  213. widthsty: '80px',
  214. },
  215. ],
  216. initTable: [{
  217. VarietyPlantId: 0,
  218. Province: '',
  219. City: '',
  220. FactoryName: '',
  221. PlantName: '',
  222. MaintenanceDate: '',
  223. ResumptionDate: '',
  224. AnnualCapacity: 0,
  225. Coefficient: 1,
  226. AverageDailyCapacityReduction: 0,
  227. AverageDailyCapacityReductionTon: 0,
  228. Day: 0,
  229. CapacityReduction: 0,
  230. Button: {
  231. Edit: true,
  232. Delete: true
  233. }
  234. }],
  235. insertIndex: {
  236. PrevVarietyPlantId: 0,
  237. NextVarietyPlantId: 0
  238. },
  239. /* 添加其他装置弹窗 */
  240. isAddOtherPlantDialog: false,
  241. plantId: 0,
  242. }
  243. },
  244. methods: {
  245. async delPlant({VarietyPlantId},index) {
  246. if(VarietyPlantId) {
  247. await this.$confirm('删除后不可恢复,确认删除吗?','提示',{ type: 'warning' })
  248. const res = await supplyApi.delPlant({VarietyPlantId});
  249. if(res.Ret !== 200) return
  250. this.$message.success('删除成功');
  251. this.$emit('getData')
  252. }else {
  253. this.tableData.splice(index,1)
  254. }
  255. },
  256. /* 日期改变 */
  257. changeDate(row) {
  258. const { ResumptionDate,MaintenanceDate } = row;
  259. if(MaintenanceDate && ResumptionDate && new Date(ResumptionDate).getTime() <= new Date(MaintenanceDate).getTime()) {
  260. this.$message.warning('复产日期不得早于检修日期 ')
  261. row.ResumptionDate = '';
  262. return
  263. }
  264. this.saveHandle(row);
  265. },
  266. /* 地区改变 */
  267. changeArea(area,row) {
  268. row.City = area.city.value;
  269. row.Province = area.province.value;
  270. this.saveHandle(row);
  271. },
  272. /* 停产 */
  273. changeStopStatus(val,row) {
  274. if(val) row.ResumptionDate = '';
  275. this.saveHandle(row);
  276. },
  277. /* 产能改变 */
  278. changeParams(row) {
  279. const { Coefficient,AnnualCapacity } = row;
  280. row.AverageDailyCapacityReduction = AnnualCapacity/Number(this.$parent.varietyInfo.ProductionDay)*Coefficient;
  281. row.AverageDailyCapacityReductionTon = $calculate.multiply(row.AverageDailyCapacityReduction,10000);
  282. this.saveHandle(row);
  283. },
  284. /* 添加行 */
  285. addRow({row,$index},type) {
  286. const row_item = type === 'copy' ? {
  287. ...row,
  288. VarietyPlantId: 0
  289. } : {
  290. VarietyPlantId: 0,
  291. Province: '',
  292. City: '',
  293. FactoryName: '',
  294. PlantName: '',
  295. MaintenanceDate: '',
  296. ResumptionDate: '',
  297. AnnualCapacity: 0,
  298. Coefficient: 1,
  299. AverageDailyCapacityReduction: 0,
  300. AverageDailyCapacityReductionTon: 0,
  301. Day: 0,
  302. CapacityReduction: 0,
  303. Button: {
  304. Edit: true,
  305. Delete: true
  306. }
  307. }
  308. this.insertIndex = {
  309. PrevVarietyPlantId: type === 'prev' ? 0 : row.VarietyPlantId,
  310. NextVarietyPlantId: type === 'prev' ? row.VarietyPlantId : 0
  311. }
  312. type === 'prev' ? this.tableData.splice($index,0,row_item) : this.tableData.splice($index+1,0,row_item)
  313. this.saveHandle(row_item);
  314. },
  315. /* 保存 */
  316. saveHandle: _.debounce(async function(row) {
  317. const { VarietyPlantId,Province,City,FactoryName,PlantName,MaintenanceDate,ResumptionDate,AnnualCapacity,Coefficient,AverageDailyCapacityReduction,IsStop} = row;
  318. let params = {
  319. Province,
  320. City,
  321. FactoryName,
  322. PlantName,
  323. MaintenanceDate,
  324. ResumptionDate,
  325. AnnualCapacity: Number(AnnualCapacity),
  326. Coefficient: Number(Coefficient),
  327. AverageDailyCapacityReduction: Number(AverageDailyCapacityReduction),
  328. IsStop,
  329. }
  330. const res = VarietyPlantId
  331. ? await supplyApi.editPlant({ VarietyPlantId,...params})
  332. : await supplyApi.addPlant({VarietyId: Number(this.$route.query.id), ...params,...this.insertIndex})
  333. if(res.Ret !== 200) return
  334. // this.$message.success('保存成功');
  335. VarietyPlantId ? this.updatedData(row) : this.$emit('getData')
  336. },200),
  337. /* 添加其他装置 */
  338. addOtherPlantHandle(VarietyPlantId) {
  339. this.plantId = VarietyPlantId;
  340. this.isAddOtherPlantDialog = true;
  341. },
  342. /* 编辑完更新市场和期间减量 */
  343. updatedData(row) {
  344. if(row.MaintenanceDate&&row.ResumptionDate&&!row.IsStop&&row.AverageDailyCapacityReduction) {
  345. let day = this.$moment(row.ResumptionDate).diff(this.$moment(row.MaintenanceDate), 'day')+1;
  346. row.Day = day;
  347. row.CapacityReduction = (row.Day * row.AverageDailyCapacityReduction).toFixed(2);
  348. }
  349. }
  350. }
  351. }
  352. </script>
  353. <style lang="scss">
  354. .plant-table {
  355. .cell {
  356. padding: 0 5px;
  357. }
  358. .cell .large-sty .el-input__inner {
  359. padding: 0 4px;
  360. }
  361. .cell .distpicker-address-wrapper select {
  362. width: 120px;
  363. }
  364. }
  365. </style>