epmet 工作端 小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
9.1 KiB

// subpages/resnoinformation/pages/resnoinformation/resnoinformation.js
import api, {
getTopTree,
waitCollectHouseList,
nonIntResiList,
recorHistory
} from "../../../../utils/api"
var http = require('../../../../utils/request.js')
// var fly = require('../../../../utils/request')
Page({
data: {
dicts: {
attentioncrowdList: [], // 注意群体列表
},
selectedAttentionCrowd: '', // 用户选择的注意群体
specialValue:'',//特殊信息的value
dictType:[],
showResident:false,
showStreet:false,
// 联级选择器的列表
angencyList:[],
// 联级字段的名称
fieldName: {
text: 'label',
value: 'id',
children: 'children'
},
// 联级选择器的默认值
cascaderValue:'',
// 显示长度
maxLength:10,
// value返回的值
cascaderName:null,
//显示菜单
showStreet:false,
level:'',
//查询参数
lowerThreshold:8,//
pageNo: 1,//当前页码
loadMoreType: "more",//more的出发加载更多数据
waitList:[],//数据列表
pageSize: 10,//每页的条数
loadMoreVisible:false,//显示更多
nodata:false,
orgId:'',
resiCategory:'',
resiCategories: [],
resultScopeType:'nonIntegrity'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getDicts()
this.getTopTreeData()
this.WaitResidentsList()
},
// 进行树状懒加载
getTopTreeData() {
getTopTree().then(res => {
// 用map获取子节点的值,并返回给arr,并让children: []为空
const arr = res.data.children.map(item => {
return {
...item,
children: []
}
})
this.setData({
// 将值赋给angencyList
angencyList: [{ ...res.data, children: arr }],
})
})
},
onChange(e) {
// value等于 e.detail.value
const { value, tabIndex, selectedOptions } = e.detail;
console.log(e.detail)
console.log(selectedOptions)
this.setData({
cascaderName:e.detail.selectedOptions.map(item => item.label).join(' ')
})
// 判断是否是第二层,并且最后自己的level部位building
if (tabIndex > 0 && selectedOptions[selectedOptions.length - 1].level != 'building') {
const level = selectedOptions[selectedOptions.length - 1].level
// level和id等于value进行作为参数
api.getNextTree({ level, id: value }).then(res => {
if (res.data.length > 0) {
const data = res.data.map(item => {
if (item.level != 'building') {
return {
...item,
children: []
}
}
return {
...item,
children: null
}
});
const arr = this.getTreeFun(value, this.data.angencyList, data);
this.setData({
angencyList: arr,
})
} else {
const arr = this.getTreeFun(value, this.data.angencyList, null);
this.setData({
angencyList: arr,
})
}
})
}
},
getTreeFun(id, arr, data) {
return arr.map(item => {
// 如果id等于子节点的id直接返回
if (id == item.id) {
return {
...item,
children: data,
}
}
if (item.children && item.children.length > 0) {
return {
...item,
children: this.getTreeFun(id, item.children, data),
}
}
return item
})
},
onFinish(e) {
// 从e中获取selectedOptions的值
const { selectedOptions, value } = e.detail;
const level = selectedOptions[selectedOptions.length - 1].level
this.setData({
// 将获取的值遍历成jason字符串
cascaderName: e.detail.selectedOptions.map(item => item.label).join(' '),
showStreet: false,
level:level
});
selectedOptions.forEach(option => {
// 如果该对象有children属性且不为null
if (option.children !== null) {
// 遍历children数组中的每个对象
option.children.forEach(child => {
// 输出每个child对象的id属性
this.setData({
orgId:child.id
})
});
}
});
if(this.data.cascaderName.length>=this.data.maxLength){
this.setData({
cascaderName :this.data.cascaderName.substring(0, this.data.maxLength) + '...'
})
}
},
onClose() {
this.setData({
showStreet: false,
});
},
onShowPoint(){
this.setData({
showStreet:true
})
},
onclickResident(){
this.setData({
showResident:true,
})
},
// 查询字典
async getDicts() {
try {
const requests = [
http.post("sys/dict/data/dictlist", {
dictType: "attention_crowd",
}),
];
const result = await http.post("sys/dict/data/dictlist", { dictType: "attention_crowd" });
if (result.code === 0) {
this.setData({
"dicts.attentioncrowdList": result.data
})
} else {
console.log("获取注意群体失败: ", result.data.msg);
}
} catch (error) {
console.log("获取字典失败: ", error);
}
},
// 获取字典的索引显示到页面上
onAttentionCrowdChange(event) {
const index = event.detail.value; // 用户选择的注意群体在字典数据数组中的索引
const selectedAttentionCrowd = this.data.dicts.attentioncrowdList[index]; // 根据索引获取选择的注意群体
this.setData({
selectedAttentionCrowd: selectedAttentionCrowd.label, // 更新选择的注意群体
specialValue:selectedAttentionCrowd.value
});
},
//查询居民信息不完整列表
WaitResidentsList(){
if (this.data.loadMoreType === 'none') {
// 如果已经没有更多数据可以加载,则直接返回
return;
}
let parm={
orgId:this.data.orgId,
pageSize: this.data.pageSize,
pageNo: this.data.pageNo,
orgType:this.data.level,
resiCategory:this.data.specialValue,
updateId:'',
resultScopeType:this.data.resultScopeType
}
api.nonIntResiList(parm).then(res => {
const { data, code } = res;
if(code===0){
const newList =data.list;
if(newList.length===0){
this.setData({
orgId:this.data.cascaderValue,
loadMoreVisible: false,
nodata: true,
loadMoreType: 'none',
});
}
else{
this.setData({
waitList: this.data.waitList.concat(newList),
pageNo: this.data.pageNo + 1,
resiCategories: this.data.waitList.map(item => item.resiCategories).flat()
});
}
}
else {
// 请求失败时处理错误信息
console.error('请求失败:', res.data.msg);
}
})
this.setData({
resiCategories: this.data.waitList.map(item => item.resiCategories).flat()
})
},
// 当到达底部时,触发事件
onScrollToLower(e) {
if (this.data.loadMoreType === 'more') {
this.setData({
// 显示更多加载
loadMoreVisible: true,
})
this.data.pageNo += 1
this.getTableData()
}
},
// 向下分页下来
getTableData: async function () {
try {
this.setData({
loadMoreVisible: true,
nodata: false,
loadMoreType: "more",
})
let parm = {
orgId:this.data.orgId,
pageSize: this.data.pageSize,
pageNo: this.data.pageNo,
orgType:this.data.level,
resiCategory:this.data.specialValue,
updateId:'',
resultScopeType:this.data.resultScopeType
}
// 从waitCollectHouseList取返回的值
let {
data,
code,
msg
} = await nonIntResiList(parm)
if (code == 0) {
this.setData({
// 获取数据的长度等于页面的显示的长度
loadMoreType: data.list.length === this.data.pageSize ? 'more' : 'none',
// 将返回的值,合并到waitList中
waitList: this.data.waitList.concat(data.list),
})
if (this.data.waitList.length == 0) {
this.setData({
loadMoreVisible: false,
nodata: true
})
}
} else {
this.setData({
loadMoreVisible: false,
nodata: true,
loadMoreType: 'none'
})
}
} catch (err) {
console.log(err);
this.setData({
loadMoreVisible: false,
nodata: true,
loadMoreType: 'none'
})
}
},
//筛选按钮
onScreen(){
this.setData({
waitList:[],
pageNo:1,
loadMoreType:'more'
})
this.WaitResidentsList()
},
toResiDetail(e) {
wx.navigateTo({
url: `/subpages/searchResult/pages/resiInfo/resiInfo?resiId=${e.currentTarget.dataset.resiid}`,
})
}
})