|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div class="page-form-container">
|
|
|
+ <div v-loading="isLoading" class="page-form-container">
|
|
|
<el-form ref="submitForm" :model="formData" :rules="rules" label-width="140px">
|
|
|
<el-form-item label="供应商名称:" prop="shopName">
|
|
|
<el-input v-model="formData.shopName" placeholder="请输入供应商名称" maxlength="50" show-word-limit />
|
|
@@ -11,9 +11,10 @@
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="关联采美供应商:">
|
|
|
- <el-select v-model="formData.shopType" placeholder="请选择需要关联的供应商" clearable>
|
|
|
- <el-option label="品牌方" :value="1" />
|
|
|
- <el-option label="代理商" :value="2" />
|
|
|
+ <el-select v-model="formData.cmShopId" placeholder="请选择需要关联的供应商" clearable>
|
|
|
+ <template v-for="shop in cmShopList">
|
|
|
+ <el-option :key="shop.cmShopId" :label="shop.cmShopName" :value="shop.cmShopId" />
|
|
|
+ </template>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="手机号:" prop="mobile">
|
|
@@ -40,8 +41,8 @@
|
|
|
/>
|
|
|
<el-input v-show="false" v-model="formData.logo" />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="旗下品牌:" prop="brandList">
|
|
|
- <template v-for="(item, index) in formData.brandList">
|
|
|
+ <el-form-item label="旗下品牌:" prop="shopInfo">
|
|
|
+ <template v-for="(item, index) in formData.shopInfo">
|
|
|
<el-tag
|
|
|
:key="index"
|
|
|
effect="dark"
|
|
@@ -54,7 +55,7 @@
|
|
|
</el-tag>
|
|
|
</template>
|
|
|
<el-tag type="primary" effect="dark" @click="onEditBrand('add')">添加品牌<span class="el-icon-plus" /></el-tag>
|
|
|
- <el-checkbox-group v-show="false" v-model="formData.brandList" />
|
|
|
+ <el-checkbox-group v-show="false" v-model="formData.shopInfo" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="微信公众号:" prop="wxAccountType">
|
|
|
<el-select v-model="formData.wxAccountType" placeholder="请选择微信公众号类型" clearable>
|
|
@@ -105,11 +106,14 @@ import UploadImage from '@/components/UploadImage'
|
|
|
import { BrandEditForm } from '@/views/components'
|
|
|
import { deepClone } from '@/utils'
|
|
|
import { isMobile } from '@/utils/validate'
|
|
|
+import { fetchCmSupplierList, createSupplier, getSupplierById } from '@/api/supplier'
|
|
|
+import { mapGetters } from 'vuex'
|
|
|
|
|
|
const generateBrandInfo = () => ({
|
|
|
+ infoId: '',
|
|
|
brandName: '',
|
|
|
- brandAuthLogo: '',
|
|
|
- country: '',
|
|
|
+ brandLogo: '',
|
|
|
+ producePlace: '',
|
|
|
manufacturer: ''
|
|
|
})
|
|
|
|
|
@@ -126,53 +130,125 @@ export default {
|
|
|
return callback()
|
|
|
}
|
|
|
return {
|
|
|
+ isLoading: false,
|
|
|
type: 'add',
|
|
|
brandEditVisible: false,
|
|
|
brandEditType: 'add',
|
|
|
brandEditIndex: 0,
|
|
|
formData: {
|
|
|
+ authUserId: '',
|
|
|
+ createBy: '',
|
|
|
shopName: '', // 供应商名称
|
|
|
shopType: '', // 供应商类型
|
|
|
mobile: '', // 手机号
|
|
|
linkMan: '', // 联系人
|
|
|
logo: '', // 代理商logo
|
|
|
- brandList: [],
|
|
|
+ shopInfo: [],
|
|
|
wxAccountType: '',
|
|
|
appId: '',
|
|
|
appSecret: '',
|
|
|
- shopStatus: 1 // 供应商状态,
|
|
|
+ shopStatus: 1, // 供应商状态,
|
|
|
+ cmShopId: ''
|
|
|
},
|
|
|
rules: {
|
|
|
shopName: [{ required: true, message: '请输入供应商名称', trigger: ['blur'] }],
|
|
|
shopType: [{ required: true, message: '请选择供应商类型', trigger: ['change'] }],
|
|
|
mobile: [
|
|
|
{ required: true, message: '请输入手机号', trigger: ['blur'] },
|
|
|
- { validator: validMobile, tigger: ['blur'] }
|
|
|
+ { validator: validMobile, trigger: ['blur'] }
|
|
|
],
|
|
|
linkMan: [{ required: true, message: '请输入联系人', trigger: ['blur'] }],
|
|
|
logo: [{ required: true, message: '请上传供应商logo', trigger: ['change'] }],
|
|
|
- brandList: [{ required: true, type: 'array', message: '请至少添加一个品牌', trigger: ['change'] }],
|
|
|
+ shopInfo: [{ required: true, type: 'array', message: '请至少添加一个品牌', trigger: ['change'] }],
|
|
|
shopStatus: [{ required: true, message: '请选择供应商状态', trigger: ['change'] }],
|
|
|
appId: [{ required: true, message: '请输入服务号appId', trigger: ['blur'] }],
|
|
|
appSecret: [{ required: true, message: '请输入服务号appSecret', trigger: ['blur'] }]
|
|
|
},
|
|
|
brandModel: generateBrandInfo(),
|
|
|
- logoImageList: []
|
|
|
+ logoImageList: [],
|
|
|
+ cmShopList: []
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ ...mapGetters(['authUserId'])
|
|
|
+ },
|
|
|
created() {
|
|
|
+ this.fetchCmSupplierList()
|
|
|
this.type = this.$route.query.type || 'add'
|
|
|
+ console.log(this.type)
|
|
|
if (this.type === 'edit') {
|
|
|
- this.initFormData()
|
|
|
+ this.fetchSupplierData()
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 获取采美供应商列表
|
|
|
+ async fetchCmSupplierList() {
|
|
|
+ try {
|
|
|
+ const res = await fetchCmSupplierList()
|
|
|
+ this.cmShopList = res.data
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取供应商信息
|
|
|
+ async fetchSupplierData() {
|
|
|
+ try {
|
|
|
+ this.isLoading = true
|
|
|
+ this.formData.authUserId = this.$route.query.id
|
|
|
+ const res = await getSupplierById({ authUserId: this.formData.authUserId })
|
|
|
+ this.initFormData(res.data)
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 初始化表单信息
|
|
|
- initFormData() {},
|
|
|
+ initFormData(data) {
|
|
|
+ for (const key in data) {
|
|
|
+ if (Object.hasOwnProperty.call(this.formData, key)) {
|
|
|
+ if (key === 'wxAccountType') {
|
|
|
+ this.formData[key] = data[key] === 0 ? '' : data[key]
|
|
|
+ } else if (key === 'cmShopId') {
|
|
|
+ this.formData[key] = data[key] ? data[key] : ''
|
|
|
+ } else {
|
|
|
+ this.formData[key] = data[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this.formData.logo) {
|
|
|
+ this.logoImageList = [{ url: this.formData.logo, name: '供应商logo' }]
|
|
|
+ }
|
|
|
+ this.$nextTick(() => (this.isLoading = false))
|
|
|
+ },
|
|
|
+
|
|
|
// 保存
|
|
|
- onSave() {
|
|
|
- console.log(this.formData)
|
|
|
+ async onSave() {
|
|
|
+ try {
|
|
|
+ this.isLoading = true
|
|
|
+ await createSupplier(this.formatSubmitData())
|
|
|
+ this.$message.success(`保存成功`)
|
|
|
+ this.$store.dispatch('tagsView/delView', this.$route)
|
|
|
+ this.$router.replace('/supplier/list')
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
+ } finally {
|
|
|
+ this.isLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 请求字段格式处理
|
|
|
+ formatSubmitData() {
|
|
|
+ const data = deepClone(this.formData)
|
|
|
+ if (data.wxAccountType === '') {
|
|
|
+ data.wxAccountType = 0
|
|
|
+ }
|
|
|
+ if (data.createBy === '') {
|
|
|
+ data.createBy = this.authUserId
|
|
|
+ }
|
|
|
+ return data
|
|
|
},
|
|
|
+
|
|
|
// 提交供应商信息
|
|
|
async onSubmit() {
|
|
|
try {
|
|
@@ -182,24 +258,28 @@ export default {
|
|
|
console.log(error)
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
// 品牌信息变化
|
|
|
onBrandFormChange(data) {
|
|
|
+ console.log(data)
|
|
|
this.brandModel = data
|
|
|
},
|
|
|
+
|
|
|
// 品牌信息确认
|
|
|
async onBrandSubmit() {
|
|
|
try {
|
|
|
await this.$refs.brandEditForm.validate()
|
|
|
if (this.brandEditType === 'add') {
|
|
|
- this.formData.brandList.push(deepClone(this.brandModel))
|
|
|
+ this.formData.shopInfo.push(deepClone(this.brandModel))
|
|
|
} else {
|
|
|
- this.formData.brandList.splice(this.brandEditIndex, 1, deepClone(this.brandModel))
|
|
|
+ this.formData.shopInfo.splice(this.brandEditIndex, 1, deepClone(this.brandModel))
|
|
|
}
|
|
|
this.brandEditVisible = false
|
|
|
} catch (error) {
|
|
|
console.log(error)
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
// 编辑品牌事件
|
|
|
onEditBrand(type, row, index) {
|
|
|
this.brandEditType = type
|
|
@@ -207,25 +287,30 @@ export default {
|
|
|
this.brandModel = type === 'add' ? generateBrandInfo() : row
|
|
|
this.brandEditVisible = true
|
|
|
},
|
|
|
+
|
|
|
// 品牌编辑取消
|
|
|
onEditBrandCancel() {
|
|
|
this.$refs.brandEditForm.clearValidate()
|
|
|
this.brandEditVisible = false
|
|
|
},
|
|
|
+
|
|
|
// 删除品牌
|
|
|
onRemoveBrand(index) {
|
|
|
- this.formData.brandList.splice(index, 1)
|
|
|
+ this.formData.shopInfo.splice(index, 1)
|
|
|
},
|
|
|
+
|
|
|
// 供应商logo上传成功
|
|
|
onUploadLogoSuccess({ response, file, fileList }) {
|
|
|
this.logoImageList = fileList
|
|
|
this.formData.logo = response.data
|
|
|
},
|
|
|
+
|
|
|
// 移除供应商logo
|
|
|
onRemoveLogoImage() {
|
|
|
this.logoImageList = []
|
|
|
this.formData.logo = ''
|
|
|
},
|
|
|
+
|
|
|
// 输入手机号时
|
|
|
onMobileInput() {
|
|
|
this.formData.mobile = this.formData.mobile.replace(/[^\w\.\/]/gi, '')
|