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

374 lines
9.8 KiB

// 引入API配置
import { chooseRoomRecDetail, checkInRecDetail, getRenewalRecordByChooseRecId, checkOutInfo, dictDataList,getCheckInRecInfo } from '../../../api/index'
Page({
data: {
xfjlData: {},
rzjlData: {},
yzjlDataList: [],
tfjlData: null,
satisfiedZt: 0,
satisfiedHj: 0,
satisfiedFw: 0,
satisfiedTy: 0,
titleActiveCode: 0,
titleList: [
{ name: '选房记录' },
{ name: '入住记录' },
{ name: '延租记录' },
{ name: '退房记录' },
],
token: '',
userInfo: {},
queryData: {},
bankList: [],
forceCheckoutReasonDict:[],
forceCheckoutReason:''
},
onLoad(options) {
// 获取页面参数
console.log(options);
if (options.id) {
this.setData({
queryData: {
id: options.id,
checkInRecId: options.checkInRecId
}
});
}
this.dictDataList();
this.setData({
titleActiveCode: 0
});
this.getChooseRoomRecDetail(this.data.queryData.id);
},
// 处理时间格式
processTime(dateTimeStr) {
const date = new Date(dateTimeStr);
const hours = date.getHours();
if (hours === 9) {
return dateTimeStr.slice(0, 16) + '-12:00';
} else {
return dateTimeStr.slice(0, 16) + '-18:00';
}
},
// 计算居住天数
calculateStayDays() {
const tfjlData = this.data.tfjlData;
if (!tfjlData.checkInDate || !tfjlData.actualCheckOutTime) {
return '';
}
try {
const checkInDate = new Date(tfjlData.checkInDate);
const checkOutDate = new Date(tfjlData.actualCheckOutTime);
// 计算时间差(毫秒)
const timeDiff = checkOutDate.getTime() - checkInDate.getTime();
// 转换为天数
const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
// 如果入住时间晚于退房时间,返回0
if (daysDiff < 0) {
return '0天';
}
return `${daysDiff}`;
} catch (error) {
console.error('计算居住天数失败:', error);
return '计算失败';
}
},
// 获取银行名称
getBankName(value) {
const bank = this.data.bankList.find(item => item.value == value);
return bank ? bank.label : '';
},
// 获取字典数据
dictDataList() {
dictDataList({ dictType: 'bank_list' }).then(res => {
if (res.code == 200) {
this.setData({
bankList: res.rows.map(item => ({
value: item.dictValue,
label: item.dictLabel,
}))
});
}
})
dictDataList({ dictType: 'forceCheckoutReason' }).then(res => {
if (res.code == 200) {
this.setData({
forceCheckoutReasonDict: res.rows.map(item => ({
value: item.dictValue,
label: item.dictLabel,
}))
});
}
})
// wx.request({
// url: api.dictDataList,
// method: 'GET',
// header: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer ' + this.data.token
// },
// data: {
// dictType: 'bank_list',
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200) {
// const deptArray = data.rows.length > 0 && data.rows.map(item => ({
// value: item.dictValue,
// label: item.dictLabel,
// }));
// this.setData({
// bankList: deptArray
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 预览图片
handleDcwjClick() {
const url = this.data.tfjlData.mzCheckOutRec.deliveryReceiptUrl;
wx.previewImage({
urls: [url],
current: url
});
},
handleDcwjClick1(e) {
const url = e.currentTarget.dataset.url;
wx.previewImage({
urls: [url],
current: url
});
},
// 获取选房记录详情
getChooseRoomRecDetail(id) {
chooseRoomRecDetail({ chooseRoomRecId: id }).then(res => {
if (res.code == 200) {
this.setData({
xfjlData: res.data
});
}
});
// wx.request({
// url: api.chooseRoomRecDetail,
// method: 'GET',
// header: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer ' + this.data.token
// },
// data: {
// chooseRoomRecId: id,
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200) {
// this.setData({
// xfjlData: data.data
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 获取入住记录详情
getCheckInRecDetail(id) {
checkInRecDetail({ checkInRecId: id }).then(res => {
if (res.code == 200) {
this.setData({
rzjlData: {
...this.data.rzjlData,
...res.data
}
});
}
});
// wx.request({
// url: api.checkInRecDetail,
// method: 'GET',
// header: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer ' + this.data.token
// },
// data: {
// checkInRecId: id,
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200) {
// this.setData({
// rzjlData: {
// ...this.data.rzjlData,
// ...data.data
// }
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 获取入住记录信息
getCheckInRecInfo(id) {
getCheckInRecInfo({ chooseRecId: id }).then(res => {
if (res.code == 200) {
this.setData({
rzjlData: {
...this.data.rzjlData,
...res.data.data
}
});
}
});
// wx.request({
// url: api.getCheckInRecInfo,
// method: 'GET',
// header: {
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer ' + this.data.token
// },
// data: {
// chooseRecId: id,
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200) {
// this.setData({
// rzjlData: {
// ...this.data.rzjlData,
// ...data.data
// }
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 获取延租记录
getRenewalRecordByChooseRecId(id) {
getRenewalRecordByChooseRecId({chooseRecId: id}).then(res => {
if (res.code == 200) {
this.setData({
yzjlDataList: res.data
});
}else{
this.setData({
yzjlDataList: []
});
}
});
// wx.request({
// url: api.getRenewalRecordByChooseRecId + id,
// method: 'GET',
// header: {
// 'Authorization': 'Bearer ' + this.data.token,
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200) {
// this.setData({
// yzjlDataList: data.data
// });
// } else {
// this.setData({
// yzjlDataList: []
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 获取退房信息
getCheckOutInfo(id) {
checkOutInfo({mzChooseRoomRecId: id}).then(res => {
if (res.code == 200) {
const forceCheckoutReason = this.data.forceCheckoutReasonDict.find(item => item.value == res.data.mzCheckOutRec.forceCheckoutReason);
console.log(forceCheckoutReason);
this.setData({
tfjlData: res.data,
forceCheckoutReason: forceCheckoutReason.label || '',
satisfiedZt: (res.data.mzCheckInEvaluate && res.data.mzCheckInEvaluate.satisfiedZt) || 0,
satisfiedHj: (res.data.mzCheckInEvaluate && res.data.mzCheckInEvaluate.satisfiedHj) || 0,
satisfiedFw: (res.data.mzCheckInEvaluate && res.data.mzCheckInEvaluate.satisfiedFw) || 0,
satisfiedTy: (res.data.mzCheckInEvaluate && res.data.mzCheckInEvaluate.satisfiedTy) || 0
});
}
});
// wx.request({
// url: api.checkOut,
// method: 'GET',
// header: {
// 'Authorization': 'Bearer ' + this.data.token,
// },
// data: {
// mzChooseRoomRecId: id,
// },
// success: (res) => {
// const data = res.data;
// if (data.code == 200 && data.data != null) {
// this.setData({
// tfjlData: data.data,
// satisfiedZt: (data.data.mzCheckInEvaluate && data.data.mzCheckInEvaluate.satisfiedZt) || 0,
// satisfiedHj: (data.data.mzCheckInEvaluate && data.data.mzCheckInEvaluate.satisfiedHj) || 0,
// satisfiedFw: (data.data.mzCheckInEvaluate && data.data.mzCheckInEvaluate.satisfiedFw) || 0,
// satisfiedTy: (data.data.mzCheckInEvaluate && data.data.mzCheckInEvaluate.satisfiedTy) || 0
// });
// }
// },
// fail: (error) => {
// console.error('出错:', error);
// }
// });
},
// 点击标签切换
handleClickInfo(e) {
const index = e.currentTarget.dataset.index;
this.setData({
titleActiveCode: index
});
switch (index) {
case 0:
this.getChooseRoomRecDetail(this.data.queryData.id);
break;
case 1:
this.setData({
rzjlData: {}
});
this.getCheckInRecDetail(this.data.queryData.checkInRecId);
this.getCheckInRecInfo(this.data.queryData.id);
break;
case 2:
this.getRenewalRecordByChooseRecId(this.data.queryData.id);
break;
case 3:
this.getCheckOutInfo(this.data.queryData.id);
break;
}
},
});