|
@@ -0,0 +1,435 @@
|
|
|
|
+<template>
|
|
|
|
+ <div class="device-edit page-form-container">
|
|
|
|
+ <el-form ref="form" label-width="100px" :model="formData" :rules="rules">
|
|
|
|
+ <el-tabs v-model="activeName">
|
|
|
|
+ <!-- 基础资料 -->
|
|
|
|
+ <el-tab-pane label="基础资料" name="first">
|
|
|
|
+ <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>
|
|
|
|
+ <el-form-item label="设备SN码:" prop="snCode">
|
|
|
|
+ <el-input v-model="formData.snCode" placeholder="设备SN码" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="购买渠道:" prop="purchaseWay">
|
|
|
|
+ <el-input v-model="formData.purchaseWay" placeholder="购买渠道" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="发票:">
|
|
|
|
+ <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-item label="认证方式:">
|
|
|
|
+ <span>{{ authTypeName }}</span>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-tab-pane>
|
|
|
|
+ <!-- 授权牌资料 -->
|
|
|
|
+ <el-tab-pane label="授权牌资料" name="second">
|
|
|
|
+ <el-form-item label="授权牌:" prop="certificateImageType">
|
|
|
|
+ <el-radio-group v-model="formData.certificateImageType" size="mini">
|
|
|
|
+ <el-radio :label="0">暂不需要</el-radio>
|
|
|
|
+ <el-radio :label="1">模板库生成</el-radio>
|
|
|
|
+ <el-radio :label="2">自定义上传</el-radio>
|
|
|
|
+ </el-radio-group>
|
|
|
|
+ <template v-if="formData.certificateImageType === 1">
|
|
|
|
+ <div v-if="authTempFlag">
|
|
|
|
+ <preview-image v-if="formData.certificateImage" :src="formData.certificateImage" />
|
|
|
|
+ </div>
|
|
|
|
+ <div v-else>无</div>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-if="formData.certificateImageType === 2">
|
|
|
|
+ <upload-image
|
|
|
|
+ tip="建议尺寸:150px * 112px"
|
|
|
|
+ :image-list="certificateImageList"
|
|
|
|
+ :before-upload="beforeCertificateImageUpload"
|
|
|
|
+ @success="uploadCertificateImageSuccess"
|
|
|
|
+ @remove="handleCertificateImageRemove"
|
|
|
|
+ />
|
|
|
|
+ </template>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item v-if="authTempFlag && formData.certificateImageType === 1" label="授权牌logo:" prop="authImageLogo">
|
|
|
|
+ <div class="form-label-tip">授权牌logo(提示:授权牌logo与机构名称组合)</div>
|
|
|
|
+ <div style="margin-top: 8px">
|
|
|
|
+ <upload-image
|
|
|
|
+ :tip="authImageLogoUploadTip"
|
|
|
|
+ :image-list="authImageLogoList"
|
|
|
|
+ :before-upload="beforeAuthImageLogoUpload"
|
|
|
|
+ @success="uploadAuthImageLogoSuccess"
|
|
|
|
+ @remove="handleAuthImageLogoRemove"
|
|
|
|
+ />
|
|
|
|
+ <el-input v-show="false" v-model="formData.authImageLogo" />
|
|
|
|
+ </div>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item v-if="formData.certificateImageType === 1" label="认证日期:" prop="authDate">
|
|
|
|
+ <el-date-picker v-model="formData.authDate" type="date" placeholder="选择日期" style="width: 100%" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+
|
|
|
|
+ </el-tab-pane>
|
|
|
|
+ </el-tabs>
|
|
|
|
+
|
|
|
|
+ <!-- 表单提交 返回 -->
|
|
|
|
+ <div class="control-box">
|
|
|
|
+ <el-button type="primary" @click="submit">保存</el-button>
|
|
|
|
+ <el-button type="warning" @click="navigateBack">返回</el-button>
|
|
|
|
+ </div>
|
|
|
|
+ </el-form>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import UploadImage from '@/components/UploadImage'
|
|
|
|
+import { fetchProductSelectList, getProductById, saveProduct } from '@/api/product'
|
|
|
|
+import { isSnCode } from '@/utils/validate'
|
|
|
|
+import { getStorage } from '@/utils/storage'
|
|
|
|
+import { authTempUsed } from '@/api/system'
|
|
|
|
+import { formatDate } from '@/utils'
|
|
|
|
+export default {
|
|
|
|
+ components: { UploadImage },
|
|
|
|
+ data() {
|
|
|
|
+ const valideSNcode = (rules, value, callback) => {
|
|
|
|
+ if (!isSnCode(value)) {
|
|
|
|
+ return callback(new Error('只能是字母+数字组合'))
|
|
|
|
+ }
|
|
|
|
+ callback()
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ activeName: 'first',
|
|
|
|
+ editType: 'add',
|
|
|
|
+ formData: {
|
|
|
|
+ authId: '', // 授权id
|
|
|
|
+ relationId: '',
|
|
|
|
+ authType: 1, // 认证类型
|
|
|
|
+ authUserId: '',
|
|
|
|
+ certificateImage: '', // 授权牌照
|
|
|
|
+ // 设备参数
|
|
|
|
+ productId: '', // 授权设备id
|
|
|
|
+ snCode: '', // 设备SN码
|
|
|
|
+ certificateImageType: 0,
|
|
|
|
+ productTypeId: '',
|
|
|
|
+ purchaseWay: '', // 购买渠道
|
|
|
|
+ invoiceImage: '', // 发票
|
|
|
|
+ authDate: '',
|
|
|
|
+ authImageLogo: ''
|
|
|
|
+ },
|
|
|
|
+ productCateList: [],
|
|
|
|
+ certificateImageList: [],
|
|
|
|
+ invoiceImageList: [],
|
|
|
|
+ rules: {
|
|
|
|
+ certificateImage: [{ required: true, message: '授权牌照不能为空', trigger: 'change' }],
|
|
|
|
+ certificateImageType: [{ required: true, message: '授权牌照不能为空', trigger: 'change' }],
|
|
|
|
+ snCode: [{ required: true, message: 'SN码不能为空' }, { validator: valideSNcode }],
|
|
|
|
+ productTypeId: [{ required: true, message: '设备名称不能为空', trigger: 'change' }],
|
|
|
|
+ // purchaseWay: [{ required: true, message: '购买渠道不能为空', trigger: 'change' }],
|
|
|
|
+ invoiceImage: [{ required: true, message: '发票不能为空', trigger: 'change' }],
|
|
|
|
+ authDate: [{ required: true, message: '认证日期不能为空', trigger: 'change' }],
|
|
|
|
+ authImageLogo: [{ required: true, message: '授权牌logo不能为空', trigger: 'change' }]
|
|
|
|
+ },
|
|
|
|
+ authTempFlag: true,
|
|
|
|
+ // 验证
|
|
|
|
+ validatorFields: {
|
|
|
|
+ authImageLogoWidth: 100,
|
|
|
|
+ authImageLogoHeight: 100
|
|
|
|
+ },
|
|
|
|
+ authImageLogoList: [],
|
|
|
|
+ initProductData: null
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ authTypeName() {
|
|
|
|
+ return this.formData.authType === 1 ? '新设备认证' : '关联已认证设备'
|
|
|
|
+ },
|
|
|
|
+ // 授权牌logo上传提示
|
|
|
|
+ authImageLogoUploadTip() {
|
|
|
|
+ return `限制尺寸:${this.validatorFields.authImageLogoWidth}px *${this.validatorFields.authImageLogoHeight}px`
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ 'formData.certificateImageType': {
|
|
|
|
+ handler(val) {
|
|
|
|
+ if (val === 1) {
|
|
|
|
+ this.fetchAuthTempUsed()
|
|
|
|
+ } else if (val === 0) {
|
|
|
|
+ this.formData.certificateImage = ''
|
|
|
|
+ this.formData.authDate = ''
|
|
|
|
+ this.formData.authImageLogo = ''
|
|
|
|
+ } else if (val === 2) {
|
|
|
|
+ this.formData.authDate = ''
|
|
|
|
+ this.formData.authImageLogo = ''
|
|
|
|
+ this.fetchAuthTempUsed()
|
|
|
|
+ }
|
|
|
|
+ if (this.$route.query.isAdd === 'true') {
|
|
|
|
+ this.formData.authDate = ''
|
|
|
|
+ this.formData.authImageLogo = ''
|
|
|
|
+ this.formData.certificateImage = ''
|
|
|
|
+ this.certificateImageList = []
|
|
|
|
+ this.fetchAuthTempUsed()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ deep: true
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ created() {
|
|
|
|
+ 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()
|
|
|
|
+ } else {
|
|
|
|
+ this.fetchAuthTempUsed()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ // 提交
|
|
|
|
+ async submit() {
|
|
|
|
+ try {
|
|
|
|
+ await this.$refs.form.validate()
|
|
|
|
+ this.onSave()
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 保存
|
|
|
|
+ async onSave() {
|
|
|
|
+ try {
|
|
|
|
+ this.formData.certificateImage = this.formData.certificateImageType === 0 ? '' : this.formData.certificateImage
|
|
|
|
+ this.formData.authDate = this.formData.authDate ? formatDate(this.formData.authDate, 'yyyy.MM.DD') : ''
|
|
|
|
+ console.log('授权牌数据', this.formData)
|
|
|
|
+ await saveProduct(this.formData)
|
|
|
|
+ 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}`)
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 获取设备信息
|
|
|
|
+ async fetchProductDetail() {
|
|
|
|
+ try {
|
|
|
|
+ const { productId, relationId } = this.formData
|
|
|
|
+ const res = await getProductById({ productId, relationId })
|
|
|
|
+ this.initFormData(res.data)
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 初始化表单数据
|
|
|
|
+ initFormData(data) {
|
|
|
|
+ this.initProductData = data
|
|
|
|
+ for (const key in this.formData) {
|
|
|
|
+ if (Object.hasOwnProperty.call(data, key)) {
|
|
|
|
+ if (key === 'productTypeId') {
|
|
|
|
+ this.formData[key] = parseInt(data[key])
|
|
|
|
+ } else {
|
|
|
|
+ this.formData[key] = data[key]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.formData.authImageLogo = data.authImageLogo
|
|
|
|
+ if (data.authImageLogo) {
|
|
|
|
+ this.authImageLogoList = [{ name: '授权牌logo', url: data.authImageLogo }]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (data.invoiceImage) {
|
|
|
|
+ this.invoiceImageList = [{ name: '发票', url: data.invoiceImage }]
|
|
|
|
+ }
|
|
|
|
+ if (data.certificateImage) {
|
|
|
|
+ this.certificateImageList = [{ name: '授权牌图片', url: data.certificateImage }]
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 获取设备分类列表
|
|
|
|
+ async fetchProductCateList() {
|
|
|
|
+ try {
|
|
|
|
+ const res = await fetchProductSelectList({ authUserId: this.authUserId })
|
|
|
|
+ this.productCateList = res.data
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 获取当前机构可用授权牌模板
|
|
|
|
+ async fetchAuthTempUsed() {
|
|
|
|
+ if (this.initProductData && this.editType === 'edit' && this.initProductData.certificateImageType === 0) {
|
|
|
|
+ try {
|
|
|
|
+ const res = await authTempUsed({
|
|
|
|
+ authUserId: this.authUserId,
|
|
|
|
+ authFlag: 1,
|
|
|
|
+ status: 1
|
|
|
|
+ })
|
|
|
|
+ this.authTempFlag = !!res.data.templateImage
|
|
|
|
+ this.formData.certificateImage = res.data.templateImage
|
|
|
|
+ const [width, height] = res.data.logoSize.split(',')
|
|
|
|
+ this.validatorFields.authImageLogoWidth = width
|
|
|
|
+ this.validatorFields.authImageLogoHeight = height
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ } else if (this.initProductData && this.editType === 'edit' && this.initProductData.certificateImageType === 1) {
|
|
|
|
+ this.certificateImageList = []
|
|
|
|
+ this.formData.authCode = this.initProductData.authCode
|
|
|
|
+ this.formData.authDate = this.initProductData.authDate
|
|
|
|
+ this.formData.authImageLogo = this.initProductData.authImageLogo
|
|
|
|
+ this.formData.certificateImage = this.initProductData.certificateImage
|
|
|
|
+ if (this.initProductData.authImageLogo) {
|
|
|
|
+ this.authImageLogoList = [{ name: '授权牌logo', url: this.initProductData.authImageLogo }]
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ const res = await authTempUsed({
|
|
|
|
+ authUserId: this.authUserId,
|
|
|
|
+ authFlag: 1,
|
|
|
|
+ status: 1
|
|
|
|
+ })
|
|
|
|
+ this.authTempFlag = !!res.data.templateImage
|
|
|
|
+ console.log(this.authTempFlag)
|
|
|
|
+ if (this.$route.query.isAdd === 'true') {
|
|
|
|
+ this.formData.certificateImage = res.data.templateImage
|
|
|
|
+ }
|
|
|
|
+ const [width, height] = res.data.logoSize.split(',')
|
|
|
|
+ this.validatorFields.authImageLogoWidth = width
|
|
|
|
+ this.validatorFields.authImageLogoHeight = height
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ } else if (this.initProductData && this.editType === 'edit' && this.initProductData.certificateImageType === 2) {
|
|
|
|
+ this.formData.certificateImage = this.initProductData.certificateImage
|
|
|
|
+ if (this.initProductData.authImage) {
|
|
|
|
+ this.certificateImageList = [{ name: '自定义授权牌', url: this.initProductData.authImage }]
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ const res = await authTempUsed({
|
|
|
|
+ authUserId: this.authUserId,
|
|
|
|
+ authFlag: 1,
|
|
|
|
+ status: 1
|
|
|
|
+ })
|
|
|
|
+ this.authTempFlag = !!res.data.templateImage
|
|
|
|
+ console.log(this.authTempFlag)
|
|
|
|
+ this.formData.certificateImage = res.data.templateImage
|
|
|
|
+ const [width, height] = res.data.logoSize.split(',')
|
|
|
|
+ this.validatorFields.authImageLogoWidth = width
|
|
|
|
+ this.validatorFields.authImageLogoHeight = height
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ const res = await authTempUsed({
|
|
|
|
+ authUserId: this.authUserId,
|
|
|
|
+ authFlag: 1,
|
|
|
|
+ status: 1
|
|
|
|
+ })
|
|
|
|
+ this.authTempFlag = !!res.data.templateImage
|
|
|
|
+ console.log(this.authTempFlag)
|
|
|
|
+ if (this.$route.query.isAdd === 'true') {
|
|
|
|
+ this.formData.certificateImage = res.data.templateImage
|
|
|
|
+ }
|
|
|
|
+ const [width, height] = res.data.logoSize.split(',')
|
|
|
|
+ this.validatorFields.authImageLogoWidth = width
|
|
|
|
+ this.validatorFields.authImageLogoHeight = height
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.log(error)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 授权牌照上传
|
|
|
|
+ beforeCertificateImageUpload(file) {
|
|
|
|
+ const flag = file.size / 1024 / 1024 < 1
|
|
|
|
+ if (!flag) {
|
|
|
|
+ this.$message.error('上传授权牌图片大小不能超过 1MB!')
|
|
|
|
+ }
|
|
|
|
+ return flag
|
|
|
|
+ },
|
|
|
|
+ uploadCertificateImageSuccess({ response, file, fileList }) {
|
|
|
|
+ this.certificateImageList = fileList
|
|
|
|
+ this.formData.certificateImage = response.data
|
|
|
|
+ },
|
|
|
|
+ handleCertificateImageRemove({ file, fileList }) {
|
|
|
|
+ this.certificateImageList = fileList
|
|
|
|
+ this.formData.certificateImage = ''
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 发票上传
|
|
|
|
+ beforeInvoiceImageUpload(file) {
|
|
|
|
+ const flag = file.size / 1024 / 1024 < 1
|
|
|
|
+ if (!flag) {
|
|
|
|
+ this.$message.error('上传授权牌图片大小不能超过 1MB!')
|
|
|
|
+ }
|
|
|
|
+ return flag
|
|
|
|
+ },
|
|
|
|
+ uploadInvoiceImageSuccess({ response, file, fileList }) {
|
|
|
|
+ this.invoiceImageList = fileList
|
|
|
|
+ this.formData.invoiceImage = response.data
|
|
|
|
+ },
|
|
|
|
+ handleInvoiceImageRemove({ file, fileList }) {
|
|
|
|
+ this.invoiceImageList = fileList
|
|
|
|
+ this.formData.invoiceImage = ''
|
|
|
|
+ },
|
|
|
|
+ // 授权牌logo上传
|
|
|
|
+ beforeAuthImageLogoUpload(file) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ if (file.size > 5 * 1024 * 1024) {
|
|
|
|
+ this.$message.error('授权牌logo图片大小不能超过 5MB!')
|
|
|
|
+ reject('图片大小超出最大限制')
|
|
|
|
+ }
|
|
|
|
+ const image = new Image()
|
|
|
|
+ image.src = URL.createObjectURL(file)
|
|
|
|
+ image.onload = (e) => {
|
|
|
|
+ const { naturalWidth, naturalHeight } = e.path ? e.path[0] : e.target
|
|
|
|
+ const { authImageLogoWidth: width, authImageLogoHeight: height } = this.validatorFields
|
|
|
|
+ if (naturalWidth > width || naturalHeight > height) {
|
|
|
|
+ this.$message.error('图片尺寸校验未通过')
|
|
|
|
+ reject('图片尺寸校验未通过')
|
|
|
|
+ } else {
|
|
|
|
+ resolve('图片尺寸校验通过')
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ uploadAuthImageLogoSuccess({ response, file, fileList }) {
|
|
|
|
+ this.authImageLogoList = fileList
|
|
|
|
+ this.formData.authImageLogo = response.data
|
|
|
|
+ },
|
|
|
|
+ handleAuthImageLogoRemove({ file, fileList }) {
|
|
|
|
+ this.authImageLogoList = fileList
|
|
|
|
+ this.formData.authImageLogo = ''
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.el-tab-pane {
|
|
|
|
+ margin-top: 24px;
|
|
|
|
+}
|
|
|
|
+::v-deep .el-tabs__item {
|
|
|
|
+ font-size: 20px;
|
|
|
|
+ font-weight: bold;
|
|
|
|
+ color: #82848a;
|
|
|
|
+}
|
|
|
|
+::v-deep .el-tabs__item.is-active {
|
|
|
|
+ color: #1890ff;
|
|
|
|
+}
|
|
|
|
+</style>
|