公寓小程序端前端代码
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.

182 lines
4.2 KiB

3 days ago
// subpages/mine/mySpace/mySpace.js
import { appointmentRecList } from "../../../api/index";
Page({
/**
* 页面的初始数据
*/
data: {
list: [],
pageNum: 1,
pageSize: 10,
total: 0,
loading: false,
refreshing: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.setData({
list: [],
pageNum: 1,
});
this.getList();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
this.setData({
refreshing: true,
pageNum: 1,
list: []
});
this.getList().finally(() => {
wx.stopPullDownRefresh();
this.setData({
refreshing: false
});
});
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {},
toReserve(e) {
wx.navigateTo({
url: `/subpages/space/reserve/reserve?id=${e.currentTarget.dataset.item.id}`,
});
},
getList() {
if (this.data.loading) return;
this.setData({
loading: true
});
let parm = {
pageSize: this.data.pageSize,
pageNum: this.data.pageNum,
};
return appointmentRecList(parm)
.then((res) => {
if (res.code === 200) {
const newData = res.data.records.map((item) => {
return {
...item,
// 格式化预约日期和时间
appointmentDate: item.appointmentDate || "",
appointTime: item.appointTime || "",
// 添加状态显示
statusText: this.getStatusText(item),
statusColor: this.getStatusColor(item)
};
});
this.setData({
list: this.data.pageNum === 1 ? newData : this.data.list.concat(newData),
total: res.data.total,
loading: false
});
}
})
.catch((err) => {
this.setData({
loading: false
});
wx.showToast({
title: err.msg || "获取数据失败",
duration: 2000,
icon: "none",
});
});
},
scrolltolower() {
if (this.data.loading) return;
if (this.data.list.length < this.data.total) {
this.setData({
pageNum: this.data.pageNum + 1,
});
this.getList();
} else if (this.data.list.length > 0) {
wx.showToast({
icon: "none",
title: "没有更多了",
});
}
},
toEvaluate(e) {
wx.navigateTo({
url: `/subpages/mine/evaluate/evaluate?id=${
e.currentTarget.dataset.item.checkInRecId
}&obj=${JSON.stringify({
apartmentName: e.currentTarget.dataset.item.apartmentName,
buildingName: e.currentTarget.dataset.item.buildingName,
buildingName: e.currentTarget.dataset.item.buildingName,
roomType: e.currentTarget.dataset.item.roomType,
unitName: e.currentTarget.dataset.item.unitName,
checkInRecId: e.currentTarget.dataset.item.checkInRecId,
houseName: e.currentTarget.dataset.item.houseName,
})}`,
});
},
// 获取状态文本
getStatusText(item) {
// 根据实际业务逻辑判断状态
const now = new Date();
const appointmentDate = new Date(item.appointmentDate);
if (appointmentDate > now) {
return '已预约';
} else if (appointmentDate.toDateString() === now.toDateString()) {
return '使用中';
} else {
return '已完成';
}
},
// 获取状态颜色
getStatusColor(item) {
const now = new Date();
const appointmentDate = new Date(item.appointmentDate);
if (appointmentDate > now) {
return '#17C4C4'; // 已预约 - 青色
} else if (appointmentDate.toDateString() === now.toDateString()) {
return '#FA9E0A'; // 使用中 - 橙色
} else {
return '#999'; // 已完成 - 灰色
}
},
});