person.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/person/person.js
  2. const app = getApp()
  3. import Order from '../../api/order'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. hasUserInfo: false,
  10. canWriteOff: 'no'
  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. let userInfo = await app.getWxUserInfo()
  28. if (userInfo) {
  29. console.log(userInfo)
  30. this.setData({
  31. userInfo: userInfo,
  32. hasUserInfo: userInfo.avatarUrl.length > 1 ? true :false,
  33. hasMobile: userInfo.mobile ? true : false
  34. })
  35. }
  36. if (userInfo.mobile) {
  37. const rs = await Order.writeOffStaff({phone: userInfo.mobile})
  38. this.setData({
  39. canWriteOff: rs.canWriteOff
  40. })
  41. }
  42. },
  43. /**
  44. * 生命周期函数--监听页面隐藏
  45. */
  46. onHide: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面卸载
  50. */
  51. onUnload: function () {
  52. },
  53. /**
  54. * 页面相关事件处理函数--监听用户下拉动作
  55. */
  56. onPullDownRefresh: function () {
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom: function () {
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. },
  68. getInfo: async function () {
  69. const _self = this
  70. // let userInfo = e.detail.userInfo
  71. // userInfo['encryptedData'] = e.detail.encryptedData
  72. // userInfo['iv'] = e.detail.iv
  73. let userInfo = {}
  74. userInfo['type'] = 'userInfo'
  75. userInfo['openId'] = this.data.userInfo.openId
  76. wx.getUserProfile({
  77. desc: '用于完善会员资料',
  78. success: async (res) =>{
  79. console.log(res)
  80. userInfo['encryptedData'] = res.encryptedData
  81. userInfo['iv'] = res.iv
  82. let info = await app.wxLogin(userInfo);
  83. let hasMobile = false;
  84. if (info.mobile) {
  85. hasMobile = true
  86. }
  87. _self.setData({
  88. hasUserInfo: true,
  89. userInfo: info,
  90. hasMobile: hasMobile,
  91. })
  92. }
  93. })
  94. },
  95. gotoComment: async function (e) {
  96. console.log(this)
  97. const isAuth = await app.isAuth()
  98. if (!isAuth) {
  99. wx.redirectTo({
  100. url: '/pages/prompt/prompt?page=pages/comments/comments',
  101. })
  102. return
  103. }
  104. wx.navigateTo({
  105. url: '../comments/comments?title=我的评论&commentstype=my',
  106. })
  107. },
  108. gotoPersonInfo: function (e) {
  109. wx.navigateTo({
  110. url: '../personinfo/personinfo',
  111. })
  112. },
  113. gotoOrder: function (e) {
  114. wx.switchTab({
  115. url: '../couponList/couponList',
  116. })
  117. },
  118. getMobile: async function (params) {
  119. console.log(params);
  120. let _self = this
  121. const data = {
  122. encryptedData:params.detail.encryptedData,
  123. iv: params.detail.iv
  124. }
  125. const userInfo = await app.getPhoneNumber(data)
  126. console.log(userInfo)
  127. let hasMobile = false
  128. if (userInfo.mobile > 1) {
  129. hasMobile:true
  130. }
  131. _self.setData({
  132. hasMobile: hasMobile,
  133. mobile: userInfo.mobile,
  134. userInfo
  135. })
  136. },
  137. async gotoMoney() {
  138. const self = this
  139. const rs = await wx.scanCode({onlyFromCamera: true, scanType: ['qrCode']})
  140. const couponInfo = await Order.couponInfo({couponSn: rs.result})
  141. console.log(couponInfo)
  142. wx.showModal({
  143. title: "提示",
  144. content: '你确定要核销 '+couponInfo['couponName']+' 的优惠券吗?',
  145. success:async (res) =>{
  146. if (res.confirm) {
  147. const data = {
  148. heXiaoPhone: self.data.userInfo.mobile,
  149. couponSn: rs.result,
  150. errMsg: 'modal'
  151. }
  152. const writeOff = await Order.writeOffCoupon(data)
  153. console.log(writeOff)
  154. wx.showModal({
  155. title: "提示",
  156. content: "核销成功"
  157. })
  158. }
  159. }
  160. })
  161. }
  162. })