Browse Source

优惠券管理:添加优惠券,指定分销商处理

shipeng 17 hours ago
parent
commit
cef07f241f

+ 89 - 10
src/views/marketing/coupon/dialog/addAndEdit.vue

@@ -53,7 +53,7 @@
           <el-radio v-model="form.useThresholdType" :label="2">指定条件</el-radio>
         </el-form-item>
         <el-form-item label="使用对象" prop="useUserType" required>
-          <el-radio-group v-model="form.useUserType" @input="handleChange">
+          <el-radio-group v-model="form.useUserType" :disabled ="isDisabled" @input="handleChange">
             <el-radio :label="1">所有用户</el-radio>
             <el-radio :label="2">指定分销商</el-radio>
           </el-radio-group>
@@ -169,7 +169,8 @@
 // import { updateNoticeMgr } from "@/api/system/noticeMgr";
 import { saveAndEdit, pageTableList } from "@/api/coupon/coupon";
 import { goodsPageList } from "@/api/programmeMr/programmeMr";
-import { tr } from "voca";
+import { pageList } from '@/api/ticketMr/ticketMr'
+// import { tr } from "voca";
 // import { getToken } from "@/utils/auth";
 // import { log } from 'mathjs';
 export default {
@@ -223,12 +224,14 @@ export default {
       options: [],
       timer: null,
       isLoading: null,
-      rowId: [],
+      // rowId: [],
       isDisabled: false,
+      dataList: [],
     };
   },
   created() {
     this.getPerformList();
+    this.getGoodsList();
   },
   methods: {
     /**
@@ -241,6 +244,7 @@ export default {
       this.open = true;
       this.reset();
       this.getOptions();
+      this.isDisabled = true
       if (obj){
         this.title = "编辑优惠券";
         this.$nextTick(() => {
@@ -258,11 +262,11 @@ export default {
             this.form.useUserId = []
           }
           obj.useUserType == 2 ? this.isDisabled = true: this.isDisabled = false;
+          this.$set(this.form, 'useUserType', obj.useUserType);
           this.$set(this.form, 'id', obj.id);
           this.$set(this.form, 'couponName', obj.couponName);
           this.$set(this.form, 'type', obj.type);
           this.$set(this.form, 'quota', obj.quota);
-          this.$set(this.form, 'useUserType', obj.useUserType);
           this.$set(this.form, 'usePerform', obj.usePerform);
           this.$set(this.form, 'useThresholdType', obj.useThresholdType);
           this.$set(this.form, 'useThresholdAmount', obj.useThresholdAmount);
@@ -280,14 +284,37 @@ export default {
           this.$set(this.form, 'useGood', obj.useGood);
           this.form.useGood= this.getGoodsIds(this.form.useGood);
         });
-      }else{
+      } else {
         this.title = "新增优惠券";
-        
+        this.$set(this.form, 'useUserType', 2);
+        this.$set(this.form, 'channelType', 2);
+        this.$set(this.form, 'useType', 2);
+        this.$set(this.form, 'useDay', '24');
       }
       this.$nextTick(() => {
         this.$refs["form"].clearValidate();
       });
     },
+    // 获取分销票档
+    getGoodsList() {
+      // this.loading = true;
+      let query ={
+        pageNum: 1,
+        pageSize: 999,
+        goodsType: 2,
+        classifyId: 1,
+        channelType: 'retail'
+      }
+      pageList(query).then(response => {
+          let resArr = response.data.rows || [];
+          if(resArr.length > 0){
+            this.dataList = resArr.filter(ele => ele.status == 0)
+          } else {
+            this.dataList = []
+          }
+        }
+      );
+    },
     /** 查询团队列表 */
     getOptions(value) {
       // if(!value) {
@@ -434,16 +461,68 @@ export default {
     },
     performChange(e){
       // console.log('performChange',e);
-      // console.log('this.performList',this.performList);
+      console.log('this.performList',this.performList);
       // this.$set(this.form, 'useGood', '');
-      // console.log('performChange',e);
+      console.log('performChange',e);
       let goodsList = this.performList.filter(item => {return item.value == e})[0].goodsList;
-      this.goodsList = goodsList;
-      // console.log('goodsList',this.goodsList);
+      if(this.dataList.length != 0) {
+        this.dataList.forEach(j => {
+          if(j.id) {
+            j.goodsId = j.id
+          }
+          // if(j.name) {
+          //   j.goodsName = j.name
+          // }
+        })
+        this.goodsList = this.getMergedCommonById(goodsList, this.dataList, 'goodsId');
+      } else {
+        this.goodsList = [];
+      }
+      // this.goodsList = goodsList;
+      console.log('useGood', goodsList, this.dataList);
+      console.log('goodsList',this.goodsList);
       // console.log('useGood',this.form.useGood);
       this.$set(this.form, 'useGood', null);
 
     },
+    /**
+    * 从两个数组中找出 id 相同的对象,并合并它们
+    * @param {Array} arr1 - 第一个对象数组
+    * @param {Array} arr2 - 第二个对象数组
+    * @param {string} [idKey='id'] - 用作唯一标识的字段名,默认是 'id'
+    * @returns {Array} 合并后的结果数组
+    */
+    getMergedCommonById(arr1, arr2, idKey = 'id') {
+      // 容错处理:确保传入的是数组
+      if (!Array.isArray(arr1)) arr1 = [];
+      if (!Array.isArray(arr2)) arr2 = [];
+    
+      // 构建 Set 存储 arr2 中所有的 id
+      const idSetInArr2 = new Set(
+        arr2.filter(obj => obj && typeof obj === 'object' && idKey in obj)
+            .map(obj => obj[idKey])
+      );
+    
+      // 找出 arr1 中 id 在 arr2 中也存在的对象
+      const commonInArr1 = arr1.filter(obj => 
+        obj && typeof obj === 'object' && idSetInArr2.has(obj[idKey])
+      );
+    
+      // 构建 Map 来快速查找 arr2 中的数据
+      const mapInArr2 = new Map();
+      arr2.forEach(obj => {
+        if (obj && typeof obj === 'object' && idKey in obj) {
+          mapInArr2.set(obj[idKey], obj);
+        }
+      });
+    
+      // 合并数据
+      return commonInArr1.map(obj => {
+        const match = mapInArr2.get(obj[idKey]);
+        return match ? { ...obj, ...match } : obj;
+      });
+    },
+    
     useStartDateChange(e){
       // console.log('useStartDateChange',e);
       // console.log('useStartDate',this.form.useDate);

+ 7 - 6
src/views/marketing/coupon/index.vue

@@ -57,7 +57,7 @@
     <el-table ref="tables" v-loading="loading" :data="dataList" border>
       <!-- <el-table-column label="序号" align="center" type="index" width="50"></el-table-column> -->
       <el-table-column label="批次号" align="center" prop="couponBatch" width="140" />
-      <el-table-column label="优惠劵名称" align="center" prop="couponName" />
+      <el-table-column label="优惠劵名称" align="center" prop="couponName"  width="120"/>
       <el-table-column label="优惠额度" align="center" prop="quota">
         <template slot-scope="scope">
           <span>{{scope.row.quota}}{{ scope.row.type==1?'(元)':'(%)' }}</span>
@@ -69,21 +69,22 @@
           <!-- <dict-tag :options="dict.type.template_ident" :value="scope.row.templateIdent"/> -->
         </template>
       </el-table-column>
-      <el-table-column label="使用对象" align="center" prop="useUserType">
+      <el-table-column label="使用对象" align="center" prop="useUserType" width="100">
         <template slot-scope="scope">
           <span v-if="scope.row.useUserType==1">所有用户</span>
+          <span v-if="scope.row.useUserType==2">指定分销商</span>
         </template>
       </el-table-column>
-      <el-table-column label="使用剧目" align="center" prop="usePerformName" />
+      <el-table-column label="使用剧目" align="center" prop="usePerformName" width="120" />
       <el-table-column label="使用票务" align="center" prop="useGoodName" />
-      <el-table-column label="使用时间类型" align="center" prop="useType">
+      <el-table-column label="使用时间类型" align="center" prop="useType" width="120">
         <template slot-scope="scope">
           <span v-if="scope.row.useType==1">指定周期</span>
           <span v-if="scope.row.useType==2">领取后计算</span>
           <!-- <dict-tag :options="dict.type.template_ident" :value="scope.row.templateIdent"/> -->
         </template>
       </el-table-column>
-      <el-table-column label="使用时间" align="center" prop="useStartDate">
+      <el-table-column label="使用时间" align="center" prop="useStartDate" width="140">
         <template slot-scope="scope">
           <span v-if="scope.row.useType==1">{{scope.row.useStartDate}}至{{scope.row.useEndDate}}</span>
           <span v-if="scope.row.useType==2">领取{{scope.row.useDay}}小时后失效</span>
@@ -94,7 +95,7 @@
           <span>{{ parseTime(scope.row.createTime) }}</span>
         </template>
       </el-table-column>
-      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
+      <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <!-- <el-button
             size="mini"