couponList.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/orderDetail/orderDetail.js
  2. const app = getApp()
  3. import Order from '../../api/order'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. nextPage: 1,
  10. companyName: "康道"
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function (options) {
  16. },
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onReady: function () {
  21. },
  22. /**
  23. * 生命周期函数--监听页面显示
  24. */
  25. onShow: async function () {
  26. await app.wxLogin({"type":"slince"})
  27. const userInfo = await app.getWxUserInfo()
  28. this.setData({
  29. userInfo
  30. })
  31. if (!userInfo.mobile) {
  32. return
  33. }
  34. await this.couponList('init')
  35. },
  36. async couponList(type) {
  37. const self = this
  38. if (type === "init") {
  39. self.setData({
  40. nextPage: 1
  41. })
  42. }
  43. const data = {
  44. phone: this.data.userInfo.mobile,
  45. nextPage: self.data.nextPage,
  46. pageSize: 10
  47. }
  48. const rs = await Order.couponList(data)
  49. if (type == "pull") {
  50. const data = self.data.list.concat(rs.records)
  51. self.setData({
  52. list: data,
  53. maxPage: rs.totalPage
  54. })
  55. }else {
  56. self.setData({
  57. list: rs.records,
  58. // list: [],
  59. maxPage: rs.totalPage
  60. })
  61. }
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. let page = this.data.nextPage
  83. let maxPage = this.data.maxPage
  84. if (page >= maxPage) {
  85. wx.showToast({
  86. title: '亲,到底了哦!', // 内容
  87. });
  88. return
  89. }
  90. this.setData({
  91. nextPage: page + 1
  92. })
  93. this.couponList('pull')
  94. },
  95. /**
  96. * 用户点击右上角分享
  97. */
  98. onShareAppMessage: function () {
  99. },
  100. jumpBuy (e) {
  101. const sn = e.currentTarget.dataset.sn
  102. const name = e.currentTarget.dataset.name
  103. const status = e.currentTarget.dataset.status
  104. if (status == 2 || status == 3) {
  105. return
  106. }
  107. wx.navigateTo({
  108. url: `/pages/qrCode/qrCode?sn=${sn}&name=${name}`,
  109. })
  110. },
  111. getMobile: async function (params) {
  112. console.log(params);
  113. let _self = this
  114. const data = {
  115. encryptedData:params.detail.encryptedData,
  116. iv: params.detail.iv
  117. }
  118. const userInfo = await app.getPhoneNumber(data)
  119. console.log(userInfo)
  120. let hasMobile = false
  121. if (userInfo.mobile > 1) {
  122. hasMobile:true
  123. }
  124. _self.setData({
  125. hasMobile: hasMobile,
  126. mobile: userInfo.mobile,
  127. userInfo
  128. })
  129. _self.couponList('init')
  130. },
  131. })