查询条件修改

This commit is contained in:
2026-03-11 14:08:36 +08:00
parent d78779741a
commit 5374b12797
2 changed files with 207 additions and 11 deletions

View File

@@ -28,7 +28,10 @@
</view>
<view class="search-item">
<text class="label">所属区域</text>
<uni-data-select v-model="formData.deptTags" :localdata="taskTypeOptions" placeholder="请选择所属区域" @change="onTaskTypeChange"></uni-data-select>
<uni-data-picker ref="picker" class="picker" placeholder="请选择所属区域" popup-title="请选择所属区域" :localdata="regions" v-model="formData.deptTags"
@change="onchange" >
</uni-data-picker>
<!-- <uni-data-select v-model="formData.deptTags" :localdata="taskTypeOptions" placeholder="请选择所属区域" @change="onTaskTypeChange"></uni-data-select> -->
</view>
</view>
</view>
@@ -221,6 +224,109 @@ const getBackgroundStyle = (imageName) => ({
backgroundRepeat: 'no-repeat'
});
const emit = defineEmits(['update:showVue'])
// 所属区域选项(可根据实际替换为动态数据)
const regions = ref([])
const picker = ref(null)
function listNotParam(){
let header={
'Authorization':uni.getStorageSync('Padmin-Token'),
'Content-Type': "application/x-www-form-urlencoded"
}
let params={}
$api.myRequest('/dispatch/dept/listNotParam',params,'get',9100,header).then((resData) => {
if(resData && resData.code == 200){
loadLevelData(resData.data[0].parentId);
// resData.data.forEach(item=>{
// const obj = {
// value: item.deptId,
// text: item.deptName,
// ancestors:item.ancestors
// }
// executeDeptOptions.value.push(obj)
// })
}
});
}
// 加载某一级的数据parentId 为空表示根)
async function loadLevelData(parentId,node) {
let header = {
'Authorization': uni.getStorageSync('Padmin-Token'),
'Content-Type': "application/x-www-form-urlencoded"
};
let params = { parentId };
try {
const resData = await $api.myRequest('/dispatch/dept/list', params, 'get', 9100, header);
if(resData.data.length==0){
picker.value.hide()
return
}
const formatted = (resData.data || []).map(item => ({
text: item.deptName,
value: item.tags,
deptId: item.deptId,
children: []
}));
if(node){
injectChildren(parentId, formatted);
}else{
regions.value=formatted
}
} catch (error) {
console.error("加载部门数据失败:", error);
// uni.showToast({ title: '加载失败', icon: 'none' });
}
}
// 将子级数据注入到对应的父节点
function injectChildren(parentValue, childrenData) {
const findAndInject = (nodes) => {
for (let node of nodes) {
if (node.deptId === parentValue) {
// 如果 children 已存在且非空,避免重复加载
if (!node.children || node.children.length === 0) {
node.children = childrenData;
}
return true;
}
if (node.children && node.children.length > 0) {
if (findAndInject(node.children)) return true;
}
}
return false;
}
findAndInject(regions.value);
// 强制更新
}
// 当用户选择时触发注意change 在每级选择后都会触发)
function onchange(e) {
const selectedValues = e.detail.value;
// formData.deptId=selectedValues.map(item => item.value).join(',');
if (selectedValues.length === 0) return;
// 获取最后一级选中的 value
const lastSelectedValue = selectedValues[selectedValues.length - 1];
// 查找该节点是否有 children如果没有则尝试加载
const node = findNodeByValue(regions.value, lastSelectedValue);
if (node && (!node.children || node.children.length === 0)) {
// 检查接口是否还有下一级(可通过接口返回判断,或先尝试加载)
// 这里我们直接尝试加载下一级
loadLevelData(node.deptId , node);
picker.value.show()
}
}
// 工具函数:根据 value 查找节点
function findNodeByValue(nodes, value) {
for (let node of nodes) {
if (node.value === value.value) {
return node;
}
if (node.children && node.children.length > 0) {
const found = findNodeByValue(node.children, value);
if (found) return found;
}
}
return null;
}
function getDictionary(){
$api.myRequest('/system/public/dict/data/type/person_database_status').then((resData) => {
if(resData && resData.code == 200){
@@ -348,6 +454,7 @@ function scrollBottom(){
}
}
onLoad((options) => {
listNotParam()
if(options.allocationId){
formData.allocationId=options.allocationId
}