Files
foton-laws-system-front/src/components/hzwlComponents/personFormItem.vue
T

105 lines
2.3 KiB
Vue

<template>
<div>
<el-form-item :label="label" :prop="prop" class="add-form-item form-item-disabled">
<el-input
:value="value"
:placeholder="placeholder"
:clearable="clearable"
readonly
@click.native="choice('role', placeholder, value)">
></el-input>
</el-form-item>
<Role-tree
:is-title="choiceTitle"
:is-visible.sync="modalShowRoleFlag"
@checkedRole="checkedRole"
:nodeList="nodeList"
></Role-tree>
</div>
</template>
<script>
export default {
name: "personFormItem",
props: {
value: {
required: true
},
prop: {
type: String
},
label: {
type: String,
},
disabled: {
type: Boolean,
default: false
},
clearable: {
type: Boolean,
default: true
},
},
data () {
return {
choiceTitle: '', // 人员选择
modalShowRoleFlag: false,
nodeList: [],
}
},
computed: {
placeholder () {
return `选择${this.label}`
},
},
methods: {
handleChange (event) {
this.$emit('input', event)
},
choice(type, title, nameId) {
this.nodeList = []
if (nameId) {
let nameId1 = nameId.split(',')
let idList = []
nameId1.forEach(item => {
let a, b
a = item.substring(item.indexOf('(') +1)
b = a.substring(0, a.lastIndexOf(')'))
idList.push(b)
})
idList = idList.join(',')
// 管理员(admin),张兰英(zhanglanying) => ['admin', 'zhanglanying']
this.nodeList = idList.split(',')
}
this.choiceTitle = title
this.modalShowRoleFlag = true
},
checkedRole(data) {
let idList = ''
let nameList = ''
data.forEach(item => {
if (nameList.length > 0) {
nameList += ','
idList += ','
}
idList += item.id
nameList += item.name
})
this.$emit('input', nameList)
this.$emit('change', {
ids: this.unique(data.map(item => item.topUnitId)).join(","),
names: this.unique(data.map(item => item.topUnit)).join(",")
})
},
unique(newArr) {
const res = new Map();
return newArr.filter((newArr) => !res.has(newArr) && res.set(newArr, 1));
},
}
}
</script>
<style scoped>
</style>