my.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // pointExchange/pages/my/my.js
  2. const app = getApp();
  3. import util from '../../../utils/util.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. appAssetsUrl:app.appAssetsUrl,
  10. typeList:[{
  11. name:'全部',
  12. value:''
  13. },{
  14. name:'未使用',
  15. value:1
  16. },{
  17. name:'已使用',
  18. value:2
  19. },{
  20. name:'已过期',
  21. value:3
  22. }],
  23. typeListIndex:0,
  24. nodata: util.nodata(),
  25. params: {
  26. sutId: util.getUserId(),
  27. pageNum: 1,
  28. pageSize: 10,
  29. status: ''
  30. },
  31. total:{
  32. currPage: 0,
  33. totalPage: 0
  34. },
  35. noMore:false,
  36. listData:[],
  37. itemData:{
  38. cdkey:'',
  39. needScore: '--'
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. if(options.index){
  47. this.setData({
  48. typeListIndex:options.index
  49. })
  50. }
  51. this.loadList(true);
  52. },
  53. switchType(e) {
  54. let index = e.currentTarget.dataset.index;
  55. this.setData({
  56. typeListIndex: index
  57. })
  58. this.loadList(true);
  59. },
  60. loadList(isRefresh) {
  61. let that = this;
  62. if (!isRefresh && this.data.noMore) {
  63. wx.showToast({
  64. title: '没有更多了~',
  65. icon: 'none'
  66. })
  67. return false;
  68. }
  69. this.setData({
  70. listData: isRefresh ? [] : this.data.listData,
  71. noMore: isRefresh ? false : this.data.noMore,
  72. params: {
  73. ...this.data.params,
  74. pageNum: isRefresh?1:this.data.params.pageNum+1,
  75. status: this.data.typeList[this.data.typeListIndex].value
  76. }
  77. })
  78. wx.showLoading({
  79. title: '努力加载中...',
  80. })
  81. app._post_form('productStu/page', '', this.data.params,
  82. function(res) {
  83. if (res.code == 0) {
  84. if(res.data.list.length>0 && that.data.listData.length>0 && res.data.list[0].id == that.data.listData[0].id){
  85. return ;
  86. }
  87. let listData = that.data.listData;
  88. listData.push(...res.data.list);
  89. that.setData({
  90. listData,
  91. currPage: res.data.currPage,
  92. totalPage: res.data.totalPage,
  93. noMore: res.data.totalPage == res.data.currPage
  94. })
  95. }
  96. })
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady: function () {
  102. this.popup3 = this.selectComponent("#popup3");
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. this.loadList();
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. },
  135. toDatail(e){
  136. wx.navigateTo({
  137. url: `/pointExchange/pages/detail/detail?id=${e.currentTarget.dataset.id}&isApply=true`
  138. })
  139. },
  140. //弹窗
  141. showPopup(e) {
  142. this[e.currentTarget.dataset.name].showPopup();
  143. this.setData({
  144. itemData:{
  145. ...this.data.itemData,
  146. needScore: e.currentTarget.dataset.needscore,
  147. cdkey: e.currentTarget.dataset.cdkey,
  148. }
  149. })
  150. },
  151. //取消事件
  152. _error(e) {
  153. this[e.currentTarget.dataset.name].hidePopup();
  154. },
  155. //使用卡券
  156. applyCoupon(e){
  157. this.popup3.hidePopup();
  158. let that = this;
  159. wx.showLoading({
  160. title: '提交中...',
  161. })
  162. app._post_form('productStu/use', "", {
  163. cdkey: this.data.itemData.cdkey,
  164. stuId: util.getUserId()
  165. }, function(res) {
  166. if (res.code === 0) {
  167. wx.showToast({
  168. title:'使用成功',
  169. icon:'none'
  170. })
  171. that.loadList(true);
  172. }
  173. })
  174. }
  175. })