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