|
@@ -1,122 +1,71 @@
|
|
|
<template>
|
|
|
- <div v-loading="isLoading" class="addProduct page-form-container">
|
|
|
- <el-form ref="addFormRef" label-width="130px" class="addForm" :model="formData" :rules="rules">
|
|
|
- <el-form-item label="认证方式:">
|
|
|
- <el-radio-group v-model="formData.authType" @change="onAuthTypeChange">
|
|
|
- <el-radio :label="1">新设备认证</el-radio>
|
|
|
- <el-radio :label="2">关联已认证设备</el-radio>
|
|
|
- </el-radio-group>
|
|
|
+ <div class="device-edit page-form-container">
|
|
|
+ <el-form label-width="130px" :model="formData" :rules="rules">
|
|
|
+ <el-form-item label="认证方式:">
|
|
|
+ <span>{{ authTypeName }}</span>
|
|
|
</el-form-item>
|
|
|
-
|
|
|
- <template v-if="formData.authType === 1 || (formData.authType === 2 && formData.snCode)">
|
|
|
- <el-form-item label="设备名称:" prop="productTypeId">
|
|
|
- <el-select v-model="formData.productTypeId" filterable placeholder="选择设备" style="width: 100%" clearable>
|
|
|
- <el-option
|
|
|
- v-for="item in deviceList"
|
|
|
- :key="item.productTypeId"
|
|
|
- :label="item.name"
|
|
|
- :value="item.productTypeId"
|
|
|
- />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- </template>
|
|
|
-
|
|
|
- <el-form-item label="设备SN码:" prop="snCode">
|
|
|
- <template v-if="formData.authType === 1">
|
|
|
- <el-input v-model="formData.snCode" placeholder="请输入设备SN码" />
|
|
|
- </template>
|
|
|
- <template v-else>
|
|
|
- <el-select
|
|
|
- v-model="formData.snCode"
|
|
|
- filterable
|
|
|
- placeholder="请选择设备SN码"
|
|
|
- style="width: 100%"
|
|
|
- clearable
|
|
|
- @change="onSnCodeChange"
|
|
|
- >
|
|
|
- <el-option v-for="code in productSnList" :key="code" :label="code" :value="code" />
|
|
|
- </el-select>
|
|
|
- </template>
|
|
|
+ <el-form-item label="设备名称:" prop="productTypeId">
|
|
|
+ <el-select v-model="formData.productTypeId" style="width: 100%" clearable>
|
|
|
+ <el-option
|
|
|
+ v-for="item in productCateList"
|
|
|
+ :key="item.productTypeId"
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.productTypeId"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
-
|
|
|
- <template v-if="formData.authType === 1 || (formData.authType === 2 && formData.snCode)">
|
|
|
- <!-- **************** 新方法配置授权牌 START ******************* -->
|
|
|
- <el-form-item label="授权牌:">
|
|
|
- <el-radio-group v-model="formData.certificateImageType" size="mini" @change="onCertificateImageTypeChange">
|
|
|
- <el-radio :label="1" border>模板库生成</el-radio>
|
|
|
- <el-radio :label="2" border>自定义上传</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- <div style="margin-top: 12px">
|
|
|
- <template v-if="formData.certificateImageType === 2">
|
|
|
- <upload-image
|
|
|
- tip="建议尺寸:150px * 112px"
|
|
|
- :image-list="certificateImageList"
|
|
|
- :before-upload="beforeCertificateImageUpload"
|
|
|
- @success="uploadCertificateImageSuccess"
|
|
|
- @remove="handleCertificateImageRemove"
|
|
|
- />
|
|
|
- <el-input v-model="formData.certificateImage" class="hiddenInput" />
|
|
|
- </template>
|
|
|
- <template v-else>
|
|
|
- <preview-image v-if="formData.certificateImage" :src="formData.certificateImage" />
|
|
|
- </template>
|
|
|
+ <el-form-item label="设备SN码:" prop="snCode">
|
|
|
+ <el-input v-model="formData.snCode" placeholder="设备SN码" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="授权牌:" prop="certificateImageType">
|
|
|
+ <el-radio-group v-model="formData.certificateImageType" size="mini">
|
|
|
+ <el-radio :label="1">模板库生成</el-radio>
|
|
|
+ <el-radio :label="2">自定义上传</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ <template v-if="formData.certificateImageType === 1">
|
|
|
+ <div>
|
|
|
+ <preview-image v-if="formData.certificateImage" :src="formData.certificateImage" />
|
|
|
</div>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="购买渠道:" prop="purchaseWay">
|
|
|
- <el-input v-model="formData.purchaseWay" placeholder="请输入购买渠道" />
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="发票:" prop="invoiceImage">
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
<upload-image
|
|
|
- tip="建议图片分辨率:242px*242px"
|
|
|
- :limit="1"
|
|
|
- :image-list="invoiceImageList"
|
|
|
- :before-upload="beforeInvoiceImageUpload"
|
|
|
- @success="uploadInvoiceImageSuccess"
|
|
|
- @remove="handleInvoiceImageRemove"
|
|
|
+ tip="建议尺寸:150px * 112px"
|
|
|
+ :image-list="certificateImageList"
|
|
|
+ :before-upload="beforeCertificateImageUpload"
|
|
|
+ @success="uploadCertificateImageSuccess"
|
|
|
+ @remove="handleCertificateImageRemove"
|
|
|
/>
|
|
|
- <el-input v-show="false" v-model="formData.invoiceImage" />
|
|
|
- </el-form-item>
|
|
|
- </template>
|
|
|
+ </template>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="购买渠道:" prop="purchaseWay">
|
|
|
+ <el-input v-model="formData.purchaseWay" placeholder="购买渠道" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="发票:" prop="invoiceImage">
|
|
|
+ <upload-image
|
|
|
+ tip="建议图片分辨率:242px*242px"
|
|
|
+ :limit="1"
|
|
|
+ :image-list="invoiceImageList"
|
|
|
+ :before-upload="beforeInvoiceImageUpload"
|
|
|
+ @success="uploadInvoiceImageSuccess"
|
|
|
+ @remove="handleInvoiceImageRemove"
|
|
|
+ />
|
|
|
+ <el-input v-show="false" v-model="formData.invoiceImage" />
|
|
|
+ </el-form-item>
|
|
|
</el-form>
|
|
|
- <div class="submit-btn">
|
|
|
+
|
|
|
+ <!-- 表单提交 返回 -->
|
|
|
+ <div class="control-box">
|
|
|
<el-button type="primary" @click="submit">保存</el-button>
|
|
|
- <el-button type="warning" @click="navigateBack()">返回</el-button>
|
|
|
+ <el-button type="warning" @click="navigateBack">返回</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import UploadImage from '@/components/UploadImage'
|
|
|
-import {
|
|
|
- saveProduct,
|
|
|
- getProductById,
|
|
|
- fetchProductSelectList,
|
|
|
- fetchProductSnList,
|
|
|
- fetchDetialBySnCode
|
|
|
-} from '@/api/product'
|
|
|
-import { mapGetters } from 'vuex'
|
|
|
+import { fetchProductSelectList, getProductById } from '@/api/product'
|
|
|
import { isSnCode } from '@/utils/validate'
|
|
|
import { getStorage } from '@/utils/storage'
|
|
|
-import { deepClone } from '@/utils'
|
|
|
-
|
|
|
-const resetFormData = () => ({
|
|
|
- authId: '', // 授权id
|
|
|
- relationId: '',
|
|
|
- authType: 1,
|
|
|
- authUserId: '',
|
|
|
- createBy: '', // 创建人id
|
|
|
- certificateImage: '', // 授权牌照
|
|
|
- // 设备参数列表
|
|
|
- productId: '', // 授权设备id
|
|
|
- snCode: '', // 设备SN码
|
|
|
- certificateImageType: 1,
|
|
|
- productTypeId: '',
|
|
|
- purchaseWay: '', // 购买渠道
|
|
|
- invoiceImage: '' // 发票
|
|
|
-})
|
|
|
-
|
|
|
export default {
|
|
|
components: { UploadImage },
|
|
|
data() {
|
|
@@ -127,112 +76,51 @@ export default {
|
|
|
callback()
|
|
|
}
|
|
|
return {
|
|
|
- isLoading: false,
|
|
|
editType: 'add',
|
|
|
- paramsCount: 4,
|
|
|
- brandList: [],
|
|
|
- deviceList: [], // 设备列表
|
|
|
- firstAuthType: '',
|
|
|
- formData: resetFormData(),
|
|
|
+ isLoading: false,
|
|
|
+ formData: {
|
|
|
+ authId: '', // 授权id
|
|
|
+ relationId: '',
|
|
|
+ authType: 1, // 认证类型
|
|
|
+ authUserId: '',
|
|
|
+ certificateImage: '', // 授权牌照
|
|
|
+ // 设备参数
|
|
|
+ productId: '', // 授权设备id
|
|
|
+ snCode: '', // 设备SN码
|
|
|
+ certificateImageType: 1,
|
|
|
+ productTypeId: '',
|
|
|
+ purchaseWay: '', // 购买渠道
|
|
|
+ invoiceImage: '' // 发票
|
|
|
+ },
|
|
|
+ productCateList: [],
|
|
|
+ certificateImageList: [],
|
|
|
+ invoiceImageList: [],
|
|
|
rules: {
|
|
|
certificateImage: [{ required: true, message: '授权牌照不能为空', trigger: 'change' }],
|
|
|
snCode: [{ required: true, message: 'SN码不能为空' }, { validator: valideSNcode }],
|
|
|
productTypeId: [{ required: true, message: '设备名称不能为空', trigger: 'change' }]
|
|
|
- },
|
|
|
- // 授权牌照图片列表
|
|
|
- certificateImageList: [],
|
|
|
- // 发票
|
|
|
- invoiceImageList: [],
|
|
|
- // sn list
|
|
|
- productSnList: [],
|
|
|
- copyData: null
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(['authUserId', 'proxyInfo', 'shopType', 'infoId'])
|
|
|
+ authTypeName() {
|
|
|
+ return this.formData.authType === 1 ? '新设备认证' : '关联已认证设备'
|
|
|
+ }
|
|
|
},
|
|
|
created() {
|
|
|
- this.init()
|
|
|
+ this.editType = this.$route.query.type || 'add'
|
|
|
+ this.formData.relationId = this.$route.query.relationId
|
|
|
+ this.formData.productId = this.$route.query.id
|
|
|
+ // 获取当前设备所属机构的id
|
|
|
+ this.formData.authId = getStorage('device-setting-authId')
|
|
|
+ this.fetchProductCateList()
|
|
|
+ if (this.editType === 'edit') {
|
|
|
+ this.fetchProductDetail()
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
- init() {
|
|
|
- this.editType = this.$route.query.type || 'add'
|
|
|
- this.formData.relationId = this.$route.query.relationId
|
|
|
- this.formData.productId = this.$route.query.id
|
|
|
- // this.formData.authUserId = this.proxyInfo?.authUserId || this.authUserId
|
|
|
- // 获取当前设备所属机构的id
|
|
|
- this.formData.authId = getStorage('device-setting-authId')
|
|
|
- this.fetchDeviceList()
|
|
|
- this.fetchProductSnList()
|
|
|
- if (this.editType === 'edit') {
|
|
|
- this.fetchProductDetail()
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 授权牌类型变化
|
|
|
- onCertificateImageTypeChange(value) {
|
|
|
- this.certificateImageList = []
|
|
|
- this.formData.certificateImage = ''
|
|
|
- this.$refs.addFormRef.clearValidate('certificateImage')
|
|
|
- },
|
|
|
-
|
|
|
- // 设备sn码变化
|
|
|
- async onSnCodeChange(snCode) {
|
|
|
- if (!snCode) return
|
|
|
- try {
|
|
|
- const res = await fetchDetialBySnCode({ snCode })
|
|
|
- this.formData.invoiceImage = res.data.invoiceImage
|
|
|
- this.formData.purchaseWay = res.data.purchaseWay
|
|
|
- this.formData.certificateImage = res.data.certificateImage
|
|
|
- this.formData.certificateImageType = res.data.certificateImageType
|
|
|
- this.formData.productTypeId = res.data.productTypeId
|
|
|
- // this.formData.productId = res.data.productId
|
|
|
- if (res.data.invoiceImage) {
|
|
|
- this.invoiceImageList = [{ name: '发票', url: res.data.invoiceImage }]
|
|
|
- }
|
|
|
- if (res.data.certificateImage) {
|
|
|
- this.certificateImageList = [{ name: '授权牌图片', url: res.data.certificateImage }]
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 设备认证类型变化
|
|
|
- onAuthTypeChange(authType) {
|
|
|
- // 拷贝数据
|
|
|
- const copyData = deepClone({
|
|
|
- certificateImageList: this.certificateImageList,
|
|
|
- invoiceImageList: this.invoiceImageList,
|
|
|
- // productSnList: this.productSnList,
|
|
|
- formData: this.formData
|
|
|
- })
|
|
|
-
|
|
|
- this.certificateImageList = []
|
|
|
- this.invoiceImageList = []
|
|
|
- // this.productSnList = []
|
|
|
- this.$refs.addFormRef.resetFields()
|
|
|
-
|
|
|
- if (this.copyData) {
|
|
|
- const { certificateImageList, invoiceImageList, formData } = this.copyData
|
|
|
- this.certificateImageList = certificateImageList
|
|
|
- this.invoiceImageList = invoiceImageList
|
|
|
- // this.productSnList = productSnList
|
|
|
- this.formData = formData
|
|
|
- }
|
|
|
- this.copyData = copyData
|
|
|
- this.formData.authType = authType
|
|
|
- },
|
|
|
-
|
|
|
- // 获取设备sn码列表
|
|
|
- async fetchProductSnList() {
|
|
|
- try {
|
|
|
- const res = await fetchProductSnList({ authId: this.formData.authId })
|
|
|
- this.productSnList = res.data
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
- },
|
|
|
+ // 提交
|
|
|
+ submit() {},
|
|
|
|
|
|
// 获取设备信息
|
|
|
async fetchProductDetail() {
|
|
@@ -263,55 +151,14 @@ export default {
|
|
|
if (data.certificateImage) {
|
|
|
this.certificateImageList = [{ name: '授权牌图片', url: data.certificateImage }]
|
|
|
}
|
|
|
- this.firstAuthType = data.authType
|
|
|
this.isLoading = false
|
|
|
},
|
|
|
|
|
|
- // 提交表单
|
|
|
- async submit() {
|
|
|
+ // 获取设备分类列表
|
|
|
+ async fetchProductCateList() {
|
|
|
try {
|
|
|
- await this.$refs.addFormRef.validate()
|
|
|
- this.onSave()
|
|
|
- } catch (error) {
|
|
|
- console.log(error)
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 保存表单数据
|
|
|
- onSave() {
|
|
|
- this.isLoading = true
|
|
|
- // createBy先判断是否为代理操作,是就从代理数据中获取,否则直接获取当前登录用户的信息
|
|
|
- this.formData.createBy = this.proxyInfo?.authUserId || this.authUserId
|
|
|
-
|
|
|
- if (this.firstAuthType === 2 && this.formData.authType === 1) {
|
|
|
- this.formData.productId = ''
|
|
|
- }
|
|
|
-
|
|
|
- saveProduct(this.formData)
|
|
|
- .then((res) => {
|
|
|
- if (res.code !== 0) return
|
|
|
- const h = this.$createElement
|
|
|
- const tip = this.editType === 'add' ? '添加' : '修改'
|
|
|
- this.$notify.success({
|
|
|
- title: tip + '设备',
|
|
|
- message: h('i', { style: 'color: #333' }, `已${tip}设备`),
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
- this.$store.dispatch('tagsView/delView', this.$route)
|
|
|
- this.$router.push(`/club/device-list?id=${this.formData.authId}`)
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- this.isLoading = false
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- // 获取设备列表
|
|
|
- async fetchDeviceList() {
|
|
|
- try {
|
|
|
- const res = await fetchProductSelectList({
|
|
|
- authUserId: this.authUserId
|
|
|
- })
|
|
|
- this.deviceList = res.data
|
|
|
+ const res = await fetchProductSelectList({ authUserId: this.authUserId })
|
|
|
+ this.productCateList = res.data
|
|
|
} catch (error) {
|
|
|
console.log(error)
|
|
|
}
|
|
@@ -354,42 +201,4 @@ export default {
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style lang="scss" scoped>
|
|
|
-.addProduct {
|
|
|
- .form-group {
|
|
|
- margin-bottom: 2%;
|
|
|
- .param-title {
|
|
|
- width: 30%;
|
|
|
- }
|
|
|
- .param-info {
|
|
|
- width: 68%;
|
|
|
- margin-left: 2%;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-.submit-btn {
|
|
|
- text-align: center;
|
|
|
- .el-button {
|
|
|
- width: 140px;
|
|
|
- }
|
|
|
-}
|
|
|
-.paramsItem {
|
|
|
- position: relative;
|
|
|
- .closed {
|
|
|
- position: absolute;
|
|
|
- top: 50%;
|
|
|
- transform: translateY(-50%);
|
|
|
- right: -20px;
|
|
|
- cursor: pointer;
|
|
|
- color: #ddd;
|
|
|
- &:hover {
|
|
|
- color: #333;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-.hiddenInput {
|
|
|
- height: 0;
|
|
|
- display: none;
|
|
|
-}
|
|
|
-</style>
|
|
|
+<style lang="scss" scoped></style>
|