vipCard.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. current: 0,
  11. list: [],
  12. total: 0,
  13. page: 1,
  14. visible: false,
  15. order_id: 0
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. this.getCardList()
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function () {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function () {
  52. if(this.data.page * 10 < this.data.total) {
  53. this.getCardList(++this.data.page)
  54. }
  55. },
  56. /**
  57. * 用户点击右上角分享
  58. */
  59. onShareAppMessage: function () {
  60. },
  61. /**
  62. * 切换状态
  63. */
  64. onTabsChange(e) {
  65. let current = e.currentTarget.dataset.id
  66. if(current == this.data.current) {
  67. return;
  68. }
  69. this.setData({
  70. current,
  71. page: 1,
  72. },() => {
  73. this.getCardList()
  74. })
  75. },
  76. /**
  77. * 打开激活弹框
  78. */
  79. onOpenPopup(e) {
  80. console.log(e)
  81. this.setData({
  82. visible:true,
  83. order_id:e.currentTarget.dataset.id
  84. })
  85. },
  86. /**
  87. * 暂不激活
  88. */
  89. onCancelUse() {
  90. this.setData({ visible: false })
  91. },
  92. /**
  93. * 确认激活
  94. */
  95. onConfirmUse(e) {
  96. let that = this;
  97. post('api/card/active',{
  98. order_id: this.data.order_id
  99. },(res) => {
  100. wx.showToast({
  101. title: res.msg,
  102. icon: 'none',
  103. })
  104. that.getCardList(1)
  105. this.setData({ visible: false })
  106. })
  107. },
  108. /**
  109. * 取消订单
  110. */
  111. onCancelOrder(e) {
  112. let that = this;
  113. wx.showModal({
  114. title: '提示',
  115. content: '是否取消当前订单',
  116. success (res) {
  117. console.log('用户点击确定')
  118. if (res.confirm) {
  119. post('api/card/refund',{
  120. order_id: e.currentTarget.dataset.id
  121. },(res) => {
  122. wx.showToast({
  123. title: res.msg,
  124. icon: 'success',
  125. duration: 2000
  126. })
  127. that.getCardList(1)
  128. })
  129. } else if (res.cancel) {
  130. console.log('用户点击取消')
  131. }
  132. }
  133. })
  134. },
  135. /**
  136. * 获取会员卡列表
  137. * /api/user/card
  138. */
  139. getCardList(_page) {
  140. let { list,current,page } = this.data;
  141. get('api/user/card',{
  142. type: Number(current)+1,
  143. page: _page || page,
  144. limit: 10
  145. },(res) => {
  146. if(_page == 1 || page == 1) {
  147. list = []
  148. this.data.page = 1
  149. }
  150. list.push(...res.data.list)
  151. this.setData({ list,total:res.data.total })
  152. console.log(res)
  153. })
  154. }
  155. })