import store from '../../store' import create from '../../utils/create' import fetch from '../../utils/http' import { get as getApi } from '../../config/api' const app = getApp() create(store, { onShow() { wx.setNavigationBarTitle({ title: '我的福利社' }) }, onLoad() { let _self = this wx.getSystemInfo({ success(res) { _self.setData({ WindowHeight: res.windowHeight }) } }) this.GetList() }, data: { list: [], DeleteIndex: null, IsNull: false, WindowHeight: 0, PostData: { pageNum: 1, pageSize: 10 }, IsLock: false, Total: 1 }, GetList() { if (!this.data.IsLock && this.data.list.length < this.data.Total) { this.setData({ IsLock: true }) let userInfo = app.globalData.UserInfo fetch({ ...getApi('user.signUpList', { openid: userInfo.openid }), query: { ...this.data.PostData }, }).then((res) => { let list = res.data.records || [] let aArr = this.data.list || [] list.map((item) => { aArr.push({ ...item, activityDate: item.activityDate.split(' ')[0]}) }) this.setData({ list: aArr, Total: res.data.total, PostData: { ...this.data.PostData, pageNum: this.data.PostData.pageNum + 1 } }) this.setData({ IsNull: !this.data.list.length }) setTimeout(() => { this.setData({ IsLock: false }) }, 300) }).catch((err) => { wx.showToast({ title: '获取列表失败', icon: 'none', }) setTimeout(() => { this.setData({ IsLock: false }) }, 300) }) } }, ShowDeleteItem(e) { // 长按显示删除 this.setData({ DeleteIndex: e.target.dataset.index }) }, ResetDeleteIndex() { // 重置删除状态 this.setData({ DeleteIndex: null }) }, DeleteItem() { // 确认删除逻辑 const delId = this.data.DeleteIndex this.ResetDeleteIndex() const _self = this wx.showModal({ title: '确认', content: '确认要删除当前记录?', success(res) { if (res.confirm) { fetch({ ...getApi('user.delAppointment', { id: delId }), }).then(() => { const list = _self.data.list.filter(x => x.appointmentId !== delId) _self.setData({ list }) }).catch((err) => { wx.showToast({ title: '删除失败', icon: 'none', }) }) } else if (res.cancel) { console.log('用户点击取消') } } }) }, onShareAppMessage: function () { return app.globalData.ShareDate } })