225 lines
5.6 KiB
JavaScript
Raw Normal View History

2024-09-02 12:00:01 +08:00
const app = getApp()
import Notify from '@vant/weapp/notify/notify';
2024-08-27 14:25:22 +08:00
import {
2024-09-02 12:00:01 +08:00
getChangyangPersonListRq,
updatePersonListRq
2024-08-27 14:25:22 +08:00
} from "../../../../api/meeting/visitorIinvitation.js"
Page({
data: {
/** 索引栏*/
indexList: [],
/** 数据*/
dataList: [],
//
2024-09-02 12:00:01 +08:00
reservationId: null,
roomContentId: null,
2024-08-27 14:25:22 +08:00
ids: [],
2024-09-02 12:00:01 +08:00
pageType: '',
userData: null,
2024-08-27 14:25:22 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let _this = this;
2024-09-02 12:00:01 +08:00
options.ids = JSON.parse(options.ids)
//
2024-08-27 14:25:22 +08:00
_this.setData({
2024-09-02 12:00:01 +08:00
...options,
userData: wx.getStorageSync('user'),
2024-08-27 14:25:22 +08:00
})
//
// 获取数据
_this.getDataList()
},
// 获取数据
getDataList() {
let _this = this;
getChangyangPersonListRq().then(res => {
console.log('getChangyangPersonListRq', res);
let filterDataList = res.data.map(item => {
let id = item.id
let label = `${item.name ? item.name : item.mobile}-${item.mobile}`
let isSelect = false
//
if (_this.data.ids.includes(id)) {
isSelect = true
}
return {
id,
label,
isSelect,
}
})
// 赋值并且格式化数据
_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 id = e.currentTarget.dataset.data.id
let dataList = _this.data.dataList
dataList.map(data => {
data.list.map(item => {
if (item.id == id) {
item.isSelect = !item.isSelect
}
})
return data
})
_this.setData({
dataList
})
},
// 提交
submit() {
let _this = this;
2024-09-02 12:00:01 +08:00
let pageType = _this.data.pageType
2024-08-27 14:25:22 +08:00
let personList = []
_this.data.dataList.map(data => {
personList = personList.concat(data.list.filter(item => item.isSelect))
})
//
let pages = getCurrentPages(); //获取page
let prevPage = pages[pages.length - 2]; //上一个页面(父页面)
// 上个页面数据
// let detail = prevPage.data.detail;
2024-09-02 12:00:01 +08:00
if (pageType == 'add') { // 添加
// 赋值上个页面的数据
prevPage.setData({
reservationPersonList: personList
})
} else if (pageType == 'update') { // 修改
updatePersonListRq({
userId: _this.data.userData.id,
roomContentId: _this.data.roomContentId,
id: _this.data.reservationId,
reservationPersonList: personList.map(item => {
return {
userId: item.id,
roomContentId: _this.data.roomContentId
}
})
}).then(res => {
console.log('updatePersonListRq', res);
if (res.code == 0) {
app.vantNotifySuccess(Notify, res.msg)
} else {
app.vantNotifyErr(Notify, res.msg)
}
})
}
2024-08-27 14:25:22 +08:00
// 后退页面
wx.navigateBack();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})