<template>
|
<div>
|
<el-dialog :visible.sync="dialogVisible" :title="title" :close-on-click-modal="false" v-if="dialogVisible" :modal-append-to-body="false" >
|
<el-form size="mini" :model="form" label-width="120px" ref="form" :rules="formRules">
|
<el-form-item label="分类名称:" prop="catName">
|
<el-input v-model="form.catName" placeholder="请输入分类名称" clearable></el-input>
|
</el-form-item>
|
<!-- <el-form-item label="分类编码:" prop="catCode">
|
<el-input v-model="form.catCode" placeholder="请输入分类编码" clearable></el-input>
|
</el-form-item> -->
|
<el-form-item label="分类序号:" prop="catIndexNum">
|
<el-input-number v-model="form.catIndexNum" :min="1" @keydown.native="limiInputType" ></el-input-number>
|
</el-form-item>
|
<el-form-item label="分类描述:" prop="catDesc">
|
<el-input v-model="form.catDesc" 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 productCategoryApi from '@/api/productmanagement/productCategory'
|
import { getStrLength } from '@/utils/getStrLength'
|
import { limiInputType } from '@/utils/limiInputType'
|
export default {
|
props: {
|
show: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: '添加品牌'
|
},
|
row: {
|
type: Object,
|
default: function () {
|
return {}
|
}
|
}
|
},
|
data () {
|
return {
|
dialogVisible: false,
|
form: {
|
catName: null,
|
catCode: null,
|
catIndexNum: 1,
|
catDesc: null,
|
parentCatId: null
|
},
|
formRules: {
|
catName: [
|
{ required: true, message: '请输入分类名称', trigger: 'change' }, {
|
validator: (rule, value, callback) => {
|
callback(getStrLength(rule, value, callback, 100, '分类名称'))
|
}
|
}],
|
catCode: [{ required: true, message: '请输入分类编码', trigger: 'change' }, {
|
validator: (rule, value, callback) => {
|
callback(getStrLength(rule, value, callback, 32, '分类编码'))
|
}
|
}],
|
catIndexNum: [{ required: true, message: '请输入排序值', trigger: 'change' }],
|
catDesc: {
|
validator: (rule, value, callback) => {
|
callback(getStrLength(rule, value, callback, 2000, '分类描述'))
|
}
|
}
|
},
|
loading: false
|
}
|
},
|
watch: {
|
/**
|
* 监控外部显示变量变化
|
* 传递到dialog组件
|
*/
|
show: function (newShow, oldShow) {
|
this.dialogVisible = newShow
|
if (this.dialogVisible) {
|
if (this.row.catId) {
|
this.form = this.row
|
} else if (this.row.parentCatId) {
|
this.form.parentCatId = this.row.parentCatId
|
}
|
}
|
},
|
/**
|
* 监控内部显示属性变化
|
* 传递到外部调用变量
|
*/
|
dialogVisible: function (newDialogShow, oldDialogShow) {
|
if (!newDialogShow) {
|
for (const i in this.form) {
|
this.form[i] = null
|
}
|
this.$emit('update:show', newDialogShow)
|
}
|
}
|
},
|
methods: {
|
/**
|
* 限制不能输入数字
|
*/
|
limiInputType (e) {
|
limiInputType(e)
|
},
|
/**
|
* 提交
|
*/
|
submit () {
|
this.$refs.form.validate().then(res => {
|
this.loading = true
|
let resDate = null
|
this.form.bizId = 'B02'
|
if (this.form.catId) {
|
resDate = productCategoryApi.updateInfo(this.form)
|
} else {
|
resDate = productCategoryApi.addInfo(this.form)
|
}
|
resDate.then(res => {
|
if (res.data) {
|
this.loading = false
|
this.$message({
|
message: '操作成功',
|
type: 'success'
|
})
|
this.$emit('hand-refresh-tree-data')
|
this.dialogVisible = false
|
} else {
|
this.loading = false
|
}
|
}).catch(() => {
|
this.loading = false
|
})
|
})
|
}
|
}
|
}
|
</script>
|