| | |
| | | <el-select v-model="form.labelsArr" style="width: 100%;" @change="changeLabel" multiple placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in cateList" |
| | | :key="item.id" |
| | | :key="item.name" |
| | | :label="item.name" |
| | | :value="item.id"> |
| | | :value="item.name"> |
| | | </el-option> |
| | | </el-select> |
| | | <el-button size="medium" style="margin-left: 15px;" @click="$refs.tagLibrary.open('标签库')">标签库</el-button> |
| | | </div> |
| | | </el-form-item> |
| | | <el-form-item label="地区" prop="area"> |
| | | <el-form-item label="省份" prop="provinceId"> |
| | | <el-select v-model="form.provinceId" filterable @change="changeProvince" placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in areas" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="城市" prop="cityId"> |
| | | <el-select v-model="form.cityId" clearablefilterable placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in citys" |
| | | :key="item.id" |
| | | :label="item.name" |
| | | :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <!-- <el-form-item label="地区" prop="area"> |
| | | <el-cascader |
| | | v-model="form.area" |
| | | :options="area" |
| | | @change="changeArea" |
| | | :props="{ label: 'name', children: 'childAreasList', value: 'id' }" /> |
| | | </el-form-item> |
| | | </el-form-item>--> |
| | | <el-form-item label="年份" prop="yearInfo"> |
| | | <el-date-picker |
| | | v-model="form.yearInfo" |
| | |
| | | area: [], |
| | | labelsArr: [] |
| | | }, |
| | | areas: [], |
| | | citys: [], |
| | | // 验证规则 |
| | | rules: { |
| | | title: [ |
| | | { required: true, message: '请输入内容', trigger: 'blur' } |
| | | ], |
| | | yearInfo: [ |
| | | { required: true, message: '请选择年份', trigger: 'blur' } |
| | | ], |
| | | labelsArr: [ |
| | | { required: true, message: '请选择表情', trigger: 'blur' } |
| | | ], |
| | | provinceId: [ |
| | | { required: true, message: '请选择省份', trigger: 'blur' } |
| | | ], |
| | | link: [ |
| | | { required: true, message: '请输入内容', trigger: 'blur' } |
| | |
| | | api: '/business/knowledge', |
| | | 'field.id': 'id' |
| | | }) |
| | | |
| | | }, |
| | | methods: { |
| | | changeLabel(e) { |
| | |
| | | this.form.cityId = e[1] |
| | | } |
| | | }, |
| | | changeProvince (e) { |
| | | this.citys = [] |
| | | this.form.cityId=null |
| | | this.areas.forEach(item => { |
| | | if (item.id === this.form.provinceId) { |
| | | this.citys = item.childAreasList || [] |
| | | } |
| | | }) |
| | | }, |
| | | open (title, target) { |
| | | this.getLabel() |
| | | this.getCityTree() |
| | | this.getCityTreeList() |
| | | this.title = title |
| | | this.visible = true |
| | | // 新建 |
| | |
| | | this.form[key] = target[key] |
| | | } |
| | | if (this.form.labels) { |
| | | this.form.labelsArr = this.form.labels.split(',').map(item => Number(item)) |
| | | this.form.labelsArr = this.form.labels.split(',') |
| | | } |
| | | if (this.form.provinceId && this.form.cityId) { |
| | | this.form.area = [this.form.provinceId, this.form.cityId] |
| | |
| | | async getLabel() { |
| | | this.cateList = await list() |
| | | }, |
| | | async getCityTreeList () { |
| | | this.areas = await findTreeList({}) |
| | | }, |
| | | async getCityTree() { |
| | | this.area = await findTreeList({}) |
| | | this.setSecondLevelChildrenToNullPrecise(this.area); |
| | | this.setSecondLevelChildrenToNullPrecise(this.area) |
| | | this.area.forEach(item => { |
| | | if (item.childAreasList.length === 0) { |
| | | item.childAreasList = null |
| | |
| | | }) |
| | | }, |
| | | setSecondLevelChildrenToNullPrecise(data, level = 1) { |
| | | if (!data || !data.length) return; |
| | | if (!data || !data.length) return |
| | | |
| | | data.forEach(item => { |
| | | if (item.childAreasList && item.childAreasList.length) { |
| | | if (level === 1) { |
| | | // 这是第一级节点,处理其子节点(第二级) |
| | | item.childAreasList.forEach(child => { |
| | | child.childAreasList = null; |
| | | }); |
| | | child.childAreasList = null |
| | | }) |
| | | } else { |
| | | // 继续递归处理更深层级 |
| | | this.setSecondLevelChildrenToNullPrecise(item.childAreasList, level + 1); |
| | | this.setSecondLevelChildrenToNullPrecise(item.childAreasList, level + 1) |
| | | } |
| | | } |
| | | }); |
| | | }) |
| | | } |
| | | } |
| | | } |