couponUpdate.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <el-page-header @back="onCancel" :content="title"></el-page-header>
  5. </h2>
  6. <!-- <h3 class="infoTitle">优惠券信息</h3>
  7. <el-divider></el-divider> -->
  8. <div class="m-core">
  9. <el-form :model="form" ref="form" class="form">
  10. <el-row>
  11. <el-col style="width: 395px">
  12. <el-form-item
  13. label="系统类型"
  14. prop="useSystem"
  15. :rules="[{ required: true, message: '系统类型' }]"
  16. >
  17. <el-select
  18. :disabled="isDisabled"
  19. placeholder="系统类型"
  20. v-model.trim="form.useSystem"
  21. filterable
  22. clearable
  23. style="width: 375px !important"
  24. @change="onUseSystemChange"
  25. >
  26. <el-option value="MALL" label="商城"></el-option>
  27. <el-option value="MEC" label="管乐迷"></el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-col>
  31. <el-col style="width: 395px">
  32. <el-form-item
  33. label="优惠券名称"
  34. prop="name"
  35. :rules="[{ required: true, message: '请输入优惠券名称' }]"
  36. >
  37. <el-input
  38. :disabled="isDisabled"
  39. v-model="form.name"
  40. placeholder="请输入优惠券名称"
  41. ></el-input>
  42. </el-form-item>
  43. </el-col>
  44. </el-row>
  45. <el-row>
  46. <el-col style="width: 395px">
  47. <el-form-item
  48. label="可用分部"
  49. prop="organId"
  50. :rules="[{ required: true, message: '请选择可用分部' }]"
  51. >
  52. <br />
  53. <select-all
  54. style="width: 375px !important"
  55. class="multiple"
  56. v-model.trim="form.organId"
  57. filterable
  58. multiple
  59. clearable
  60. placeholder="请选择分部"
  61. >
  62. <el-option
  63. v-for="(item, index) in selects.branchs"
  64. :key="index"
  65. :label="item.name"
  66. :value="item.id"
  67. ></el-option>
  68. </select-all>
  69. </el-form-item>
  70. </el-col>
  71. <el-col style="width: 395px">
  72. <el-form-item
  73. label="描述"
  74. prop="description"
  75. :rules="[{ required: true, message: '请输入优惠券描述' }]"
  76. >
  77. <el-input
  78. :disabled="isDisabled"
  79. v-model="form.description"
  80. maxlength="20"
  81. type="textarea"
  82. :rows="3"
  83. show-word-limit
  84. placeholder="请输入优惠券描述,该描述会在优惠券上展示"
  85. ></el-input>
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. <el-row :gutter="20">
  90. <el-col style="width: 395px">
  91. <el-form-item
  92. label="领券方式"
  93. prop="issuanceType"
  94. :rules="[{ required: true, message: '领券方式' }]"
  95. >
  96. <el-select
  97. :disabled="isDisabled"
  98. placeholder="领券方式"
  99. v-model.trim="form.issuanceType"
  100. filterable
  101. clearable
  102. style="width: 375px !important"
  103. >
  104. <el-option :value="0" label="学员主动领取"></el-option>
  105. <el-option :value="1" label="后台手动发放"></el-option>
  106. </el-select>
  107. </el-form-item>
  108. </el-col>
  109. <el-col style="width: 395px">
  110. <el-form-item
  111. label="优惠券类型"
  112. prop="typeDetail"
  113. :rules="[{ required: true, message: '请选择优惠券类型' }]"
  114. >
  115. <el-select
  116. :disabled="isDisabled"
  117. placeholder="请选择优惠券类型"
  118. v-model.trim="form.typeDetail"
  119. filterable
  120. clearable
  121. style="width: 375px !important"
  122. >
  123. <el-option
  124. v-for="item in coupontypeDetail"
  125. :key="item.value"
  126. :value="item.value"
  127. :label="item.label"
  128. :disabled="item.disabled"
  129. ></el-option>
  130. </el-select>
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <el-row :gutter="20">
  135. <!-- <el-col style="width: 395px">
  136. <el-form-item
  137. label="优惠券类型"
  138. prop="type"
  139. :rules="[{ required: true, message: '请选择优惠券类型' }]"
  140. >
  141. <el-select
  142. :disabled="isDisabled"
  143. placeholder="优惠券类型"
  144. v-model.trim="form.type"
  145. filterable
  146. clearable
  147. @change="changeType"
  148. style="width: 375px !important"
  149. >
  150. <el-option
  151. v-for="item in couponTypeList"
  152. :key="item.value"
  153. :value="item.value"
  154. :label="item.label"
  155. ></el-option>
  156. </el-select>
  157. </el-form-item>
  158. </el-col> -->
  159. <el-col style="width: 395px" v-if="form.type == 'FULL_REDUCTION'">
  160. <el-form-item
  161. label="满减金额"
  162. prop="fullAmount"
  163. :rules="[{ required: true, message: '请输入满减金额' }]"
  164. >
  165. <el-input
  166. v-model="form.fullAmount"
  167. placeholder="请输入满减金额"
  168. :disabled="isDisabled"
  169. >
  170. <template slot="append"
  171. >元</template
  172. >
  173. </el-input>
  174. </el-form-item>
  175. </el-col>
  176. <el-col style="width: 395px" v-if="form.type == 'FULL_REDUCTION'">
  177. <el-form-item
  178. label="面值"
  179. prop="faceValue"
  180. :rules="[{ required: true, message: '请输入面值' }]"
  181. >
  182. <el-input
  183. v-model="form.faceValue"
  184. placeholder="请输入面值"
  185. :disabled="isDisabled"
  186. >
  187. <template slot="append"
  188. >元</template
  189. >
  190. </el-input>
  191. </el-form-item>
  192. </el-col>
  193. <el-col style="width: 395px" v-if="form.type == 'DISCOUNT'">
  194. <el-form-item
  195. label="折扣"
  196. prop="faceValue"
  197. :rules="[{ required: true, message: '请输入折扣' }]"
  198. >
  199. <el-input
  200. v-model="form.faceValue"
  201. placeholder="请输入折扣"
  202. :disabled="isDisabled"
  203. >
  204. <template slot="append"
  205. >%</template
  206. >
  207. </el-input>
  208. </el-form-item>
  209. </el-col>
  210. </el-row>
  211. <el-row :gutter="20">
  212. <el-col style="width: 395px">
  213. <el-form-item
  214. label="有效期类型"
  215. prop="effectiveType"
  216. :rules="[{ required: true, message: '请选择有效期类型' }]"
  217. >
  218. <el-select
  219. style="width: 375px !important"
  220. placeholder="优惠券类型"
  221. v-model.trim="form.effectiveType"
  222. filterable
  223. clearable
  224. @change="changeEffectiveType"
  225. :disabled="isDisabled"
  226. >
  227. <el-option label="固定有效期天数" value="DAYS"></el-option>
  228. <el-option label="固定时间段" value="TIME_BUCKET"></el-option>
  229. </el-select>
  230. </el-form-item>
  231. </el-col>
  232. <el-col style="width: 395px" v-if="form.effectiveType == 'DAYS'">
  233. <el-form-item
  234. prop="deadline"
  235. :rules="[{ required: true, message: '请输入有效期天数' }]"
  236. >
  237. <span style="color: #606266"
  238. ><span style="color: #f56c6c">*</span>有效期天数
  239. <el-tooltip placement="top" popper-class="mTooltip">
  240. <div slot="content">自领取之日起多少天有效</div>
  241. <i
  242. class="el-icon-question"
  243. style="font-size: 18px; color: #f56c6c"
  244. ></i> </el-tooltip
  245. ></span>
  246. <el-input
  247. v-model="form.deadline"
  248. placeholder="请输入有效期天数"
  249. :disabled="isDisabled"
  250. >
  251. <template slot="append"
  252. >天</template
  253. >
  254. </el-input>
  255. </el-form-item>
  256. </el-col>
  257. <el-col
  258. style="width: 395px"
  259. v-if="form.effectiveType == 'TIME_BUCKET'"
  260. >
  261. <el-form-item
  262. prop="effectiveTime"
  263. :rules="[{ required: true, message: '请选择有效期' }]"
  264. >
  265. <span style="color: #606266"
  266. ><span style="color: #f56c6c">*</span>有效期
  267. <el-tooltip placement="top" popper-class="mTooltip">
  268. <div slot="content">优惠券可使用时间段</div>
  269. <i
  270. class="el-icon-question"
  271. style="font-size: 18px; color: #f56c6c"
  272. ></i> </el-tooltip
  273. ></span>
  274. <el-date-picker
  275. style="width: 100%"
  276. v-model="form.effectiveTime"
  277. :picker-options="{ firstDayOfWeek: 1 }"
  278. type="datetimerange"
  279. :default-time="['00:00:00', '23:59:59']"
  280. range-separator="-"
  281. start-placeholder="活动开始日期"
  282. end-placeholder="活动结束日期"
  283. :disabled="isDisabled"
  284. >
  285. </el-date-picker>
  286. </el-form-item>
  287. </el-col>
  288. </el-row>
  289. <el-row :gutter="20">
  290. <el-col style="width: 395px">
  291. <el-form-item
  292. label="库存总量"
  293. prop="stockCount"
  294. :rules="[{ required: true, message: '请输入库存总量' }]"
  295. >
  296. <el-input
  297. :disabled="form.stockCount == -1"
  298. v-model="form.stockCount"
  299. placeholder="请输入库存总量"
  300. >
  301. <template slot="append"
  302. >张</template
  303. >
  304. </el-input>
  305. <el-checkbox
  306. v-model="form.stockCount"
  307. :true-label="-1"
  308. false-label=""
  309. @change="
  310. val => {
  311. checkNo(val, 'stockCount');
  312. }
  313. "
  314. >不限制</el-checkbox
  315. >
  316. </el-form-item>
  317. </el-col>
  318. <el-col style="width: 395px">
  319. <el-form-item
  320. prop="limitExchangeNum"
  321. :rules="[
  322. { required: true, message: '请输入领取上限' },
  323. {
  324. pattern: /^[1-9][0-9]?$/,
  325. message: '请输入1-99的正整数',
  326. trigger: 'blur'
  327. }
  328. ]"
  329. >
  330. <span style="color: #606266">
  331. <span style="color: #f56c6c">*</span> 领取上限
  332. <el-tooltip placement="top" popper-class="mTooltip">
  333. <div slot="content">用户可领取最大张数</div>
  334. <i
  335. class="el-icon-question"
  336. style="font-size: 18px; color: #f56c6c"
  337. ></i> </el-tooltip
  338. ></span>
  339. <el-input
  340. :disabled="isDisabled"
  341. v-model="form.limitExchangeNum"
  342. placeholder="请输入领取上限"
  343. >
  344. <template slot="append"
  345. >张</template
  346. >
  347. </el-input>
  348. </el-form-item>
  349. </el-col>
  350. </el-row>
  351. <el-row :gutter="20">
  352. <el-col style="width: 395px">
  353. <el-form-item
  354. label="领取时间"
  355. prop="getTime"
  356. :rules="[{ required: true, message: '请输入领取时间' }]"
  357. >
  358. <el-date-picker
  359. style="width: 100%"
  360. v-model="form.getTime"
  361. :picker-options="{ firstDayOfWeek: 1 }"
  362. type="datetimerange"
  363. :default-time="['00:00:00', '23:59:59']"
  364. range-separator="-"
  365. start-placeholder="活动开始日期"
  366. end-placeholder="活动结束日期"
  367. >
  368. </el-date-picker>
  369. </el-form-item>
  370. </el-col>
  371. </el-row>
  372. <el-form-item>
  373. <el-button type="primary" v-if="activeRow" @click="resetCoupon"
  374. >保存</el-button
  375. >
  376. <el-button type="primary" v-else @click="addCoupon">提交</el-button>
  377. <el-button type="danger" @click="resetForm">重置</el-button>
  378. </el-form-item>
  379. </el-form>
  380. </div>
  381. </div>
  382. </template>
  383. <script>
  384. import { addSysCoupon, resetSysCoupon } from "./api.js";
  385. import { couponTypeList, coupontypeDetailList } from "@/utils/searchArray";
  386. import { getTimes } from "@/utils";
  387. const mallTypeList = [
  388. {
  389. value: "MALLCOUPON",
  390. label: "商城"
  391. }
  392. ];
  393. export default {
  394. data() {
  395. return {
  396. couponTypeList,
  397. coupontypeDetail: coupontypeDetailList,
  398. form: {
  399. useSystem: "",
  400. typeDetail: null,
  401. name: "",
  402. description: "",
  403. type: "FULL_REDUCTION",
  404. faceValue: "",
  405. fullAmount: "",
  406. effectiveType: "",
  407. effectiveTime: [],
  408. stockCount: "",
  409. warningStockNum: "",
  410. limitExchangeNum: "",
  411. getTime: [],
  412. organId: []
  413. },
  414. activeRow: null,
  415. isDisabled: false,
  416. title: "新增优惠券",
  417. warningStockNum: ""
  418. };
  419. },
  420. mounted() {
  421. this.$store.dispatch("setBranchs");
  422. if (this.$route.query.row) {
  423. this.activeRow = JSON.parse(this.$route.query.row);
  424. let organIdStr = "";
  425. if (
  426. this.activeRow.useCondition &&
  427. JSON.parse(this.activeRow.useCondition) &&
  428. JSON.parse(this.activeRow.useCondition).organId
  429. ) {
  430. organIdStr = JSON.parse(this.activeRow.useCondition).organId;
  431. }
  432. let organId = [];
  433. if (organIdStr) {
  434. organId =
  435. organIdStr.split(",").map(item => {
  436. return Number(item);
  437. }) || [];
  438. }
  439. this.form = { ...this.activeRow, organId };
  440. // 优惠券只能时满减
  441. this.form.type = "FULL_REDUCTION";
  442. let effectiveStartTime = this.activeRow.effectiveStartTime;
  443. let effectiveExpireTime = this.activeRow.effectiveExpireTime;
  444. let startDate = this.activeRow.startDate;
  445. let endDate = this.activeRow.endDate;
  446. this.$set(this.form, "effectiveTime", [
  447. effectiveStartTime,
  448. effectiveExpireTime
  449. ]);
  450. this.$set(this.form, "getTime", [startDate, endDate]);
  451. this.title = this.activeRow.name;
  452. if (this.activeRow?.consumeNum > 0) {
  453. this.isDisabled = true;
  454. }
  455. }
  456. },
  457. methods: {
  458. onUseSystemChange(val) {
  459. if (val === "MALL") {
  460. this.coupontypeDetail.forEach(item => {
  461. if (item.value === "MALLCOUPON") {
  462. item.disabled = false;
  463. } else {
  464. item.disabled = true;
  465. }
  466. });
  467. } else if (val === "MEC") {
  468. this.coupontypeDetail.forEach(item => {
  469. if (item.value === "MALLCOUPON") {
  470. item.disabled = true;
  471. } else {
  472. item.disabled = false;
  473. }
  474. });
  475. }
  476. this.form.typeDetail = null;
  477. // 处理显示问题
  478. setTimeout(() => {
  479. this.$refs.form.clearValidate("typeDetail");
  480. }, 0);
  481. },
  482. changeType(val) {
  483. this.form.faceValue = "";
  484. this.form.fullAmount = "";
  485. },
  486. changeEffectiveType() {
  487. // this.form.effectiveTime = [];
  488. this.$set(this.form, "effectiveTime", []);
  489. this.$set(this.form, "deadline", null);
  490. // this.form.deadline = "";
  491. },
  492. onCancel() {
  493. this.$router.push("/couponManager");
  494. },
  495. resetForm() {
  496. this.$refs.form.resetFields();
  497. if (this.activeRow) {
  498. let organIdStr = JSON.parse(this.activeRow.useCondition);
  499. let organId = [];
  500. if (organIdStr) {
  501. organId = organIdStr.split(",") || [];
  502. }
  503. this.form = { ...this.activeRow, organId };
  504. let effectiveStartTime = this.activeRow.effectiveStartTime;
  505. let effectiveExpireTime = this.activeRow.effectiveExpireTime;
  506. let startDate = this.activeRow.startDate;
  507. let endDate = this.activeRow.endDate;
  508. this.$set(this.form, "effectiveTime", [
  509. effectiveStartTime,
  510. effectiveExpireTime
  511. ]);
  512. this.$set(this.form, "getTime", [startDate, endDate]);
  513. }
  514. },
  515. async addCoupon() {
  516. this.$refs.form.validate(async some => {
  517. if (some) {
  518. this.$confirm("您确定新增优惠券?", "提示", {
  519. confirmButtonText: "确定",
  520. cancelButtonText: "取消",
  521. type: "warning"
  522. })
  523. .then(async () => {
  524. try {
  525. let { effectiveTime, getTime, ...rest } = this.form;
  526. let str = JSON.stringify({
  527. organId: this.form.organId.join(",")
  528. });
  529. let params = {
  530. ...rest,
  531. ...getTimes(
  532. effectiveTime,
  533. ["effectiveStartTime", "effectiveExpireTime"],
  534. "YYYY-MM-DD HH:mm:ss"
  535. ),
  536. ...getTimes(
  537. getTime,
  538. ["startDate", "endDate"],
  539. "YYYY-MM-DD HH:mm:ss"
  540. ),
  541. useCondition: str
  542. };
  543. const res = await addSysCoupon(params);
  544. this.$message.success("新增成功");
  545. this.onCancel();
  546. } catch (e) {
  547. console.log(e);
  548. }
  549. })
  550. .catch(() => {});
  551. }
  552. });
  553. },
  554. resetCoupon() {
  555. this.$refs.form.validate(async some => {
  556. if (some) {
  557. this.$confirm("您确定修改优惠券?", "提示", {
  558. confirmButtonText: "确定",
  559. cancelButtonText: "取消",
  560. type: "warning"
  561. })
  562. .then(async () => {
  563. try {
  564. let { effectiveTime, getTime, ...rest } = this.form;
  565. let str = JSON.stringify({
  566. organId: this.form.organId.join(",")
  567. });
  568. let params = {
  569. ...rest,
  570. ...getTimes(
  571. effectiveTime,
  572. ["effectiveStartTime", "effectiveExpireTime"],
  573. "YYYY-MM-DD HH:mm:ss"
  574. ),
  575. ...getTimes(
  576. getTime,
  577. ["startDate", "endDate"],
  578. "YYYY-MM-DD HH:mm:ss"
  579. ),
  580. useCondition: str
  581. };
  582. const res = await resetSysCoupon(params);
  583. this.$message.success("修改成功");
  584. this.onCancel();
  585. } catch (e) {
  586. console.log(e);
  587. }
  588. })
  589. .catch(() => {});
  590. }
  591. });
  592. },
  593. checkNo(val, type) {
  594. if (val) {
  595. this.form[type] = val;
  596. } else {
  597. this.form[type] = null;
  598. }
  599. }
  600. }
  601. };
  602. </script>
  603. <style lang="scss" scoped>
  604. .form {
  605. // margin-top: 30px;
  606. }
  607. .infoTitle {
  608. font-weight: 400;
  609. margin-top: 30px;
  610. font-size: 18px;
  611. }
  612. ::v-deep label {
  613. font-weight: 400;
  614. }
  615. </style>