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

157 lines
3.5 KiB

// 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 || "",
statusColor: this.getColorByStatus(item.currentStatus)
};
});
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,
})}`,
});
},
getColorByStatus(status) {
if (status === 1) return '#17C4C4';
if (status === 2) return '#FA9E0A';
return '#999';
}
});