Explorar o código

完善添加盲票组

hwb0 %!s(int64=3) %!d(string=hai) anos
pai
achega
9b38bf7c0e
Modificáronse 1 ficheiros con 35 adicións e 25 borrados
  1. 35 25
      src/views/business/ticket/create.vue

+ 35 - 25
src/views/business/ticket/create.vue

@@ -128,7 +128,7 @@
             <el-table-column label="奖品类型">
               <template slot-scope="scope">
                 <div v-if="scope.row.prizeType == 'goods'">商品</div>
-                <div v-if="scope.row.prizeType == 'coupon'">代金券</div>
+                <div v-if="scope.row.prizeType == 'coupon'">券</div>
                 <div v-if="scope.row.prizeType == 'coin'">盲豆</div>
               </template>
             </el-table-column>
@@ -140,7 +140,6 @@
                     controls-position="right"
                     @change="handleChange($event, index)"
                     :min="1"
-                    :max="100"
                     size="small"
                   ></el-input-number>
                 </div>
@@ -165,7 +164,7 @@
             </el-button>
             <el-dropdown-menu slot="dropdown">
               <el-dropdown-item command="goods">商品</el-dropdown-item>
-              <el-dropdown-item command="coupon">代金券</el-dropdown-item>
+              <el-dropdown-item command="coupon">券</el-dropdown-item>
               <el-dropdown-item command="coin">盲豆</el-dropdown-item>
             </el-dropdown-menu>
           </el-dropdown>
@@ -258,16 +257,16 @@
     </el-dialog>
     <!-- 添加卡券 -->
     <el-dialog
-      title="添加代金券奖品"
+      title="添加券奖品"
       width="1000px"
       :visible.sync="couponTableVisible"
       :before-close="close"
     >
       <div class="dialog-search">
-        <div>代金券名称:</div>
+        <div>券名称:</div>
         <el-input
           v-model="couponTitle"
-          placeholder="请输入代金券名称"
+          placeholder="请输入券名称"
           clearable
           size="small"
           style="width: 240px"
@@ -294,8 +293,8 @@
           align="center"
           fixed="left"
         />
-        <el-table-column label="代金券ID" prop="couponId" />
-        <el-table-column label="代金券图片">
+        <el-table-column label="券ID" prop="couponId" />
+        <el-table-column label="券图片">
           <template slot-scope="scope">
             <div>
               <el-image
@@ -307,13 +306,13 @@
             </div>
           </template>
         </el-table-column>
-        <el-table-column label="代金券名称" prop="title" min-width="85" />
-        <el-table-column label="代金券类型" min-width="85">
+        <el-table-column label="券名称" prop="title" min-width="85" />
+        <el-table-column label="使用场景" min-width="85">
           <template slot-scope="scope">
             <div>{{ scope.row.type.desc }}</div>
           </template>
         </el-table-column>
-        <el-table-column label="代金券价格" min-width="85">
+        <el-table-column label="券价格" min-width="85">
           <template slot-scope="scope">
             <div>¥{{ $numberFormat(scope.row.discount) }}</div>
           </template>
@@ -370,6 +369,7 @@
   </div>
 </template>
 <script>
+import CustomFieldsMixin from "@/mixins/CustomFields";
 import { getGoodsList } from "@/api/business/goods";
 import { getCouponList } from "@/api/business/coupon";
 import { ticketBoxCreate } from "@/api/business/ticket";
@@ -377,6 +377,7 @@ import { publicFileGetUrl } from "@/api/common";
 import { accMul } from "@/utils/util";
 export default {
   name: "TicketCreate",
+  mixins: [CustomFieldsMixin],
   data() {
     return {
       loading: false,
@@ -387,7 +388,7 @@ export default {
         facePrice: "", // 面值
         salePrice: "", // 售价
         quantity: "", // 数量
-        pkgUnit: "", // 张数
+        pkgUnit: 200, // 张数
         pkgSalePrice: "", // 单价
         saleCommRate: "", // 基数
       },
@@ -501,7 +502,7 @@ export default {
       goodsTotal: 0, // 商品总数
       selectGoodsList: [], // 选中商品
 
-      couponTitle: "", // 代金券名称
+      couponTitle: "", // 券名称
       couponTableVisible: false, // 添加卡券弹框
       couponList: [], // 卡券列表
       couponTotal: 0, // 卡券总数
@@ -579,7 +580,8 @@ export default {
 
     // 保存
     submitForm() {
-      this.$refs["form"].validate((valid) => {
+      const subForm = this.$refs["form"]
+      subForm.validate((valid) => {
         if (valid) {
           let prizeIndex = this.awardsList.findIndex((item) => {
             return !item.prizeList.length;
@@ -591,10 +593,25 @@ export default {
             );
             return;
           }
+
+          if ((this.form.quantity % this.form.pkgUnit != 0) && this.form.type == 'offline') {
+            this.$message.error("每包数量错误!");
+            return
+          }
+
+          let quantityTotal = 0;
+          this.awardsList.forEach((item) => {
+            quantityTotal += item.quantity;
+          });
+          if (this.form.quantity != quantityTotal) {
+            this.$message.error("盲票数量和奖品数量不一致!");
+            return
+          }
+
           this.awardsList.forEach((item) => {
             item.prizeList = item.prizeList.map((ele) => {
               return {
-                // ...ele,
+                ...ele,
                 refId: ele.goodsId || ele.couponId,
                 prizeType: ele.prizeType,
                 quantity: ele.quantity,
@@ -618,25 +635,18 @@ export default {
           });
           ticketBoxCreate(data)
             .then((res) => {
+              loading.close();
               if (res.code == 0) {
                 this.msgSuccess("保存成功");
                 this.$store.dispatch("tagsView/delView", this.$route);
                 this.$router.go(-1);
-                loading.close();
-              } else {
-                this.$message.error("保存失败,请重新添加!");
-                this.$store.dispatch("tagsView/delView", this.$route);
-                this.$router.go(-1);
-                loading.close();
               }
             })
             .catch(() => {
-              this.$message.error("保存失败,请重新添加!");
-              this.$store.dispatch("tagsView/delView", this.$route);
-              this.$router.go(-1);
               loading.close();
             });
         } else {
+          this.getFormErrorMessage(subForm);
           return false;
         }
       });
@@ -686,7 +696,7 @@ export default {
       this.getGoodsList(this.goodsTitle);
     },
 
-    // 查询代金
+    // 查询券
     handleQueryCoupon() {
       this.getCouponList(this.couponTitle);
     },