<template>
|
<div>
|
<el-dialog :visible.sync="dialogVisible" :title="title" :close-on-click-modal="false" :modal-append-to-body="false" v-if="dialogVisible">
|
<el-form size="mini" :model="form" label-width="120px" ref="form" :rules="formRules">
|
<el-form-item label="一级分类名称:" v-show="form.pid" prop="publicityName">
|
<el-select :disabled="true" v-model="form.pid">
|
<el-option
|
v-for="item in publicityArr"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item :label="form.pid ? '二级分类名称:':'一级分类名称:'" prop="publicityName"
|
:rules="[{ required: true, message: `请输入${form.pid ? '二级分类名称' :'一级分类名称'}`, trigger: 'change' },
|
{ max: form.pid ? 6:4, message: `${form.pid ? '二级分类名称最多只能输入 6 个字' :'一级分类名称最多只能输入 4 个字'}`, trigger: 'change' }
|
]"
|
>
|
<el-input v-model="form.publicityName" :placeholder="`请输入${form.pid ? '二级分类名称' :'一级分类名称'}`" clearable></el-input>
|
</el-form-item>
|
<el-form-item label="排序" prop="sort" v-if="form.pid">
|
<el-input-number v-model="form.sort" :min="1" :max="999" clearable></el-input-number>
|
<div>提示:若排序编号已存在则无法添加</div>
|
</el-form-item>
|
<el-form-item label="描述:" prop="publicityDesc">
|
<el-input v-model="form.publicityDesc" type="textarea" :autosize="{minRows:2,maxRows:4}" placeholder="请输入描述" clearable></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button size="mini" @click="submit" type="primary" :loading="loading">保存</el-button>
|
<el-button size="mini" @click="dialogVisible = false">取消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
<script>
|
import catPublicityApi from '@/api/proPublicityMgt/catPublicity'
|
import { objectCopy } from '@/utils/objectCopyHelper'
|
import { inputNumberValid } from '@/utils/validator'
|
export default {
|
props: {
|
show: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: '新增分类'
|
},
|
row: {
|
type: Object,
|
default: function () {
|
return {}
|
}
|
}
|
},
|
data () {
|
return {
|
dialogVisible: false,
|
form: {
|
publicityName: null,
|
publicityDesc: null,
|
pid: null,
|
sort: undefined
|
},
|
formRules: {
|
culturalType: [
|
{ required: true, message: '请输入一级分类名称', trigger: 'change' },
|
{ max: 4, message: '一级分类名称最多只能输入 4 个字', trigger: 'change' }
|
],
|
publicityDesc: [{ max: 200, message: '描述最多只能输入 200 个字' }],
|
sort: [
|
{ required: true, message: '请输入排序' },
|
{ validator: inputNumberValid }
|
]
|
},
|
loading: false,
|
publicityArr: []
|
}
|
},
|
watch: {
|
row: {
|
handler (newValue, oldValue) {
|
if (this.title === '新增二级分类') {
|
this.form.pid = this.row.publicityId
|
this.getCategory()
|
} else if (newValue.publicityId) {
|
this.form = objectCopy(this.row)
|
this.form.sort = this.row.sort ? this.row.sort : undefined
|
}
|
},
|
deep: true
|
},
|
/**
|
* 监控外部显示变量变化
|
* 传递到dialog组件
|
*/
|
show: function (newShow, oldShow) {
|
this.dialogVisible = newShow
|
},
|
/**
|
* 监控内部显示属性变化
|
* 传递到外部调用变量
|
*/
|
dialogVisible: function (newDialogShow, oldDialogShow) {
|
if (!newDialogShow) {
|
for (const i in this.form) {
|
this.form[i] = null
|
}
|
this.$emit('update:show', newDialogShow)
|
}
|
}
|
},
|
methods: {
|
// 获取分类
|
async getCategory () {
|
try {
|
const res = await catPublicityApi.getNoDelete({ level: '1' })
|
if (res.code === '0') {
|
this.publicityArr = res.data.map(item => {
|
return {
|
id: item.publicityId,
|
name: item.publicityName
|
}
|
})
|
}
|
} catch (error) {
|
}
|
},
|
// 编辑
|
async editInfo () {
|
try {
|
const res = await catPublicityApi.updateInfo(this.form)
|
if (res.code === '0') {
|
this.$message({
|
message: '编辑成功',
|
type: 'success'
|
})
|
this.dialogVisible = false
|
this.loading = false
|
this.$parent.queryData()
|
} else {
|
this.loading = false
|
}
|
} catch (error) {
|
this.loading = false
|
}
|
},
|
// 新增
|
async addInfo () {
|
try {
|
const res = await catPublicityApi.addInfo(this.form)
|
if (res.code === '0') {
|
this.$message({
|
message: '新增成功',
|
type: 'success'
|
})
|
this.loading = false
|
this.dialogVisible = false
|
this.$parent.queryData()
|
} else {
|
this.loading = false
|
}
|
} catch (error) {
|
this.loading = false
|
}
|
},
|
/**
|
* 提交
|
*/
|
submit () {
|
this.$refs.form.validate().then(res => {
|
this.loading = true
|
if (this.form.publicityId) {
|
this.editInfo()
|
} else {
|
this.addInfo()
|
}
|
})
|
}
|
}
|
}
|
</script>
|