123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import store from '../../store'
  2. import create from '../../utils/create'
  3. import fetch from '../../utils/http'
  4. import {
  5. get as getApi
  6. } from '../../config/api'
  7. const app = getApp()
  8. create(store, {
  9. onShow() {
  10. wx.setNavigationBarTitle({
  11. title: '我的福利社'
  12. })
  13. },
  14. onLoad() {
  15. let _self = this
  16. wx.getSystemInfo({
  17. success(res) {
  18. _self.setData({
  19. WindowHeight: res.windowHeight
  20. })
  21. }
  22. })
  23. this.GetList()
  24. },
  25. data: {
  26. list: [],
  27. DeleteIndex: null,
  28. IsNull: false,
  29. WindowHeight: 0,
  30. PostData: {
  31. pageNum: 1,
  32. pageSize: 10
  33. },
  34. IsLock: false,
  35. Total: 1
  36. },
  37. GetList() {
  38. if (!this.data.IsLock && this.data.list.length < this.data.Total) {
  39. this.setData({
  40. IsLock: true
  41. })
  42. let userInfo = app.globalData.UserInfo
  43. fetch({
  44. ...getApi('user.signUpList', {
  45. openid: userInfo.openid
  46. }),
  47. query: {
  48. ...this.data.PostData
  49. },
  50. }).then((res) => {
  51. let list = res.data.records || []
  52. let aArr = this.data.list || []
  53. list.map((item) => {
  54. aArr.push({ ...item, activityDate: item.activityDate.split(' ')[0]})
  55. })
  56. this.setData({
  57. list: aArr,
  58. Total: res.data.total,
  59. PostData: {
  60. ...this.data.PostData,
  61. pageNum: this.data.PostData.pageNum + 1
  62. }
  63. })
  64. this.setData({
  65. IsNull: !this.data.list.length
  66. })
  67. setTimeout(() => {
  68. this.setData({
  69. IsLock: false
  70. })
  71. }, 300)
  72. }).catch((err) => {
  73. wx.showToast({
  74. title: '获取列表失败',
  75. icon: 'none',
  76. })
  77. setTimeout(() => {
  78. this.setData({
  79. IsLock: false
  80. })
  81. }, 300)
  82. })
  83. }
  84. },
  85. ShowDeleteItem(e) { // 长按显示删除
  86. this.setData({
  87. DeleteIndex: e.target.dataset.index
  88. })
  89. },
  90. ResetDeleteIndex() { // 重置删除状态
  91. this.setData({
  92. DeleteIndex: null
  93. })
  94. },
  95. DeleteItem() { // 确认删除逻辑
  96. const delId = this.data.DeleteIndex
  97. this.ResetDeleteIndex()
  98. const _self = this
  99. wx.showModal({
  100. title: '确认',
  101. content: '确认要删除当前记录?',
  102. success(res) {
  103. if (res.confirm) {
  104. fetch({
  105. ...getApi('user.delAppointment', {
  106. id: delId
  107. }),
  108. }).then(() => {
  109. const list = _self.data.list.filter(x => x.appointmentId !== delId)
  110. _self.setData({
  111. list
  112. })
  113. }).catch((err) => {
  114. wx.showToast({
  115. title: '删除失败',
  116. icon: 'none',
  117. })
  118. })
  119. } else if (res.cancel) {
  120. console.log('用户点击取消')
  121. }
  122. }
  123. })
  124. },
  125. onShareAppMessage: function () {
  126. return app.globalData.ShareDate
  127. }
  128. })