|
|
|
@ -1,20 +1,72 @@
|
|
|
|
|
<template> |
|
|
|
|
<view class="view"> |
|
|
|
|
<view class="block" v-for="(tag, index) in data" :key="index"> |
|
|
|
|
<view style=""> |
|
|
|
|
<view class="block"> |
|
|
|
|
<view> |
|
|
|
|
<text style="color: #f8285a; margin-right: 4px">*</text> |
|
|
|
|
{{ tag.name }} |
|
|
|
|
所在区域 |
|
|
|
|
</view> |
|
|
|
|
<view class="value" @click="showPicker(tag)"> |
|
|
|
|
<view class="input-value" v-if="form[tag.name]"> |
|
|
|
|
{{ form[tag.name].name }} |
|
|
|
|
<view class="value" @click="showPicker('qy')"> |
|
|
|
|
<view class="input-value" v-if="form.qy"> |
|
|
|
|
{{ form.qy.name }} |
|
|
|
|
</view> |
|
|
|
|
<view class="input-value" style="color: #808080" v-else> |
|
|
|
|
{{ `请选择${tag.name}` }} |
|
|
|
|
请选择所在区域 |
|
|
|
|
</view> |
|
|
|
|
<u-icon name="arrow-right"></u-icon> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<!-- 行业类型 --> |
|
|
|
|
<view class="block"> |
|
|
|
|
<view> |
|
|
|
|
<text style="color: #f8285a; margin-right: 4px">*</text> |
|
|
|
|
行业类型 |
|
|
|
|
</view> |
|
|
|
|
<view class="value" @click="showPicker('hy')"> |
|
|
|
|
<view class="input-value" v-if="form.hy"> |
|
|
|
|
{{ form.hy.name }} |
|
|
|
|
</view> |
|
|
|
|
<view class="input-value" style="color: #808080" v-else> |
|
|
|
|
请选择行业类型 |
|
|
|
|
</view> |
|
|
|
|
<u-icon name="arrow-right"></u-icon> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<!-- 省厅类型 --> |
|
|
|
|
<view class="block"> |
|
|
|
|
<view> |
|
|
|
|
<text style="color: #f8285a; margin-right: 4px">*</text> |
|
|
|
|
所属生态 |
|
|
|
|
</view> |
|
|
|
|
<view class="value" @click="showPicker('st')"> |
|
|
|
|
<view class="input-value" v-if="form.st"> |
|
|
|
|
{{ form.st.name }} |
|
|
|
|
</view> |
|
|
|
|
<view class="input-value" style="color: #808080" v-else> |
|
|
|
|
请选择所属生态 |
|
|
|
|
</view> |
|
|
|
|
<u-icon name="arrow-right"></u-icon> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<!-- 污染类型 --> |
|
|
|
|
<view class="block"> |
|
|
|
|
<view> |
|
|
|
|
<text style="color: #f8285a; margin-right: 4px">*</text> |
|
|
|
|
污染类型 |
|
|
|
|
</view> |
|
|
|
|
<view class="value" @click="showPicker('wr')"> |
|
|
|
|
<view class="input-value" v-if="form.wr"> |
|
|
|
|
{{ form.wr.name }} |
|
|
|
|
</view> |
|
|
|
|
<view class="input-value" style="color: #808080" v-else> |
|
|
|
|
请选择污染类型 |
|
|
|
|
</view> |
|
|
|
|
<u-icon name="arrow-right"></u-icon> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
|
<u-picker |
|
|
|
|
:show="picker.show" |
|
|
|
|
:columns="picker.data" |
|
|
|
@ -34,11 +86,20 @@
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import { |
|
|
|
|
getTagData |
|
|
|
|
} from '@/api/system/dict.js' |
|
|
|
|
export default { |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
data: [], |
|
|
|
|
form: {}, |
|
|
|
|
form: { |
|
|
|
|
qy: '', |
|
|
|
|
hy: '', |
|
|
|
|
st: '', |
|
|
|
|
wr: '' |
|
|
|
|
}, |
|
|
|
|
dictMap: {}, |
|
|
|
|
// 选择器 |
|
|
|
|
picker: { |
|
|
|
|
show: false, |
|
|
|
@ -49,35 +110,53 @@ export default {
|
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onLoad(res) { |
|
|
|
|
this.getData() |
|
|
|
|
if(res.tags){ |
|
|
|
|
this.form = JSON.parse(res.tags) |
|
|
|
|
} |
|
|
|
|
this.getDict() |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
getData() { |
|
|
|
|
this.data = new Array(5).fill(1).map((i, index) => { |
|
|
|
|
this.form[`Tag${index + 1}`] = '' |
|
|
|
|
return { |
|
|
|
|
name: `Tag${index + 1}`, |
|
|
|
|
label: `标签${index + 1}`, |
|
|
|
|
value: index, |
|
|
|
|
children: new Array(10).fill(1).map((c, cIndex) => { |
|
|
|
|
return { |
|
|
|
|
name: `subTag${cIndex + 1}`, |
|
|
|
|
value: cIndex * 10 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getDict() { |
|
|
|
|
try { |
|
|
|
|
const tags = await getTagData(['qy', 'hy', 'st', 'wr'].join(',')) |
|
|
|
|
if (tags.code === 0 && tags.data) { |
|
|
|
|
let tagMap = {} |
|
|
|
|
tags.data.forEach(t => { |
|
|
|
|
// 将子项处理成选择器需要的格式 |
|
|
|
|
const children = t.children.map(child => ({ |
|
|
|
|
name: child.tagName, |
|
|
|
|
value: child.id, |
|
|
|
|
code: child.tagCode |
|
|
|
|
})) |
|
|
|
|
tagMap[t.tagCode] = children |
|
|
|
|
}) |
|
|
|
|
this.dictMap = tagMap |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
console.log(this.data) |
|
|
|
|
} catch (error) { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: '获取数据失败', |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 选择器确认回调 |
|
|
|
|
* @param {Object} e |
|
|
|
|
*/ |
|
|
|
|
confirmPicker(e) { |
|
|
|
|
confirmPicker(e) { |
|
|
|
|
const { value } = e |
|
|
|
|
this.form[this.picker.key] = value[0].value |
|
|
|
|
// 修改保存选中值的方式 |
|
|
|
|
this.form[this.picker.key] = { |
|
|
|
|
name: value[0].name, |
|
|
|
|
id: value[0].value, |
|
|
|
|
code: value[0].code, |
|
|
|
|
tagCode: this.picker.key // 添加标签类型 |
|
|
|
|
} |
|
|
|
|
this.closePicker() |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 关闭选择器 |
|
|
|
|
*/ |
|
|
|
@ -88,26 +167,38 @@ export default {
|
|
|
|
|
data: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
showPicker(tag) { |
|
|
|
|
this.picker.data.push(tag.children) |
|
|
|
|
this.picker.key = tag.name |
|
|
|
|
showPicker(type) { |
|
|
|
|
console.log(type,this.dictMap[type]) |
|
|
|
|
console.log(this.dictMap) |
|
|
|
|
this.picker.data = [this.dictMap[type] || []] |
|
|
|
|
this.picker.key = type |
|
|
|
|
this.picker.show = true |
|
|
|
|
}, |
|
|
|
|
submit() { |
|
|
|
|
const msg = Object.keys(this.form).filter(k => { |
|
|
|
|
if (this.form[k] == '') { |
|
|
|
|
return this.data.find(d => d.name == k).label |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
if (msg.length > 0) { |
|
|
|
|
// 校验所有字段是否已填写 |
|
|
|
|
if (!this.form.qy || !this.form.hy || !this.form.st || !this.form.wr) { |
|
|
|
|
const emptyFields = [] |
|
|
|
|
if (!this.form.qy) emptyFields.push('所在区域') |
|
|
|
|
if (!this.form.hy) emptyFields.push('行业类型') |
|
|
|
|
if (!this.form.st) emptyFields.push('所属生态') |
|
|
|
|
if (!this.form.wr) emptyFields.push('污染类型') |
|
|
|
|
|
|
|
|
|
uni.showToast({ |
|
|
|
|
icon: 'none', |
|
|
|
|
title: `${msg.join('\n')}不能为空` |
|
|
|
|
title: `请选择${emptyFields.join('、')}`, |
|
|
|
|
icon: 'none' |
|
|
|
|
}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
uni.$emit('enterpriseTag', this.form) |
|
|
|
|
console.log(this.form) |
|
|
|
|
|
|
|
|
|
// 构造提交的数据格式 |
|
|
|
|
const submitData = { |
|
|
|
|
qy: this.form.qy, |
|
|
|
|
hy: this.form.hy, |
|
|
|
|
st: this.form.st, |
|
|
|
|
wr: this.form.wr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uni.$emit('enterpriseTag', submitData) |
|
|
|
|
uni.navigateBack() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|