addAndEdit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!--
  2. * @Description: 新增/编辑弹框
  3. * @Author: Sugar.
  4. * @Date: 2023-11-24 13:55:00
  5. * @LastEditors: gcz
  6. * @LastEditTime: 2024-03-15 15:37:32
  7. * @FilePath: \great_webui\src\views\marketing\activity\dialog\addAndEdit.vue
  8. * @Copyright: Copyright (c) 2016~2023 by Sugar., All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. :title="title"
  13. :visible.sync="open"
  14. width="1200px"
  15. append-to-body
  16. :close-on-click-modal="false"
  17. @close="cancel"
  18. >
  19. <div class="dialog">
  20. <el-form :model="form" ref="form" :rules="rules" label-width="120px">
  21. <el-form-item label="活动名称" prop="activityName" required>
  22. <el-input
  23. v-model="form.activityName"
  24. placeholder="活动名称"
  25. clearable
  26. style="width: 100%;"
  27. />
  28. </el-form-item>
  29. <el-form-item label="活动时间" prop="activityDate" required>
  30. <el-date-picker
  31. @change="dateChange"
  32. v-model="form.activityDate"
  33. value-format="yyyy-MM-dd HH:mm:ss"
  34. type="datetimerange"
  35. range-separator="至"
  36. start-placeholder="开始日期"
  37. end-placeholder="结束日期">
  38. </el-date-picker>
  39. </el-form-item>
  40. <!-- <el-form-item label="优惠劵总数" prop="couponNum" required>
  41. <el-input
  42. v-model="form.couponNum"
  43. @change="changeNumber('couponNum')"
  44. placeholder="优惠劵总数"
  45. clearable
  46. style="width: 100%;"
  47. />
  48. </el-form-item> -->
  49. <el-form-item label="优惠劵" prop="couponList" required>
  50. <!-- <el-input
  51. v-model="form.couponList"
  52. placeholder="优惠劵"
  53. clearable
  54. style="width: 100%;"
  55. v-show="false"
  56. /> -->
  57. <span style="color: deepskyblue;cursor: pointer;" @click="showSelectTable = true">选择</span>
  58. </el-form-item>
  59. </el-form>
  60. <div class="select-table">
  61. <el-table
  62. :data="tempCouponList"
  63. border
  64. style="width: 100%;"
  65. >
  66. <el-table-column prop="couponBatch" label="批次号" width="140" />
  67. <el-table-column prop="couponName" label="优惠劵名称" />
  68. <el-table-column label="类型" align="center" prop="type">
  69. <template slot-scope="scope">
  70. <span>{{ scope.row.type==1?'满减':'折扣' }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  74. <template slot-scope="scope">
  75. <span>{{ parseTime(scope.row.createTime) }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="数量" align="center" prop="num" width="250">
  79. <template slot-scope="scope">
  80. <el-input-number v-model="scope.row.num" controls-position="right"></el-input-number>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. </div>
  86. <span slot="footer" class="dialog-footer">
  87. <el-button @click="cancel">取消</el-button>
  88. <el-button
  89. type="primary"
  90. @click="submitForm"
  91. v-loading.fullscreen.lock="loading"
  92. element-loading-text="提交中..."
  93. element-loading-spinner="el-icon-loading"
  94. element-loading-background="rgba(0, 0, 0, 0.8)"
  95. >
  96. <span v-if="loading">提交中...</span>
  97. <span v-else>保存</span>
  98. </el-button>
  99. </span>
  100. <el-dialog title="选择优惠券" :visible.sync="showSelectTable" width="1000px" append-to-body>
  101. <div class="dialog select-table">
  102. <div class="table-title"></div>
  103. <el-table
  104. :data="couponList"
  105. border
  106. style="width: 100%;margin-bottom: 20px;"
  107. @selection-change="handleSelectionChange"
  108. >
  109. <el-table-column type="selection" width="55" />
  110. <el-table-column prop="couponBatch" label="批次号" width="140" />
  111. <el-table-column prop="couponName" label="优惠劵名称" />
  112. <el-table-column label="类型" align="center" prop="type">
  113. <template slot-scope="scope">
  114. <span>{{ scope.row.type==1?'满减':'折扣' }}</span>
  115. </template>
  116. </el-table-column>
  117. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  118. <template slot-scope="scope">
  119. <span>{{ parseTime(scope.row.createTime) }}</span>
  120. </template>
  121. </el-table-column>
  122. </el-table>
  123. <span slot="footer" class="dialog-footer" style="float: right;">
  124. <el-button @click="showSelectTable=false">取消</el-button>
  125. <el-button
  126. type="primary"
  127. @click="confirmSelection(true)"
  128. element-loading-text="提交中..."
  129. element-loading-spinner="el-icon-loading"
  130. element-loading-background="rgba(0, 0, 0, 0.8)"
  131. >
  132. <span>确定</span>
  133. </el-button>
  134. </span>
  135. </div>
  136. </el-dialog>
  137. </el-dialog>
  138. </template>
  139. <script>
  140. // import { updateNoticeMgr } from "@/api/system/noticeMgr";
  141. import { saveAndEdit } from "@/api/activity/activity";
  142. import { unBoundList as couponPageList } from '@/api/coupon/coupon'
  143. // import { getToken } from "@/utils/auth";
  144. // import { log } from 'mathjs';
  145. export default {
  146. name: "addAndEdit",
  147. props: {
  148. dict: {
  149. type: Object,
  150. default: () => [],
  151. },
  152. },
  153. components: {
  154. },
  155. data() {
  156. return {
  157. title: "编辑",
  158. model: "EDIT",
  159. activeName: '01',
  160. open: false,
  161. loading: false,
  162. form: {
  163. id: undefined,
  164. },
  165. rules: {
  166. activityName: [{ required: true, message: "请输入活动名称", trigger: ["change","blur"] }],
  167. activityDate: [{ required: true, message: "开始时间", trigger: ["change","blur"] }],
  168. startDate: [{ required: true, message: "开始时间", trigger: ["change","blur"] }],
  169. endDate: [{ required: true, message: "结束时间", trigger: ["change","blur"] }],
  170. couponNum: [{ required: true, message: "请输入优惠劵总数(大于或等于1的整数)", trigger: ["change","blur"] }],
  171. couponList: [
  172. { required: true, message: "请选择优惠劵", trigger: ["change","blur"] },
  173. ],
  174. },
  175. tempCouponList:[],
  176. couponList:[],
  177. showSelectTable:false,
  178. };
  179. },
  180. created(){
  181. this.getCouponList();
  182. },
  183. methods: {
  184. /**
  185. * 打开弹框
  186. * @date 2023-11-22
  187. * @param {any} obj
  188. * @returns {any}
  189. */
  190. openDialog(title, obj) {
  191. this.open = true;
  192. this.reset();
  193. if (obj){
  194. this.title = "编辑活动";
  195. this.$nextTick(() => {
  196. this.$set(this.form, 'id', obj.id);
  197. this.$set(this.form, 'activityName', obj.activityName);
  198. this.$set(this.form, 'startDate', obj.startDate);
  199. this.$set(this.form, 'endDate', obj.endDate);
  200. this.$set(this.form, 'couponNum', obj.couponNum);
  201. this.$set(this.form, 'couponList', obj.couponList);
  202. this.$set(this.form, 'activityDate', [obj.startDate, obj.endDate]);
  203. this.$set(this, 'tempCouponList', obj.couponInfoList||[]);
  204. this.confirmSelection();
  205. });
  206. }else{
  207. this.title = "新增活动";
  208. this.reset()
  209. this.$nextTick(() => {
  210. this.$refs["form"].clearValidate();
  211. });
  212. }
  213. },
  214. /**
  215. * 重置
  216. * @date 2023-11-22
  217. * @returns {any}
  218. */
  219. reset() {
  220. this.$set(this.form, 'id', '');
  221. this.$set(this.form, 'activityName', '');
  222. this.$set(this.form, 'startDate', '');
  223. this.$set(this.form, 'endDate', '');
  224. this.$set(this.form, 'couponNum', '');
  225. this.$set(this.form, 'couponList', []);
  226. this.$set(this.form, 'activityDate', []);
  227. this.$set(this, 'tempCouponList', []);
  228. },
  229. changeNumber(key) {
  230. if(!Number.isInteger(this.form[key] * 1) || this.form[key] * 1 < 1){
  231. this.$message.error("输入需大于或等于1的整数!");
  232. this.$set(this.form, key, '');
  233. return false
  234. }
  235. },
  236. /**
  237. * 保存
  238. * @date 2023-11-22
  239. * @returns {any}
  240. */
  241. submitForm() {
  242. this.$refs["form"].validate(async (valid) => {
  243. if (valid) {
  244. try {
  245. let params = JSON.parse(JSON.stringify(this.form))
  246. let flog = false
  247. this.tempCouponList.forEach((item,index)=>{
  248. if(!item.num && item.num != 0) {
  249. flog = true
  250. }
  251. })
  252. if(flog) {
  253. this.$message.error("请输入优惠卷的数量!");
  254. return
  255. }
  256. params.couponList = this.tempCouponList.map(item=>{return {
  257. couponId: item.id,
  258. num: item.num
  259. }});
  260. this.loading = true;
  261. const { code } = await saveAndEdit({ ...params });
  262. if (code === 200) {
  263. this.$message.success("操作成功!");
  264. this.$emit("getList");
  265. this.cancel();
  266. }
  267. } catch (error) {
  268. } finally {
  269. this.loading = false;
  270. }
  271. }
  272. });
  273. },
  274. /**
  275. * 关闭弹框
  276. * @date 2023-11-22
  277. * @returns {any}
  278. */
  279. cancel() {
  280. this.reset();
  281. this.open = false;
  282. },
  283. /**
  284. * 上传成功
  285. * @date 2023-11-22
  286. * @param {any} res
  287. * @returns {any}
  288. */
  289. handleAvatarSuccess(res) {
  290. if (res.code === 200) {
  291. // this.form.mainImg = res?.data?.url;
  292. this.$set(this.form, 'mainImg', res?.data?.url)
  293. }
  294. },
  295. /**
  296. * 上传文件之前之前
  297. * @date 2023-11-22
  298. * @param {any} file
  299. * @returns {any}
  300. */
  301. beforeAvatarUpload(file) {
  302. const isJPG = file.type === "image/jpeg" || "image/png";
  303. if (!isJPG) {
  304. this.$message.error("上传头像图片只能是jpg或png格式!");
  305. }
  306. return isJPG;
  307. },
  308. /** 查询优惠券列表 */
  309. getCouponList() {
  310. couponPageList({pageNum:1,pageSize:999})
  311. .then(response => {
  312. this.couponList = response.data.rows;
  313. }
  314. );
  315. },
  316. dateChange(e){
  317. console.log('useStartDateChange',e);
  318. // console.log('useStartDate',this.form.useDate);
  319. this.form.startDate = e[0];
  320. this.form.endDate = e[1];
  321. console.log(' this.form.activityDate', this.form.activityDate);
  322. },
  323. handleSelectionChange(val) {
  324. // console.log('val', val);
  325. this.tempCouponList = val;
  326. },
  327. confirmSelection(init) {
  328. this.showSelectTable = false;
  329. console.log('this.tempCouponList', this.tempCouponList);
  330. this.form.couponList = this.tempCouponList.map(item=>{return {
  331. couponId: item.id,
  332. num: item.num
  333. }});
  334. }
  335. },
  336. };
  337. </script>
  338. <style lang="scss" scoped>
  339. .dialog {
  340. padding: 0 30px;
  341. max-height: 65vh;
  342. overflow-y: auto;
  343. }
  344. .dialog {
  345. padding: 0 30px;
  346. .upload-btn {
  347. width: 100px;
  348. height: 100px;
  349. background-color: #fbfdff;
  350. border: dashed 1px #c0ccda;
  351. border-radius: 5px;
  352. i {
  353. font-size: 30px;
  354. margin-top: 20px;
  355. }
  356. &-text {
  357. margin-top: -10px;
  358. }
  359. }
  360. .avatar {
  361. cursor: pointer;
  362. }
  363. }
  364. </style>