Ver código fonte

优化操作体验

yuwenjun 3 anos atrás
pai
commit
c7272a6659

+ 13 - 3
src/views/supplier/auth/index.vue

@@ -195,7 +195,12 @@ export default {
               return
             }
             this.getList()
-            this.$message.success(res.data)
+            const h = this.$createElement
+            this.$notify.success({
+              title: '添加授权机构',
+              message: h('i', { style: 'color: #333' }, `已添加授权机构:"${this.addAuthFormData.authParty}"`),
+              duration: 3000
+            })
             this.$refs.addAuthForm.resetFields()
           }).catch(err => {
             console.log(err)
@@ -221,9 +226,14 @@ export default {
       // 要执行的操作
       this.listLoading = true
       removeAuth({	authId: item.authId }).then(res => {
-        this.$message.success(res.data)
+        if (res.code !== 0) return
+        const h = this.$createElement
+        this.$notify.success({
+          title: '移除授权机构',
+          message: h('i', { style: 'color: #333' }, `移除授权机构:"${item.authParty}"`),
+          duration: 3000
+        })
       }).catch(err => {
-        this.$message.danger('删除失败')
         console.log(err)
       }).finally(() => {
         this.listLoading = false

+ 13 - 5
src/views/supplier/components/uploadFile.vue

@@ -13,6 +13,7 @@
       :accept="accept"
       :before-upload="beforeUpload"
       :on-remove="remove"
+      :on-change="change"
     >
       <el-button slot="trigger" size="mini" type="primary">选取文件</el-button>
       <!-- <el-button style="margin-left: 10px;" size="mini" type="success" @click="uploadFile">上传</el-button> -->
@@ -81,14 +82,21 @@ export default {
     // 图片上传之前的钩子
     beforeUpload(file) {
       this.params.authUserId = this.authUserId || -1
-      // const size = file.size
-      // if (size > 1024 * 2000) {
-      //   this.$message.warning('文件上传大小超出限制(≤2MB)')
-      //   return false
-      // }
+      const size = file.size
+      if (size > 1024 * 5000) {
+        const h = this.$createElement
+        this.$notify.info({
+          title: '上传文件过大',
+          message: h('p', { style: 'color: #333' }, '文件上传保存需要一定的时间,请您耐心等待,在此期间请勿执执行其他操作,以免影响文件上传失败!'),
+          duration: 5000
+        })
+      }
     },
     remove() {
       this.$emit('remove')
+    },
+    change() {
+      this.$emit('change')
     }
   }
 }

+ 6 - 1
src/views/supplier/product/add.vue

@@ -168,7 +168,12 @@ export default {
         if (res.code !== 0) {
           return
         }
-        this.$message.success('保存成功')
+        const h = this.$createElement
+        this.$notify.success({
+          title: '新增商品',
+          message: h('i', { style: 'color: #333' }, `已添加商品:"${this.formData.productName}"`),
+          duration: 2000
+        })
         this.$refs.addFormRef.resetFields()
         this.clearFormData()
         this.$router.push(`/product/list?id=${this.formData.authId}`)

+ 6 - 2
src/views/supplier/product/edit.vue

@@ -184,8 +184,12 @@ export default {
       this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
       this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
       saveProduct(this.formData).then(res => {
-        console.log(res)
-        this.$message.success(res.data)
+        const h = this.$createElement
+        this.$notify.success({
+          title: '修改商品',
+          message: h('i', { style: 'color: #333' }, `已修改商品:"${this.formData.productName}"`),
+          duration: 2000
+        })
         this.$router.back()
       }).finally(() => {
         this.isLoading = false

+ 7 - 2
src/views/supplier/product/index.vue

@@ -152,7 +152,7 @@ export default {
     },
     // 删除商品
     async handleRemoveProduct(item) {
-      const text = await this.$confirm('此操作将删除该授权机构, 是否继续?', '提示', {
+      const text = await this.$confirm('此操作将删除该商品, 是否继续?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
@@ -162,7 +162,12 @@ export default {
       if (text !== 'confirm') return
 
       removeProduct({ productId: item.productId }).then(res => {
-        this.$message.success(res.data)
+        const h = this.$createElement
+        this.$notify.success({
+          title: '删除商品',
+          message: h('i', { style: 'color: #333' }, `已删除商品:"${item.productName}"`),
+          duration: 2000
+        })
       }).finally(() => {
         this.getList()
       })

+ 61 - 12
src/views/supplier/user/add.vue

@@ -45,7 +45,7 @@
             <el-tag v-for="(brand , index) in supplierBrands" :key="index" closable type="success" @close="handleRemove(index)" @click="handleShowInfo(index)">{{ brand.brandName }}</el-tag>
           </template>
           <el-tag type="primary" @click="handleShowDialog">添加品牌<span class="el-icon-plus" /></el-tag>
-        <!-- <el-input v-model="formData1.shopInfo" class="hiddenInput" /> -->
+          <!-- <el-input v-model="formData1.shopInfo" class="hiddenInput" /> -->
         </el-form-item>
       </transition>
 
@@ -177,6 +177,7 @@
             @success="fileUploadSuccess"
             @error="fileUploadFaild"
             @remove="fileRemove"
+            @change="fileChange"
           />
           <el-input v-model="formData2.statementFileId" type="hidden" class="hiddenInput" />
         </el-form-item>
@@ -221,6 +222,7 @@ export default {
       excludeBrandList: [], // 已经选择的品牌,需要被排除在外的
       selectedShopType: 1,
       currentIndex: '',
+      prevBrandId: '',
       // 表单1
       formData1: {
         shopType: 1, // 供应商类型
@@ -232,7 +234,7 @@ export default {
         brandAuthLogo: '', // 品牌logo
         securityLink: '', // 官网认证链接
         shopStatus: 1, // 供应商状态,
-        shopInfo: []
+        shopInfo: ''
       },
       // 表单2
       formData2: {
@@ -260,7 +262,7 @@ export default {
         linkMan: { required: true, message: '联系人不能为空', tigger: 'blur' },
         countryId: { required: true, message: '产地不能为空', tigger: 'change', type: 'number' },
         brandAuthLogo: { required: true, message: '品牌logo不能为空', tigger: 'change' },
-        shopInfo: { required: true, message: '代理品牌不能为空', tigger: 'change' },
+        shopInfo: { required: true, message: '代理品牌不能为空', tigger: 'change', type: 'string' },
         brandId: { required: true, message: '品牌不能为空', tigger: 'change', type: 'number' },
         statementContent: { required: true, message: '声明内容不能为空', tigger: 'change' }, // 声明内容
         statementFileId: { required: true, message: '声明文件不能为空', tigger: 'change', type: 'number' }, // 声明文件id
@@ -282,6 +284,15 @@ export default {
       })
     }
   },
+  watch: {
+    supplierBrands() {
+      if (this.supplierBrands.length > 0) {
+        this.formData1.shopInfo = '1'
+      } else {
+        this.formData1.shopInfo = ''
+      }
+    }
+  },
   created() {
     this.getBrandList(1)
   },
@@ -290,13 +301,20 @@ export default {
     submit() {
       this.$refs.formData1Ref.validate(valid => {
         if (!valid) return
-        console.log(this.setAddParams())
+        this.isLoading = true
         addSupplier(this.setAddParams()).then(res => {
           if (res.code !== 0) {
             return
           }
-          console.log(res)
-          this.$message.success(res.msg)
+          const h = this.$createElement
+          this.$notify.success({
+            title: '添加供应商',
+            message: h('i', { style: 'color: #333' }, `已添加供应商:"${this.formData1.shopName}"`),
+            duration: 3000
+          })
+          this.$router.push('/supplier')
+        }).finally(() => {
+          this.isLoading = false
         })
       })
     },
@@ -318,7 +336,7 @@ export default {
         for (const key in result) {
           if (Object.hasOwnProperty.call(result, key)) {
             if (key !== 'shopInfo') {
-              result[key] = this.formData1[key] || null
+              result[key] = this.formData1[key]
             }
           }
         }
@@ -334,7 +352,20 @@ export default {
           statementLink: ''
         })
       }
+
+      // 代理商
+      if (this.selectedShopType === 2) {
+        for (const key in result) {
+          if (Object.hasOwnProperty.call(result, key)) {
+            if (key !== 'shopInfo') {
+              result[key] = this.formData1[key]
+            }
+          }
+        }
+        result.shopInfo = this.supplierBrands
+      }
       result.createBy = this.authUserId
+      console.log(result)
       return result
     },
 
@@ -377,15 +408,15 @@ export default {
     // 添加品牌
     handleAddBrand() {
       this.dialogLoading = true
-      // 如果声明类型为4,则需要先上传文件再保存
+      // 如果声明类型为4,并且文件id为空或null,则需要先上传文件再保存
       if (this.formData2.statementType === 4 && (this.formData2.statementFileId === '' || this.formData2.statementFileId === null)) {
-        console.log(this.$refs.formData2Ref)
         this.$refs.uploadFileRef.$refs.upload.submit()
       } else {
         this.saveShopInfo()
       }
     },
     saveShopInfo() {
+      this.dialogLoading = false
       this.$refs.formData2Ref.validate(valid => {
         if (!valid) {
           return
@@ -400,19 +431,32 @@ export default {
         }
         this.addExcludeBrand(shopInfo.brandId)
         shopInfo.isNew = false
-        this.dialogLoading = false
+        this.prevBrandId = ''
         this.showDialog = false
+        const h = this.$createElement
+        this.$notify.success({
+          title: '新增品牌',
+          message: h('i', { style: 'color: #333' }, `新增品牌:"${shopInfo.brandName}"`),
+          duration: 2000
+        })
       })
     },
     // 移除品牌
     handleRemove(index) {
       const pop = this.supplierBrands.splice(index, 1)[0]
       this.removeExcludeBrand(pop.brandId)
+      const h = this.$createElement
+      this.$notify.success({
+        title: '移除品牌',
+        message: h('i', { style: 'color: #333' }, `已移除品牌:"${pop.brandName}"`),
+        duration: 2000
+      })
     },
     // 修改品牌
     handleShowInfo(index) {
       this.currentIndex = index
       this.formData2 = this.supplierBrands[index]
+      this.prevBrandId = this.supplierBrands[index].brandId // 保存当前的品牌id
       this.fileList2 = [{ name: '', url: this.formData2.brandAuthLogo }]
       this.fileList3 = [{ name: '', url: this.formData2.statementImage }]
       this.fileList4 = [{ name: this.formData2.statementFileName, url: '' }]
@@ -421,6 +465,10 @@ export default {
     },
     // 添加品牌对话框关闭
     dialogClosed() {
+      if (this.prevBrandId) {
+        this.addExcludeBrand(this.prevBrandId)
+        this.prevBrandId = ''
+      }
       this.resetFormData2()
     },
     // 声明类型切换
@@ -462,7 +510,8 @@ export default {
       console.log('删除文件')
     },
     fileChange() {
-      // this.$refs.statementFileRef
+      console.log('文件改变')
+      this.$refs.statementFileRef.clearValidate()
     },
 
     // 图片上传成功 品牌logo  1
@@ -533,7 +582,7 @@ export default {
         securityLink: '', // 官网认证链接
         statementType: 1, // 代理声明类型
         statementContent: '', // 声明内容
-        statementFileId: '', // 声明文件id
+        statementFileId: null, // 声明文件id
         statementImage: '', // 声明图片
         statementLink: '', // 声明链接
         statementFileName: ''

+ 507 - 71
src/views/supplier/user/edit.vue

@@ -1,61 +1,61 @@
 <template>
   <div v-loading="isLoading" class="addSupplier">
-    <el-form ref="addFromDataRef" :model="addFromData" :rules="addFromDataRules" label-width="120px" class="addForm">
+    <el-form ref="formData1Ref" :model="formData1" :rules="formDataRules" label-width="120px" class="addForm">
       <el-form-item label="供应商类型:" prop="shopType">
-        <el-input v-if="addFromData.shopType===1" placeholder="请输入供应商名称" disabled value="品牌方" />
-        <el-input v-if="addFromData.shopType===2" placeholder="请输入供应商名称" disabled value="代理商" />
-        <el-select
-          v-model="addFromData.shopType"
+        <!-- <el-select
+          v-model="formData1.shopType"
           placeholder="请选择供应商类型"
           style="width: 100%"
           disabled
-          class="hiddenInput"
           @change="handleTypeChange"
         >
           <el-option label="品牌方" :value="1" />
           <el-option label="代理商" :value="2" />
-        </el-select>
+        </el-select> -->
+        <el-input v-if="formData1.shopType===1" value="品牌方" disabled />
+        <el-input v-if="formData1.shopType===2" value="代理商" disabled />
       </el-form-item>
 
       <!-- 供应商名称 -->
-      <el-form-item v-if="addFromData.shopType === 2" label="供应商名称:" prop="shopName">
-        <el-input v-model="addFromData.shopName" placeholder="请输入供应商名称" disabled />
+      <el-form-item v-if="formData1.shopType === 2" label="供应商名称:" prop="shopName">
+        <el-input v-model="formData1.shopName" placeholder="请输入供应商名称" maxlength="50" show-word-limit disabled />
       </el-form-item>
 
-      <el-form-item v-if="addFromData.shopType === 1" label="供应商名称:" prop="brandId">
-        <el-input v-model="addFromData.shopName" placeholder="请输入供应商名称" disabled />
-        <el-select
-          v-model="addFromData.brandId"
-          disabled
+      <el-form-item v-if="formData1.shopType === 1" label="供应商名称:" prop="brandId">
+        <!-- <el-select
+          v-model="formData1.brandId"
           placeholder="请选择品牌"
           style="width: 100%"
           filterable
-          class="hiddenInput"
-          @change="setShopName"
+          @change="handleBrandChange"
         >
           <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
-        </el-select>
+        </el-select> -->
+        <el-input v-model="formData1.brandName" disabled />
       </el-form-item>
       <!-- 供应商名称END -->
 
       <el-form-item label="手机号:" prop="mobile">
-        <el-input v-model="addFromData.mobile" placeholder="请输入手机号" maxlength="11" show-word-limit @input="handleInput" />
+        <el-input v-model="formData1.mobile" placeholder="请输入手机号" maxlength="11" show-word-limit @input="handleInput" />
       </el-form-item>
 
       <el-form-item label="联系人:" prop="linkMan">
-        <el-input v-model="addFromData.linkMan" placeholder="请输入联系人" />
+        <el-input v-model="formData1.linkMan" placeholder="请输入联系人" />
       </el-form-item>
 
-      <el-form-item v-if="addFromData.shopType === 2" label="代理品牌:" prop="shopInfo" class="brand-list">
-        <template v-if="supplierBrands !== []">
-          <el-tag v-for="(brand , index) in supplierBrands" :key="index" closable type="success" @close="handleRemove(index)" @click="handleShowInfo(index)">{{ brand.brandName }}</el-tag>
-        </template>
-        <el-tag type="primary" @click="handleShowDialog">添加品牌<span class="el-icon-plus" /></el-tag>
-      </el-form-item>
+      <transition name="fade">
+        <el-form-item v-if="formData1.shopType === 2" ref="shopInfoRef" label="代理品牌:" prop="shopInfo" class="brand-list">
+          <template v-if="supplierBrands !== []">
+            <el-tag v-for="(brand , index) in supplierBrands" :key="index" closable type="success" @close="handleRemove(index)" @click="handleShowInfo(index)">{{ brand.brandName }}</el-tag>
+          </template>
+          <el-tag type="primary" @click="handleShowDialog">添加品牌<span class="el-icon-plus" /></el-tag>
+          <!-- <el-input v-model="formData1.shopInfo" class="hiddenInput" /> -->
+        </el-form-item>
+      </transition>
 
-      <template v-if="addFromData.shopType === 1">
+      <template v-if="formData1.shopType === 1">
         <el-form-item label="产地:" prop="countryId">
-          <el-select v-model="addFromData.countryId" placeholder="产地" style="width: 100%" filterable>
+          <el-select v-model="formData1.countryId" placeholder="产地" style="width: 100%" filterable>
             <el-option
               v-for="item in countryList"
               :key="item.countryId"
@@ -73,16 +73,16 @@
             @error="imageUploadFaild1"
             @remove="imageRemove1"
           />
-          <el-input v-model="addFromData.brandAuthLogo" type="hidden" class="hiddenInput" />
+          <el-input v-model="formData1.brandAuthLogo" type="hidden" class="hiddenInput" />
         </el-form-item>
 
         <el-form-item label="官网认证链接:">
-          <el-input v-model="addFromData.securityLink" placeholder="请输入官网认证链接" />
+          <el-input v-model="formData1.securityLink" placeholder="请输入官网认证链接" />
         </el-form-item>
       </template>
 
       <el-form-item label="供应商状态:">
-        <el-select v-model="addFromData.shopStatus" placeholder="请选择供应商状态" style="width: 100%">
+        <el-select v-model="formData1.shopStatus" placeholder="请选择供应商状态" style="width: 100%" @change="handleShopStatusChange">
           <el-option label="启用" :value="1" />
           <el-option label="禁用" :value="0" />
         </el-select>
@@ -94,22 +94,23 @@
     </div>
 
     <!-- 供应商添加品牌的对话框 -->
-    <el-dialog v-loading="dialogLoading" title="添加代理品牌" :visible.sync="showDialog" width="width" @closed="dialogClosed">
-      <el-form ref="brandDataRef" :model="brandData" :rules="brandDataRules" label-width="120px">
+    <el-dialog title="添加代理品牌" :visible.sync="showDialog" width="width" @closed="dialogClosed">
+      <el-form ref="formData2Ref" :model="formData2" label-width="120px" :rules="formDataRules">
+
         <el-form-item label="选择品牌:" prop="brandId">
           <el-select
-            v-model="brandData.brandId"
+            v-model="formData2.brandId"
             placeholder="请选择品牌"
             style="width: 100%"
             filterable
-            @change="setShopName"
+            @change="handleBrandChange"
           >
-            <el-option v-for="item in brandListCody" :key="item.id" :label="item.name" :value="item.id" />
+            <el-option v-for="item in brandListCopy" :key="item.id" :label="item.name" :value="item.id" />
           </el-select>
         </el-form-item>
 
         <el-form-item label="产地:" prop="countryId">
-          <el-select v-model="brandData.countryId" placeholder="产地" style="width: 100%" filterable>
+          <el-select v-model="formData2.countryId" placeholder="产地" style="width: 100%" filterable>
             <el-option
               v-for="item in countryList"
               :key="item.countryId"
@@ -121,16 +122,17 @@
 
         <el-form-item label="品牌logo:" class="no-input" prop="brandAuthLogo">
           <upload-image
-            ref="uploadImageRef1"
-            :file-list="fileList1"
-            @success="imageUploadSuccess1"
-            @error="imageUploadFaild1"
+            ref="uploadImageRef2"
+            :file-list="fileList2"
+            @success="imageUploadSuccess2"
+            @error="imageUploadFaild2"
+            @remove="imageRemove2"
           />
-          <el-input v-model="brandData.brandAuthLogo" type="hidden" class="hiddenInput" />
+          <el-input v-model="formData2.brandAuthLogo" type="hidden" class="hiddenInput" />
         </el-form-item>
 
         <el-form-item label="代理声明:">
-          <el-radio-group v-model="brandData.statementType" @change="handleStatementChange">
+          <el-radio-group v-model="formData2.statementType" @change="handleStatementChange">
             <el-radio :label="1">弹窗</el-radio>
             <el-radio :label="2">链接</el-radio>
             <el-radio :label="3">图片</el-radio>
@@ -138,60 +140,61 @@
           </el-radio-group>
         </el-form-item>
 
-        <el-form-item v-if="brandData.statementType === 1" ref="statement1" label="弹窗:" prop="statementContent">
+        <el-form-item v-if="formData2.statementType === 1" ref="statement1" label="弹窗:" prop="statementContent">
           <el-input
-            v-if="brandData.statementType === 1"
-            v-model="brandData.statementContent"
+            v-if="formData2.statementType === 1"
+            v-model="formData2.statementContent"
             type="textarea"
           />
         </el-form-item>
 
-        <el-form-item v-else-if="brandData.statementType === 2" ref="statement2" label="链接:" prop="statementLink">
-          <el-input v-if="brandData.statementType === 2" v-model="brandData.statementLink" />
+        <el-form-item v-else-if="formData2.statementType === 2" ref="statement2" label="链接:" prop="statementLink">
+          <el-input v-if="formData2.statementType === 2" v-model="formData2.statementLink" />
         </el-form-item>
 
         <el-form-item
-          v-else-if="brandData.statementType === 3"
+          v-else-if="formData2.statementType === 3"
           ref="statement3"
           label="图片:"
           class="no-input"
           prop="statementImage"
         >
           <upload-image
-            v-if="brandData.statementType === 3"
-            ref="uploadImageRef2"
-            :file-list="fileList2"
-            tip-title="宽760px"
-            @success="imageUploadSuccess2"
-            @error="imageUploadFaild2"
-            @remove="imageRemove2"
+            v-if="formData2.statementType === 3"
+            ref="uploadImageRef3"
+            :file-list="fileList3"
+            tip-title="宽760px"
+            @success="imageUploadSuccess3"
+            @error="imageUploadFaild3"
+            @remove="imageRemove3"
           />
-          <el-input v-model="brandData.statementImage" type="hidden" class="hiddenInput" />
+          <el-input v-model="formData2.statementImage" type="hidden" class="hiddenInput" />
         </el-form-item>
 
-        <el-form-item v-else ref="statement4" label="文件:" prop="statementFileId">
+        <el-form-item v-else ref="statementFileRef" label="文件:" prop="statementFileId">
           <upload-file
-            v-if="brandData.statementType === 4"
+            v-if="formData2.statementType === 4"
             ref="uploadFileRef"
-            :auth-user-id="addFromData.authUserId"
-            :brand-id="brandId"
-            :file-list="fileList3"
+            :auth-user-id="id"
+            :brand-id="formData2.brandId"
+            :file-list="fileList4"
             @success="fileUploadSuccess"
             @error="fileUploadFaild"
             @remove="fileRemove"
+            @change="fileChange"
           />
-          <el-input v-model="brandData.statementFileId" type="hidden" class="hiddenInput" />
+          <el-input v-model="formData2.statementFileId" type="hidden" class="hiddenInput" />
         </el-form-item>
 
         <el-form-item label="官网认证链接:">
-          <el-input v-model="brandData.securityLink" placeholder="请输入官网认证链接" />
+          <el-input v-model="formData2.securityLink" placeholder="请输入官网认证链接" />
         </el-form-item>
 
       </el-form>
 
       <div slot="footer">
         <el-button @click="showDialog = false">取 消</el-button>
-        <el-button type="primary" @click="handleAddBrand">确 定</el-button>
+        <el-button type="primary" :loading="dialogLoading" @click="handleAddBrand">确 定</el-button>
       </div>
     </el-dialog>
 
@@ -202,26 +205,459 @@
 import UploadImage from '../components/uploadImage'
 import UploadFile from '../components/uploadFile'
 import { mapGetters } from 'vuex'
-// import { isMobile } from '@/utils/validate'
-// import { fetchBrandList } from '@/api/brand'
-// import { addSupplier, getSupplierById } from '@/api/supplier'
+import { isMobile } from '@/utils/validate'
+import { fetchBrandList } from '@/api/brand'
+import { addSupplier, getSupplierById } from '@/api/supplier'
 
 export default {
   components: { UploadImage, UploadFile },
   data() {
-
+    const validMobile = (rule, value, callback) => {
+      if (!isMobile(value)) {
+        return callback(new Error('手机号格式不正确'))
+      }
+      return callback()
+    }
+    return {
+      id: '',
+      isCheckout: true,
+      isLoading: false,
+      dialogLoading: false,
+      showDialog: false,
+      excludeBrandList: [], // 已经选择的品牌,需要被排除在外的
+      selectedShopType: 1,
+      currentIndex: '',
+      prevBrandId: '',
+      // 表单1
+      formData1: {
+        shopType: 1, // 供应商类型
+        shopName: '', // 供应商名称
+        brandId: '', // 品牌id
+        mobile: '', // 手机号
+        linkMan: '', // 联系人
+        countryId: 1, // 产地id
+        brandAuthLogo: '', // 品牌logo
+        securityLink: '', // 官网认证链接
+        shopStatus: 1, // 供应商状态,
+        shopInfo: ''
+      },
+      // 表单2
+      formData2: {
+        index: '',
+        isNew: true,
+        brandName: '',
+        brandId: '', // 品牌id
+        countryId: 1, // 产地id
+        brandAuthLogo: '', // 品牌logo
+        securityLink: '', // 官网认证链接
+        statementType: 1, // 代理声明类型
+        statementContent: '', // 声明内容
+        statementFileId: null, // 声明文件id
+        statementImage: '', // 声明图片
+        statementLink: '', // 声明链接
+        statementFileName: '' // 上传图片的名称
+      },
+      supplierBrands: [],
+      brandList: [],
+      // 表单数据校验
+      formDataRules: {
+        shopType: { required: true, message: '供应商类型不能为空', tigger: 'change', type: 'number' },
+        shopName: { required: true, message: '供应名称不能为空', tigger: 'change' },
+        mobile: [{ required: true, message: '手机号不能为空', tigger: 'change' }, { validator: validMobile, tigger: 'change' }],
+        linkMan: { required: true, message: '联系人不能为空', tigger: 'blur' },
+        countryId: { required: true, message: '产地不能为空', tigger: 'change', type: 'number' },
+        brandAuthLogo: { required: true, message: '品牌logo不能为空', tigger: 'change' },
+        shopInfo: { required: true, message: '代理品牌不能为空', tigger: 'change', type: 'number' },
+        brandId: { required: true, message: '品牌不能为空', tigger: 'change', type: 'number' },
+        statementContent: { required: true, message: '声明内容不能为空', tigger: 'change' }, // 声明内容
+        statementFileId: { required: true, message: '声明文件不能为空', tigger: 'change', type: 'number' }, // 声明文件id
+        statementImage: { required: true, message: '声明图片不能为空', tigger: 'change' }, // 声明图片
+        statementLink: { required: true, message: '声明链接不能为空', tigger: 'change' } // 声明链接
+      },
+      // 上传的文件列表
+      fileList1: [],
+      fileList2: [],
+      fileList3: [],
+      fileList4: [] // 文件
+    }
   },
   computed: {
-    ...mapGetters(['name', 'countryList', 'authUserId'])
+    ...mapGetters(['countryList', 'authUserId']),
+    brandListCopy() {
+      return this.brandList.filter(item => {
+        return !this.excludeBrandList.includes(item.id)
+      })
+    }
   },
   watch: {
-
+    supplierBrands() {
+      if (this.supplierBrands.length > 0) {
+        this.formData1.shopInfo = 1
+       this.$refs.shopInfoRef?.clearValidate()
+       console.log('供应商列表不为空')
+      } else {
+        this.formData1.shopInfo = null
+        console.log('供应商列表为空')
+      }
+    }
   },
   created() {
-
+    this.isLoading = true
+    this.id = parseInt(this.$route.query.id)
+    this.getSupplierInfo()
   },
   methods: {
+    handleShopStatusChange(i) {
+      console.log(i)
+    },
+    getSupplierInfo() {
+      getSupplierById({ authUserId: this.id }).then(res => {
+        if (res.code !== 0) {
+          return
+        }
+        this.selectedShopType = res.data.shopType
+        this.getBrandList(this.selectedShopType)
+        this.setFormData(res.data)
+      }).finally(() => {
+        this.isLoading = false
+      })
+    },
+    // 为表单赋值
+    setFormData(data) {
+      this.formData1 = {
+        ...this.formData1,
+        ...data,
+        shopInfo: ''
+      }
+      // 品牌方
+      if (this.selectedShopType === 1) {
+        this.formData1.brandId = data.shopInfo[0].brandId
+        this.formData1.brandAuthLogo = data.shopInfo[0].brandAuthLogo
+        this.formData1.brandName = data.shopInfo[0].brandName
+        this.formData1.countryId = data.shopInfo[0].countryId
+        this.formData1.securityLink = data.shopInfo[0].securityLink
+        this.fileList1 = [{ name: this.formData1.brandName, url: this.formData1.brandAuthLogo }]
+      }
+      // 供应商
+      if (this.selectedShopType === 2) {
+        data.shopInfo.forEach(item => {
+          item.isNew = false
+          this.excludeBrandList.push(item.brandId)
+        })
+        this.supplierBrands = data.shopInfo
+      }
+    },
+    // 提交保存
+    submit() {
+      this.$refs.formData1Ref.validate(valid => {
+        if (!valid) return
+        this.isLoading = true
+
+        addSupplier(this.setAddParams()).then(res => {
+          if (res.code !== 0) {
+            return
+          }
+          const h = this.$createElement
+          this.$notify.success({
+            title: '修改供应商',
+            message: h('i', { style: 'color: #333' }, `已修改供应商:"${this.formData1.shopName}"`),
+            duration: 3000
+          })
+          this.$router.push('/supplier')
+        }).finally(() => {
+          this.isLoading = false
+        })
+      })
+    },
+    // 封装请求参数
+    setAddParams() {
+      // 品牌方的参数列表
+      const result = {
+        authUserId: '',
+        createBy: '',
+        linkMan: '',
+        mobile: '',
+        shopName: '',
+        shopStatus: '',
+        shopType: '',
+        shopInfo: []
+      }
+      // 品牌方
+      if (this.selectedShopType === 1) {
+        // debugger
+        for (const key in result) {
+          if (Object.hasOwnProperty.call(result, key)) {
+            if (key !== 'shopInfo') {
+              result[key] = this.formData1[key]
+            }
+          }
+        }
+        result.shopInfo.push({
+          brandId: this.formData1.brandId,
+          countryId: this.formData1.countryId,
+          brandAuthLogo: this.formData1.brandAuthLogo,
+          securityLink: this.formData1.securityLink,
+          statementType: 1,
+          statementContent: '',
+          statementFileId: null,
+          statementImage: '',
+          statementLink: ''
+        })
+      }
 
+      // 代理商
+      if (this.selectedShopType === 2) {
+        for (const key in result) {
+          if (Object.hasOwnProperty.call(result, key)) {
+            if (key !== 'shopInfo') {
+              result[key] = this.formData1[key]
+            }
+          }
+        }
+        result.shopInfo = this.supplierBrands
+      }
+      result.createBy = this.authUserId
+      console.log(result)
+      return result
+    },
+
+    // 获取品牌列表
+    getBrandList(type) {
+      fetchBrandList({ type }).then(res => {
+        if (res.code !== 0) {
+          return
+        }
+        this.brandList = res.data
+      })
+    },
+    // 品牌改变事件
+    handleBrandChange(id) {
+      const selectBrand = this.brandList.filter(item => item.id === id)[0]
+      // 选择品牌方
+      if (this.formData1.shopType === 1) {
+        this.formData1.shopName = selectBrand.name
+        this.formData1.brandAuthLogo = selectBrand.authLogo
+        this.formData1.brandId = selectBrand.id
+        if (selectBrand.authLogo) {
+          this.fileList1 = [{ name: selectBrand.name, url: selectBrand.authLogo }]
+        }
+      }
+      // 如果选择代理应商
+      if (this.formData1.shopType === 2) {
+        this.formData2.brandAuthLogo = selectBrand.authLogo
+        this.formData2.brandName = selectBrand.name
+        this.formData2.brandId = selectBrand.id
+        if (selectBrand.authLogo) {
+          this.fileList2 = [{ name: selectBrand.name, url: selectBrand.authLogo }]
+        }
+      }
+    },
+    // 添加品牌对话框
+    handleShowDialog() {
+      this.showDialog = true
+      this.resetFormData2()
+    },
+    // 添加品牌
+    handleAddBrand() {
+      this.dialogLoading = true
+      // 如果声明类型为4,并且文件id为空或null,则需要先上传文件再保存
+      if (this.formData2.statementType === 4 && (this.formData2.statementFileId === '' || this.formData2.statementFileId === null)) {
+        this.$refs.uploadFileRef.$refs.upload.submit()
+      } else {
+        this.saveShopInfo()
+      }
+    },
+    // 保存品牌信息
+    saveShopInfo() {
+      this.dialogLoading = false
+      this.$refs.formData2Ref.validate(valid => {
+        if (!valid) {
+          return
+        }
+        // 如果是新增的
+        const shopInfo = this.clone(this.formData2)
+        if (shopInfo.isNew) {
+          this.supplierBrands.push(shopInfo)
+        } else {
+        // 修改的
+          this.supplierBrands.splice(this.currentIndex, shopInfo)
+        }
+        this.addExcludeBrand(shopInfo.brandId)
+        shopInfo.isNew = false
+        this.prevBrandId = ''
+        this.showDialog = false
+        const h = this.$createElement
+        this.$notify.success({
+          title: '新增品牌',
+          message: h('i', { style: 'color: #333' }, `新增品牌:"${shopInfo.brandName}"`),
+          duration: 2000
+        })
+      })
+    },
+    // 移除品牌
+    handleRemove(index) {
+      const pop = this.supplierBrands.splice(index, 1)[0]
+      this.removeExcludeBrand(pop.brandId)
+      const h = this.$createElement
+      this.$notify.success({
+        title: '移除品牌',
+        message: h('i', { style: 'color: #333' }, `已移除品牌:"${pop.brandName}"`),
+        duration: 2000
+      })
+    },
+    // 修改品牌
+    handleShowInfo(index) {
+      this.currentIndex = index
+      this.formData2 = this.supplierBrands[index]
+      this.prevBrandId = this.supplierBrands[index].brandId // 保存当前的品牌id
+      this.fileList2 = [{ name: '', url: this.formData2.brandAuthLogo }]
+      this.fileList3 = [{ name: '', url: this.formData2.statementImage }]
+      this.fileList4 = [{ name: this.formData2.statementFileName, url: '' }]
+      this.removeExcludeBrand(this.supplierBrands[index].brandId)
+      this.showDialog = true
+    },
+    // 添加品牌对话框关闭
+    dialogClosed() {
+      if (this.prevBrandId) {
+        this.addExcludeBrand(this.prevBrandId)
+        this.prevBrandId = ''
+      }
+      this.resetFormData2()
+    },
+    // 声明类型切换
+    handleStatementChange() {},
+    // 供应商类型改变事件
+    handleTypeChange(shopType) {
+      this.selectedShopType = shopType
+      this.getBrandList(shopType)
+      this.resetFormData1(shopType)
+    },
+    // 添加排除品牌
+    addExcludeBrand(id) {
+      this.excludeBrandList.push(id)
+    },
+    // 移除排除品牌
+    removeExcludeBrand(id) {
+      const index = this.excludeBrandList.indexOf(id)
+      this.excludeBrandList.splice(index, 1)
+    },
+    // 输入框输入时
+    handleInput() {
+      this.formData1.mobile = this.formData1.mobile.replace(/[^\w\.\/]/ig, '')
+    },
+
+    // 文件上传成功
+    fileUploadSuccess(data) {
+      this.formData2.statementFileName = data.data.fileName
+      this.formData2.statementFileId = data.data.fileId
+      if (data.code === 0) {
+        this.saveShopInfo()
+      }
+    },
+    fileUploadFaild(err, file, fileList) {
+      this.$message.error('文件上传失败')
+      console.log(err)
+    },
+    fileRemove() {
+      this.formData2.statementFileId = null
+      console.log('删除文件')
+    },
+    fileChange() {
+      console.log('文件改变')
+      this.$refs.statementFileRef.clearValidate()
+    },
+
+    // 图片上传成功 品牌logo  1
+    imageUploadSuccess1(data) {
+      this.formData1.brandAuthLogo = data.data
+    },
+    imageUploadFaild1(err, file, fileList) {
+      this.$message.error('图片上传失败')
+      console.log(err)
+    },
+    imageRemove1() {
+      this.formData1.brandAuthLogo = ''
+      console.log('删除图片')
+    },
+    // 图片上传成功 品牌logo 2
+    imageUploadSuccess2(data) {
+      this.formData2.brandAuthLogo = data.data
+    },
+    imageUploadFaild2(err, file, fileList) {
+      this.$message.error('图片上传失败')
+      console.log(err)
+    },
+    imageRemove2() {
+      this.formData2.brandAuthLogo = ''
+      console.log('删除图片')
+    },
+    // 图片上传成功 声明图片  3
+    imageUploadSuccess3(data) {
+      this.formData2.statementImage = data.data
+    },
+    imageUploadFaild3(err, file, fileList) {
+      this.$message.error('图片上传失败')
+      console.log(err)
+    },
+    imageRemove3() {
+      this.formData2.statementImage = ''
+      console.log('删除图片')
+    },
+    // 重置表单1
+    resetFormData1(shopType) {
+      this.formData1 = {
+        shopType: shopType, // 供应商类型
+        shopName: '', // 供应商名称
+        brandId: '', // 品牌id
+        mobile: '', // 手机号
+        linkMan: '', // 联系人
+        countryId: '', // 产地id
+        brandAuthLogo: '', // 品牌logo
+        securityLink: '', // 官网认证链接
+        shopStatus: 1, // 供应商状态,
+        shopInfo: []
+      }
+      this.fileList1 = []
+      this.fileList2 = []
+      this.fileList3 = []
+      this.fileList4 = []
+      this.$refs.formData1Ref.clearValidate()
+    },
+    // 重置表单2
+    resetFormData2() {
+      this.formData2 = {
+        index: '',
+        isNew: true,
+        brandName: '',
+        brandId: '', // 品牌id
+        countryId: 1, // 产地id
+        brandAuthLogo: '', // 品牌logo
+        securityLink: '', // 官网认证链接
+        statementType: 1, // 代理声明类型
+        statementContent: '', // 声明内容
+        statementFileId: null, // 声明文件id
+        statementImage: '', // 声明图片
+        statementLink: '', // 声明链接
+        statementFileName: ''
+      }
+      this.fileList1 = []
+      this.fileList2 = []
+      this.fileList3 = []
+      this.fileList4 = []
+      setTimeout(() => {
+        this.$refs.formData2Ref.clearValidate()
+      }, 200)
+    },
+    // 克隆
+    clone(data) {
+      const result = {}
+      for (const key in data) {
+        if (Object.hasOwnProperty.call(data, key)) {
+          result[key] = data[key]
+        }
+      }
+      return result
+    }
   }
 }
 </script>

+ 7 - 1
src/views/supplier/user/index.vue

@@ -220,7 +220,13 @@ export default {
       if (text !== 'confirm') return
       // 要执行的操作
       resetPassword({ authUserId: item.authUserId }).then(res => {
-        this.$message.success(res.data)
+        if (res.code !== 0) return
+        const h = this.$createElement
+        this.$notify.success({
+          title: '重置密码',
+          message: h('i', { style: 'color: #333' }, `已重置供应商"${item.name}"的面膜`),
+          duration: 2000
+        })
       })
     },
     // 代他操作