<template>
|
<div class="gift_info">
|
<el-dialog :visible.sync="dialogVisible" :title="title" width="1100px" :close-on-click-modal="false" :modal-append-to-body="false" v-if="dialogVisible">
|
<el-form size="mini" :model="form" :disabled="isDisabled" label-width="110px" ref="form" :rules="formRules">
|
<el-form-item label="赠品编码:" prop="prodSpu.spuNum">
|
<el-input v-model="form.prodSpu.spuNum" :disabled="title === '编辑赠品'" placeholder="请输入赠品编码" clearable></el-input>
|
</el-form-item>
|
<el-form-item label="赠品名称:" prop="prodSpu.spuName">
|
<el-input v-model="form.prodSpu.spuName" placeholder="请输入赠品名称" clearable></el-input>
|
</el-form-item>
|
<el-form-item label="赠品类型:" prop="prodSpu.giftTypeEnum">
|
<el-select v-model="form.prodSpu.giftTypeEnum" style="width:100%;" placeholder="请选择赠品类型">
|
<el-option label="物料" value="MATERIAL" key="2"></el-option>
|
<el-option label="商品" value="DEPUTY_PROD" key="3"></el-option>
|
<el-option label="品鉴" value="TASTING" key="4"></el-option>
|
<el-option label="非卖品" value="GIFT" key="1"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="赠品图片:" prop="prodImgs">
|
<custom-upload-img
|
:limitNumber="3"
|
@handle-success="handleSuccess"
|
@handle-remove="handleRemove"
|
:isHideDelete='!isDisabled'
|
:fileList="form.prodImgs"
|
:imageSize="'754*754'"
|
:isAppendTobody="true"
|
></custom-upload-img>
|
</el-form-item>
|
<el-form-item label="赠品规格:" class="spuProps_propName" prop="spuProps.propName">
|
<el-row>
|
<el-col class="item_prop" :span="2">规格名</el-col>
|
<el-col :span="6">
|
<el-input v-model="form.spuProps.propName" placeholder="请输入规格名" clearable></el-input>
|
</el-col>
|
</el-row>
|
</el-form-item>
|
<el-form-item label="" v-for="(item, index) in form.spuProps.giftPropValueList" :key="index">
|
<el-row>
|
<el-col class="item_prop" :span="2">规格值</el-col>
|
<el-col :span="6">
|
<el-form-item label="" :prop="'spuProps.giftPropValueList.'+index+'.value'" :rules="formRules.propValue">
|
<el-input v-model="item.value" placeholder="请输入规格值" clearable></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col class="item_prop" :span="2">计量单位</el-col>
|
<el-col :span="6">
|
<el-form-item label="" :prop="'spuProps.giftPropValueList.'+index+'.skuReduceStorage'" :rules="formRules.skuReduceStorage">
|
<el-input-number v-model="item.skuReduceStorage" clearable></el-input-number>
|
</el-form-item>
|
</el-col>
|
<el-col class="button_style" :span="4">
|
<el-button type="primary" v-show="!isDisabled && index <= 1 && index === form.spuProps.giftPropValueList.length-1" @click="addItem(row,index)">新增</el-button>
|
<el-button type="danger" v-show="!isDisabled && form.spuProps.giftPropValueList.length !== 1" @click="deleteItem(row,index)">删除</el-button>
|
</el-col>
|
</el-row>
|
</el-form-item>
|
<el-form-item label="赠品描述:" v-if="!isDisabled" prop="spuDetails[0].spuContent">
|
<Editor ref="editor" :content.sync="form.spuDetails[0].spuContent"></Editor>
|
</el-form-item>
|
<el-form-item v-else label="赠品描述:" prop="spuDetails[0].spuContent">
|
<div class="content" v-html="form.spuDetails[0].spuContent"></div>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button size="mini" @click="submit" v-show="!isDisabled" type="primary" :loading="loading">保存</el-button>
|
<el-button type="success" v-show="!isDisabled" size="mini" @click="preView">预览</el-button>
|
<el-button size="mini" @click="dialogVisible = false">取消</el-button>
|
</div>
|
</el-dialog>
|
<el-dialog :visible.sync="dialogPrevVisible" title="赠品详情" class="gift_pre_info" :close-on-click-modal="false" :modal-append-to-body="false" width="433px">
|
<preview-info :form="previewform"></preview-info>
|
<div slot="footer" class="dialog-footer">
|
<el-button size="mini" @click="dialogPrevVisible=false">关闭</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
<script>
|
import giftPrdApi from '@/api/giftPrd'
|
import { objectCopy } from '@/utils/objectCopyHelper'
|
import Editor from '@/components/editor/editor.vue'
|
import previewInfo from '@/views/giftMgt/components/previewInfo.vue'
|
import { inputNumberValid } from '@/utils/validator'
|
|
export default {
|
components: { Editor, previewInfo },
|
props: {
|
show: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: '添加赠品'
|
},
|
row: {
|
type: Object,
|
default: function () {
|
return {}
|
}
|
}
|
},
|
data () {
|
return {
|
isDisabled: false,
|
dialogVisible: false,
|
form: {
|
prodSpu: {
|
spuNum: null,
|
spuName: null,
|
isGift: '1',
|
giftTypeEnum: null
|
},
|
prodImgs: [], // 图片数组集合
|
spuProps: {
|
propName: null,
|
giftPropValueList: [{
|
value: null,
|
skuReduceStorage: null
|
}]
|
},
|
spuDetails: [{
|
spuContent: '',
|
spuShowType: '2'
|
}]
|
},
|
formRules: {
|
'prodSpu.spuNum': [
|
{ required: true, message: '请输入赠品编码', trigger: 'change' },
|
{ max: 32, message: '赠品编码最多只能输入 32 个字' },
|
{ pattern: /^[0-9a-zA-Z]+(-[0-9a-zA-Z]+)*$/, message: '仅支持数字、字母、字符【-】;开头和结尾不允许输入【-】;示例:14aa-0900-001,DY000', trigger: 'blur' }
|
],
|
'prodSpu.spuName': [{ required: true, message: '请输入赠品名称', trigger: 'change' },
|
{ max: 128, message: '赠品名称最多只能输入 128 个字' }
|
],
|
prodImgs: [{ type: 'array', required: true, message: '请上传赠品图片' }],
|
'spuDetails[0].spuContent': [{ required: true, message: '请输入赠品描述', trigger: 'change' },
|
{ max: 4194304, message: '赠品描述最多只能输入 4194304 个字' }
|
],
|
'spuProps.propName': [{ required: true, message: '请输入规格名称', trigger: 'change' }],
|
'prodSpu.giftTypeEnum': [{ required: true, message: '请选择赠品类型', trigger: 'change' }],
|
skuReduceStorage: [
|
{ required: true, message: '请输入赠品数量' },
|
{ validator: inputNumberValid }
|
],
|
propValue: [{ required: true, message: '请输入规格值', trigger: 'change' },
|
{ max: 128, message: '规格值最多只能输入 128 字', trigger: 'change' }]
|
},
|
loading: false,
|
dialogPrevVisible: false, // 预览弹窗
|
previewform: {}
|
}
|
},
|
watch: {
|
row: {
|
handler (newValue, oldValue) {
|
if (newValue.spuBase.spuId) {
|
const formData = objectCopy(this.row)
|
if (this.title === '赠品详情') {
|
this.isDisabled = true
|
}
|
this.form.prodImgs = []
|
this.handGetData(formData)
|
}
|
},
|
deep: true
|
},
|
/**
|
* 监控外部显示变量变化
|
* 传递到dialog组件
|
*/
|
show: function (newShow, oldShow) {
|
this.dialogVisible = newShow
|
},
|
/**
|
* 监控内部显示属性变化
|
* 传递到外部调用变量
|
*/
|
dialogVisible: function (newDialogShow, oldDialogShow) {
|
this.$emit('update:show', newDialogShow)
|
if (!newDialogShow) {
|
this.form = {
|
prodSpu: {
|
spuNum: null,
|
spuName: null,
|
isGift: '1'
|
},
|
prodImgs: [], // 图片数组集合
|
spuProps: {
|
propName: null,
|
giftPropValueList: [{
|
value: null,
|
skuReduceStorage: null
|
}]
|
},
|
spuDetails: [{
|
spuContent: '',
|
spuShowType: '2'
|
}]
|
}
|
this.isDisabled = false
|
}
|
}
|
},
|
methods: {
|
// 处理获取的数据
|
handGetData (data) {
|
const { spuName, spuNum, spuId, giftType } = data.spuBase
|
if (data.images.length) {
|
this.form.prodImgs = data.images.map(item => { return { url: item.imgUrl, id: item.imgId } })
|
}
|
this.form.spuDetails = data.spuDetails
|
this.form.prodSpu = { spuName, spuNum }
|
this.form.prodSpu.isGift = '1'
|
this.$set(this.form.prodSpu, 'giftTypeEnum', giftType)
|
this.form.spuId = spuId
|
data.spuProp.skuProps.forEach(item => {
|
this.form.spuProps = {
|
propName: item.propName,
|
giftPropValueList: JSON.parse(item.propVal)
|
}
|
})
|
},
|
// 预览
|
preView () {
|
this.previewform = JSON.parse(JSON.stringify(this.form))
|
this.previewform.articleContent = this.$refs.editor.getData()
|
this.dialogPrevVisible = true
|
},
|
/**
|
* 获取上传成功的图片
|
*/
|
handleSuccess (data) {
|
this.form.prodImgs.push(data)
|
this.$refs.form.clearValidate('prodImgs')
|
},
|
/**
|
* 移除图片
|
*/
|
handleRemove (file) {
|
this.form.prodImgs = this.form.prodImgs.filter(v => {
|
return v.id !== file.id
|
})
|
},
|
// 新增规格
|
addItem (row, index) {
|
this.form.spuProps.giftPropValueList.push({
|
value: null,
|
skuReduceStorage: null
|
})
|
},
|
// 删除规格
|
deleteItem (row, index) {
|
this.form.spuProps.giftPropValueList.splice(index, 1)
|
},
|
/**
|
* 提交
|
*/
|
submit () {
|
this.form.spuDetails[0].spuContent = this.$refs.editor.getData()
|
this.$refs.form.validate().then(res => {
|
this.loading = true
|
const data = JSON.parse(JSON.stringify(this.form))
|
data.prodImgs = this.form.prodImgs.map((item, index) => { return { imgId: item.id, imgNum: index + 1, imgUrl: item.url } })
|
if (this.form.spuId) {
|
this.editInfo(data)
|
} else {
|
this.addInfo(data) // 新增文章
|
}
|
})
|
},
|
/**
|
* 增加文章
|
*/
|
async addInfo (data) {
|
try {
|
const res = await giftPrdApi.addInfo(data)
|
if (res.code === '0') {
|
this.$message({
|
message: '添加成功',
|
type: 'success'
|
})
|
this.loading = false
|
this.$parent.queryData()
|
this.dialogVisible = false
|
} else {
|
this.loading = false
|
}
|
} catch (error) {
|
this.loading = false
|
}
|
},
|
/**
|
* 编辑文章
|
*/
|
async editInfo (data) {
|
try {
|
const res = await giftPrdApi.updateInfo(data)
|
if (res.code === '0') {
|
this.$message({
|
message: '编辑成功',
|
type: 'success'
|
})
|
this.loading = false
|
this.$parent.queryData()
|
this.dialogVisible = false
|
} else {
|
this.loading = false
|
}
|
} catch (error) {
|
this.loading = false
|
}
|
}
|
}
|
}
|
</script>
|
<style lang="scss">
|
.gift_info{
|
.spuProps_propName{
|
.el-form-item__error{
|
margin-left: 62px;
|
}
|
}
|
.item_prop{
|
width: auto;
|
padding: 0 10px;
|
}
|
.button_style {
|
margin-left: 10px;
|
}
|
.content {
|
width: 90%;
|
max-height: 440px;
|
border: 1px solid #cccccc;
|
padding: 25px;
|
overflow-y: auto;
|
overflow-x: hidden;
|
border-radius: 6px;
|
background-color: #F5F7FA;
|
border-color: #E4E7ED;
|
img, video{width: 100%;height: auto}
|
div,p{
|
width: 100% !important;
|
}
|
}
|
}
|
.gift_pre_info{
|
.el-dialog__body{
|
padding:15px 20px;
|
height: 600px;
|
position: relative;
|
overflow: hidden;
|
.gift_prd_pre{
|
position: absolute;
|
top: 0;
|
right: -17px;
|
bottom: 0;
|
overflow-y: scroll;
|
overflow-x: hidden;
|
padding: 0 10px;
|
}
|
}
|
}
|
</style>
|