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.

142 lines
2.5KB

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