2024-03-09 14:24:42 +08:00

178 lines
4.1 KiB
JavaScript

import {
visitorListRq,
visitorSelectUserByCustomerRq,
} from "../../../../api/meeting/visitorIinvitation.js"
Page({
data: {
title: '',
/** 索引栏*/
indexList: [],
/** 数据*/
dataList: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let _this = this;
_this.setData({
...options
})
wx.setNavigationBarTitle({
title: '请选择' + options.title,
})
//
//
if (_this.data.title == '单位') {
// 获取所有的企业
_this.getVisitorList()
}
if (_this.data.title == '人员') {
// 获取企业下的所有用户
_this.getVisitorSelectUserByCustomer()
}
},
// 获取所有的企业
getVisitorList() {
let _this = this;
visitorListRq().then(res => {
console.log('getVisitorList', res);
let filterDataList = res.rows.map(item => {
let otherData = JSON.stringify({
id: item.id,
name: item.name,
mailAddress: item.mailAddress,
})
return {
label: item.name,
value: item.id,
otherData
}
})
// 赋值并且格式化数据
_this.setAndFormatData(filterDataList)
})
},
// 获取企业下的所有用户
getVisitorSelectUserByCustomer() {
visitorSelectUserByCustomerRq().then(res => {
console.log('getVisitorSelectUserByCustomer', res);
})
},
// 格式化数据
setAndFormatData(transferList) {
let _this = this;
// 索引列
let indexList = _this.getFirstCharacterList(transferList)
// 对应每个索引的数据列表
let dataList = indexList.map(item => {
let title = item;
let collectList = [];
for (let i = 0; i < transferList.length; i++) {
let transferData = transferList[i];
if (title == transferData.label.substring(0, 1)) {
collectList.push(transferData)
}
}
return {
title,
list: collectList
}
})
_this.setData({
indexList,
dataList
})
},
// 获取第一个字符数组,不重复
getFirstCharacterList(list) {
let firstNameList = list.map(item => {
return {
name: item.label.substring(0, 1),
exist: false
}
});
for (let i = 0; i < firstNameList.length; i++) {
for (let j = i + 1; j < firstNameList.length; j++) {
// 已重复的数据直接跳过
if (firstNameList[j].exist) {
continue;
}
// 数据重复
if (firstNameList[i].name == firstNameList[j].name) {
firstNameList[j].exist = true;
}
}
}
return firstNameList.filter(item => !item.exist).map(item => item.name)
},
// 选择
selectClick(e) {
console.log('selectClick', e);
let label = e.currentTarget.dataset.label
let value = e.currentTarget.dataset.value
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})