setAnnualWaterRight.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <el-dialog
  3. title="修改"
  4. :visible.sync="dialogVisible"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. @close="handleClose"
  8. width="660px"
  9. >
  10. <el-tooltip
  11. class="item_tooltip"
  12. effect="dark"
  13. content="操作提示:设置每亩农田同水量的水价信息和用电量的电价信息"
  14. placement="right"
  15. >
  16. <i class="el-alert__icon el-icon-info"></i>
  17. </el-tooltip>
  18. <el-form
  19. ref="baseForm"
  20. class="base-form"
  21. label-position="right"
  22. label-width="100px"
  23. :model="baseForm"
  24. size="small"
  25. >
  26. <el-row>
  27. <el-col :span="24">
  28. <el-form-item label="所属区域">
  29. <el-row>
  30. <el-col :span="24">
  31. <el-input
  32. style="width: 100%"
  33. placeholder="请选择您的行政区"
  34. disabled
  35. v-model="editRow.cusareaName"
  36. />
  37. </el-col>
  38. </el-row>
  39. </el-form-item>
  40. </el-col>
  41. </el-row>
  42. <el-row>
  43. <h3>水价</h3>
  44. <el-col :span="24">
  45. <el-form-item label="水价计费方式">
  46. <el-row>
  47. <el-col :span="18">
  48. <el-radio v-model="constantWaterPrice" label="0">恒定水价</el-radio>
  49. <el-radio v-model="constantWaterPrice" label="1">阶梯水价</el-radio>
  50. </el-col>
  51. </el-row>
  52. </el-form-item>
  53. <el-form-item label="水价"
  54. v-if="constantWaterPrice == 0"
  55. prop="priceconfigWaterunitprice"
  56. :rules="[{ required: true, message: '请选择您的恒定水价', trigger: 'blur' }]"
  57. >
  58. <el-row>
  59. <el-col :span="18">
  60. <el-input
  61. style="width: 50%"
  62. type="number"
  63. v-model="baseForm.priceconfigWaterunitprice"
  64. />
  65. <span style="display:inline-block;margin-left:5px">元/吨</span>
  66. </el-col>
  67. </el-row>
  68. </el-form-item>
  69. <ladderLikeWaterPrice
  70. v-else
  71. :type="'water'"
  72. @changeList="changeList"
  73. :list="baseForm.waterPriceSteps || []"
  74. />
  75. </el-col>
  76. </el-row>
  77. <el-row>
  78. <h3>电价</h3>
  79. <el-col :span="24">
  80. <el-form-item label="电价计费方式">
  81. <el-row>
  82. <el-col :span="18">
  83. <el-radio v-model="ladderLikeWaterPrice" label="0">恒定电价</el-radio>
  84. <el-radio v-model="ladderLikeWaterPrice" label="1">阶梯电价</el-radio>
  85. </el-col>
  86. </el-row>
  87. </el-form-item>
  88. <el-form-item
  89. label="电价"
  90. v-if="ladderLikeWaterPrice == 0"
  91. :rules="[{ required: true, message: '请选择您的恒定电价', trigger: 'blur' }]"
  92. prop="priceconfigElectricityunitprice"
  93. >
  94. <el-row>
  95. <el-col :span="18">
  96. <el-input
  97. style="width: 50%"
  98. type="number"
  99. v-model="baseForm.priceconfigElectricityunitprice"
  100. />
  101. <span style="display:inline-block;margin-left:5px">元/度</span>
  102. </el-col>
  103. </el-row>
  104. </el-form-item>
  105. <ladderLikeWaterPrice
  106. v-else
  107. :type="'electricity'"
  108. @changeList="changeList"
  109. :list="baseForm.elecPriceSteps || []"
  110. />
  111. </el-col>
  112. </el-row>
  113. </el-form>
  114. <div style="text-align: right;margin-top: 20px;">
  115. <el-button type="info" plain @click="resetForm('baseForm')"
  116. >取消</el-button
  117. >
  118. <el-button
  119. type="primary"
  120. style="margin-left:16px;"
  121. @click="submitForm('baseForm')"
  122. :disabled="dialogSubmitLoading"
  123. :loading="dialogSubmitLoading"
  124. >确定</el-button
  125. >
  126. </div>
  127. </el-dialog>
  128. </template>
  129. <script>
  130. import { assign } from 'lodash-es';
  131. import { Message } from 'element-ui'
  132. import ladderLikeWaterPrice from './ladderLikeWaterPrice.vue'
  133. import { editPrice } from '@/api/price/index.js'
  134. export default {
  135. name: 'setAnnualWaterRight',
  136. props: {
  137. data: {
  138. default() {
  139. return {};
  140. }
  141. },
  142. visible: {
  143. type: Boolean,
  144. default: false
  145. },
  146. editRow: {
  147. type: Object
  148. }
  149. },
  150. components: {
  151. ladderLikeWaterPrice
  152. },
  153. data() {
  154. return {
  155. dialogSubmitLoading: false,
  156. constantWaterPrice: '1',
  157. ladderLikeWaterPrice: '1',
  158. dialogVisible: false,
  159. priceconfigElectricityunitprice: '',
  160. priceconfigWaterunitprice: '',
  161. baseForm: {
  162. priceconfigElectricityunitprice: '',
  163. priceconfigWaterunitprice: '',
  164. elecPriceSteps: [],
  165. waterPriceSteps: []
  166. },
  167. hasFetched: false,
  168. rules1: {
  169. priceconfigWaterunitprice: [
  170. { required: true, message: '输入您的恒定水价', trigger: 'blur' }
  171. ],
  172. },
  173. rules2: {
  174. priceconfigElectricityunitprice: [
  175. { required: true, message: '输入您的恒定电价', trigger: 'blur' }
  176. ]
  177. },
  178. rules3: {
  179. priceconfigWaterunitprice: [
  180. { required: true, message: '输入您的恒定水价', trigger: 'blur' }
  181. ],
  182. priceconfigElectricityunitprice: [
  183. { required: true, message: '输入您的恒定电价', trigger: 'blur' }
  184. ]
  185. },
  186. rules4: {
  187. stockAmount: [
  188. { required: true, message: '请选择负责人', trigger: 'blur' }
  189. ],
  190. sourceinfoId: [
  191. { required: true, message: '请选择管辖范围', trigger: 'blur' }
  192. ],
  193. productName: [
  194. { required: true, message: '请输入协会名称', trigger: 'blur' }
  195. ],
  196. supplierId: [
  197. { required: false, message: '请输入协会介绍', trigger: 'blur' }
  198. ],
  199. goodsSpecValue: [
  200. { required: true, message: '请选择规格', trigger: 'blur' }
  201. ]
  202. }
  203. };
  204. },
  205. watch: {
  206. visible(val) {
  207. if (val !== this.dialogVisible) {
  208. this.dialogVisible = val;
  209. if (val) {
  210. assign(this.baseForm, this.data);
  211. if (!this.hasFetched) {
  212. this.hasFetched = true;
  213. }
  214. }
  215. }
  216. },
  217. data: {
  218. deep: true,
  219. handler(val) {
  220. assign(this.baseForm, val);
  221. }
  222. },
  223. editRow: {
  224. handler(val) {
  225. this.constantWaterPrice = val?.priceconfigWaterchargingtype
  226. this.ladderLikeWaterPrice = val?.priceconfigElectricitychargingtype
  227. this.baseForm.priceconfigWaterunitprice = val?.priceconfigWaterunitprice
  228. this.baseForm.priceconfigElectricityunitprice = val?.priceconfigElectricityunitprice
  229. this.baseForm.elecPriceSteps = val?.elecPriceSteps?.length > 0 ? val.elecPriceSteps : [{
  230. pricestepUsagemin: '0',
  231. pricestepUsagemax: '',
  232. pricestepUnitprice: '',
  233. }, {
  234. pricestepUsagemin: '',
  235. pricestepUsagemax: '',
  236. pricestepUnitprice: '',
  237. }]
  238. this.baseForm.waterPriceSteps = val?.waterPriceSteps?.length > 0 ? val?.waterPriceSteps : [{
  239. pricestepUsagemin: '0',
  240. pricestepUsagemax: '',
  241. pricestepUnitprice: '',
  242. }, {
  243. pricestepUsagemin: '',
  244. pricestepUsagemax: '',
  245. pricestepUnitprice: '',
  246. }]
  247. }
  248. },
  249. immediate: true
  250. },
  251. methods: {
  252. changeList(list,type,row, index) {
  253. if (type === 'water') {
  254. if (this.baseForm.waterPriceSteps[index + 1]) {
  255. const params = this.baseForm.waterPriceSteps[index + 1]
  256. params.pricestepUsagemin = row
  257. this.$set(this.baseForm.waterPriceSteps, index + 1, params)
  258. }
  259. } else {
  260. if (this.baseForm.elecPriceSteps[index + 1]) {
  261. const params = this.baseForm.elecPriceSteps[index + 1]
  262. params.pricestepUsagemin = row
  263. this.$set(this.baseForm.elecPriceSteps, index + 1, params)
  264. }
  265. }
  266. },
  267. async editPriceHandler() {
  268. const { areaId, priceconfigId } = this.editRow
  269. if (this.constantWaterPrice == 1) {
  270. for (let i = 0; i < this.baseForm.waterPriceSteps.length; i++) {
  271. const waterPriceItem = this.baseForm.waterPriceSteps[i]
  272. if (waterPriceItem?.pricestepUsagemin != '' && waterPriceItem?.pricestepUsagemax != '' && +waterPriceItem?.pricestepUsagemax < +waterPriceItem?.pricestepUsagemin) {
  273. Message({
  274. type: 'warning',
  275. message: `水价第${i+1}阶梯的最大量不能小于最小量`
  276. })
  277. return
  278. }
  279. if (!waterPriceItem?.pricestepUnitprice) {
  280. Message({
  281. type: 'warning',
  282. message: '请正确输入您的水价信息'
  283. })
  284. return
  285. }
  286. waterPriceItem.pricestepNum = i
  287. }
  288. }
  289. if (this.ladderLikeWaterPrice == 1) {
  290. for (let i = 0; i < this.baseForm.elecPriceSteps.length; i++) {
  291. const elePriceItem = this.baseForm.elecPriceSteps[i]
  292. if (elePriceItem?.pricestepUsagemin != '' && elePriceItem?.pricestepUsagemax != '' && +elePriceItem?.pricestepUsagemax < +elePriceItem?.pricestepUsagemin) {
  293. Message({
  294. type: 'warning',
  295. message: `电价第${i + 1}阶梯的最大量不能小于最小量`
  296. })
  297. return
  298. }
  299. if (!elePriceItem?.pricestepUnitprice) {
  300. Message({
  301. type: 'warning',
  302. message: '请正确输入您的电价信息'
  303. })
  304. return
  305. }
  306. elePriceItem.pricestepNum = i
  307. }
  308. }
  309. const params = {
  310. areaId,
  311. priceconfigId,
  312. priceconfigWaterchargingtype: this.constantWaterPrice,
  313. priceconfigElectricityunitprice: this.ladderLikeWaterPrice == 0 ? this.baseForm.priceconfigElectricityunitprice: '0',
  314. priceconfigElectricitychargingtype: this.ladderLikeWaterPrice,
  315. priceconfigWaterunitprice: this.constantWaterPrice == 0 ? this.baseForm.priceconfigWaterunitprice :'0',
  316. waterPriceSteps: this.constantWaterPrice == 1 ? this.baseForm.waterPriceSteps : [],
  317. elePriceSteps: this.ladderLikeWaterPrice == 1 ? this.baseForm.elecPriceSteps : [],
  318. }
  319. await editPrice(
  320. params
  321. )
  322. this.handleClose()
  323. },
  324. resetForm(formName) {
  325. this.$refs[formName].resetFields();
  326. // this.resetFormData();
  327. this.dialogVisible = false;
  328. },
  329. resetFormData() {
  330. this.baseForm = {};
  331. },
  332. submitForm(formName) {
  333. this.$refs[formName].validate((valid) => {
  334. valid && this.editPriceHandler()
  335. })
  336. },
  337. handleClose() {
  338. this.$emit('update:visible', false);
  339. this.$emit('clearEdit')
  340. this.resetForm('baseForm');
  341. },
  342. }
  343. };
  344. </script>
  345. <style lang="scss" scoped>
  346. ::v-deep .el-form-item__label{
  347. text-align: right !important;
  348. }
  349. .item_tooltip{
  350. position: absolute;
  351. top: 25px;
  352. left: 70px;
  353. color: #00000066;
  354. }
  355. h3{
  356. color: #303133;
  357. font-family: Source Han Sans CN VF;
  358. font-size: 14px;
  359. font-style: normal;
  360. font-weight: 700;
  361. line-height: 24px;
  362. }
  363. .base-form {
  364. max-height: 70vh;
  365. overflow-y: auto;
  366. overflow-x: hidden;
  367. padding: 0 20px;
  368. }
  369. </style>
  370. <style lang="css" scoped>
  371. ::v-deep .el-dialog__header {
  372. border-bottom: 1px solid #ebeef5;
  373. }
  374. </style>
  375. <style>
  376. .el-tooltip__popper.is-dark {
  377. background: rgba(0,0,0,0.5);
  378. }
  379. .el-tooltip__popper[x-placement^=right] .popper__arrow{
  380. border-right-color:#888;
  381. }
  382. .el-tooltip__popper[x-placement^=right] .popper__arrow::after{
  383. border-right-color:#888;
  384. }
  385. </style>