feat: 新增需求
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
<selectBox v-model="innerValue" :placeholder="placeholder" @openSelect="openSelect" :select-open="selectShow"
|
||||
:disabled="disabled" />
|
||||
<SelectPopup v-model="selectShow" :multiple="multiple" :selectedData="selectedData" @close="handleClose"
|
||||
@confirm="handleConfirm" :selectType="selectType" :ableIds="ableIds" />
|
||||
@confirm="handleConfirm" :selectType="selectType" :type="type" :ableIds="ableIds" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import SelectPopup from './SelectPopup';
|
||||
import selectBox from '@/components/selectBox'
|
||||
import {
|
||||
getOrgSelectedList
|
||||
} from '@/api/common'
|
||||
// 移除接口导入:不再需要 getOrgSelectedList
|
||||
// import { getOrgSelectedList } from '@/api/common'
|
||||
|
||||
export default {
|
||||
name: 'jnpf-organize-select',
|
||||
components: {
|
||||
@@ -39,9 +39,17 @@
|
||||
type: String,
|
||||
default: 'all'
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'all'
|
||||
},
|
||||
ableIds: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
innerSelectedData: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@@ -53,24 +61,40 @@
|
||||
},
|
||||
watch: {
|
||||
modelValue: {
|
||||
handler() {
|
||||
this.setDefault()
|
||||
handler(val) {
|
||||
this.setDefault(val) // 传入modelValue,直接处理赋值
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
innerSelectedData: {
|
||||
handler(val) {
|
||||
if(val.length){
|
||||
const data = val[0]
|
||||
this.selectedData = val
|
||||
this.setDefault(data['id'])
|
||||
}
|
||||
},
|
||||
immediate: true,
|
||||
deep: true
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
setDefault() {
|
||||
if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
|
||||
const ids = this.multiple ? this.modelValue : [this.modelValue];
|
||||
getOrgSelectedList({
|
||||
ids
|
||||
}).then((res) => {
|
||||
if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
|
||||
const selectedData = res.data.list || []
|
||||
this.selectedData = selectedData
|
||||
this.innerValue = this.selectedData.map(o => o.orgNameTree).join();
|
||||
});
|
||||
// 重构setDefault:不再调用接口,直接处理赋值
|
||||
setDefault(val) {
|
||||
if (!val || !val.length) {
|
||||
return this.setNullValue();
|
||||
}
|
||||
// 场景1:父组件传入初始值(modelValue)时,直接匹配已选数据赋值
|
||||
// 如果没有初始选中数据,innerValue为空即可,无需请求接口
|
||||
// 重点:这里不再调用getOrgSelectedList,直接用已有的selectedData或空值
|
||||
|
||||
if (this.selectedData.length > 0) {
|
||||
// 有已选数据时,直接拼接名称
|
||||
this.innerValue = this.selectedData.map(o => o.deptName || o.orgNameTree).join();
|
||||
} else {
|
||||
// 无已选数据时,若modelValue是ID,暂时显示空(或根据需要处理)
|
||||
this.innerValue = '';
|
||||
}
|
||||
},
|
||||
setNullValue() {
|
||||
this.innerValue = '';
|
||||
@@ -80,7 +104,16 @@
|
||||
if (this.disabled) return
|
||||
this.selectShow = true
|
||||
},
|
||||
// 核心修改:确认选择时,直接用弹窗返回的原始数据赋值
|
||||
handleConfirm(selectedData, selectedIds) {
|
||||
// 1. 保存选中的原始数据
|
||||
this.selectedData = selectedData;
|
||||
// 2. 直接拼接名称到显示框(innerValue),无需接口
|
||||
this.innerValue = selectedData.map(o => o.deptName || o.orgNameTree).join();
|
||||
// 3. 向父组件传递选中值(保持原有逻辑)
|
||||
console.log(this.multiple,'this.multiple')
|
||||
console.log(selectedData[0],'selectedData[0]')
|
||||
console.log(selectedIds[0],'selectedIds[0]')
|
||||
if (!this.multiple) {
|
||||
this.$emit('update:modelValue', selectedIds[0])
|
||||
this.$emit('change', selectedIds[0], selectedData[0])
|
||||
@@ -88,6 +121,8 @@
|
||||
this.$emit('update:modelValue', selectedIds)
|
||||
this.$emit('change', selectedIds, selectedData)
|
||||
}
|
||||
// 4. 关闭弹窗
|
||||
this.selectShow = false;
|
||||
},
|
||||
handleClose() {
|
||||
this.selectShow = false
|
||||
|
||||
Reference in New Issue
Block a user