|
@@ -1,5 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div v-loading="isLoading" class="addProduct">
|
|
|
|
|
|
+ <div v-loading="isLoading" class="addProduct page-form-container">
|
|
<el-form ref="addFormRef" label-width="130px" class="addForm" :model="formData" :rules="rules">
|
|
<el-form ref="addFormRef" label-width="130px" class="addForm" :model="formData" :rules="rules">
|
|
<!--
|
|
<!--
|
|
<el-form-item label="设备名称:" prop="productName">
|
|
<el-form-item label="设备名称:" prop="productName">
|
|
@@ -28,24 +28,6 @@
|
|
<el-input v-model="formData.snCode" placeholder="请输入设备SN码" />
|
|
<el-input v-model="formData.snCode" placeholder="请输入设备SN码" />
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
|
|
|
- <el-form-item v-if="shopType === 2" label="所属品牌:" prop="brandId">
|
|
|
|
- <el-select v-model="formData.brandId" placeholder="请选择品牌" style="width: 100%" filterable>
|
|
|
|
- <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="设备图片:" prop="productImage">
|
|
|
|
- <upload-image
|
|
|
|
- tip="建议尺寸:542px * 542px"
|
|
|
|
- :image-list="productImageList"
|
|
|
|
- :before-upload="beforeProductImageUpload"
|
|
|
|
- @success="uploadProductImageSuccess"
|
|
|
|
- @remove="handleProductImageRemove"
|
|
|
|
- />
|
|
|
|
- <el-input v-model="formData.productImage" class="hiddenInput" />
|
|
|
|
- </el-form-item>
|
|
|
|
- -->
|
|
|
|
-
|
|
|
|
<!-- **************** 新方法配置授权牌 START ******************* -->
|
|
<!-- **************** 新方法配置授权牌 START ******************* -->
|
|
<!-- <el-form-item label="授权牌:">
|
|
<!-- <el-form-item label="授权牌:">
|
|
<el-radio-group v-model="formData.addQrCodeFlag" size="mini">
|
|
<el-radio-group v-model="formData.addQrCodeFlag" size="mini">
|
|
@@ -83,16 +65,16 @@
|
|
<el-input v-model="formData.certificateImage" class="hiddenInput" />
|
|
<el-input v-model="formData.certificateImage" class="hiddenInput" />
|
|
</el-form-item>
|
|
</el-form-item>
|
|
<!-- 是否生成二维码授权牌 -->
|
|
<!-- 是否生成二维码授权牌 -->
|
|
- <el-form-item label="生成二维码授权牌:">
|
|
|
|
|
|
+ <!-- <el-form-item label="生成二维码授权牌:">
|
|
<el-radio-group v-model="formData.addQrCodeFlag" size="mini">
|
|
<el-radio-group v-model="formData.addQrCodeFlag" size="mini">
|
|
<el-radio :label="0" border>否</el-radio>
|
|
<el-radio :label="0" border>否</el-radio>
|
|
<el-radio :label="1" border :disabled="certificateImageList.length <= 0">是</el-radio>
|
|
<el-radio :label="1" border :disabled="certificateImageList.length <= 0">是</el-radio>
|
|
</el-radio-group>
|
|
</el-radio-group>
|
|
- </el-form-item>
|
|
|
|
|
|
+ </el-form-item> -->
|
|
<!-- 二维码授权牌模板 -->
|
|
<!-- 二维码授权牌模板 -->
|
|
- <el-form-item v-if="formData.addQrCodeFlag === 1" label="选择模板:">
|
|
|
|
|
|
+ <!-- <el-form-item v-if="formData.addQrCodeFlag === 1" label="选择模板:">
|
|
<auth-card-template v-model="formData.addTemplateType" :image-list="certificateImageList" />
|
|
<auth-card-template v-model="formData.addTemplateType" :image-list="certificateImageList" />
|
|
- </el-form-item>
|
|
|
|
|
|
+ </el-form-item> -->
|
|
<!-- **************** 旧方法配置授权牌 END ******************* -->
|
|
<!-- **************** 旧方法配置授权牌 END ******************* -->
|
|
|
|
|
|
<el-form-item label="购买渠道:">
|
|
<el-form-item label="购买渠道:">
|
|
@@ -110,15 +92,6 @@
|
|
/>
|
|
/>
|
|
<el-input v-show="false" v-model="formData.invoiceImage" />
|
|
<el-input v-show="false" v-model="formData.invoiceImage" />
|
|
</el-form-item>
|
|
</el-form-item>
|
|
-
|
|
|
|
- <el-form-item label="相关参数:" prop="paramList">
|
|
|
|
- <div v-for="(item, index) in paramList" :key="index" class="form-group paramsItem">
|
|
|
|
- <el-input v-model="item.paramName" class="param-title" :placeholder="item.tip.first" maxlength="10" />
|
|
|
|
- <el-input v-model="item.paramContent" class="param-info" placeholder="请输入参数信息" maxlength="50" />
|
|
|
|
- <span v-if="paramsCount > 4" class="closed el-icon-close" @click="handleRemoveParam(index)" />
|
|
|
|
- </div>
|
|
|
|
- <el-button type="primary" size="mini" @click="handleAddParam">添加参数</el-button>
|
|
|
|
- </el-form-item>
|
|
|
|
</el-form>
|
|
</el-form>
|
|
<div class="submit-btn">
|
|
<div class="submit-btn">
|
|
<el-button type="primary" @click="submit">保存</el-button>
|
|
<el-button type="primary" @click="submit">保存</el-button>
|
|
@@ -130,13 +103,12 @@
|
|
<script>
|
|
<script>
|
|
import UploadImage from '@/components/UploadImage'
|
|
import UploadImage from '@/components/UploadImage'
|
|
import { saveProduct, getProductById, fetchProductSelectList } from '@/api/product'
|
|
import { saveProduct, getProductById, fetchProductSelectList } from '@/api/product'
|
|
-import { fetchBrandList } from '@/api/brand'
|
|
|
|
import { mapGetters } from 'vuex'
|
|
import { mapGetters } from 'vuex'
|
|
import { isSnCode } from '@/utils/validate'
|
|
import { isSnCode } from '@/utils/validate'
|
|
-import AuthCardTemplate from '@/views/components/AuthCardTemplate/index.vue'
|
|
|
|
|
|
+// import AuthCardTemplate from '@/views/components/AuthCardTemplate/index.vue'
|
|
import { getStorage } from '@/utils/storage'
|
|
import { getStorage } from '@/utils/storage'
|
|
export default {
|
|
export default {
|
|
- components: { UploadImage, AuthCardTemplate },
|
|
|
|
|
|
+ components: { UploadImage },
|
|
data() {
|
|
data() {
|
|
const valideSNcode = (rules, value, callback) => {
|
|
const valideSNcode = (rules, value, callback) => {
|
|
if (!isSnCode(value)) {
|
|
if (!isSnCode(value)) {
|
|
@@ -144,26 +116,6 @@ export default {
|
|
}
|
|
}
|
|
callback()
|
|
callback()
|
|
}
|
|
}
|
|
-
|
|
|
|
- const valideBrandId = (rules, value, callback) => {
|
|
|
|
- if (!value) {
|
|
|
|
- return callback(new Error('所属品牌不能为空'))
|
|
|
|
- }
|
|
|
|
- callback()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const paramListValidate = (rules, value, callback) => {
|
|
|
|
- value.every((item) => item.paramName && item.paramContent)
|
|
|
|
- const notEmptyList = value.filter((item) => item.paramName.trim() && item.paramContent.trim())
|
|
|
|
- if (notEmptyList.length === 0) {
|
|
|
|
- callback(new Error('参数列表不能为空'))
|
|
|
|
- } else if (notEmptyList.length < 4) {
|
|
|
|
- callback(new Error('请填写至少4项参数'))
|
|
|
|
- } else {
|
|
|
|
- callback()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return {
|
|
return {
|
|
isLoading: false,
|
|
isLoading: false,
|
|
editType: 'add',
|
|
editType: 'add',
|
|
@@ -176,10 +128,8 @@ export default {
|
|
certificateImage: '', // 授权牌照
|
|
certificateImage: '', // 授权牌照
|
|
createBy: '', // 创建人id
|
|
createBy: '', // 创建人id
|
|
// 设备参数列表
|
|
// 设备参数列表
|
|
- paramList: [],
|
|
|
|
productId: '', // 授权设备id
|
|
productId: '', // 授权设备id
|
|
productImage: '', // 设备图片
|
|
productImage: '', // 设备图片
|
|
- // productName: '', // 设备名称
|
|
|
|
snCode: '', // 设备SN码
|
|
snCode: '', // 设备SN码
|
|
status: 2, // 上架状态:0下线,1上线 2待审核
|
|
status: 2, // 上架状态:0下线,1上线 2待审核
|
|
brandId: '',
|
|
brandId: '',
|
|
@@ -189,21 +139,11 @@ export default {
|
|
purchaseWay: '', // 购买渠道
|
|
purchaseWay: '', // 购买渠道
|
|
invoiceImage: '' // 发票
|
|
invoiceImage: '' // 发票
|
|
},
|
|
},
|
|
- paramList: [], // 参数列表
|
|
|
|
rules: {
|
|
rules: {
|
|
certificateImage: [{ required: true, message: '授权牌照不能为空' }],
|
|
certificateImage: [{ required: true, message: '授权牌照不能为空' }],
|
|
- paramList: [{ validator: paramListValidate, trigger: 'change' }],
|
|
|
|
- // productImage: [{ required: true, message: '设备图片不能为空' }], 暂时移除
|
|
|
|
snCode: [{ required: true, message: 'SN码不能为空' }, { validator: valideSNcode }],
|
|
snCode: [{ required: true, message: 'SN码不能为空' }, { validator: valideSNcode }],
|
|
- // productName: [
|
|
|
|
- // { required: true, message: '设备名称不能为空' },
|
|
|
|
- // { max: 50, message: '字数在50字符以内' }
|
|
|
|
- // ],
|
|
|
|
- productTypeId: [{ required: true, message: '设备名称不能为空', trigger: 'change' }],
|
|
|
|
- brandId: [{ required: true, validator: valideBrandId, trigger: 'change' }]
|
|
|
|
|
|
+ productTypeId: [{ required: true, message: '设备名称不能为空', trigger: 'change' }]
|
|
},
|
|
},
|
|
- // 参数框的提示语
|
|
|
|
- tipList: ['例如:品牌', '例如:尺寸', '例如:功率', '例如:重量'],
|
|
|
|
|
|
|
|
// 商品图片列表
|
|
// 商品图片列表
|
|
productImageList: [],
|
|
productImageList: [],
|
|
@@ -216,24 +156,14 @@ export default {
|
|
computed: {
|
|
computed: {
|
|
...mapGetters(['authUserId', 'proxyInfo', 'shopType', 'brandId'])
|
|
...mapGetters(['authUserId', 'proxyInfo', 'shopType', 'brandId'])
|
|
},
|
|
},
|
|
- watch: {
|
|
|
|
- paramList: {
|
|
|
|
- deep: true,
|
|
|
|
- handler: function() {
|
|
|
|
- this.formData.paramList = this.setParamToFormData()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
created() {
|
|
created() {
|
|
this.editType = this.$route.query.type || 'add'
|
|
this.editType = this.$route.query.type || 'add'
|
|
this.formData.productId = this.$route.query.id
|
|
this.formData.productId = this.$route.query.id
|
|
this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
// 获取当前设备所属机构的id
|
|
// 获取当前设备所属机构的id
|
|
this.formData.authId = getStorage('device-setting-authId')
|
|
this.formData.authId = getStorage('device-setting-authId')
|
|
- this.initFormData()
|
|
|
|
- // 如果供应商类型为代理商 则需要获取它代理的品牌列表
|
|
|
|
- if (this.shopType === 2) {
|
|
|
|
- this.getBrandList()
|
|
|
|
|
|
+ if (this.editType === 'edit') {
|
|
|
|
+ this.initFormData()
|
|
}
|
|
}
|
|
// 如果供应商类型为品牌方,则自动设置品牌id
|
|
// 如果供应商类型为品牌方,则自动设置品牌id
|
|
if (this.shopType === 1) {
|
|
if (this.shopType === 1) {
|
|
@@ -249,68 +179,32 @@ export default {
|
|
},
|
|
},
|
|
// 初始化表单数据
|
|
// 初始化表单数据
|
|
initFormData() {
|
|
initFormData() {
|
|
- if (this.editType !== 'edit') {
|
|
|
|
- this.initParamList()
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
this.isLoading = true
|
|
this.isLoading = true
|
|
getProductById({ productId: this.formData.productId }).then((res) => {
|
|
getProductById({ productId: this.formData.productId }).then((res) => {
|
|
console.log(res)
|
|
console.log(res)
|
|
for (const key in res.data) {
|
|
for (const key in res.data) {
|
|
if (Object.hasOwnProperty.call(res.data, key)) {
|
|
if (Object.hasOwnProperty.call(res.data, key)) {
|
|
- if (key !== 'paramList') {
|
|
|
|
- this.formData[key] = res.data[key]
|
|
|
|
- }
|
|
|
|
if (key === 'productTypeId') {
|
|
if (key === 'productTypeId') {
|
|
this.formData[key] = parseInt(res.data[key])
|
|
this.formData[key] = parseInt(res.data[key])
|
|
|
|
+ } else {
|
|
|
|
+ this.formData[key] = res.data[key]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // 初始化参数
|
|
|
|
- this.paramList = res.data.paramList.map((param) => {
|
|
|
|
- param.tip = {}
|
|
|
|
- param.tip.first = '参数名'
|
|
|
|
- param.tip.second = '请输入参数信息'
|
|
|
|
- return param
|
|
|
|
- })
|
|
|
|
- console.log(this.paramList)
|
|
|
|
- this.paramsCount = this.paramList.length
|
|
|
|
- if (this.paramsCount < 4) {
|
|
|
|
- this.initParamList(4 - this.paramsCount)
|
|
|
|
- }
|
|
|
|
this.initImageList()
|
|
this.initImageList()
|
|
|
|
|
|
- this.invoiceImageList = [{ name: '', url: res.data.invoiceImage }]
|
|
|
|
|
|
+ if (res.data.invoiceImage) {
|
|
|
|
+ this.invoiceImageList = [{ name: '', url: res.data.invoiceImage }]
|
|
|
|
+ }
|
|
|
|
|
|
this.isLoading = false
|
|
this.isLoading = false
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
- // 初始化参数列表
|
|
|
|
- initParamList(count) {
|
|
|
|
- if (this.editType === 'add') {
|
|
|
|
- count = this.paramsCount
|
|
|
|
- }
|
|
|
|
- for (let i = 0; i < count; i++) {
|
|
|
|
- this.paramList.push({
|
|
|
|
- paramContent: '',
|
|
|
|
- paramName: '',
|
|
|
|
- tip: {
|
|
|
|
- first: this.tipList[i],
|
|
|
|
- second: '请输入参数信息'
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
// 初始化上传图片列表
|
|
// 初始化上传图片列表
|
|
initImageList() {
|
|
initImageList() {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- // const productImage = this.formData.productImage // 暂时移除
|
|
|
|
const certificateImage = this.formData.certificateImage
|
|
const certificateImage = this.formData.certificateImage
|
|
- // if (productImage) { // 暂时移除
|
|
|
|
- // this.productImageList.push({ name: 'productImage', url: productImage })
|
|
|
|
- // }
|
|
|
|
if (certificateImage) {
|
|
if (certificateImage) {
|
|
this.certificateImageList.push({ name: 'certificateImage', url: certificateImage })
|
|
this.certificateImageList.push({ name: 'certificateImage', url: certificateImage })
|
|
}
|
|
}
|
|
@@ -325,7 +219,6 @@ export default {
|
|
|
|
|
|
// 提交表单
|
|
// 提交表单
|
|
submit() {
|
|
submit() {
|
|
- this.formData.paramList = this.setParamToFormData()
|
|
|
|
this.$refs.addFormRef.validate((valide) => {
|
|
this.$refs.addFormRef.validate((valide) => {
|
|
if (valide) {
|
|
if (valide) {
|
|
this.save()
|
|
this.save()
|
|
@@ -339,6 +232,7 @@ export default {
|
|
// createBy先判断是否为代理操作,是就从代理数据中获取,否则直接获取当前登录用户的信息
|
|
// createBy先判断是否为代理操作,是就从代理数据中获取,否则直接获取当前登录用户的信息
|
|
this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
|
|
this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
|
|
this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
|
|
+ this.formData.addQrCodeFlag = 0
|
|
saveProduct(this.formData)
|
|
saveProduct(this.formData)
|
|
.then((res) => {
|
|
.then((res) => {
|
|
if (res.code !== 0) return
|
|
if (res.code !== 0) return
|
|
@@ -349,8 +243,6 @@ export default {
|
|
message: h('i', { style: 'color: #333' }, `已${tip}设备`),
|
|
message: h('i', { style: 'color: #333' }, `已${tip}设备`),
|
|
duration: 2000
|
|
duration: 2000
|
|
})
|
|
})
|
|
- this.$refs.addFormRef.resetFields()
|
|
|
|
- this.clearFormData()
|
|
|
|
this.$store.dispatch('tagsView/delView', this.$route)
|
|
this.$store.dispatch('tagsView/delView', this.$route)
|
|
this.$router.push(`/club/device-list?id=${this.formData.authId}`)
|
|
this.$router.push(`/club/device-list?id=${this.formData.authId}`)
|
|
})
|
|
})
|
|
@@ -359,19 +251,6 @@ export default {
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
- // 保存参数到formdata
|
|
|
|
- setParamToFormData() {
|
|
|
|
- return this.paramList.filter((item) => item.paramContent !== '' && item.paramName !== '')
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 获取品牌信息
|
|
|
|
- getBrandList() {
|
|
|
|
- fetchBrandList({ type: 3, authUserId: this.formData.authUserId }).then((res) => {
|
|
|
|
- console.log(res)
|
|
|
|
- this.brandList = res.data
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
// 获取设备列表
|
|
// 获取设备列表
|
|
async fetchDeviceList() {
|
|
async fetchDeviceList() {
|
|
try {
|
|
try {
|
|
@@ -384,25 +263,6 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
- // 添加一栏参数
|
|
|
|
- handleAddParam() {
|
|
|
|
- this.paramsCount += 1
|
|
|
|
- this.paramList.push({
|
|
|
|
- paramContent: '',
|
|
|
|
- paramName: '',
|
|
|
|
- tip: {
|
|
|
|
- first: '参数名称',
|
|
|
|
- second: '请输入参数信息'
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 删除一栏参数
|
|
|
|
- handleRemoveParam(index) {
|
|
|
|
- this.paramsCount -= 1
|
|
|
|
- this.paramList.splice(index, 1)
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
// 产品图片上传
|
|
// 产品图片上传
|
|
beforeProductImageUpload(file) {
|
|
beforeProductImageUpload(file) {
|
|
const flag = file.size / 1024 / 1024 < 1
|
|
const flag = file.size / 1024 / 1024 < 1
|
|
@@ -453,13 +313,6 @@ export default {
|
|
handleInvoiceImageRemove({ file, fileList }) {
|
|
handleInvoiceImageRemove({ file, fileList }) {
|
|
this.invoiceImageList = fileList
|
|
this.invoiceImageList = fileList
|
|
this.formData.invoiceImage = ''
|
|
this.formData.invoiceImage = ''
|
|
- },
|
|
|
|
-
|
|
|
|
- // 清除表单数据
|
|
|
|
- clearFormData() {
|
|
|
|
- this.paramList = []
|
|
|
|
- this.paramsCount = 4
|
|
|
|
- this.initParamList()
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -467,7 +320,6 @@ export default {
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
.addProduct {
|
|
.addProduct {
|
|
- margin-bottom: 80px;
|
|
|
|
.form-group {
|
|
.form-group {
|
|
margin-bottom: 2%;
|
|
margin-bottom: 2%;
|
|
.param-title {
|
|
.param-title {
|
|
@@ -479,11 +331,7 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-.addForm {
|
|
|
|
- width: 640px;
|
|
|
|
- margin: 0 auto;
|
|
|
|
- margin-top: 80px;
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
.submit-btn {
|
|
.submit-btn {
|
|
text-align: center;
|
|
text-align: center;
|
|
.el-button {
|
|
.el-button {
|