<template>
|
<GlobalWindow
|
:title="title"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" :rules="rules">
|
<el-form-item label="类别名称" prop="name">
|
<el-input v-model="form.name" placeholder="请输入类别名称,不超过6个字" maxlength="6" v-trim/>
|
</el-form-item>
|
<el-form-item label="图标" prop="imgurl">
|
<el-upload
|
:action="action"
|
:class="{ hide: hideUpload }"
|
:file-list="form.fileList"
|
:data="{ folder: 'projects' }"
|
list-type="picture-card"
|
:limit="1"
|
:on-success="fileSuccess"
|
:on-exceed="exceed"
|
:on-remove="handleRemove">
|
<i class="el-icon-plus"></i>
|
<div slot="tip" class="el-upload__tip">只能上传图片格式,png格式,建议尺寸120*120px</div>
|
</el-upload>
|
<!-- <el-input v-model="form.imgurl" placeholder="请输入图标" v-trim/> -->
|
</el-form-item>
|
<el-form-item label="排序码(升序)" prop="sortnum">
|
<el-input v-model="form.sortnum" placeholder="请输入排序码" v-trim/>
|
</el-form-item>
|
|
<el-form-item label="筛选属性1名称" prop="attrFirst">
|
<el-input v-model="form.attrFirst" maxlength="6" placeholder="请输入筛选属性名称,不超过6个字" v-trim/>
|
</el-form-item>
|
<el-form-item label="筛选属性1的值" prop="attrFirst">
|
<el-input v-model="form.attrFirst1" maxlength="10" @keypress.enter.native="confirmVal(1)" placeholder="配置筛选属性值,按回车完成配置,单个值不超过10个字" v-trim/>
|
<div style="display: flex; align-items: center; flex-wrap: wrap;">
|
<el-tag style="margin-right: 10px; margin-top: 10px;" @close="close(index, 1)" closable v-for="(item, index) in form.attrFirstList" :key="index">{{ item.name }}</el-tag>
|
</div>
|
</el-form-item>
|
<el-form-item label="筛选属性2名称" prop="attrSecond">
|
<el-input v-model="form.attrSecond" maxlength="6" placeholder="请输入筛选属性名称,不超过6个字" v-trim/>
|
</el-form-item>
|
<el-form-item label="筛选属性2的值" prop="attrSecond">
|
<el-input v-model="form.attrSecond1" maxlength="10" @keypress.enter.native="confirmVal(2)" placeholder="配置筛选属性值,按回车完成配置,单个值不超过10个字" v-trim/>
|
<div style="display: flex; align-items: center; flex-wrap: wrap;">
|
<el-tag style="margin-right: 10px; margin-top: 10px;" @close="close(index, 2)" closable v-for="(item, index) in form.attrSecondList" :key="index">{{ item.name }}</el-tag>
|
</div>
|
</el-form-item>
|
|
<el-form-item label="参数属性名" prop="parameter">
|
<el-input v-model="form.parameter" maxlength="10" @keypress.enter.native="confirmVal(3)" placeholder="配置参数属性名,按回车完成配置,单个值不超过10个字" v-trim/>
|
<div style="display: flex; align-items: center; flex-wrap: wrap;">
|
<el-tag style="margin-right: 10px; margin-top: 10px;" @close="close(index, 3)" closable v-for="(item, index) in form.paramList" :key="index">{{ item.name }}</el-tag>
|
</div>
|
</el-form-item>
|
|
<el-form-item label="预算区间" prop="attrSecond">
|
<div style="display: flex; align-items: center; margin-bottom: 10px;" v-for="(item, index) in form.budgetList" :key="index">
|
<el-input v-model="item.minamount" type="number" @input="changeInput(1, index)" placeholder="下限" v-trim/>
|
<span style="margin: 0 20px;"> ~ </span>
|
<el-input v-model="item.maxamount" type="number" @input="changeInput(2, index)" placeholder="上限" v-trim/>
|
<el-button type="primary" style="margin-left: 20px;" @click="add" v-if="index === 0">增加区间</el-button>
|
<el-button type="danger" style="margin-left: 20px;" @click="dele(index)" v-else>删除区间</el-button>
|
</div>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
import { create, updateById } from '@/api/business/category.js'
|
export default {
|
name: 'OperaCategoryWindow',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
action: process.env.VUE_APP_API_PREFIX + '/public/uploadLocal',
|
|
hideUpload: false,
|
|
// 表单数据
|
form: {
|
id: null,
|
name: '',
|
attrFirst: '',
|
attrFirst1: '',
|
attrFirstList: [],
|
attrSecond: '',
|
attrSecond1: '',
|
attrSecondList: [],
|
sortnum: '',
|
parameter: '',
|
paramList: [],
|
imgurl: '',
|
budgetList: [
|
{
|
maxamount: '',
|
minamount: ''
|
}
|
],
|
fileList: [],
|
attributeValueOne: []
|
},
|
// 验证规则
|
rules: {
|
name: [
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
]
|
},
|
dialogVisible: false
|
}
|
},
|
created () {
|
this.config({
|
api: '/business/category',
|
'field.id': 'id'
|
})
|
},
|
methods: {
|
changeInput(type, index) {
|
if (type === 1) {
|
if (!this.form.budgetList[index].minamount) return
|
if (!/^[0-9]*[1-9][0-9]*$/.test(this.form.budgetList[index].minamount)) {
|
this.$message.warning({
|
type: 'warning',
|
message: '预算只能输入正整数'
|
})
|
this.form.budgetList[index].minamount = ''
|
}
|
} else {
|
if (!this.form.budgetList[index].maxamount) return
|
if (!/^[0-9]*[1-9][0-9]*$/.test(this.form.budgetList[index].maxamount)) {
|
this.$message.warning({
|
type: 'warning',
|
message: '预算只能输入正整数'
|
})
|
this.form.budgetList[index].maxamount = ''
|
}
|
}
|
},
|
exceed() {
|
this.$message.warning({
|
message: '只能上传一个图标'
|
})
|
},
|
confirm() {
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
this.isWorking = true
|
if (!this.form.id) {
|
create(this.form)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('新建成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
} else {
|
updateById(this.form)
|
.then(() => {
|
this.visible = false
|
this.$tip.apiSuccess('编辑成功')
|
this.$emit('success')
|
})
|
.catch(e => {
|
this.$tip.apiFailed(e)
|
})
|
.finally(() => {
|
this.isWorking = false
|
})
|
}
|
} else {
|
return false;
|
}
|
});
|
},
|
close(index, type) {
|
if (type === 1) {
|
this.form.attrFirstList.splice(index, 1)
|
} else if (type === 2) {
|
this.form.attrSecondList.splice(index, 1)
|
} else if (type === 3) {
|
this.form.paramList.splice(index, 1)
|
}
|
},
|
confirmVal(type) {
|
if (type === 1) {
|
if (!this.form.attrFirst1) return
|
this.form.attrFirstList.push({ name: this.form.attrFirst1 })
|
this.form.attrFirst1 = ''
|
} else if (type === 2) {
|
if (!this.form.attrSecond1) return
|
this.form.attrSecondList.push({ name: this.form.attrSecond1 })
|
this.form.attrSecond1 = ''
|
} else if (type === 3) {
|
if (!this.form.parameter) return
|
this.form.paramList.push({ name: this.form.parameter })
|
this.form.parameter = ''
|
}
|
},
|
fileSuccess(response) {
|
this.form.fileList.push({ imgaddr: response.data.imgaddr, url: response.data.url })
|
this.form.imgurl = response.data.imgaddr
|
},
|
handleRemove() {
|
this.form.fileList = []
|
this.form.imgurl = ''
|
},
|
add() {
|
this.form.budgetList.push({ minamount: '', maxamount: '' })
|
},
|
dele(i) {
|
if (this.form.budgetList.length === 1) return
|
this.form.budgetList.splice(i, 1)
|
}
|
},
|
watch: {
|
visible: {
|
handler(news, old) {
|
if (!news) {
|
this.form = {
|
id: null,
|
name: '',
|
attrFirst: '',
|
attrFirst1: '',
|
attrFirstList: [],
|
attrSecond: '',
|
attrSecond1: '',
|
attrSecondList: [],
|
sortnum: '',
|
parameter: '',
|
paramList: [],
|
imgurl: '',
|
budgetList: [
|
{
|
maxamount: '',
|
minamount: ''
|
}
|
],
|
fileList: [],
|
attributeValueOne: []
|
}
|
}
|
}
|
}
|
}
|
}
|
</script>
|
|