fix:四级帮扶所属区域条件查询异常

This commit is contained in:
xuchao
2025-12-24 17:07:01 +08:00
parent 98677bf997
commit 74ff0b5238

View File

@@ -40,7 +40,7 @@
<!-- 所属区域下拉选择 -->
<view class="search-item">
<text class="label">所属区域</text>
<uni-data-picker ref="picker" class="picker" placeholder="请选择所属区域" popup-title="请选择所属区域" :localdata="regions" v-model="formData.helpArea"
<uni-data-picker ref="picker" class="picker" placeholder="请选择所属区域" popup-title="请选择所属区域" :localdata="regions" v-model="formData.deptTags"
@change="onchange" >
</uni-data-picker>
</view>
@@ -180,10 +180,11 @@ const initialForm = {
idCard: '',
taskType: '',
createByName: '',
helpArea: [],
startTime: '',
endTime: '',
deptId:''
// helpArea: [],
// startTime: '',
// endTime: '',
// deptId:'',
deptTags:''
}
const formData = reactive({ ...initialForm });
const taskTypeOptions=ref([])
@@ -228,12 +229,17 @@ const handleReset = () =>{
onMounted(async () => {
// await loadLevelData('201');
});
onLoad(async () => {
onLoad(() => {
let token=uni.getStorageSync('fourLevelLinkage-token')
if(token){
await loadLevelData('201');
getDictionary()
getDataList('refresh');
$api.myRequest("/system/user/login/user/info", {}, "GET", 9100, {
Authorization: `Bearer ${uni.getStorageSync("fourLevelLinkage-token")}`
}).then(async (resData) => {
await loadLevelData(resData.sysUser.dept.deptId);
getDictionary()
getDataList('refresh');
});
}else{
navTo('/packageB/login2');
}
@@ -259,7 +265,7 @@ function getTaskTypeLabelByValue(value) {
return item ? item.text : '暂无帮扶类型'
}
// 加载某一级的数据parentId 为空表示根)
async function loadLevelData(parentId) {
async function loadLevelData(parentId,node) {
let header = {
'Authorization': uni.getStorageSync('fourLevelLinkage-token'),
'Content-Type': "application/x-www-form-urlencoded"
@@ -274,15 +280,14 @@ async function loadLevelData(parentId) {
}
const formatted = (resData.data || []).map(item => ({
text: item.deptName,
value: item.deptId,
value: item.tags,
deptId: item.deptId,
children: []
}));
if (parentId === '201') {
// 第一层
regions.value = formatted;
} else {
// 找到父节点并注入 children
if(node){
injectChildren(parentId, formatted);
}else{
regions.value=formatted
}
} catch (error) {
console.error("加载部门数据失败:", error);
@@ -293,7 +298,7 @@ async function loadLevelData(parentId) {
function injectChildren(parentValue, childrenData) {
const findAndInject = (nodes) => {
for (let node of nodes) {
if (node.value === parentValue) {
if (node.deptId === parentValue) {
// 如果 children 已存在且非空,避免重复加载
if (!node.children || node.children.length === 0) {
node.children = childrenData;
@@ -313,7 +318,7 @@ function injectChildren(parentValue, childrenData) {
// 当用户选择时触发注意change 在每级选择后都会触发)
function onchange(e) {
const selectedValues = e.detail.value;
formData.deptId=selectedValues.map(item => item.value).join(',');
// formData.deptId=selectedValues.map(item => item.value).join(',');
if (selectedValues.length === 0) return;
// 获取最后一级选中的 value
const lastSelectedValue = selectedValues[selectedValues.length - 1];
@@ -322,7 +327,7 @@ function onchange(e) {
if (node && (!node.children || node.children.length === 0)) {
// 检查接口是否还有下一级(可通过接口返回判断,或先尝试加载)
// 这里我们直接尝试加载下一级
loadLevelData(lastSelectedValue.value);
loadLevelData(node.deptId , node);
picker.value.show()
}
}