editRateCfg.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div class="container">
  3. <ComHeader :title="title">
  4. <div slot="options">
  5. <el-button type="primary" size="mini" @click="submit">保 存</el-button>
  6. </div>
  7. </ComHeader>
  8. <div class="form">
  9. <el-form ref="form" :model="form" :rules="rules" class="custom-form-label" label-width="120px" label-position="left">
  10. <div class="com-line-title">基础设置</div>
  11. <el-row :gutter="0">
  12. <el-col :span="12">
  13. <el-form-item label="收费标准名称:" prop="charge_name">
  14. <el-input v-model="form.charge_name" placeholder="收费标准名称" />
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="12">
  18. <el-form-item label="门店归属:" prop="shop_id">
  19. <lazy-tree
  20. ref="addTree"
  21. :tree="form.shop_name"
  22. :disabled="!!$route.query.sn"
  23. input-width="400px"
  24. is-gap
  25. style="margin-bottom: 0;display:flex;width:100%"
  26. @handleSelectGroup="selectGroup"
  27. />
  28. </el-form-item>
  29. </el-col>
  30. <!-- <el-col :span="12">
  31. <el-form-item label="服务费规则:" prop="service_fee_type">
  32. <el-checkbox-group v-model="form.service_fee_type">
  33. <el-checkbox label="1">按时间</el-checkbox>
  34. </el-checkbox-group>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="12">
  38. <el-form-item label="计费类型:" prop="charge_way">
  39. <el-radio-group v-model="form.charge_way">
  40. <el-radio label="2">按电量</el-radio>
  41. </el-radio-group>
  42. </el-form-item>
  43. </el-col> -->
  44. <el-col :span="12">
  45. <el-form-item label="满电功率:" prop="full_power">
  46. <el-input v-model="form.full_power" type="number" placeholder="满电功率">
  47. <template slot="append">W</template>
  48. </el-input>
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="12">
  52. <el-form-item label="过载功率:" prop="over_power">
  53. <el-input v-model="form.over_power" type="number" placeholder="过载功率">
  54. <template slot="append">W</template>
  55. </el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="判满延时:" prop="full_delay">
  60. <el-input v-model="form.full_delay" type="number" placeholder="判满延时">
  61. <template slot="append">秒</template>
  62. </el-input>
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="12">
  66. <el-form-item label="拔掉停充延时:" prop="off_delay">
  67. <el-input v-model="form.off_delay" type="number" placeholder="拔掉停充延时">
  68. <template slot="append">秒</template>
  69. </el-input>
  70. </el-form-item>
  71. </el-col>
  72. <el-col :span="12">
  73. <el-form-item label="退款渠道:" prop="refund_type">
  74. <el-radio-group v-model="form.refund_type">
  75. <el-radio :label="1">退钱包</el-radio>
  76. <el-radio :label="2">原路返回</el-radio>
  77. </el-radio-group>
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. <div class="title-row">
  82. <div class="com-line-title mb0">服务费配置</div>
  83. <el-tooltip content="新增服务费配置" placement="top">
  84. <i class="el-icon-circle-plus-outline icon" @click="addItem('service_fee')" />
  85. </el-tooltip>
  86. </div>
  87. <el-table :data="form.service_fee">
  88. <el-table-column align="center" label="序号" width="120">
  89. <template slot-scope="scope">
  90. {{ scope.$index + 1 }}
  91. </template>
  92. </el-table-column>
  93. <el-table-column align="center" label="功率">
  94. <template slot-scope="scope">
  95. <div style="display: flex;justify-content: center;">
  96. <el-input
  97. v-model="scope.row.begin_power"
  98. size="mini"
  99. maxlength="6"
  100. style="width: 240px;"
  101. placeholder="开始功率"
  102. @input="limitDecimalPlaces(scope.row, 'begin_power')"
  103. >
  104. <template slot="append">W</template>
  105. </el-input>
  106. <div style="margin: 0 10px;">-</div>
  107. <el-input
  108. v-model="scope.row.end_power"
  109. size="mini"
  110. maxlength="6"
  111. style="width: 240px;"
  112. placeholder="结束功率"
  113. @input="limitDecimalPlaces(scope.row, 'end_power')"
  114. >
  115. <template slot="append">W</template>
  116. </el-input>
  117. </div>
  118. </template>
  119. </el-table-column>
  120. <el-table-column align="center" label="服务费">
  121. <template slot-scope="scope">
  122. <el-input
  123. v-model="scope.row.price"
  124. style="width: 240px;"
  125. maxlength="6"
  126. placeholder="请输入服务费"
  127. size="mini"
  128. @input="limitDecimalPlaces(scope.row, 'price')"
  129. >
  130. <template slot="append">元/时</template>
  131. </el-input>
  132. </template>
  133. </el-table-column>
  134. <el-table-column align="center" label="操作" width="120">
  135. <template slot-scope="scope">
  136. <i
  137. class="el-icon-delete"
  138. style="color: #f00;font-size: 16px;cursor: pointer;"
  139. @click="deleteItem(scope, 'service_fee')"
  140. />
  141. </template>
  142. </el-table-column>
  143. </el-table>
  144. <div class="title-row">
  145. <div class="com-line-title mb0">电费配置</div>
  146. <el-tooltip content="新增电费配置" placement="top">
  147. <i class="el-icon-circle-plus-outline icon" @click="addItem('charge_standard')" />
  148. </el-tooltip>
  149. </div>
  150. <el-table ref="table" :data="form.charge_standard">
  151. <el-table-column align="center" label="序号" width="120">
  152. <template slot-scope="scope">
  153. {{ scope.$index + 1 }}
  154. </template>
  155. </el-table-column>
  156. <el-table-column align="center" label="时间段">
  157. <template slot-scope="scope">
  158. <div style="display: flex;justify-content: center;">
  159. <el-time-picker
  160. v-model="scope.row.begin_time"
  161. style="width: 240px;"
  162. format="HH:mm"
  163. value-format="HH:mm"
  164. size="mini"
  165. placeholder="开始时间"
  166. @change="changeBeginTime(scope)"
  167. />
  168. <div style="margin: 0 10px;">-</div>
  169. <el-time-picker
  170. :ref="`entTime${scope.$index}`"
  171. v-model="scope.row.end_time"
  172. style="width: 240px;"
  173. size="mini"
  174. format="HH:mm"
  175. value-format="HH:mm"
  176. placeholder="结束时间"
  177. />
  178. </div>
  179. </template>
  180. </el-table-column>
  181. <el-table-column align="center" label="电费">
  182. <template slot-scope="scope">
  183. <el-input
  184. v-model="scope.row.price"
  185. style="width: 240px;"
  186. maxlength="6"
  187. placeholder="请输入电费"
  188. size="mini"
  189. @input="limitDecimalPlaces(scope.row, 'price')"
  190. >
  191. <template slot="append">元/度</template>
  192. </el-input>
  193. </template>
  194. </el-table-column>
  195. <el-table-column align="center" label="操作" width="120">
  196. <template slot-scope="scope">
  197. <i
  198. class="el-icon-delete"
  199. style="color: #f00;font-size: 16px;cursor: pointer;"
  200. @click="deleteItem(scope, 'charge_standard')"
  201. />
  202. </template>
  203. </el-table-column>
  204. </el-table>
  205. <div class="title-row">
  206. <div class="com-line-title mb0">支付档位设置</div>
  207. <el-tooltip content="新增支付档位设置" placement="top">
  208. <i class="el-icon-circle-plus-outline icon" @click="addItem('prepay_list')" />
  209. </el-tooltip>
  210. <div class="switch-wrap">
  211. <div class="txt">
  212. 充满自停
  213. </div>
  214. <el-switch
  215. v-model="form.auto_charge"
  216. :active-value="1"
  217. :inactive-value="0"
  218. active-color="#13ce66"
  219. inactive-color="#ccc"
  220. />
  221. </div>
  222. </div>
  223. <el-table :data="form.prepay_list">
  224. <el-table-column align="center" label="序号" width="120">
  225. <template slot-scope="scope">
  226. {{ scope.$index + 1 }}
  227. </template>
  228. </el-table-column>
  229. <el-table-column align="center" label="金额">
  230. <template slot-scope="scope">
  231. <el-input
  232. v-model="scope.row.money"
  233. style="width: 400px;"
  234. maxlength="6"
  235. placeholder="请输入金额"
  236. size="mini"
  237. @input="limitDecimalPlaces(scope.row, 'money')"
  238. >
  239. <template slot="append">元</template>
  240. </el-input>
  241. </template>
  242. </el-table-column>
  243. <el-table-column align="center" label="预计充电时长">
  244. <template slot-scope="scope">
  245. <el-input
  246. v-model="scope.row.hours"
  247. style="width: 240px;"
  248. maxlength="6"
  249. placeholder="请输入预计充电时长"
  250. size="mini"
  251. @input="limitDecimalPlaces(scope.row, 'hours')"
  252. >
  253. <template slot="append">小时</template>
  254. </el-input>
  255. </template>
  256. </el-table-column>
  257. <el-table-column align="center" label="操作" width="120">
  258. <template slot-scope="scope">
  259. <i
  260. class="el-icon-delete"
  261. style="color: #f00;font-size: 16px;cursor: pointer;"
  262. @click="deleteItem(scope, 'prepay_list')"
  263. />
  264. </template>
  265. </el-table-column>
  266. </el-table>
  267. </el-form>
  268. </div>
  269. </div>
  270. </template>
  271. <script>
  272. import { apiAddBillingStandard, apiEditBillingStandard, apiQueryBillingStandardDtl } from '@/api/billingCfg'
  273. import LazyTree from '@/components/LazyTree'
  274. import ComHeader from '@/common/components/ComHeader'
  275. export default {
  276. components: {
  277. LazyTree,
  278. ComHeader
  279. },
  280. data() {
  281. return {
  282. rules: {
  283. charge_name: [{ required: true, message: '请输入收费标准名称', trigger: 'blur' }],
  284. shop_id: [{ required: true, message: '请选择门店', trigger: 'blur' }],
  285. charge_way: [{ required: true, message: '请选择计费类型', trigger: 'blur' }],
  286. service_fee_type: [{ required: true, message: '请选择服务费规则', trigger: 'blur' }],
  287. full_power: [{ required: true, message: '请输入满电功率', trigger: 'blur' }],
  288. over_power: [{ required: true, message: '请输入过载功率', trigger: 'blur' }],
  289. full_delay: [{ required: true, message: '请输入判满延时', trigger: 'blur' }],
  290. off_delay: [{ required: true, message: '请输入拔掉停充延时', trigger: 'blur' }]
  291. },
  292. isEdit: false,
  293. form: {
  294. charge_way: 2,
  295. service_fee: [],
  296. charge_standard: [],
  297. prepay_list: [],
  298. // service_fee_type: ['1'],
  299. refund_type: 1
  300. }
  301. }
  302. },
  303. beforeRouteLeave(to, from, next) {
  304. to.meta.refresh = true
  305. next()
  306. },
  307. computed: {
  308. title() {
  309. const { sn } = this.$route.query
  310. const title = sn ? '编辑费率设置' : '新增费率设置'
  311. return title
  312. }
  313. },
  314. created() {
  315. this._initData()
  316. // const title = this.title
  317. // this._setTagsViewTitle(title)
  318. },
  319. methods: {
  320. _setTagsViewTitle(title) {
  321. const route = Object.assign({}, this.$route, { title })
  322. this.$store.dispatch('updateVisitedView', route)
  323. },
  324. _initData() {
  325. const { sn } = this.$route.query
  326. if (!sn) return
  327. this.isEdit = true
  328. apiQueryBillingStandardDtl({ billing_standard_sn: sn }).then(res => {
  329. if (res.succeed) {
  330. const data = { ...res.body }
  331. if (Array.isArray(data.service_fee)) {
  332. data.service_fee.forEach(v => {
  333. v.price = ((v.price || 0) / 100)
  334. })
  335. }
  336. if (Array.isArray(data.charge_standard)) {
  337. data.charge_standard.forEach(v => {
  338. v.price = ((v.price || 0) / 100)
  339. })
  340. }
  341. if (Array.isArray(data.prepay_list)) {
  342. data.prepay_list.forEach(v => {
  343. v.money = ((v.money || 0) / 100)
  344. })
  345. }
  346. this.form = res.body
  347. }
  348. })
  349. // if (data) {
  350. // const obj = JSON.parse(data)
  351. // console.log(obj, 'obj')
  352. // obj.service_fee_type = obj.service_fee_type.split(',')
  353. // this.form = obj
  354. // this.isEdit = true
  355. // }
  356. },
  357. // 限制只能输入两位小数
  358. limitDecimalPlaces(row, field) {
  359. if (row[field].includes('.')) {
  360. const parts = row[field].split('.')
  361. if (parts[1].length > 2) {
  362. parts[1] = parts[1].slice(0, 2)
  363. row[field] = parts.join('.')
  364. }
  365. }
  366. },
  367. changeBeginTime({ $index, row }) {
  368. this.$refs[`entTime${$index}`].focus()
  369. const [hours, minutes] = row.begin_time.split(':').map(Number)
  370. const beginDate = new Date()
  371. beginDate.setHours(hours, minutes, 0, 0)
  372. const endDate = new Date(beginDate.getTime() + 60 * 60 * 1000)
  373. const endTime = `${String(endDate.getHours()).padStart(2, '0')}:${String(endDate.getMinutes()).padStart(2, '0')}`
  374. this.$set(this.form.charge_standard[$index], 'end_time', endTime)
  375. },
  376. addItem(type) {
  377. this.form[type].push({})
  378. },
  379. deleteItem({ $index }, type) {
  380. this.form[type].splice($index, 1)
  381. },
  382. selectGroup(group) {
  383. this.$set(this.form, 'shop_id', group.shop_id)
  384. this.$set(this.form, 'shop_name', group.shop_name)
  385. },
  386. submit() {
  387. const request = this.isEdit ? apiEditBillingStandard : apiAddBillingStandard
  388. this.$refs.form.validate(valid => {
  389. if (!valid) return
  390. const form = JSON.parse(JSON.stringify(this.form))
  391. // if (form.service_fee_type) {
  392. // form.service_fee_type = form.service_fee_type.join(',')
  393. // }
  394. if (!form.service_fee.length) {
  395. this.$message({ message: '服务费配置不能为空', type: 'warning' })
  396. return
  397. }
  398. if (!form.charge_standard.length) {
  399. this.$message({ message: '电费配置不能为空', type: 'warning' })
  400. return
  401. }
  402. if (!form.prepay_list.length) {
  403. this.$message({ message: '支付档位设置不能为空', type: 'warning' })
  404. return
  405. }
  406. form.service_fee.forEach(v => {
  407. v.price = ((v.price || 0) * 100)
  408. })
  409. form.charge_standard.forEach(v => {
  410. v.price = ((v.price || 0) * 100)
  411. })
  412. form.prepay_list.forEach(v => {
  413. v.money = ((v.money || 0) * 100)
  414. })
  415. request(form).then(res => {
  416. const { code } = res.data
  417. if (code === 200) {
  418. this.$message({
  419. message: '操作成功',
  420. type: 'success'
  421. })
  422. this.$router.go(-1)
  423. } else {
  424. this.$message({
  425. message: res.data.msg,
  426. type: 'error'
  427. })
  428. }
  429. })
  430. })
  431. }
  432. }
  433. }
  434. </script>
  435. <style lang="scss" scoped>
  436. .container {
  437. background: #F0F4F7;
  438. }
  439. .form {
  440. padding: 20px 14px;
  441. overflow: auto;
  442. background: #fff;
  443. height: calc(100vh - 150px);
  444. }
  445. .title-row {
  446. display: flex;
  447. align-items: center;
  448. margin: 12px 0;
  449. }
  450. .icon {
  451. font-size: 20px;
  452. color: #409EFF;
  453. cursor: pointer;
  454. }
  455. .cfg-row {
  456. display: flex;
  457. .input {
  458. width: 300px;
  459. }
  460. }
  461. .submit-btn {
  462. cursor: pointer;
  463. color: #409EFF;
  464. padding: 15px;
  465. text-align: center;
  466. border: 1px solid #409EFF;
  467. &:active {
  468. opacity: .6;
  469. }
  470. }
  471. .switch-wrap {
  472. font-size: 14px;
  473. display: flex;
  474. align-items: center;
  475. margin-left: 10px;
  476. .txt {
  477. margin-right: 8px;
  478. }
  479. }
  480. </style>