Переглянути джерело

商品管理编辑,新增优化

ltx529596 4 роки тому
батько
коміт
9db983422d
1 змінених файлів з 125 додано та 196 видалено
  1. 125 196
      src/pages/shop/shopdetail.vue

+ 125 - 196
src/pages/shop/shopdetail.vue

@@ -62,6 +62,7 @@
                 @change="changeShop"
                 :value="shopIndex"
                 :range="shopList"
+                :disabled="nameDisabled"
                 range-key="name"
                 class="selectlist"
               >
@@ -364,7 +365,7 @@ export default {
     Header,
     uniCalendar,
   },
-  data() {
+  data () {
     return {
       loading: false,
       scenicId: uni.getStorageSync('scenicId'),
@@ -389,6 +390,7 @@ export default {
       shopIndex: 0,
       shopId: '',
       shopname: '',
+      nameDisabled: true,
 
       hasNameList: 0, // 判断是否有商品名称列表
 
@@ -472,190 +474,123 @@ export default {
       },
     };
   },
-  onUnload() {
+  onUnload () {
     uni.removeStorageSync('Id');
   },
-  onShow() {
+  onShow () {
     // if (this.storeId != '') {
     //   this.getLine(this.storeId)
     // }
   },
-  onReady() {
+  onReady () {
     myCloud = uniCloud.init({
       provider: 'aliyun',
       spaceId: 'db8671a1-69bd-470d-ad59-ba927c88f4a4',
       clientSecret: '8nOzV70edtpCd0El6qce3g==',
     });
   },
-  onLoad() {
+  onLoad () {
     this.SHOPID = uni.getStorageSync('Id');
 
     if (this.SHOPID) {
-      this.getShopBuyId(this.SHOPID).then( () => {
-        this.getShopList().then(()=>{
+      this.getShopBuyId(this.SHOPID).then(() => {
+        this.getShopList().then(() => {
           this.getShopName(this.typeId, this.storeId);
-        })
+        });
 
-        setTimeout(() => {
-          // 判断返回的是否是自营商品
-          this.price = this.shopData.salePrice / 100;
-          this.rateprice = this.shopData.price / 100;
+        // 判断返回的是否是自营商品
+        this.price = this.shopData.salePrice / 100;
+        this.rateprice = this.shopData.price / 100;
 
-          if (this.shopData.expiredTime) {
-            this.expirationDate = this.shopData.expiredTime.slice(0, 10)
-              ? this.shopData.expiredTime.slice(0, 10)
-              : '请选择商品过期日期';
-          }
+        if (this.shopData.expiredTime) {
+          this.expirationDate = this.shopData.expiredTime.slice(0, 10)
+            ? this.shopData.expiredTime.slice(0, 10)
+            : '请选择商品过期日期';
+        }
 
-          let rule = JSON.parse(this.shopData.saleRuleJson);
+        let rule = JSON.parse(this.shopData.saleRuleJson);
 
-          if (rule) {
-            this.astrictDate.data.saleDay = rule.data.saleDay
-              ? rule.data.saleDay
-              : 0;
-            this.astrictDate.data.saleNum = rule.data.saleNum
-              ? rule.data.saleNum
-              : 0;
-            // 有效期模式
-            this.astrictDate.dateSetting = rule.data.dateSetting;
-            this.patterIndex = +rule.data.dateSetting;
-            // 库存模式
-            this.astrictDate.goodsStockFlag = rule.data.goodsStockFlag;
-            this.shopNumIndex = +rule.data.goodsStockFlag;
+        if (rule) {
+          this.astrictDate.data.saleDay = rule.data.saleDay
+            ? rule.data.saleDay
+            : 0;
+          this.astrictDate.data.saleNum = rule.data.saleNum
+            ? rule.data.saleNum
+            : 0;
+          // 有效期模式
+          this.astrictDate.dateSetting = rule.data.dateSetting;
+          this.patterIndex = +rule.data.dateSetting;
+          // 库存模式
+          this.astrictDate.goodsStockFlag = rule.data.goodsStockFlag;
+          this.shopNumIndex = +rule.data.goodsStockFlag;
 
-            if (this.shopNumIndex === 1) {
-              this.dateInventory = this.shopData.inventory;
-            } else if (this.shopNumIndex === 2) {
-              this.sunInventory = this.shopData.inventory;
-            }
-            // 预订数量
-            this.astrictDate.data.bookRule = rule.data.bookRule;
-            // 实名制
-            if (rule.data.isRealName === '0') {
-              this.trueNme = true;
-            } else {
-              this.trueNme = false;
-            }
-            this.astrictDate.data.isRealName = rule.data.isRealName;
-            // 可退规则
-            this.bookingIndex = +rule.data.usubscribeRule;
-            this.astrictDate.usubscribeRule = rule.data.usubscribeRule;
-            // 二维码
-            if (rule.data.isShowQrcode === '0') {
-              this.codeShow = true;
-            } else {
-              this.codeShow = false;
-            }
-            this.astrictDate.data.isShowQrcode = rule.data.isShowQrcode;
+          if (this.shopNumIndex === 1) {
+            this.dateInventory = this.shopData.inventory;
+          } else if (this.shopNumIndex === 2) {
+            this.sunInventory = this.shopData.inventory;
           }
-          // 限制购票回显
-          if (this.shopData.saleRule === '1') {
-            this.showoperat = true;
+          // 预订数量
+          this.astrictDate.data.bookRule = rule.data.bookRule;
+          // 实名制
+          if (rule.data.isRealName === '0') {
+            this.trueNme = true;
           } else {
-            this.showoperat = false;
+            this.trueNme = false;
           }
-
-          // 图标回显
-          if (this.shopData.icon) {
-            this.iconurl = this.shopData.icon;
+          this.astrictDate.data.isRealName = rule.data.isRealName;
+          // 可退规则
+          this.bookingIndex = +rule.data.usubscribeRule;
+          this.astrictDate.usubscribeRule = rule.data.usubscribeRule;
+          // 二维码
+          if (rule.data.isShowQrcode === '0') {
+            this.codeShow = true;
           } else {
-            this.iconurl = '';
+            this.codeShow = false;
           }
-          this.loading = false;
-        }, 1);
-      })
-    }
+          this.astrictDate.data.isShowQrcode = rule.data.isShowQrcode;
+        }
+        // 限制购票回显
+        if (this.shopData.saleRule === '1') {
+          this.showoperat = true;
+        } else {
+          this.showoperat = false;
+        }
 
-    // this.getShopList();
+        // 图标回显
+        if (this.shopData.icon) {
+          this.iconurl = this.shopData.icon;
+        } else {
+          this.iconurl = '';
+        }
+        this.loading = false;
+      });
+    } else {
+      this.getShopList()
+    }
   },
   methods: {
     // 获取单个商品信息
-    async getShopBuyId(id) {
+    async getShopBuyId (id) {
       this.loading = true;
       await this.$http.get('/goods/getById/' + id).then((res) => {
         if (res.code === 200 && res.msg === 'OK') {
+          console.log(res);
           this.shopData = res.data;
           this.storeId = res.data.shopId;
           this.typeId = res.data.typeId;
           this.loading = false;
-          // setTimeout(() => {
-          //   this.price = this.shopData.salePrice / 100;
-          //   this.rateprice = this.shopData.price / 100;
-
-          //   if (this.shopData.expiredTime) {
-          //     this.expirationDate = this.shopData.expiredTime.slice(0, 10)
-          //       ? this.shopData.expiredTime.slice(0, 10)
-          //       : '请选择商品过期日期';
-          //   }
-
-          //   let rule = JSON.parse(this.shopData.saleRuleJson);
-
-          //   if (rule) {
-          //     this.astrictDate.data.saleDay = rule.data.saleDay
-          //       ? rule.data.saleDay
-          //       : 0;
-          //     this.astrictDate.data.saleNum = rule.data.saleNum
-          //       ? rule.data.saleNum
-          //       : 0;
-          //     // 有效期模式
-          //     this.astrictDate.dateSetting = rule.data.dateSetting;
-          //     this.patterIndex = +rule.data.dateSetting;
-          //     // 库存模式
-          //     this.astrictDate.goodsStockFlag = rule.data.goodsStockFlag;
-          //     this.shopNumIndex = +rule.data.goodsStockFlag;
-
-          //     if (this.shopNumIndex === 1) {
-          //       this.dateInventory = this.shopData.inventory;
-          //     } else if (this.shopNumIndex === 2) {
-          //       this.sunInventory = this.shopData.inventory;
-          //     }
-          //     // 预订数量
-          //     this.astrictDate.data.bookRule = rule.data.bookRule;
-          //     // 实名制
-          //     if (rule.data.isRealName === '0') {
-          //       this.trueNme = true;
-          //     } else {
-          //       this.trueNme = false;
-          //     }
-          //     this.astrictDate.data.isRealName = rule.data.isRealName;
-          //     // 可退规则
-          //     this.bookingIndex = +rule.data.usubscribeRule;
-          //     this.astrictDate.usubscribeRule = rule.data.usubscribeRule;
-          //     // 二维码
-          //     if (rule.data.isShowQrcode === '0') {
-          //       this.codeShow = true;
-          //     } else {
-          //       this.codeShow = false;
-          //     }
-          //     this.astrictDate.data.isShowQrcode = rule.data.isShowQrcode;
-          //   }
-          //   // 限制购票回显
-          //   if (this.shopData.saleRule === '1') {
-          //     this.showoperat = true;
-          //   } else {
-          //     this.showoperat = false;
-          //   }
-
-          //   // 图标回显
-          //   if (this.shopData.icon) {
-          //     this.iconurl = this.shopData.icon;
-          //   } else {
-          //     this.iconurl = '';
-          //   }
-          //   this.loading = false;
-          // }, 500);
         }
       });
     },
     // 打开日历
-    openTime() {
+    openTime () {
       this.$refs.calendar.open();
     },
-    confirm(e) {
+    confirm (e) {
       this.expirationDate = e.fulldate;
     },
     // 自定义属性
-    radioChange(evt) {
+    radioChange (evt) {
       for (let i = 0; i < this.patterList.length; i++) {
         if (this.patterList[i].id === evt.target.value) {
           this.patterIndex = i;
@@ -665,7 +600,7 @@ export default {
       this.astrictDate.data.dateSetting = evt.detail.value;
     },
     // 库存模式
-    shopNumChange(e) {
+    shopNumChange (e) {
       for (let i = 0; i < this.shopNumList.length; i++) {
         if (this.shopNumList[i].id === e.target.value) {
           this.shopNumIndex = i;
@@ -682,7 +617,7 @@ export default {
       this.astrictDate.data.goodsStockFlag = e.detail.value;
     },
     // 可退模式
-    bookingChange(e) {
+    bookingChange (e) {
       for (let i = 0; i < this.bookingList.length; i++) {
         if (this.bookingList[i].id === e.target.value) {
           this.bookingIndex = i;
@@ -692,7 +627,7 @@ export default {
       this.astrictDate.data.usubscribeRule = e.detail.value;
     },
     // 实名制
-    trueNmeChange(e) {
+    trueNmeChange (e) {
       if (e.detail.value) {
         this.astrictDate.data.isRealName = '0';
       } else {
@@ -700,7 +635,7 @@ export default {
       }
     },
     // 显示二维码
-    codeShowChange(e) {
+    codeShowChange (e) {
       if (e.detail.value) {
         this.astrictDate.data.isShowQrcode = '0';
       } else {
@@ -708,7 +643,7 @@ export default {
       }
     },
     // 初始化编辑器
-    onEditorReady() {
+    onEditorReady () {
       uni
         .createSelectorQuery()
         .select('#editor')
@@ -722,7 +657,7 @@ export default {
     },
     // -----------------------------------------------------------------
     // 跳转到管理分类页面
-    toClassify() {
+    toClassify () {
       if (this.storeId) {
         uni.setStorageSync('shopid', this.storeId);
         this.$mRouter.push({ route: '/pages/shop/classify' });
@@ -731,28 +666,36 @@ export default {
       }
     },
     // 选择店铺
-    changeStore(e) {
+    changeStore (e) {
       this.storeIndex = e.detail.value;
       this.storeId = this.storeList[this.storeIndex].id;
       this.typeProperty = this.storeList[this.storeIndex].type;
+
+      if (!this.SHOPID) {
+        this.getType(this.storeId)
+        this.getLine(this.storeId)
+      }
     },
     // 选择商品类型
-    changeType(e) {
+    changeType (e) {
       this.typeIndex = e.detail.value;
       this.typeId = this.typeList[this.typeIndex].id;
+      if (!this.SHOPID) {
+        this.getShopName(this.typeId, this.storeId);
+      }
     },
     // 商品名称选择
-    changeShop(e) {
+    changeShop (e) {
       this.shopIndex = e.detail.value;
       this.shopId = this.shopList[this.shopIndex].id;
     },
     // 分类
-    changeClassify(e) {
+    changeClassify (e) {
       this.lineIndex = e.detail.value;
       this.lineId = this.lineList[this.lineIndex].id;
     },
     // 所属店铺
-    async getShopList() {
+    async getShopList () {
       this.storeList = [{ name: '所属店铺', id: '', type: '' }];
       await this.$http
         .get('/shop/getList', { mid: this.scenicId })
@@ -786,7 +729,7 @@ export default {
         });
     },
     // 商品类型
-    async getType(storeId) {
+    async getType (storeId) {
       this.typeList = [{ name: '商品类型(请先选择所属店铺)', id: '' }];
       this.$http
         .get('/type/getTypeListByShopId', {
@@ -814,8 +757,7 @@ export default {
         });
     },
     // 商品名称
-    async getShopName(typeId, storeId) {
-      this.loading = true
+    async getShopName (typeId, storeId) {
       this.shopList = [{ name: '商品名称(请先选择商品类型)', id: '' }];
       await this.$http
         .get('/goods/getTicketGoods', {
@@ -825,42 +767,32 @@ export default {
         .then(async (res) => {
           if (res.code === 200) {
             let arr = [];
-            res.data.forEach((element) => {
-              arr.push({ name: element.ticket_name, id: element.ticket_no });
-            });
+            res.data.forEach(element => arr.push({ name: element.ticket_name, id: element.ticket_no }));
             this.shopList = this.shopList.concat(arr);
-            this.loading = false
+            this.nameDisabled = false
 
             // 回显名称
             if (this.shopData.name) {
-              this.loading = true
-              if (this.shopData.ticketNo) {
-                // 分销没有ticketNo
-                this.shopList[0] = {
-                  name: this.shopData.name,
-                  id: this.shopData.ticketNo,
-                };
+              this.loading = true;
+              if (this.typeProperty != 0) {
+                this.shopList[0] = { name: this.shopData.name, id: '' };
+                this.shopIndex = 0
+                this.shopId = this.shopList[this.shopIndex].id;
+                if (this.shopList[0].name === this.shopList[1].name) {
+                  this.shopList.length = 1
+                }
               } else {
                 // 自营商品直接赋值
-                this.shopname = this.shopname.name;
+                this.shopname = this.shopData.name;
               }
-              this.shopList.forEach((item, index) => {
-                if (this.shopData.name === item.name) {
-                  // this.shopList[0] = { name: '商品名称(请先选择商品类型)', id: '' }
-                  this.shopIndex = index;
-                } else {
-                  this.shopIndex = 0;
-                }
-              });
-              this.shopId = this.shopList[this.shopIndex].id;
-              this.loading = false
+
+              this.loading = false;
             }
           }
         });
     },
     // 线路分配
-    async getLine(storeId) {
-      this.loading = true
+    async getLine (storeId) {
       this.lineList = [{ name: '分类(请先选择所属商品)', id: '' }];
       await this.$http
         .get('/goods/getCustomGroupList', {
@@ -874,26 +806,25 @@ export default {
           });
           this.lineList = this.lineList.concat(arr);
           this.lineDidsable = false;
-          this.loading = false
 
           // 分类回显
           if (this.shopData.customGroupId) {
-            this.loading = true
+            this.loading = true;
             this.lineList.forEach((item, index) => {
               if (this.shopData.customGroupId === item.id) {
                 this.lineIndex = index;
               }
             });
             this.lineId = this.lineList[this.lineIndex].id;
-            this.loading = false
+            this.loading = false;
           }
         });
     },
     // 账号限制
-    Change(e) {
+    Change (e) {
       this.showoperat = e.detail.value;
     },
-    subtractUser() {
+    subtractUser () {
       if (this.astrictDate.data.saleDay <= 1) {
         this.$mHelper.toast('最少一天');
         return;
@@ -901,10 +832,10 @@ export default {
         this.astrictDate.data.saleDay--;
       }
     },
-    addUser() {
+    addUser () {
       this.astrictDate.data.saleDay++;
     },
-    subtractDate() {
+    subtractDate () {
       if (this.astrictDate.data.saleNum <= 1) {
         this.$mHelper.toast('最少一张票');
         return;
@@ -912,11 +843,11 @@ export default {
         this.astrictDate.data.saleNum--;
       }
     },
-    addDate() {
+    addDate () {
       this.astrictDate.data.saleNum++;
     },
     // 图标上传
-    uploadImg() {
+    uploadImg () {
       let _self = this;
       _self.uploadtxt = '上传中...';
       _self.progress = 0;
@@ -937,7 +868,7 @@ export default {
                 _self.Icon = res.fileID;
               }
             },
-            fail: function (msg) {},
+            fail: function (msg) { },
             onUploadProgress: function (progressEvent) {
               _self.progress = Math.round(
                 (progressEvent.loaded * 100) / progressEvent.total
@@ -954,7 +885,7 @@ export default {
       });
     },
     // 图册上传
-    uploadList() {
+    uploadList () {
       let _self = this;
       uni.chooseImage({
         count: 6,
@@ -968,6 +899,7 @@ export default {
             _self.$mHelper.toast('最多只可上传6张图片');
           } else {
             _self.pickList = _self.pickList.concat(img);
+
             // for (let i = 0; i < _self.pickList.length; i++) {
             //   let element = _self.pickList[i];
             //   myCloud.uploadFile({
@@ -985,20 +917,21 @@ export default {
             //     },
             //   });
             // }
+
           }
         },
       });
     },
     // 删除图册中的图片
-    deleteThisImg(index) {
+    deleteThisImg (index) {
       this.pickList.splice(index, 1);
     },
     // 富文本失去焦点保存内容
-    saveTxt(e) {
+    saveTxt (e) {
       this.mastKnow = e.detail.html;
     },
     // 内容提交
-    submitMesage() {
+    submitMesage () {
       let _this = this;
       // 判断是否限制账号购买
       if (this.showoperat) {
@@ -1010,17 +943,13 @@ export default {
       }
 
       let name = '';
-      console.log('是否自营');
-      console.log(this.typeProperty);
       if (this.typeProperty === 1) {
-        name = this.shopList[this.shopIndex].id;
+        name = this.shopList[this.shopIndex].name;
       } else if (this.typeProperty === 0) {
         name = this.shopname;
       }
 
       console.log(name);
-
-      return;
       if (!this.storeId) {
         this.$mHelper.toast('请选择所属商铺!');
         return;