Dzk_Rule.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <template>
  2. <PermissionContainer
  3. :jiBieArr="[1, 2]"
  4. :type="2"
  5. :isFlag="true"
  6. :tipArr="[
  7. ,
  8. '电子卡功能只对集团和站点级别开放',
  9. '因为集团上关于电子卡的共享配置,此级没有配置权限',
  10. ,
  11. '您暂未启动电子卡功能',
  12. ]"
  13. >
  14. <div class="app-container">
  15. <el-form
  16. ref="settingForm"
  17. :model="settingForm"
  18. :rules="settingRules"
  19. label-width="200px"
  20. >
  21. <el-form-item label="是否启用电子卡" prop="cardEnabledFlag">
  22. <el-radio-group v-model="settingForm.cardEnabledFlag">
  23. <el-radio label="0">关闭</el-radio>
  24. <el-radio label="1">开启</el-radio>
  25. </el-radio-group>
  26. </el-form-item>
  27. <div v-show="settingForm.cardEnabledFlag == 1">
  28. <el-form-item label="启用哪种电子卡">
  29. <el-checkbox-group
  30. v-model="settingForm.cardOilsType"
  31. @change="effectiveRefresh"
  32. >
  33. <el-checkbox label="1">汽油卡</el-checkbox>
  34. <el-checkbox label="2">柴油卡</el-checkbox>
  35. <!-- <el-checkbox label="3">非油品卡</el-checkbox> -->
  36. <el-checkbox label="4">LNG卡</el-checkbox>
  37. <el-checkbox label="5">CNG卡</el-checkbox>
  38. </el-checkbox-group>
  39. </el-form-item>
  40. <div style="width: 900px; margin-left: 90px;margin-bottom:40px;">
  41. <div style="text-align: right">
  42. <el-button type="primary" @click="handleAdd" size="mini" style="margin-bottom:20px;margin-right:50px">
  43. 新 增 规 则
  44. </el-button>
  45. </div>
  46. <el-table
  47. :data="settingForm.detailList"
  48. >
  49. <af-table-column
  50. label="电子卡"
  51. align="center"
  52. :formatter="oilNameFormatter"
  53. />
  54. <af-table-column
  55. label="条件"
  56. align="center"
  57. prop="discountAmtTerm"
  58. >
  59. <template slot-scope="scope1">
  60. {{ scope1.row.discountAmtStart }}≤充值金额(元)&lt;{{
  61. scope1.row.discountAmtEnd
  62. }}
  63. </template>
  64. </af-table-column>
  65. <af-table-column label="赠送" align="center">
  66. <template slot-scope="scope">
  67. {{
  68. scope.row.settingRuleType == 1
  69. ? "按金额赠送"
  70. : scope.row.settingRuleType == 2
  71. ? "按比例赠送"
  72. : ""
  73. }}
  74. --- 额度为 {{ scope.row.presentAmt }}
  75. {{
  76. scope.row.settingRuleType == "1"
  77. ? "元"
  78. : scope.row.settingRuleType == "2"
  79. ? "%"
  80. : ""
  81. }}
  82. </template>
  83. </af-table-column>
  84. <af-table-column label="生效状态" align="center">
  85. <template slot-scope="scope">
  86. {{ effective(scope.row.cardType) }}
  87. </template>
  88. </af-table-column>
  89. <af-table-column
  90. label="操作"
  91. align="center"
  92. class-name="small-padding fixed-width"
  93. >
  94. <template slot-scope="scope">
  95. <el-button
  96. size="mini"
  97. type="text"
  98. icon="el-icon-edit"
  99. @click="handleUpdate(scope.$index, scope.row)"
  100. >修改</el-button
  101. >
  102. <el-button
  103. size="mini"
  104. type="text"
  105. icon="el-icon-delete"
  106. @click="handleDelete(scope.$index, scope.row)"
  107. >删除</el-button
  108. >
  109. </template>
  110. </af-table-column>
  111. </el-table>
  112. </div>
  113. <el-form-item label="充值活动" required prop="discountTimeSetting">
  114. <el-radio-group v-model="settingForm.discountTimeSetting">
  115. <el-radio label="0">关闭</el-radio>
  116. <el-radio label="1">开启</el-radio>
  117. </el-radio-group>
  118. </el-form-item>
  119. <div v-show="settingForm.discountTimeSetting == 1">
  120. <el-form-item
  121. label="活动的周期类型"
  122. prop="discountTimeType"
  123. :required="settingForm.discountTimeSetting == 1"
  124. >
  125. <el-select
  126. v-model="settingForm.discountTimeType"
  127. clearable
  128. size="mini"
  129. @change="timeClear"
  130. >
  131. <el-option label="每周指定日" value="1"></el-option>
  132. <el-option label="每月指定日" value="2"></el-option>
  133. <el-option label="固定活动日" value="3"></el-option>
  134. </el-select>
  135. <div
  136. v-show="settingForm.discountTimeType != 3"
  137. style="
  138. display: flex;
  139. flex-wrap: wrap;
  140. border-style: solid;
  141. border-color: #f5f7fa;
  142. "
  143. >
  144. <div
  145. v-for="(item, index) in timeSelect[
  146. settingForm.discountTimeType
  147. ]"
  148. :key="index"
  149. style="margin: 3px"
  150. >
  151. <div
  152. class="hover-style"
  153. style="
  154. border-radius: 5px;
  155. font-weight: bold;
  156. font-size: 12px;
  157. cursor: pointer;
  158. "
  159. @click="timeClickCalendar(index)"
  160. >
  161. <div>{{ item }}</div>
  162. <div
  163. v-if="
  164. settingForm.collectClickCalendar.indexOf(index) > -1
  165. "
  166. style="
  167. width: 4px;
  168. height: 4px;
  169. border-radius: 50%;
  170. background-color: red;
  171. position: relative;
  172. left: calc(50% - 2px);
  173. "
  174. ></div>
  175. <div v-else style="width: 4px; height: 4px"></div>
  176. </div>
  177. </div>
  178. </div>
  179. <div v-show="settingForm.discountTimeType == 3">
  180. <el-date-picker
  181. clearable
  182. size="small"
  183. style="margin-left: 10px; width: 200px"
  184. v-model="settingForm.collectClickDay"
  185. type="dates"
  186. value-format="yyyy-MM-dd"
  187. placeholder="选择提醒时间设置"
  188. >
  189. </el-date-picker>
  190. </div>
  191. </el-form-item>
  192. <el-form-item
  193. label="活动的赠送比例"
  194. prop="presentScale"
  195. :required="settingForm.discountTimeSetting == 1"
  196. >
  197. <el-input
  198. v-model="settingForm.presentScale"
  199. placeholder="请输入赠送比例"
  200. style="width: 70px"
  201. />%
  202. </el-form-item>
  203. </div>
  204. <el-form-item
  205. prop="isMarket"
  206. label="是否叠加优惠方案"
  207. :required="settingForm.cardEnabledFlag == 1"
  208. >
  209. <el-radio-group v-model="settingForm.isMarket">
  210. <el-radio label="1">叠加</el-radio>
  211. <el-radio label="0">不叠加</el-radio>
  212. </el-radio-group>
  213. </el-form-item>
  214. <el-form-item
  215. prop="isGradeSetting"
  216. label="是否叠加等级优惠"
  217. :required="settingForm.cardEnabledFlag == 1"
  218. >
  219. <el-radio-group v-model="settingForm.isGradeSetting">
  220. <el-radio label="1">叠加</el-radio>
  221. <el-radio label="0">不叠加</el-radio>
  222. </el-radio-group>
  223. </el-form-item>
  224. <!-- <el-form-item
  225. prop="isDiscountCoupon"
  226. label="是否叠加优惠券"
  227. :required="settingForm.cardEnabledFlag == 1"
  228. >
  229. <el-radio-group v-model="settingForm.isDiscountCoupon">
  230. <el-radio label="1">叠加</el-radio>
  231. <el-radio label="0">不叠加</el-radio>
  232. </el-radio-group>
  233. </el-form-item> -->
  234. <el-form-item
  235. prop="isLabel"
  236. label="是否叠加标签"
  237. :required="settingForm.cardEnabledFlag == 1"
  238. >
  239. <el-radio-group v-model="settingForm.isLabel">
  240. <el-radio label="1">叠加</el-radio>
  241. <el-radio label="0">不叠加</el-radio>
  242. </el-radio-group>
  243. </el-form-item>
  244. <el-form-item
  245. prop="enjoyIntegralMultiple"
  246. label="支付产生积分倍数"
  247. :required="settingForm.cardEnabledFlag == 1"
  248. >
  249. 电子卡支付产生的积分数量是微信支付产生积分数量的
  250. <el-input
  251. v-model="settingForm.enjoyIntegralMultiple"
  252. style="width: 60px"
  253. size="mini"
  254. />倍
  255. </el-form-item>
  256. </div>
  257. </el-form>
  258. <div slot="footer" class="dialog-footer">
  259. <el-button type="primary" @click="submitForm" size="mini"
  260. >确 定</el-button
  261. >
  262. </div>
  263. <!-- 添加或修改客户电子会员卡充值优惠设置明细对话框 -->
  264. <el-dialog :title="title" :visible.sync="open" append-to-body>
  265. <el-form
  266. ref="infoForm"
  267. :model="infoForm"
  268. :rules="infoRules"
  269. label-width="120px"
  270. >
  271. <el-form-item label="电子卡" prop="cardType" required>
  272. <el-select
  273. v-model="infoForm.cardType"
  274. placeholder="请选择电子卡"
  275. clearable
  276. size="mini"
  277. >
  278. <el-option label="汽油卡" value="1"></el-option>
  279. <el-option label="柴油卡" value="2"></el-option>
  280. <el-option label="非油品卡" value="3"></el-option>
  281. <el-option label="LNG卡" value="4"></el-option>
  282. <el-option label="CNG卡" value="5"></el-option>
  283. </el-select>
  284. </el-form-item>
  285. <el-form-item label="条件设置" prop="discountAmtEnd" required>
  286. <el-input-number
  287. v-model="infoForm.discountAmtStart"
  288. size="mini"
  289. style="width: 120px"
  290. />
  291. <span>≤ 充值金额(元) &lt;</span>
  292. <el-input-number
  293. v-model="infoForm.discountAmtEnd"
  294. size="mini"
  295. style="width: 120px"
  296. />
  297. </el-form-item>
  298. <el-form-item label="赠送方式" prop="presentAmt" required>
  299. <div>
  300. <el-select
  301. v-model="infoForm.settingRuleType"
  302. placeholder="请选择赠送方式"
  303. size="mini"
  304. >
  305. <el-option label="按金额赠送" value="1"></el-option>
  306. <el-option label="按比例赠送" value="2"></el-option>
  307. </el-select>
  308. <div v-show="!!this.infoForm.settingRuleType">
  309. <el-input
  310. v-model="infoForm.presentAmt"
  311. style="width: 100px"
  312. size="mini"
  313. />
  314. <span>{{
  315. this.infoForm.settingRuleType == "1"
  316. ? "元"
  317. : this.infoForm.settingRuleType == "2"
  318. ? "%"
  319. : ""
  320. }}</span>
  321. </div>
  322. </div>
  323. </el-form-item>
  324. <el-form-item>
  325. <div>
  326. <div style="color: red">例:</div>
  327. <div style="color: red">按赠送金额:充100赠送10元</div>
  328. <div style="color: red">按赠送比例:充100赠送10%</div>
  329. </div>
  330. </el-form-item>
  331. </el-form>
  332. <div slot="footer" class="dialog-footer">
  333. <el-button type="primary" @click="addItem">添加</el-button>
  334. </div>
  335. </el-dialog>
  336. </div>
  337. </PermissionContainer>
  338. </template>
  339. <script>
  340. import {
  341. addSetting,
  342. updateSetting,
  343. selectCustomerCardSetting,
  344. } from "@/api/customer/cardSetting";
  345. export default {
  346. name: "Dzk_Rule",
  347. data() {
  348. const validateCardType = (rule, value, callback) => {
  349. if (!this.infoForm.cardType) {
  350. callback(new Error("请选择电子卡"));
  351. return;
  352. }
  353. callback();
  354. };
  355. const validateDiscountAmtEnd = (rule, value, callback) => {
  356. if (!this.infoForm.discountAmtStart) {
  357. callback(new Error("请填写条件的开始金额"));
  358. return;
  359. }
  360. if (!this.infoForm.discountAmtEnd) {
  361. callback(new Error("请填写条件的结束金额"));
  362. return;
  363. }
  364. const start = +this.infoForm.discountAmtStart;
  365. const end = +this.infoForm.discountAmtEnd;
  366. if (start >= end) {
  367. callback(new Error("请填写条件的逻辑合理性"));
  368. return;
  369. }
  370. callback();
  371. };
  372. const validatePresentAmt = (rule, value, callback) => {
  373. if (!this.infoForm.settingRuleType) {
  374. callback(new Error("请选择赠送方式"));
  375. return;
  376. }
  377. if (!this.infoForm.presentAmt) {
  378. callback(new Error("请填写赠送值"));
  379. return;
  380. }
  381. callback();
  382. };
  383. const validateDiscountTimeType = (rule, value, callback) => {
  384. if (this.settingForm.discountTimeSetting == 0) {
  385. callback();
  386. return;
  387. }
  388. if (!this.settingForm.discountTimeType) {
  389. callback(new Error("请选择活动的周期类型"));
  390. return;
  391. }
  392. if (
  393. this.settingForm.discountTimeType == 1 ||
  394. this.settingForm.discountTimeType == 2
  395. ) {
  396. if (this.settingForm.collectClickCalendar.length <= 0) {
  397. callback(new Error("请选择活动的时间"));
  398. return;
  399. }
  400. }
  401. if (this.settingForm.discountTimeType == 3) {
  402. if (
  403. this.settingForm.collectClickDay == null ||
  404. this.settingForm.collectClickDay.length <= 0
  405. ) {
  406. callback(new Error("请填写活动时间"));
  407. return;
  408. }
  409. }
  410. callback();
  411. };
  412. return {
  413. title: "",
  414. // 表单参数
  415. settingForm: {
  416. detailList: [],
  417. collectClickCalendar: [], // 收集固定日期选择的日子
  418. collectClickDay: [],
  419. cardOilsType: [],
  420. },
  421. itemIndex: null,
  422. open: false,
  423. infoForm: {},
  424. timeSelect: [
  425. ,
  426. ["周天", "周一", "周二", "周三", "周四", "周五", "周六"],
  427. [
  428. "01",
  429. "02",
  430. "03",
  431. "04",
  432. "05",
  433. "06",
  434. "07",
  435. "08",
  436. "09",
  437. "10",
  438. "11",
  439. "12",
  440. "13",
  441. "14",
  442. "15",
  443. "16",
  444. "17",
  445. "18",
  446. "19",
  447. "20",
  448. "21",
  449. "22",
  450. "23",
  451. "24",
  452. "25",
  453. "26",
  454. "27",
  455. "28",
  456. "29",
  457. "30",
  458. "31",
  459. ],
  460. ],
  461. infoRules: {
  462. cardType: [{ validator: validateCardType, trigger: "change" }],
  463. discountAmtEnd: [
  464. { validator: validateDiscountAmtEnd, trigger: "change" },
  465. ],
  466. presentAmt: [{ validator: validatePresentAmt, trigger: "change" }],
  467. },
  468. settingRules: {
  469. cardEnabledFlag: [
  470. {
  471. required: true,
  472. message: "请选择是否启用电子卡",
  473. trigger: "change",
  474. },
  475. ],
  476. presentScale: [{ trigger: "change" }],
  477. discountTimeType: [
  478. { validator: validateDiscountTimeType, trigger: "change" },
  479. ],
  480. discountTimeSetting: [
  481. {
  482. required: true,
  483. message: "请选择是否启用电子卡",
  484. trigger: "change",
  485. },
  486. ],
  487. },
  488. };
  489. },
  490. created() {
  491. this.init();
  492. },
  493. methods: {
  494. init() {
  495. selectCustomerCardSetting().then((response) => {
  496. this.settingForm = response.data;
  497. this.settingForm.collectClickCalendar = [];
  498. this.settingForm.collectClickDay = "";
  499. if (this.settingForm.cardOilsType == null) {
  500. this.settingForm.cardOilsType = "";
  501. }
  502. const cardOilsType = this.settingForm.cardOilsType
  503. .split(",")
  504. .filter((ele) => {
  505. return ele != "";
  506. });
  507. this.settingForm.cardOilsType = cardOilsType;
  508. if (
  509. this.settingForm.discountTimeType == "1" ||
  510. this.settingForm.discountTimeType == "2"
  511. ) {
  512. // if( this.form.discountTime == ""){
  513. // this.form.collectClickCalendar = [];
  514. // }
  515. this.settingForm.collectClickCalendar = this.settingForm.discountTime
  516. .split(",")
  517. .map(parseFloat);
  518. } else if (this.settingForm.discountTimeType == "3") {
  519. if (this.settingForm.discountTime.length == 0) {
  520. this.settingForm.collectClickDay = [];
  521. } else {
  522. this.settingForm.collectClickDay =
  523. this.settingForm.discountTime.split(",");
  524. }
  525. }
  526. this.settingForm = { ...this.settingForm };
  527. });
  528. },
  529. timeClear() {
  530. this.settingForm.collectClickCalendar = [];
  531. this.settingForm.collectClickDay = [];
  532. },
  533. effectiveRefresh(e) {
  534. this.settingForm = { ...this.settingForm };
  535. },
  536. effective(no) {
  537. return this.settingForm.cardOilsType.includes(no) ? "生效中" : "未生效";
  538. },
  539. timeClickCalendar(index) {
  540. if (this.settingForm.collectClickCalendar.indexOf(index) === -1) {
  541. this.settingForm.collectClickCalendar.push(index);
  542. } else if (this.settingForm.collectClickCalendar.indexOf(index) > -1) {
  543. const temp = this.settingForm.collectClickCalendar.findIndex((ele) => {
  544. return ele == index;
  545. });
  546. this.settingForm.collectClickCalendar.splice(temp, 1);
  547. }
  548. this.$refs.settingForm.validateField("discountTimeType");
  549. this.settingForm = { ...this.settingForm };
  550. },
  551. oilNameFormatter(row, column) {
  552. if (row.cardType === "1") {
  553. return "汽油卡";
  554. } else if (row.cardType === "2") {
  555. return "柴油卡";
  556. } else if (row.cardType === "3") {
  557. return "非油品卡";
  558. } else if (row.cardType === "4") {
  559. return "LNG卡";
  560. } else if (row.cardType === "5") {
  561. return "CNG卡";
  562. } else {
  563. return row.cardType;
  564. }
  565. },
  566. /** 新增按钮操作 */
  567. handleAdd() {
  568. this.itemIndex = this.settingForm.detailList.length;
  569. this.open = true;
  570. this.title = "添加电子卡充值规则";
  571. },
  572. /** 修改按钮操作 */
  573. handleUpdate(index, row) {
  574. this.itemIndex = index;
  575. this.infoForm = JSON.parse(JSON.stringify(row));
  576. this.open = true;
  577. this.title = "修改电子卡充值规则";
  578. },
  579. /** 提交按钮 */
  580. submitForm() {
  581. this.$refs["settingForm"].validate((valid) => {
  582. if (valid) {
  583. this.settingForm.cardOilsType =
  584. this.settingForm.cardOilsType.toString();
  585. if (
  586. this.settingForm.discountTimeType == "1" ||
  587. this.settingForm.discountTimeType == "2"
  588. ) {
  589. this.settingForm.discountTime =
  590. this.settingForm.collectClickCalendar.toString();
  591. } else {
  592. this.settingForm.discountTime =
  593. this.settingForm.collectClickDay.toString();
  594. }
  595. if (this.settingForm.id != null) {
  596. updateSetting(this.settingForm).then((response) => {
  597. this.msgSuccess("修改成功");
  598. this.init();
  599. });
  600. } else {
  601. addSetting(this.settingForm).then((response) => {
  602. this.msgSuccess("新增成功");
  603. this.init();
  604. });
  605. }
  606. }
  607. });
  608. },
  609. /** 删除按钮操作 */
  610. handleDelete(index) {
  611. this.settingForm.detailList.splice(index, 1);
  612. },
  613. addItem() {
  614. this.$refs["infoForm"].validate((valid) => {
  615. if (valid) {
  616. this.settingForm.detailList.splice(this.itemIndex, 1, this.infoForm);
  617. this.infoForm = {};
  618. this.open = false;
  619. }
  620. });
  621. },
  622. },
  623. };
  624. </script>