Browse Source

商品编辑完成,等后端把接口改好再测试

ltx529596 4 years ago
parent
commit
3df3d173a2
3 changed files with 124 additions and 30 deletions
  1. 1 0
      src/pages/components/header.vue
  2. 12 12
      src/pages/shop/shop.vue
  3. 111 18
      src/pages/shop/shopdetail.vue

+ 1 - 0
src/pages/components/header.vue

@@ -37,6 +37,7 @@ export default {
   display: flex;
   padding: 23upx 33upx;
   position: fixed;
+  z-index: 99;
   .back {
     width: 24upx;
     height: 43upx;

+ 12 - 12
src/pages/shop/shop.vue

@@ -34,7 +34,7 @@
           <image
             src="../../static/images/addicon.png"
             class="timeicon"
-            @tap="addShop"
+            @tap="topage()"
           ></image>
         </view>
       </view>
@@ -95,7 +95,7 @@
         <view class="operate">
           <view class="btn stick" id="one" @tap="sticktop(item.id)">置顶</view>
           <view class="btn sold" @tap="passGet(item.id)">审核</view>
-          <view class="btn compile" @tap="topage(item)">编辑</view>
+          <view class="btn compile" @tap="topage(item.id)">编辑</view>
           <view class="btn delete" @tap="deleteshop(item.id)">删除</view>
         </view>
       </view>
@@ -128,7 +128,7 @@
         <view class="operate">
           <view class="btn stick" id="one" @tap="sticktop(item.id)">置顶</view>
           <view class="btn sold" @tap="shopPutDown(item.id)">下架</view>
-          <view class="btn compile" @tap="topage(item)">编辑</view>
+          <view class="btn compile" @tap="topage(item.id)">编辑</view>
           <view class="btn delete" @tap="deleteshop(item.id)">删除</view>
         </view>
       </view>
@@ -161,7 +161,7 @@
         <view class="operate">
           <view class="btn stick" id="one" @tap="sticktop(item.id)">置顶</view>
           <view class="btn sold" @tap="shopPutUp(item.id)">上架</view>
-          <view class="btn compile" @tap="topage(item)">编辑</view>
+          <view class="btn compile" @tap="topage(item.id)">编辑</view>
           <view class="btn delete" @tap="deleteshop(item.id)">删除</view>
         </view>
       </view>
@@ -269,9 +269,13 @@ export default {
   },
   //方法集合
   methods: {
-    // 新增商品
-    addShop() {
-      this.$mRouter.push({ route: '/pages/shop/shopdetail' });
+    // 跳转详情
+    topage(id) {
+      console.log(id);
+      if (id) {
+        uni.setStorageSync('Id', id);
+      }
+      this.$mRouter.push({ route: '/pages/shop/shopdetail'});
     },
     // 删除商品
     async deleteshop(id) {
@@ -356,11 +360,7 @@ export default {
         }
       });
     },
-    // 跳转详情
-    topage(data) {
-      uni.setStorageSync('shopData', data);
-      this.$mRouter.push({ route: '/pages/shop/shopdetail' });
-    },
+    
     // 商品列表(待审核状态)
     async getTicketShopList() {
       this.soleStatus = 1;

+ 111 - 18
src/pages/shop/shopdetail.vue

@@ -12,7 +12,7 @@
                 class="selectlist"
                 mode="selector"
                 @change="changeStore"
-                :value="0"
+                :value="storeIndex"
                 :range="storeList"
                 range-key="name"
               >
@@ -173,6 +173,7 @@
             class="ql-container"
             :placeholder="placeholder"
             @input="saveTxt"
+            @ready="onEditorReady"
           ></editor>
         </view>
       </view>
@@ -228,13 +229,14 @@ export default {
 
       // -------------- 编辑分界线 ------------------------------------
 
-      shopData: uni.getStorageSync('shopData'),  // 携带的编辑信息
-      
+      SHOPID: 0,
+      shopData: {},
     };
   },
+  onUnload() {
+    uni.removeStorageSync('Id');
+  },
   onLoad() {
-    console.log('编辑');
-    console.log(this.shopData);
     // 初始化阿里云
     myCloud = uniCloud.init({
       provider: 'aliyun',
@@ -242,8 +244,73 @@ export default {
       clientSecret: '8nOzV70edtpCd0El6qce3g==',
     });
     this.getShopList();
+
+    // ---------------------------------------------------
+    this.SHOPID = uni.getStorageSync('Id');
+    if (this.SHOPID) {
+      this.getShopBuyId();
+    }
   },
   methods: {
+    // 获取单个商品信息
+    async getShopBuyId() {
+      if (!this.SHOPID) return;
+      await this.$http
+        .get('/goods/getById/' + this.SHOPID)
+        .then(async (res) => {
+          if (res.code === 200 && res.msg === 'OK') {
+            console.log(res);
+            this.shopData = res.data;
+
+            // 所属店铺回显
+            this.storeList.forEach((item, index) => {
+              if (this.shopData.shopId === item.id) {
+                this.storeIndex = index;
+              }
+            });
+            this.storeId = this.storeList[this.storeIndex].id;
+
+            // 商品类型回显
+            this.getType();
+            this.getLine();
+
+            // 限制购票回显
+            if (this.shopData.saleRule === '1') {
+              let sale = JSON.parse(this.shopData.saleRuleJson);
+              this.showoperat = true;
+              this.num1 = sale.data.saleDay;
+              this.num2 = sale.data.saleNum;
+            } else {
+              this.showoperat = false;
+            }
+
+            // 图标回显
+            if (this.shopData.icon) {
+              console.log('有图标');
+              this.iconurl = this.shopData.icon
+            }
+
+          }
+        });
+    },
+    // 所属店铺怎么回显???
+
+    // 初始化编辑器
+    onEditorReady() {
+      uni
+        .createSelectorQuery()
+        .select('#editor')
+        .context((res) => {
+          this.editorCtx = res.context;
+          this.editorCtx.setContents({
+            html: this.shopData.describ, //this.EditGoodsDetail.content为赋值内容。
+          });
+        })
+        .exec();
+    },
+
+    // -----------------------------------------------------------------
+
     // 跳转到管理分类页面
     toClassify() {
       if (this.storeId) {
@@ -257,7 +324,6 @@ export default {
     changeStore(e) {
       this.storeIndex = e.detail.value;
       this.storeId = this.storeList[this.storeIndex].id;
-
       // 未选择商铺不能进行商铺类型选择
       if (this.storeId != '') {
         this.getType();
@@ -312,6 +378,17 @@ export default {
             arr.push({ name: element.name, id: element.id });
           });
           this.typeList = this.typeList.concat(arr);
+
+          // 商品类型回显
+          if (this.shopData.typeId) {
+            this.typeList.forEach((item, index) => {
+              if (this.shopData.typeId === item.id) {
+                this.typeIndex = index;
+              }
+            });
+            this.typeId = this.typeList[this.typeIndex].id;
+            this.shopname = this.shopData.name;
+          }
         });
     },
     // 商品名称
@@ -329,6 +406,7 @@ export default {
             arr.push({ name: element.ticket_name, id: element.ticket_no });
           });
           this.shopList = this.shopList.concat(arr);
+          console.log(1);
           console.log(this.shopList);
         });
     },
@@ -339,18 +417,39 @@ export default {
           shopId: this.storeId,
         })
         .then(async (res) => {
-          console.log(res);
           let arr = [];
           this.hasNameList = +res.data.shopFrom;
           res.data.customGroupList.forEach((element) => {
             arr.push({ name: element.name, id: element.id });
           });
           this.lineList = this.lineList.concat(arr);
+
+          // 可选择商品名称回显
+          if (this.shopData.name) {
+            this.getShopName();
+            this.shopList.forEach((item, index) => {
+              if (this.shopData.name === item.name) {
+                this.shopIndex = index;
+              } else {
+                this.shopIndex = 0;
+              }
+            });
+            this.shopId = this.shopList[this.shopIndex].id;
+          }
+
+          // 分类回显
+          if (this.shopData.customGroupId) {
+            this.lineList.forEach((item, index) => {
+              if (this.shopData.customGroupId === item.id) {
+                this.lineIndex = index;
+              }
+            });
+            this.lineId = this.lineList[this.lineIndex].id;
+          }
         });
     },
     // 账号限制
     Change(e) {
-      console.log(e);
       this.showoperat = e.detail.value;
     },
     subtractUser() {
@@ -385,9 +484,6 @@ export default {
         success: function (res) {
           // 成功则返回图片的本地文件路径列表 tempFilePaths
           _self.iconurl = res.tempFilePaths[0];
-
-          console.log(_self.iconurl);
-
           myCloud.uploadFile({
             url: 'http://192.168.100.135:83/merch/common/upload/oss',
             filePath: _self.iconurl, // 要上传的文件对象
@@ -398,12 +494,10 @@ export default {
               let percentCompleted = Math.round(
                 (progressEvent.loaded * 100) / progressEvent.total
               );
-              console.log(percentCompleted);
             },
             success: (res) => {
               if (res.fileID) {
                 _self.Icon = res.fileID;
-                console.log(_self.Icon);
               }
             },
           });
@@ -437,10 +531,8 @@ export default {
             //       let percentCompleted = Math.round(
             //         (progressEvent.loaded * 100) / progressEvent.total
             //       );
-            //       console.log(percentCompleted);
             //     },
             //     success: (res) => {
-            //       console.log(res);
             //     },
             //   });
             // }
@@ -476,7 +568,7 @@ export default {
       }
       // 判断是否可以自定义商品名称
       let name = '';
-      if ((this.shopList.length = 1)) {
+      if ((this.shopList.length === 1)) {
         name = this.shopname;
       } else {
         name = this.shopList[this.shopIndex].id;
@@ -496,7 +588,7 @@ export default {
         this.loading = false;
         return;
       }
-
+      
       this.$http
         .post('/goods/add', {
           mid: this.scenicId,
@@ -518,7 +610,8 @@ export default {
             }, 500);
           }
         });
-    },
+    }
+
   },
 };
 </script>