You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
2.6KB

  1. // pages/home/home.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. phone:'',//手机号
  9. isQuerying: false,
  10. storeName: '', //店名
  11. },
  12. /**
  13. * 核销查询
  14. */
  15. check: function(e) {
  16. if (this.data.isQuerying) {
  17. return
  18. }
  19. var data = e.detail.value;
  20. if (data.phone.length != 11) {
  21. wx.showToast({
  22. title: '输入的手机号码有误',
  23. icon: 'none',
  24. duration: 2000
  25. })
  26. return
  27. } else {
  28. this.setData({
  29. isQuerying: true
  30. })
  31. this.query(data);
  32. }
  33. },
  34. query(data) {
  35. app.requestGet('couponbuy/searchbyphone', {
  36. user_phone: data.phone
  37. }, res => {
  38. this.setData({
  39. isQuerying: false
  40. })
  41. if (res.code == 200) {
  42. app.globalData.couponData = res.data[0];
  43. app.globalData.couponToken = res.token;
  44. wx.navigateTo({
  45. url: '../coupon/coupon?phone=' + data.phone
  46. })
  47. } else {
  48. wx.showToast({
  49. title: res.message,
  50. icon: 'none',
  51. duration: 2000
  52. })
  53. }
  54. })
  55. },
  56. /**
  57. * 扫码
  58. */
  59. scanCode() {
  60. wx.scanCode({
  61. onlyFromCamera: true,
  62. success(res) {
  63. var result = res.result;
  64. app.requestGet('couponbuy/searchbycouponcode', {
  65. coupon_code: result
  66. }, res => {
  67. if (res.code == 200) {
  68. app.globalData.couponData = res.data;
  69. app.globalData.couponToken = res.token;
  70. wx.navigateTo({
  71. url: '../coupon/coupon?code=' + result
  72. })
  73. } else {
  74. wx.showToast({
  75. title: res.message,
  76. icon: 'none',
  77. duration: 2000
  78. })
  79. }
  80. })
  81. }
  82. })
  83. },
  84. /**
  85. * 生命周期函数--监听页面加载
  86. */
  87. onLoad: function(options) {
  88. wx.hideShareMenu();
  89. this.setData({
  90. storeName: app.globalData.storeData.shop_name
  91. })
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function() {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function() {
  102. this.setData({
  103. phone:''
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function() {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function() {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function() {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function() {
  130. }
  131. })