181 lines
4.5 KiB
JavaScript
Raw Normal View History

2024-07-30 16:33:21 +08:00
import {
visitorListRq,
visitorSelectUserByCustomerRq,
} from "../../../../api/meeting/visitorIinvitation.js"
Page({
data: {
title: '',
id: null,
/** 索引栏*/
indexList: [],
/** 数据*/
dataList: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let _this = this;
_this.setData({
...options
})
// 获取所有的企业
_this.getVisitorList()
},
// 获取所有的企业
getVisitorList() {
let _this = this;
visitorListRq().then(res => {
console.log('getVisitorList', res);
let filterDataList = res.rows.map(item => {
return {
label: item.name,
otherData: JSON.stringify({
id: item.id,
name: item.name,
})
}
})
// 赋值并且格式化数据
_this.setAndFormatData(filterDataList)
})
},
// 格式化数据
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 _this = this;
// 获取点击行数据
let label = e.currentTarget.dataset.label
let otherdata = JSON.parse(e.currentTarget.dataset.otherdata)
//
let pages = getCurrentPages(); //获取page
let prevPage = pages[pages.length - 2]; //上一个页面(父页面)
// 上个页面数据
let detail = prevPage.data.detail;
// 更新上个页面对应的数据
if (_this.data.title == '单位') {
detail.customerId = otherdata.id //企业id
detail.customerName = otherdata.name //企业名称
detail.userId = null //被访人id
detail.username = null //被访人姓名
detail.mobile = null //被访人手机号
}
if (_this.data.title == '人员') {
detail.userId = otherdata.id //被访人id
detail.username = otherdata.username //被访人姓名
detail.mobile = otherdata.mobile //被访人手机号
}
// 赋值上个页面的数据
prevPage.setData({
detail
})
// 后退页面
wx.navigateBack();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})