Files
ClassContent/项目合集/校园失物招领/min-tpl/pages/history/history.js
2024-09-27 02:06:13 +08:00

136 lines
2.5 KiB
JavaScript

const {
user,
util
} = getApp().globalData
Page({
data: {
active: 0,
historyArr: [
{
title: '失物招领',
thing_type: 1,
content: []
},
{
title: '寻物启事',
thing_type: 2,
content: []
},
],
userInfo: {},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (util.checkIsLogin()) {
this.setData({ userInfo: wx.getStorageSync('user') });
this.setData({
active: options.id - 1
});
this.history();
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
async history() {
let { userInfo, historyArr, active } = this.data;
let res = await user.history({
user_id: userInfo.user_id,
thing_type: historyArr[active].thing_type
})
let temp = `historyArr[${active}].content`
this.setData({ [ temp ]: res })
},
async changeItemStatus(e) {
wx.showModal({
title: '',
content: '请确定已与【失主】或【物主】进行详细沟通并成功拿到丢失物品,一但确定不可取消!',
success: async (res) => {
if (res.confirm) {
let item = e.currentTarget.dataset.item;
if (item.thing_status == 0) {
let res = await user.changeStatus({
thing_status: !item.thing_status * true,
thing_id: item.thing_id,
user_id: item.user_id
})
util.showToast({
title: '更新成功',
icon: 'none',
duration: 2000,
close: () => {
this.history();
}
})
}
}
}
})
},
onChange(event) {
this.setData({ active: event.detail.name });
this.history();
},
enterInfo(e) {
wx.navigateTo({
url: `/pages/info/info?id=${e.currentTarget.dataset.id}`
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})