|
@@ -10,6 +10,17 @@
|
|
|
<el-form-item label="商品名称:" prop="productName">
|
|
|
<el-input v-model="formData.productName" placeholder="请输入商品名称" />
|
|
|
</el-form-item>
|
|
|
+ <el-form-item v-if="shopType === 2" label="所属品牌:" prop="brandId">
|
|
|
+ <el-select
|
|
|
+ v-model="formData.brandId"
|
|
|
+ placeholder="请选择品牌"
|
|
|
+ style="width: 100%"
|
|
|
+ filterable
|
|
|
+ @change="handleChange"
|
|
|
+ >
|
|
|
+ <el-option v-for="item in brandList" :key="item.id" :label="item.name" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="商品SN码:" prop="snCode">
|
|
|
<el-input v-model="formData.snCode" placeholder="请输入商品SN码" />
|
|
|
</el-form-item>
|
|
@@ -68,6 +79,7 @@
|
|
|
<script>
|
|
|
import UploadImage from '../components/uploadImage'
|
|
|
import { saveProduct } from '@/api/product'
|
|
|
+import { fetchBrandList } from '@/api/brand'
|
|
|
import { mapGetters } from 'vuex'
|
|
|
import { isSnCode } from '@/utils/validate'
|
|
|
export default {
|
|
@@ -79,10 +91,18 @@ export default {
|
|
|
}
|
|
|
callback()
|
|
|
}
|
|
|
+ const valideBrandId = (rules, value, callback) => {
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('所属品牌不能为空'))
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ }
|
|
|
return {
|
|
|
isLoading: false,
|
|
|
paramsCount: 4,
|
|
|
+ brandList: [],
|
|
|
formData: {
|
|
|
+ authUserId: '',
|
|
|
authId: '', // 授权id
|
|
|
certificateImage: '', // 授权牌照
|
|
|
createBy: '', // 创建人id
|
|
@@ -92,25 +112,34 @@ export default {
|
|
|
productImage: '', // 商品图片
|
|
|
productName: '', // 商品名称
|
|
|
snCode: '', // 商品SN码
|
|
|
- status: 1 // 上架状态:0下架,1上架
|
|
|
+ status: 1, // 上架状态:0下架,1上架
|
|
|
+ brandId: ''
|
|
|
},
|
|
|
rules: {
|
|
|
certificateImage: [{ required: true, message: '授权牌照不能为空' }],
|
|
|
paramList: [{ required: true, message: '参数不能为空' }],
|
|
|
productImage: [{ required: true, message: '商品图片不能为空' }],
|
|
|
snCode: [{ required: true, message: 'SN码不能为空' }, { validator: valideSNcode }],
|
|
|
- productName: [{ required: true, message: '商品名称不能为空' }, { max: 50, message: '字数在50字符以内' }]
|
|
|
+ productName: [{ required: true, message: '商品名称不能为空' }, { max: 50, message: '字数在50字符以内' }],
|
|
|
+ brandId: [{ required: true, validator: valideBrandId, tigger: 'change' }]
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(['authUserId', 'proxyInfo'])
|
|
|
+ ...mapGetters(['authUserId', 'proxyInfo', 'shopType'])
|
|
|
},
|
|
|
created() {
|
|
|
this.formData.authId = this.$route.query.id
|
|
|
+ this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
|
this.initParamList()
|
|
|
+ if (this.shopType === 2) {
|
|
|
+ this.getBrandList()
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
+ handleChange() {
|
|
|
+ console.log(this.formData)
|
|
|
+ },
|
|
|
// 提交
|
|
|
submit() {
|
|
|
this.$refs.addFormRef.validate(valide => {
|
|
@@ -124,10 +153,12 @@ export default {
|
|
|
this.isLoading = true
|
|
|
// createBy先判断是否为代理操作,是就从代理数据中获取,否则直接获取当前登录用户的信息
|
|
|
this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
|
|
|
+ this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
|
saveProduct(this.formData).then(res => {
|
|
|
this.$message.success(res.data)
|
|
|
this.$refs.addFormRef.resetFields()
|
|
|
this.clearFormData()
|
|
|
+ this.$router.replace(`/product/list?id=${this.formData.authId}`)
|
|
|
}).finally(() => {
|
|
|
this.isLoading = false
|
|
|
})
|
|
@@ -141,6 +172,14 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ // 获取品牌信息
|
|
|
+ getBrandList() {
|
|
|
+ fetchBrandList({ type: 3, authUserId: this.formData.authUserId }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+
|
|
|
+ this.brandList = res.data
|
|
|
+ })
|
|
|
+ },
|
|
|
// 添加一栏参数
|
|
|
handleAddParam() {
|
|
|
this.paramsCount += 1
|