feat: 新增需求

This commit is contained in:
caijun
2026-01-19 17:34:15 +08:00
parent 8fa31df250
commit 9f5b2a92c4
67 changed files with 7518 additions and 481 deletions

View File

@@ -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