Browse Source

修复被钟大哥重构商家列表页面产生的 bug

wzy 8 months ago
parent
commit
849bb910cf
1 changed files with 42 additions and 5 deletions
  1. 42 5
      src/views/business/businessList/components/EditModal.vue

+ 42 - 5
src/views/business/businessList/components/EditModal.vue

@@ -169,13 +169,22 @@
                 </el-form-item>
 
                 <el-form-item prop="advertisement" label="广告图">
-                  <el-upload
+                  <!-- <el-upload
                     class="avatar-uploader" list-type="picture-card" :file-list="formData.advertisement"
                     :action="uploadUrl"
                     :on-success="(r) => formData.advertisement.push({ url: r.url, uid: r.url + Math.random() + Date.now() })"
                     :on-remove="(e) => formData.advertisement.filter((item) => item.uid !== e.uid)"
                   >
                     <i class="el-icon-plus avatar-uploader-icon" />
+                  </el-upload> -->
+                  
+                  <el-upload
+                    class="avatar-uploader" list-type="picture-card" :file-list="uploadList"
+                    :action="uploadUrl"
+                    :on-success="uploadSuccess"
+                    :on-remove="removeSuccess"
+                  >
+                    <i class="el-icon-plus avatar-uploader-icon" />
                   </el-upload>
                 </el-form-item>
               </el-tab-pane>
@@ -319,7 +328,8 @@ export default {
         }
       },
       uploadUrl,
-      categoryList: []
+      categoryList: [],
+      uploadList:[]
     }
   },
   watch: {
@@ -358,8 +368,9 @@ export default {
     handleOpen(params = {}) {
       this.modalOptions.title = params.shopId ? '修改商家' : '新增商家'
       this.formData = Object.assign(this.$options.data().formData, params, {
-        advertisement: params.advertisement ? params.advertisement.split(',').map((item) => ({ url: item, uid: item + Math.random() + new Date() })) : []
+        // advertisement: params.advertisement ? params.advertisement.split(',').map((item) => ({ url: item, uid: item + Math.random() + new Date() })) : []
       })
+      // this.uploadList = this.formData.advertisement.split("&")
       const categoryItem = XeUtils.findTree(this.categoryList, (item) => item.id === String(params.classificationId))
       if (categoryItem && Array.isArray(categoryItem.nodes)) {
         this.formData.classificationArr = categoryItem.nodes.map((v) => v.id)
@@ -379,8 +390,21 @@ export default {
         const res = await businessListGetById({ shopId: id })
         this.formData = Object.assign(this.$options.data().formData, res.data, {
           shopId: res.data.shopId || '',
-          advertisement: res.data.advertisement ? res.data.advertisement.split(',').map((item) => ({ url: item, uid: item + Math.random() + new Date() })) : []
+          voucherReturn:Number(res.data.voucherReturn)
+          // advertisement: res.data.advertisement ? res.data.advertisement.split(',').map((item) => ({ url: item, uid: item + Math.random() + new Date() })) : []
+          // advertisement
         })
+        let arr = this.formData.advertisement.split(",");
+        if(arr[0] == ""){
+          this.uploadList = []
+        }else{
+          this.uploadList = arr.map(item=>{
+          return {
+            url: item,
+            uid: item + Math.random() + new Date()
+          }
+        })
+        }
         const categoryItem = XeUtils.findTree(this.categoryList, (item) => item.id === String(res.data.classificationId))
         if (categoryItem && Array.isArray(categoryItem.nodes)) {
           this.formData.classificationArr = categoryItem.nodes.map((v) => v.id)
@@ -401,9 +425,15 @@ export default {
             const { advertisement, classificationArr, ...otps } = this.formData
             const params = {
               ...otps,
-              advertisement: Array.isArray(advertisement) ? advertisement.map((v) => v.url || v).join(',') : '',
+              // advertisement: Array.isArray(advertisement) ? advertisement.map((v) => v.url || v).join(',') : '',
               classificationId: Array.isArray(classificationArr) && classificationArr.length ? classificationArr[classificationArr.length - 1] : ''
             }
+            params.advertisement = this.uploadList.reduce((prev,item,index)=>{
+              prev += item.url + ","
+              return prev
+            },"")
+            //  删除最后一个字符
+            params.advertisement = params.advertisement.substring(0,params.advertisement.length - 1)
             this.formData.shopId ? await businessListUpdate(params) : await businessListSave(params)
             loading.close()
             this.$message({ message: `${this.formData.shopId ? '编辑' : '添加'}成功!`, type: 'success' })
@@ -419,6 +449,13 @@ export default {
           return false
         }
       })
+    },
+    uploadSuccess(r){
+      console.log(r);
+      this.uploadList.push({url:r.data.url,uid: r.url + Math.random() + Date.now()})
+    },
+    removeSuccess(r){
+      this.uploadList = this.uploadList.filter(item => item.uid !== r.uid)
     }
   }
 }