add.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <zz-form :cols="cols" :data="formData" :rules="formRules" ref="form" labelWidth="80">
  3. <template slot="communityId">
  4. <el-select v-model="formData.communityId" placeholder="请选择社区">
  5. <el-option v-for="(item, index) in communityArr" :key="index" :label="item.communityName" :value="item.id"></el-option>
  6. </el-select>
  7. </template>
  8. <template slot="chargeType">
  9. <el-select v-model="formData.chargeType">
  10. <el-option label="物业费" :value="1"></el-option>
  11. <el-option label="水费" :value="2"></el-option>
  12. <el-option label="电费" :value="3"></el-option>
  13. </el-select>
  14. </template>
  15. <template slot="chargeMode">
  16. <el-select v-model="formData.chargeMode">
  17. <template v-if="formData.chargeType == 1">
  18. <el-option label="固定收费" :value="1"></el-option>
  19. <el-option label="价格*面积收费" :value="2"></el-option>
  20. </template>
  21. <template v-else>
  22. <el-option label="单价*用量" :value="2"></el-option>
  23. <el-option label="阶梯计费" :value="3"></el-option>
  24. </template>
  25. </el-select>
  26. </template>
  27. <template slot="chargeCycle">
  28. <div class="form-item-flex">
  29. <el-select v-model="formData.chargeCycle" class="select" disabled>
  30. <el-option label="1" :value="1"></el-option>
  31. </el-select>
  32. <div class="widthFlex">个月</div>
  33. </div>
  34. </template>
  35. <template slot="lateFee">
  36. <div class="form-item-flex">
  37. <!-- <el-input-number
  38. v-model="formData.lateFee"
  39. :precision="2"
  40. controls-position="right"
  41. :step="0.1"
  42. :min="0"
  43. :max="100"
  44. @change="lateAdd"
  45. >
  46. <i slot="suffix" style="font-style: normal; margin-right: 10px">℃</i>
  47. </el-input-number> -->
  48. <el-input
  49. class="input-number"
  50. v-model="formData.lateFee"
  51. :precision="2"
  52. controls-position="right"
  53. :step="0.1"
  54. :min="0"
  55. :max="100"
  56. >
  57. <i slot="suffix" style="font-style: normal; margin-right: 70px"
  58. >‰
  59. <div class="input-button">
  60. <span class="button down" @click="lateAdd('-')"><i class="el-icon-arrow-down"></i></span>
  61. <span class="button up" @click="lateAdd('+')"><i class="el-icon-arrow-up"></i></span>
  62. </div>
  63. </i>
  64. </el-input>
  65. <el-tooltip class="item" effect="light" placement="right">
  66. <div slot="content" v-html="lateFeeMsg"></div>
  67. <img src="@/assets/img/menuicon/icon_tishi_zhengchang.png" alt="" />
  68. </el-tooltip>
  69. <div>欠费时间(>)</div>
  70. <el-input class="input" v-model="formData.arrearsDays" placeholder="请输入天数"></el-input>
  71. </div>
  72. </template>
  73. <template slot="generationRules">
  74. <el-select v-model="formData.generationRules">
  75. <el-option label="当月生成上月" :value="1"></el-option>
  76. <el-option label="当月生成当月" :value="2"></el-option>
  77. </el-select>
  78. </template>
  79. <template :slot="'price' + (index + 1)" v-for="(item, index) in formData.ladderList">
  80. <div class="form-item-flex just" :key="index">
  81. <div>价格(元)</div>
  82. <el-input class="input100" v-model="item.price" placeholder="请输入价格"></el-input>
  83. <div v-if="formData.chargeType === 2">阶梯水量(吨)</div>
  84. <div v-if="formData.chargeType === 3">阶梯电量(度)</div>
  85. <el-input class="input100" v-model="item.quantity" placeholder="请输入用量"></el-input>
  86. <div class="sunm" @click="addPrice" v-if="index === 0 && formData.ladderList.length < 5">
  87. <i class="zoniot_font zoniot-icon-tianjia1"></i>
  88. </div>
  89. <div class="sunm" v-else style="cursor: inherit"></div>
  90. <div class="sunm" @click="delePrice" v-if="index === 0 && formData.ladderList.length > 1">
  91. <i class="zoniot_font zoniot-icon-shanjian"></i>
  92. </div>
  93. <div class="sunm" v-else style="cursor: inherit"></div>
  94. </div>
  95. </template>
  96. </zz-form>
  97. </template>
  98. <script >
  99. export default {
  100. props: ['params'],
  101. data() {
  102. let _this = this;
  103. return {
  104. formData: {
  105. communityId: '',
  106. chargeType: 1,
  107. chargeName: '',
  108. chargeMode: '',
  109. chargePrice: '',
  110. chargeCycle: 1,
  111. chargeCycleUnit: 1,
  112. generationRules: '',
  113. lateFee: 0.0,
  114. remark: '',
  115. ladderList: [
  116. {
  117. ladder: 1,
  118. price: '',
  119. quantity: ''
  120. },
  121. {
  122. ladder: 2,
  123. price: '',
  124. quantity: ''
  125. }
  126. ]
  127. },
  128. lateFeeMsg: '滞纳金计算规则:</br>月费用*逾期天数*滞纳金标准',
  129. cols: [
  130. [
  131. {
  132. label: '所属社区',
  133. prop: 'communityId',
  134. slot: 'communityId'
  135. },
  136. {
  137. label: '费用类型',
  138. prop: 'chargeType',
  139. slot: 'chargeType'
  140. },
  141. {
  142. label: '费用名称',
  143. prop: 'chargeName',
  144. slot: 'chargeName',
  145. input: true
  146. },
  147. {
  148. label: '计费方式',
  149. prop: 'chargeMode',
  150. slot: 'chargeMode'
  151. },
  152. {
  153. label: '价格(元)',
  154. prop: 'chargePrice',
  155. input: true
  156. },
  157. {
  158. label: '计费周期',
  159. prop: 'chargeCycle',
  160. slot: 'chargeCycle'
  161. },
  162. {
  163. label: '收滞纳金',
  164. prop: 'lateFee',
  165. slot: 'lateFee'
  166. },
  167. {
  168. label: '生成规则',
  169. prop: 'generationRules',
  170. slot: 'generationRules'
  171. },
  172. {
  173. label: ' 一阶水价',
  174. prop: 'price',
  175. slot: 'price1',
  176. showRequired: true,
  177. offShow: true
  178. },
  179. {
  180. label: ' 二阶水价',
  181. prop: 'price',
  182. slot: 'price2',
  183. showRequired: true,
  184. offShow: true
  185. },
  186. {
  187. label: ' 三阶水价',
  188. prop: 'price',
  189. slot: 'price3',
  190. showRequired: true,
  191. offShow: true
  192. },
  193. {
  194. label: ' 四阶水价',
  195. prop: 'price',
  196. slot: 'price4',
  197. showRequired: true,
  198. offShow: true
  199. },
  200. {
  201. label: ' 五阶水价',
  202. prop: 'price',
  203. slot: 'price5',
  204. showRequired: true,
  205. offShow: true
  206. },
  207. {
  208. label: '备注信息',
  209. prop: 'remark',
  210. textarea: true,
  211. maxlength: 100
  212. }
  213. ]
  214. ],
  215. formRules: {
  216. chargeName: [this.$valid.inputRequired('费用名称')],
  217. chargePrice: [this.$valid.inputRequired('价格')],
  218. chargeMode: [this.$valid.selectRequired('计费方式')],
  219. chargeType: [this.$valid.selectRequired('费用类型')],
  220. communityId: [this.$valid.selectRequired('社区')]
  221. }
  222. };
  223. },
  224. computed: {
  225. communityArr() {
  226. return this.$store.getters['getAreaSelect'];
  227. }
  228. },
  229. watch: {
  230. // 切换是否阶梯
  231. 'formData.chargeMode'(val) {
  232. if (!!val) {
  233. this.$refs.form.clearValidate();
  234. if (val == 2) {
  235. this.cols[0][4].offShow = false;
  236. this.cols[0][5].offShow = true;
  237. for (let a = 0; a < this.formData.ladderList.length; a++) {
  238. this.cols[0][8 + a].offShow = true;
  239. }
  240. } else if (val == 3) {
  241. this.cols[0][4].offShow = true;
  242. this.cols[0][5].offShow = false;
  243. for (let a = 0; a < this.formData.ladderList.length; a++) {
  244. this.cols[0][8 + a].offShow = false;
  245. }
  246. }
  247. }
  248. },
  249. // 切换电水label
  250. 'formData.chargeType'(val) {
  251. // this.formData.chargeMode = '';
  252. let sunm = ['一', '二', '三', '四', '五'];
  253. let type = '水';
  254. this.$refs.form.clearValidate();
  255. if (val === 1) {
  256. this.cols[0][5].offShow = false;
  257. this.cols[0][6].offShow = false;
  258. this.cols[0][7].offShow = false;
  259. } else {
  260. this.cols[0][5].offShow = true;
  261. this.cols[0][6].offShow = true;
  262. this.cols[0][7].offShow = true;
  263. if (val === 2) {
  264. for (let a = 8; a < 13; a++) {
  265. this.cols[0][a].label = sunm[a - 8] + '阶' + type + '价';
  266. }
  267. } else if (val == 3) {
  268. type = '电';
  269. for (let a = 8; a < 13; a++) {
  270. this.cols[0][a].label = sunm[a - 8] + '阶' + type + '价';
  271. }
  272. }
  273. }
  274. }
  275. },
  276. methods: {
  277. // 添加删除显示item-label
  278. addPrice() {
  279. this.formData.ladderList.push({
  280. ladder: this.formData.ladderList.length + 1,
  281. price: '',
  282. quantity: ''
  283. });
  284. for (let a = 0; a < this.formData.ladderList.length; a++) {
  285. this.cols[0][8 + a].offShow = false;
  286. }
  287. },
  288. delePrice() {
  289. this.formData.ladderList.splice(this.formData.ladderList.length - 1, 1);
  290. for (let a = 0; a < 5 - this.formData.ladderList.length; a++) {
  291. this.cols[0][12 - a].offShow = true;
  292. }
  293. },
  294. lateAdd(fu) {
  295. if (this.formData.lateFee == null || this.formData.lateFee == undefined) {
  296. this.formData.lateFee = 0.0;
  297. }
  298. let newx = Number(Number(this.formData.lateFee).toFixed(2));
  299. if (newx >= 0) {
  300. if (fu === '-') {
  301. if (newx <= 0) {
  302. this.formData.lateFee = 0.0;
  303. } else {
  304. this.formData.lateFee = Number(Number(this.formData.lateFee - 0.1).toFixed(2));
  305. }
  306. } else if (fu === '+') {
  307. this.formData.lateFee = Number(Number(this.formData.lateFee + 0.1).toFixed(2));
  308. }
  309. } else {
  310. this.formData.lateFee = 0.0;
  311. }
  312. },
  313. submit() {
  314. new Promise((resolve) => {
  315. this.$refs.form.validate(resolve);
  316. }).then(() => {
  317. if (!this.checkFromData()) {
  318. this.$message.error('阶梯价格与用量必须');
  319. return;
  320. }
  321. let formData = this.installFromData();
  322. var loading = this.$loading();
  323. let url = '/sc-charge/scChargeStrategy/add';
  324. if (this.params.todo === 'edit') {
  325. formData.id = this.params.data.id;
  326. url = '/sc-charge/scChargeStrategy/update';
  327. }
  328. this.$http
  329. .post(url, formData)
  330. .then(({ status, msg }) => {
  331. if (status == 0) {
  332. this.$message.success(msg);
  333. this.params.callback();
  334. this.$emit('close');
  335. } else {
  336. this.$message.error(msg);
  337. }
  338. loading.close();
  339. })
  340. .catch(() => {
  341. loading.close();
  342. });
  343. });
  344. },
  345. installFromData() {
  346. let installData = {
  347. communityId: this.formData.communityId,
  348. chargeType: this.formData.chargeType,
  349. chargeName: this.formData.chargeName,
  350. chargeMode: this.formData.chargeMode,
  351. remark: this.formData.remark
  352. };
  353. if (this.formData.chargeType === 1) {
  354. installData.chargePrice = this.formData.chargePrice;
  355. installData.chargeCycle = this.formData.chargeCycle;
  356. installData.lateFee = this.formData.lateFee;
  357. installData.arrearsDays = this.formData.arrearsDays;
  358. installData.generationRules = this.formData.generationRules;
  359. } else {
  360. if (this.formData.chargeMode === 2) {
  361. installData.chargePrice = this.formData.chargePrice;
  362. } else {
  363. installData.chargeCycle = this.formData.chargeCycle;
  364. installData.ladderList = this.formData.ladderList;
  365. }
  366. }
  367. return installData;
  368. },
  369. checkFromData() {
  370. let isOK = true;
  371. if (this.formData.chargeMode === 3) {
  372. this.formData.ladderList.forEach((item) => {
  373. if (item.price === '' || item.price == null || item.price == undefined) {
  374. isOK = false;
  375. }
  376. if (item.quantity === '' || item.quantity == null || item.quantity == undefined) {
  377. isOK = false;
  378. }
  379. });
  380. }
  381. return isOK;
  382. }
  383. },
  384. created() {
  385. if (this.params.todo == 'edit') {
  386. Object.assign(this.formData, this.params.data);
  387. this.formData.ladderList = JSON.parse(this.formData.chargePriceLadder) || this.formData.ladderList;
  388. }
  389. }
  390. };
  391. </script>
  392. <style lang="scss" scoped>
  393. .just {
  394. justify-content: space-between;
  395. }
  396. .form-item-flex {
  397. display: flex;
  398. .input {
  399. width: 110px;
  400. margin: 0 15px 0 12px;
  401. }
  402. .input-number {
  403. width: 110px;
  404. /deep/ .el-input--suffix .el-input__inner {
  405. padding-right: 50px;
  406. }
  407. .input-button {
  408. line-height: 15px;
  409. .up {
  410. position: absolute;
  411. top: 2px;
  412. height: 16px;
  413. width: 25px;
  414. right: -4px;
  415. border-radius: 0px 4px 0 0;
  416. background: #f5f7fa;
  417. border-bottom: 1px solid #dcdfe6;
  418. border-left: 1px solid #dcdfe6;
  419. }
  420. .down {
  421. position: absolute;
  422. bottom: 1px;
  423. height: 16px;
  424. width: 25px;
  425. right: -4px;
  426. background: #f5f7fa;
  427. border-radius: 0 0 4px 0;
  428. border-top: 1px solid #dcdfe6;
  429. border-left: 1px solid #dcdfe6;
  430. }
  431. }
  432. }
  433. .input100 {
  434. width: 100px;
  435. }
  436. .select {
  437. width: 360px !important;
  438. }
  439. .el-tooltip {
  440. margin: 10px 10px 0 16px;
  441. width: 16px;
  442. height: 16px;
  443. }
  444. .widthFlex {
  445. flex: 1;
  446. text-align: right;
  447. }
  448. .sunm {
  449. width: 15px;
  450. text-align: center;
  451. cursor: pointer;
  452. }
  453. }
  454. </style>