discount.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. ref="ruleForm"
  5. :model="ruleForm"
  6. :rules="rules"
  7. label-width="130px"
  8. >
  9. <el-form-item label="当前执行优惠方案">
  10. {{ currentDiscountName }}
  11. </el-form-item>
  12. <el-form-item label="优惠方案">
  13. <el-select
  14. v-model="ruleForm.discountSetting"
  15. placeholder="请选择优惠方案"
  16. clearable
  17. size="small"
  18. @change="discountSettingChang"
  19. >
  20. <el-option label="无" value="0"></el-option>
  21. <el-option label="满减" value="1"></el-option>
  22. <el-option label="立减" value="2"></el-option>
  23. <el-option label="直降" value="3"></el-option>
  24. </el-select>
  25. <el-button size="mini" @click="save" type="primary"
  26. >确定执行该优惠方案</el-button
  27. >
  28. </el-form-item>
  29. </el-form>
  30. <hr />
  31. <el-dialog
  32. :title="title"
  33. :visible.sync="openDialog"
  34. width="550px"
  35. append-to-body
  36. >
  37. <el-form
  38. ref="updateForm"
  39. :model="updateForm"
  40. :rules="rules"
  41. label-width="140px"
  42. >
  43. <el-form-item label="方案名称" prop="grade">
  44. <el-input v-model="updateForm.grade" placeholder="请输入方案名称" />
  45. </el-form-item>
  46. <el-form-item label="油品名称" prop="oilName">
  47. <el-select
  48. v-model="updateForm.oilName"
  49. placeholder="油品名称"
  50. clearable
  51. size="small"
  52. >
  53. <el-option
  54. v-for="dict in oilNameOptions"
  55. :key="dict.oilName"
  56. :label="dict.oilName"
  57. :value="dict.oilName"
  58. />
  59. </el-select>
  60. </el-form-item>
  61. <el-form-item label="优惠条件" prop="gasoilDiscountAmt" required>
  62. <el-radio-group v-model="updateForm.discountTerm">
  63. <el-radio :label="0">按加油金额优惠</el-radio>
  64. <el-radio :label="1">按加油升数优惠</el-radio>
  65. </el-radio-group>
  66. <div
  67. v-show="
  68. updateForm.discountTerm == 0 || updateForm.discountTerm == 1
  69. "
  70. >
  71. <el-input-number
  72. v-model="updateForm.discountAmt"
  73. size="mini"
  74. :min="0"
  75. />
  76. <span>{{ updateForm.discountTerm == 0 ? "元" : "L" }}</span>
  77. 每升优惠
  78. <el-input-number
  79. v-model="updateForm.gasoilDiscountAmt"
  80. size="mini"
  81. :min="0"
  82. />元
  83. </div>
  84. </el-form-item>
  85. <el-form-item label="叠加等级优惠" prop="vipDiscountyPlus">
  86. <el-radio-group v-model="updateForm.vipDiscountyPlus">
  87. <el-radio label="1">是</el-radio>
  88. <el-radio label="0">否</el-radio>
  89. </el-radio-group>
  90. <div style="margin-left: 20px; color: red">
  91. 注:"否" 客户只享受 {{ discountName }} 优惠
  92. </div>
  93. </el-form-item>
  94. <el-form-item label="可否叠加劵" prop="couponPlus">
  95. <el-radio-group v-model="updateForm.couponPlus">
  96. <el-radio label="1">是</el-radio>
  97. <el-radio label="0">否</el-radio>
  98. </el-radio-group>
  99. <div style="margin-left: 20px; color: red">
  100. 注:"否" 客户只享受 {{ discountName }} 优惠
  101. </div>
  102. </el-form-item>
  103. <el-form-item
  104. v-show="false"
  105. label="优惠方案类型"
  106. prop="discountPlanType"
  107. >
  108. <el-select
  109. v-model="updateForm.discountPlanType"
  110. placeholder="请选择优惠方案类型"
  111. >
  112. <el-option label="请选择字典生成" value="" />
  113. </el-select>
  114. </el-form-item>
  115. </el-form>
  116. <div slot="footer" class="dialog-footer">
  117. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  118. <el-button @click="cancelSubmit">取 消</el-button>
  119. </div>
  120. </el-dialog>
  121. <el-form
  122. :model="queryParams"
  123. ref="queryForm"
  124. :inline="true"
  125. label-width="68px"
  126. v-show="discountSetting!=0"
  127. >
  128. <div>
  129. <span style="color: #ff9955; font-size: 25px">|</span
  130. ><span style="font-size: 25px">
  131. {{
  132. this.discountSetting == 1
  133. ? "满减方案"
  134. : this.discountSetting == 2
  135. ? "立减方案"
  136. : this.discountSetting == 3
  137. ? "直降方案"
  138. : "无"
  139. }}
  140. </span>
  141. <el-button
  142. icon="el-icon-plus"
  143. size="mini"
  144. @click="handleUpdateClick"
  145. style="float: right"
  146. type="warning"
  147. >
  148. {{
  149. this.discountSetting == 1
  150. ? "添加满减方案条目"
  151. : this.discountSetting == 2
  152. ? "添加立减方案条目"
  153. : this.discountSetting == 3
  154. ? "添加直降方案条目"
  155. : "无"
  156. }}
  157. </el-button>
  158. </div>
  159. </el-form>
  160. <el-table :data="discountList" v-show="discountSetting!=0">
  161. <af-table-column label="id" align="center" prop="id" v-if="false" />
  162. <af-table-column label="方案名称" align="center" prop="grade" />
  163. <af-table-column label="油品名称" align="center" prop="oilName" />
  164. <af-table-column
  165. label="优惠条件"
  166. align="center"
  167. v-show="discountSetting == 3"
  168. >
  169. <template slot-scope="scope">
  170. 满 {{ scope.row.discountAmt }}元,每升优惠
  171. {{ scope.row.gasoilDiscountAmt }} 元
  172. </template>
  173. </af-table-column>
  174. <af-table-column
  175. label="优惠条件"
  176. align="center"
  177. v-show="discountSetting == 3"
  178. >
  179. <template slot-scope="scope">
  180. 满 {{ scope.row.discountAmt }}升,每升优惠
  181. {{ scope.row.gasoilDiscountAmt }} 元
  182. </template>
  183. </af-table-column>
  184. <af-table-column
  185. label="优惠条件"
  186. align="center"
  187. v-show="discountSetting == 1"
  188. >
  189. <template slot-scope="scope">
  190. 每满 {{ scope.row.discountAmt }} 元,减
  191. {{ scope.row.gasoilDiscountAmt }} 元
  192. </template>
  193. </af-table-column>
  194. <af-table-column
  195. label="优惠条件"
  196. align="center"
  197. v-show="discountSetting == 2"
  198. >
  199. <template slot-scope="scope">
  200. 满 {{ scope.row.discountAmt }} 元,减
  201. {{ scope.row.gasoilDiscountAmt }} 元
  202. </template>
  203. </af-table-column>
  204. <af-table-column
  205. label="优惠条件金额"
  206. v-if="false"
  207. align="center"
  208. prop="discountAmt"
  209. />
  210. <af-table-column
  211. label="优惠金额"
  212. v-if="false"
  213. align="center"
  214. prop="gasoilDiscountAmt"
  215. />
  216. <af-table-column
  217. label="是否叠加等级优惠"
  218. align="center"
  219. prop="vipDiscountyPlus"
  220. :formatter="vipDiscountyPlusFotmat"
  221. />
  222. <af-table-column
  223. label="可否叠加劵"
  224. align="center"
  225. prop="couponPlus"
  226. :formatter="couponPlusFotmat"
  227. />
  228. <af-table-column
  229. label="优惠方案类型"
  230. v-if="false"
  231. align="center"
  232. prop="discountPlanType"
  233. />
  234. <af-table-column
  235. label="操作"
  236. align="center"
  237. class-name="small-padding fixed-width"
  238. >
  239. <template slot-scope="scope">
  240. <el-button
  241. size="mini"
  242. type="text"
  243. icon="el-icon-edit"
  244. @click="handleUpdate(scope.row)"
  245. >修改</el-button
  246. >
  247. <el-button
  248. size="mini"
  249. type="text"
  250. icon="el-icon-delete"
  251. @click="handleDelete(scope.row)"
  252. >删除</el-button
  253. >
  254. </template>
  255. </af-table-column>
  256. </el-table>
  257. </div>
  258. </template>
  259. <script>
  260. import {
  261. listPlan,
  262. getPlan,
  263. delPlan,
  264. addPlan,
  265. updatePlan,
  266. exportPlan,
  267. } from "@/api/market/plan";
  268. import { getStationPay, updatePay } from "@/api/station/pay";
  269. import { getDept } from "@/api/system/dept";
  270. import { listPrice } from "@/api/station/price";
  271. export default {
  272. name: "Setting",
  273. data() {
  274. const validatorGasoilDiscountAmt = (rule, value, callback) => {
  275. console.log(this.updateForm.discountTerm);
  276. if (
  277. this.updateForm.discountTerm === undefined ||
  278. this.updateForm.discountTerm === ""
  279. ) {
  280. callback(new Error("请选择优惠方式"));
  281. return;
  282. }
  283. const start = +this.updateForm.discountAmt;
  284. const end = +this.updateForm.gasoilDiscountAmt;
  285. if (isNaN(start) || isNaN(end)) {
  286. callback(new Error("检查优惠方式完整性"));
  287. return;
  288. }
  289. callback();
  290. };
  291. return {
  292. discountList: [],
  293. // 总条数
  294. total: 0,
  295. couponPlusOptions: [],
  296. vipDiscountyPlusOptions: [],
  297. discountSettingOptions: [],
  298. stationOptions: [],
  299. oilNameOptions: [],
  300. oilNameOptionsDT: [],
  301. oilNameOptionsZJ: [],
  302. discountTermOptions: [],
  303. // 弹出层标题
  304. title: "",
  305. fangan: "",
  306. // 是否显示弹出层
  307. open: false,
  308. openDialog: false,
  309. yuan: true,
  310. laters: false,
  311. // 查询参数
  312. queryParams: {
  313. pageNum: 1,
  314. pageSize: 10,
  315. grade: null,
  316. discountWay: null,
  317. gasoilDiscountLitre: null,
  318. dieseloilDiscountLitre: null,
  319. gradeType: null,
  320. gasoilConsume: null,
  321. gasoilGrowthValue: null,
  322. dieseloilConsume: null,
  323. dieseloilGrowthValue: null,
  324. growthValue: null,
  325. date: null,
  326. deductionGrowthValue: null,
  327. },
  328. // 表单参数
  329. form: {},
  330. ruleForm: {
  331. imgFileList: [],
  332. },
  333. // 表单校验
  334. rules: {
  335. grade: [{ required: true, message: "请输入方案名称", trigger: "blur" }],
  336. oilName: [
  337. { required: true, message: "请选择油品名称", trigger: "change" },
  338. ],
  339. discountTerm: [
  340. { required: true, message: "选择油品名称", trigger: "change" },
  341. ],
  342. gasoilDiscountAmt: [
  343. { validator: validatorGasoilDiscountAmt, trigger: "change" },
  344. ],
  345. discountAmt: [
  346. { required: true, message: "请填写优惠金额", trigger: "blur" },
  347. ],
  348. vipDiscountyPlus: [
  349. {
  350. required: true,
  351. message: "选择等级优惠是否叠加",
  352. trigger: "change",
  353. },
  354. ],
  355. couponPlus: [
  356. { required: true, message: "选择可否叠加券", trigger: "change" },
  357. ],
  358. },
  359. dtrules: {},
  360. discountSetting: 0,
  361. updateForm: {},
  362. currentDiscountName:'',
  363. };
  364. },
  365. computed: {
  366. discountName() {
  367. return this.discountSetting == 1
  368. ? "满减"
  369. : this.discountSetting == 2
  370. ? "立减"
  371. : this.discountSetting == 3
  372. ? "直降"
  373. : "无";
  374. },
  375. },
  376. created() {
  377. this.getDicts("coupon_plus").then((response) => {
  378. this.couponPlusOptions = response.data;
  379. });
  380. this.getDicts("discount_term").then((response) => {
  381. this.discountTermOptions = response.data;
  382. });
  383. this.getDicts("vip_discounty_plus").then((response) => {
  384. this.vipDiscountyPlusOptions = response.data;
  385. });
  386. //查看当前优惠设置
  387. listPrice().then((response) => {
  388. this.oilNameOptions = response.rows;
  389. });
  390. this.getPay().then(()=>{
  391. this.getList()
  392. })
  393. getStationPay().then((response) => {
  394. this.ruleForm = response.data;
  395. this.discountSetting = response.data.discountSetting;
  396. this.getList();
  397. });
  398. this.getDicts("discount_setting").then((response) => {
  399. this.discountSettingOptions = response.data;
  400. });
  401. },
  402. methods: {
  403. getPay() {
  404. return getStationPay().then((response) => {
  405. this.ruleForm = response.data;
  406. this.discountSetting = response.data.discountSetting;
  407. this.currentDiscountName = this.discountName;
  408. });
  409. },
  410. save() {
  411. this.$refs["ruleForm"].validate((valid) => {
  412. if (valid) {
  413. if (this.ruleForm.payId != null) {
  414. let e = this.ruleForm.discountSetting;
  415. if (e == "0") {
  416. updatePay(this.ruleForm).then((response) => {
  417. this.fangan = "不执行优惠";
  418. this.msgSuccess("优惠方案设置成功");
  419. });
  420. } else if (e == "1") {
  421. if (this.discountList.length > 0) {
  422. updatePay(this.ruleForm).then((response) => {
  423. this.fangan = "满减";
  424. this.msgSuccess("优惠方案设置成功");
  425. });
  426. } else {
  427. this.msgError("满减规则下无方案");
  428. }
  429. } else if (e == "2") {
  430. if (this.discountList.length > 0) {
  431. updatePay(this.ruleForm).then((response) => {
  432. this.fangan = "立减";
  433. this.msgSuccess("优惠方案设置成功");
  434. });
  435. } else {
  436. this.msgError("立减规则下无方案");
  437. }
  438. } else if (e == "3") {
  439. if (this.discountList.length > 0) {
  440. updatePay(this.ruleForm).then((response) => {
  441. this.fangan = "直降";
  442. this.msgSuccess("优惠方案设置成功");
  443. });
  444. } else {
  445. this.msgError("直降规则下无方案");
  446. }
  447. }
  448. }
  449. this.getPay()
  450. }
  451. });
  452. },
  453. discountSettingChang(e) {
  454. this.discountSetting = e;
  455. this.getList();
  456. },
  457. getList() {
  458. const query = {
  459. pageNum: 1,
  460. pageSize: 10,
  461. discountPlanType: this.discountSetting,
  462. };
  463. listPlan(query).then((response) => {
  464. this.discountList = response.rows;
  465. this.total = response.total;
  466. });
  467. },
  468. vipDiscountyPlusFotmat(row, column) {
  469. if (row.vipDiscountyPlus === "1") {
  470. return "是";
  471. } else if (row.vipDiscountyPlus === "0") {
  472. return "否";
  473. }
  474. },
  475. couponPlusFotmat(row, column) {
  476. if (row.couponPlus === "1") {
  477. return "是";
  478. } else if (row.couponPlus === "0") {
  479. return "否";
  480. }
  481. },
  482. handleUpdateClick() {
  483. this.openDialog = true;
  484. this.updateForm = {
  485. discountPlanType: this.discountSetting,
  486. };
  487. },
  488. handleSubmit() {
  489. this.$refs["updateForm"].validate((valid) => {
  490. if (valid) {
  491. if (this.updateForm.id != null) {
  492. updatePlan(this.updateForm).then((response) => {
  493. this.msgSuccess("修改成功");
  494. this.openDialog = false;
  495. this.getList();
  496. });
  497. } else {
  498. addPlan(this.updateForm).then((response) => {
  499. this.msgSuccess("新增成功");
  500. this.openDialog = false;
  501. this.getList();
  502. });
  503. }
  504. }
  505. });
  506. },
  507. cancelSubmit() {
  508. this.openDialog = false;
  509. },
  510. /** 修改按钮操作 */
  511. handleUpdate(row) {
  512. const id = row.id;
  513. this.title = "修改满减优惠";
  514. this.openDialog = true;
  515. this.updateForm = row;
  516. },
  517. /** 删除按钮操作 */
  518. handleDelete(row) {
  519. const ids = row.id;
  520. this.$confirm("是否确认删除满减优惠方案?", "警告", {
  521. confirmButtonText: "确定",
  522. cancelButtonText: "取消",
  523. type: "warning",
  524. })
  525. .then(function () {
  526. return delPlan(ids);
  527. })
  528. .then(() => {
  529. this.getList();
  530. this.msgSuccess("删除成功");
  531. });
  532. },
  533. // /** 导出按钮操作 */
  534. // handleExport() {
  535. // const queryParams = this.queryParams;
  536. // this.$confirm("是否确认导出所有优惠设置数据项?", "警告", {
  537. // confirmButtonText: "确定",
  538. // cancelButtonText: "取消",
  539. // type: "warning",
  540. // })
  541. // .then(function () {
  542. // return exportPlan(queryParams);
  543. // })
  544. // .then((response) => {
  545. // this.download(response.msg);
  546. // });
  547. // },
  548. discountTermFormat(row, column) {
  549. if (row.discountTerm === "1") {
  550. return "按加油升数优惠";
  551. } else {
  552. return "按加油金额优惠";
  553. }
  554. },
  555. planFormat(row, column) {
  556. if (row.discountTerm === "1") {
  557. let ss =
  558. "满 " +
  559. row.discountAmt +
  560. "L,每升优惠 " +
  561. row.gasoilDiscountAmt +
  562. "元";
  563. return ss;
  564. } else {
  565. let ss =
  566. "满 " +
  567. row.discountAmt +
  568. "元,每升优惠 " +
  569. row.gasoilDiscountAmt +
  570. "元";
  571. return ss;
  572. }
  573. },
  574. },
  575. };
  576. </script>
  577. <style>
  578. </style>