yuwenjun 3 anni fa
parent
commit
373719c706

+ 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

@@ -154,7 +154,7 @@ export default {
     },
     // 删除商品
     async handleRemoveProduct(item) {
-      const text = await this.$confirm('此操作将删除该授权机构, 是否继续?', '提示', {
+      const text = await this.$confirm('此操作将删除该商品, 是否继续?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
@@ -164,7 +164,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()
       })

+ 342 - 338
src/views/supplier/user/add.vue

@@ -1,9 +1,9 @@
 <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-select
-          v-model="addFromData.shopType"
+          v-model="formData1.shopType"
           placeholder="请选择供应商类型"
           style="width: 100%"
           @change="handleTypeChange"
@@ -14,17 +14,17 @@
       </el-form-item>
 
       <!-- 供应商名称 -->
-      <el-form-item v-if="addFromData.shopType === 2" label="供应商名称:" prop="shopName">
-        <el-input v-model="addFromData.shopName" placeholder="请输入供应商名称" maxlength="50" show-word-limit />
+      <el-form-item v-if="formData1.shopType === 2" label="供应商名称:" prop="shopName">
+        <el-input v-model="formData1.shopName" placeholder="请输入供应商名称" maxlength="50" show-word-limit />
       </el-form-item>
 
-      <el-form-item v-if="addFromData.shopType === 1" label="供应商名称:" prop="brandId">
+      <el-form-item v-if="formData1.shopType === 1" label="供应商名称:" prop="brandId">
         <el-select
-          v-model="addFromData.brandId"
+          v-model="formData1.brandId"
           placeholder="请选择品牌"
           style="width: 100%"
           filterable
-          @change="setShopName"
+          @change="handleBrandChange"
         >
           <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
         </el-select>
@@ -32,24 +32,26 @@
       <!-- 供应商名称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-input v-model="addFromData.shopInfo" class="hiddenInput" /> -->
-      </el-form-item>
+      <transition name="fade">
+        <el-form-item v-if="formData1.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-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"
@@ -67,16 +69,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%">
           <el-option label="启用" :value="1" />
           <el-option label="禁用" :value="0" />
         </el-select>
@@ -88,23 +90,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"
@@ -116,16 +118,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>
@@ -133,60 +136,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="brandData.authUserId"
-            :brand-id="brandData.brandId"
-            :file-list="fileList3"
+            :auth-user-id="formData2.authUserId"
+            :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>
 
@@ -204,155 +208,120 @@ import { addSupplier } from '@/api/supplier'
 export default {
   components: { UploadImage, UploadFile },
   data() {
-    const valideMobile = (rule, value, callback) => {
+    const validMobile = (rule, value, callback) => {
       if (!isMobile(value)) {
-        callback(new Error('手机号格式不正确'))
-      } else {
-        callback()
-      }
-    }
-
-    const valideShopInfo = (rule, value, callback) => {
-      if (value.length <= 0) {
-        callback(new Error('品牌不能为空'))
-      } else {
-        callback()
+        return callback(new Error('手机号格式不正确'))
       }
+      return callback()
     }
     return {
-      dialogLoading: false,
+      isCheckout: true,
       isLoading: false,
-      // 是否显示对话框
+      dialogLoading: false,
       showDialog: false,
-      // 需要排除的品牌列表
-      excludeBrand: [],
-      // 上1个选中的品牌
-      prevBrandId: -1,
-      // 品牌列表
-      brandList: [],
-      // 品牌列表处理后的结果
-      brandListCody: [],
-      // 加入的品牌列表
-      supplierBrands: [],
-      // 当前选中的品牌索引在数组中的id
-      currentBrandIndex: '',
-      // 表单校验数据1
-      addFromData: {
-        authUserId: null, // 供应商id
-        shopType: 1, //	供应商类型:1品牌方,2代理商
-        brandId: '', // 品牌id
+      excludeBrandList: [], // 已经选择的品牌,需要被排除在外的
+      selectedShopType: 1,
+      currentIndex: '',
+      prevBrandId: '',
+      // 表单1
+      formData1: {
+        shopType: 1, // 供应商类型
         shopName: '', // 供应商名称
+        brandId: '', // 品牌id
         mobile: '', // 手机号
         linkMan: '', // 联系人
-        countryId: 1, // 产地国家id
-        brandAuthLogo: '', //	品牌授权logo
-        createBy: '', // 创建人用户id
+        countryId: 1, // 产地id
+        brandAuthLogo: '', // 品牌logo
         securityLink: '', // 官网认证链接
-        shopStatus: 1, // 供应商状态:0停用 1启用
-        shopInfo: 1
+        shopStatus: 1, // 供应商状态,
+        shopInfo: ''
       },
-      // 表单校验数据2
-      brandData: {
+      // 表单2
+      formData2: {
+        index: '',
         isNew: true,
-        brandId: '', // 供应商id
-        countryId: 1, // 产地国家id
-        brandAuthLogo: '', //	品牌授权logo
         brandName: '',
+        brandId: '', // 品牌id
+        countryId: 1, // 产地id
+        brandAuthLogo: '', // 品牌logo
         securityLink: '', // 官网认证链接
-        statementType: 1, // 声明类型
-        statementContent: '', // 声明弹窗内容
+        statementType: 1, // 代理声明类型
+        statementContent: '', // 声明内容
         statementFileId: null, // 声明文件id
         statementImage: '', // 声明图片
         statementLink: '', // 声明链接
-        statementFileName: ''
+        statementFileName: '' // 上传图片的名称
       },
-      // 表单校验规则1
-      addFromDataRules: {
-        shopType: { required: true, message: '供应商类型不能为空', trigger: 'change', type: 'number' },
-        brandId: { required: true, message: '品牌不能为空', trigger: 'change', type: 'number' },
-        shopName: { required: true, message: '请输入供应商名称', trigger: 'change' },
-        mobile: [
-          { required: true, message: '请输入手机号', trigger: 'blur' },
-          { validator: valideMobile, trigger: 'blur' }
-        ],
-        linkMan: { required: true, message: '联系人不能为空', trigger: 'blur' },
-        countryId: { required: true, message: '产地不能为空', trigger: 'change', type: 'number' },
-        brandAuthLogo: { required: true, message: '品牌logo不能为空', trigger: 'change' },
-        shopInfo: { validator: valideShopInfo, trigger: 'change', required: true }
-      },
-      // 表单校验规则2
-      brandDataRules: {
-        brandId: { required: true, message: '品牌不能为空', trigger: 'change', type: 'number' },
-        countryId: { required: true, message: '产地不能为空', trigger: 'change', type: 'number' },
-        brandAuthLogo: { required: true, message: '品牌logo不能为空', trigger: 'change' },
-        statementContent: { required: true, message: '声明内容不能为空', trigger: 'blur' },
-        statementLink: { required: true, message: '声明链接不能为空', trigger: 'blur' },
-        statementFileId: { required: true, message: '请上传声明文件', trigger: 'change', type: 'number' },
-        statementImage: { required: true, message: '请上传声明图片', trigger: 'change' }
+      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: 'string' },
+        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: [], // 已上传的图片列表 品牌logo
-      fileList2: [], // 已上传的图片列表 声明图片
-      fileList3: [] // 已上传的图片列表 声明文件
+      // 上传的文件列表
+      fileList1: [],
+      fileList2: [],
+      fileList3: [],
+      fileList4: [] // 文件
     }
   },
   computed: {
-    ...mapGetters(['userIdentity', 'name', 'countryList', 'authUserId'])
+    ...mapGetters(['countryList', 'authUserId']),
+    brandListCopy() {
+      return this.brandList.filter(item => {
+        return !this.excludeBrandList.includes(item.id)
+      })
+    }
   },
   watch: {
-    excludeBrand() {
-      this.excludeBrandHandle()
+    supplierBrands() {
+      if (this.supplierBrands.length > 0) {
+        this.formData1.shopInfo = '1'
+      } else {
+        this.formData1.shopInfo = ''
+      }
     }
   },
   created() {
-    this.initAddForm()
+    this.getBrandList(1)
   },
   methods: {
-
-    // 初始添加供应商时的表单数据
-    initAddForm() {
-      // this.addFromData.authUserId = this.authUserId
-      this.getBrandList(1)
-      this.addFromData.shopName = ''
-    },
-    // 提交表单数据
+    // 提交保存
     submit() {
-      this.$refs.addFromDataRef.validate(valide => {
-        if (valide) {
-          console.log('校验通过')
-          if (this.addFromData.shopType === 1) {
-            this.save()
-          } else if (this.addFromData.shopType === 2) {
-            if (this.supplierBrands.length < 1) {
-              this.$alert('请至少添加一个代理品牌', '不满足提交要求', { type: 'warning' })
-              return
-            }
-            this.save()
-          }
-        }
-      })
-    },
-    // 保存
-    save() {
-      this.isLoading = true
-      addSupplier(this.createAddData())
-        .then(res => {
+      this.$refs.formData1Ref.validate(valid => {
+        if (!valid) return
+        this.isLoading = true
+        addSupplier(this.setAddParams()).then(res => {
           if (res.code !== 0) {
             return
           }
-          console.log(res)
-          this.$message.success('添加成功')
-          this.$router.replace('/supplier')
-        })
-        .finally(() => {
+          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
         })
+      })
     },
-    // 创建请求参数
-    createAddData() {
-      let addData = {}
-      // 参数模板
-      const temp1 = {
+    // 封装请求参数
+    setAddParams() {
+      // 品牌方的参数列表
+      const result = {
         authUserId: '',
         createBy: '',
         linkMan: '',
@@ -362,231 +331,270 @@ export default {
         shopType: '',
         shopInfo: []
       }
-      const temp2 = {
-        brandId: 1,
-        countryId: 2,
-        brandAuthLogo: '',
-        securityLink: '',
-        statementType: 1,
-        statementContent: '',
-        statementFileId: null,
-        statementImage: '',
-        statementLink: ''
-      }
-      // 指定创建者为当前登录的账号id
-      this.addFromData.createBy = this.authUserId
-      for (const key in temp1) {
-        if (Object.hasOwnProperty.call(temp1, key)) {
-          temp1[key] = this.addFromData[key]
-        }
-      }
-      // 如果为品牌方
-      if (this.addFromData.shopType === 1) {
-        for (const key in temp2) {
-          if (Object.hasOwnProperty.call(temp2, key)) {
-            temp2[key] = this.addFromData[key] || ''
+      // 品牌方
+      if (this.selectedShopType === 1) {
+        for (const key in result) {
+          if (Object.hasOwnProperty.call(result, key)) {
+            if (key !== 'shopInfo') {
+              result[key] = this.formData1[key]
+            }
           }
         }
-        temp2.statementType = 1
-        temp2.statementFileId = null
-        addData = {
-          ...temp1,
-          shopInfo: [temp2]
-        }
+        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.addFromData.shopType === 2) {
-        addData = {
-          ...temp1,
-          shopInfo: this.supplierBrands
+
+      // 代理商
+      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
       }
-
-      return addData
+      result.createBy = this.authUserId
+      console.log(result)
+      return result
     },
+
     // 获取品牌列表
     getBrandList(type) {
-      // 获取品牌列表
-      fetchBrandList({ type })
-        .then(res => {
-          console.log(res)
-          if (res.code === 0) {
-            this.brandList = res.data
-            this.brandListCody = res.data
-          }
-        })
-        .catch(err => console.log(err))
-    },
-    // 供应商类型切换
-    handleTypeChange(id) {
-      const type = id
-      this.$refs.addFromDataRef.clearValidate()
-      this.addFromData = {
-        authUserId: null, // 供应商id
-        shopType: type, //	供应商类型:1品牌方,2代理商
-        brandId: '', // 品牌id
-        shopName: '', // 供应商名称
-        mobile: '', // 手机号
-        linkMan: '', // 联系人
-        countryId: 1, // 产地国家id
-        brandAuthLogo: '', //	品牌授权logo
-        createBy: '', // 创建人用户id
-        securityLink: '', // 官网认证链接
-        shopStatus: 1, // 供应商状态:0停用 1启用
-        shopInfo: 1
-      }
-      this.fileList1 = []
-      this.getBrandList(type)
+      fetchBrandList({ type }).then(res => {
+        if (res.code !== 0) {
+          return
+        }
+        this.brandList = res.data
+      })
     },
-    // 设置品牌名称
-    setShopName(id) {
-      const selectBrand = this.brandList.filter(item => {
-        return item.id === id
-      })[0]
-      const str = this.addFromData.shopType === 1 ? 'addFromData' : 'brandData'
-      this[str].shopName = selectBrand.name
-      this[str].brandAuthLogo = selectBrand.authLogo
-      this[str].brandId = selectBrand.id
-      if (str === 'brandData') {
-        this[str].brandName = selectBrand.name
+    // 品牌改变事件
+    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 (selectBrand.authLogo) {
-        this.fileList1 = [{ 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.brandData.brandId = ''
       this.showDialog = true
+      this.resetFormData2()
     },
     // 添加品牌
     handleAddBrand() {
-      // 如果声明类型为文件
-      if (this.brandData.statementType === 4 && (this.brandData.statementFileId === null || this.brandData.statementFileId === '')) {
-        this.brandData.statementFileId = this.brandData.statementFileId === null ? '' : null
+      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.saveBrand()
+        this.saveShopInfo()
       }
     },
-    // 保存品牌信息
-    saveBrand() {
-      this.$refs.brandDataRef.validate(valid => {
-        if (valid) {
-          const brandInfo = this.clone(this.brandData)
-          console.log(brandInfo)
-          if (brandInfo.isNew) {
-            brandInfo.isNew = false
-            this.supplierBrands.push(brandInfo)
-          } else {
-            this.supplierBrands.splice(this.currentBrandIndex, 1, brandInfo)
-          }
-
-          if (this.addFromData.shopType === 2) {
-            this.excludeBrand.push(this.brandData.brandId)
-            this.prevBrandId = -1
-            console.log('添加:' + this.excludeBrand)
-          }
-          this.showDialog = false
+    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.currentBrandIndex = index
-      this.brandData = this.clone(this.supplierBrands[index])
-      this.brandData.isNew = false
-      this.prevBrandId = this.brandData.brandId
-      if (this.addFromData.shopType === 2) {
-        const i = this.excludeBrand.indexOf(this.brandData.brandId)
-        this.excludeBrand.splice(i, 1)
-      }
-      if (this.brandData.brandAuthLogo) {
-        this.fileList1 = [{ name: '文件已上传', url: this.brandData.brandAuthLogo }]
-      }
-      if (this.brandData.statementImage) {
-        this.fileList2 = [{ name: '文件已上传', url: this.brandData.statementImage }]
-      }
-      if (this.brandData.statementFileId) {
-        this.fileList3 = [{ name: this.brandData.statementFileName, url: '' }]
-      }
+      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
     },
-    // 删除
-    handleRemove(index) {
-      const i = this.excludeBrand.indexOf(this.supplierBrands[index].brandId)
-      this.excludeBrand.splice(i, 1)
-      this.supplierBrands.splice(index, 1)
-      console.log('删除:' + this.excludeBrand)
-    },
-    // 对话框关闭
+    // 添加品牌对话框关闭
     dialogClosed() {
-      this.$refs.brandDataRef.resetFields()
-      this.brandData.brandId = ''
-      this.fileList1 = []
-      this.fileList2 = []
-      this.fileList3 = []
-      this.brandData.isNew = true
-      // 如果部位-1 代表没有保存 则恢复到上一次的排除结果
-      if (this.prevBrandId !== -1) {
-        this.excludeBrand.push(this.prevBrandId)
-        this.prevBrandId = -1
+      if (this.prevBrandId) {
+        this.addExcludeBrand(this.prevBrandId)
+        this.prevBrandId = ''
       }
+      this.resetFormData2()
     },
     // 声明类型切换
-    handleStatementChange(index) {
-      console.log(index)
-      const ref = 'statement' + index
-      this.$refs[ref].clearValidate()
+    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.brandData.statementFileId = data.data.fileId
-      this.brandData.statementFileName = data.data.fileName
+      this.formData2.statementFileName = data.data.fileName
+      this.formData2.statementFileId = data.data.fileId
       if (data.code === 0) {
-        this.saveBrand()
+        this.saveShopInfo()
       }
     },
     fileUploadFaild(err, file, fileList) {
+      this.$message.error('文件上传失败')
       console.log(err)
     },
     fileRemove() {
+      this.formData2.statementFileId = null
       console.log('删除文件')
-      this.brandData.statementFileId = null
+    },
+    fileChange() {
+      console.log('文件改变')
+      this.$refs.statementFileRef.clearValidate()
     },
 
-    // 图片上传成功 品牌logo
+    // 图片上传成功 品牌logo  1
     imageUploadSuccess1(data) {
-      const str = this.addFromData.shopType === 1 ? 'addFromData' : 'brandData'
-      this[str].brandAuthLogo = data.data
+      this.formData1.brandAuthLogo = data.data
     },
     imageUploadFaild1(err, file, fileList) {
+      this.$message.error('图片上传失败')
       console.log(err)
     },
     imageRemove1() {
-      const str = this.addFromData.shopType === 1 ? 'addFromData' : 'brandData'
-      this[str].brandAuthLogo = ''
-      console.log('删除文件')
+      this.formData1.brandAuthLogo = ''
+      console.log('删除图片')
     },
-
-    // 图片上传成功 声明图片
+    // 图片上传成功 品牌logo 2
     imageUploadSuccess2(data) {
-      this.brandData.statementImage = data.data
+      this.formData2.brandAuthLogo = data.data
     },
     imageUploadFaild2(err, file, fileList) {
+      this.$message.error('图片上传失败')
       console.log(err)
     },
     imageRemove2() {
-      this.brandData.statementImage = ''
-      console.log('删除文件')
+      this.formData2.brandAuthLogo = ''
+      console.log('删除图片')
     },
-    // 对品牌列表做排除操作
-    excludeBrandHandle() {
-      this.brandListCody = this.brandList.filter((item, index) => {
-        return this.excludeBrand.indexOf(item.id) === -1
-      })
+    // 图片上传成功 声明图片  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 = {}
@@ -596,10 +604,6 @@ export default {
         }
       }
       return result
-    },
-    // 输入框输入时
-    handleInput() {
-      this.addFromData.mobile = this.addFromData.mobile.replace(/[^\w\.\/]/ig, '')
     }
   }
 }

File diff suppressed because it is too large
+ 393 - 390
src/views/supplier/user/edit.vue


+ 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
+        })
       })
     },
     // 代他操作

Some files were not shown because too many files changed in this diff