Market_Discount.vue 16 KB

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