cardverify.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // pages/cardverify/cardverify.js
  2. const app = getApp();
  3. const api = require('../../api/api');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. navbarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '订单核销', //导航栏 中间的标题
  12. capsuleMode: 'navBack', //显示模式(navBack:返回上一页;navHome:返回首页)
  13. },
  14. card_number: '', //卡券号
  15. code_result: '', //扫码返回结果
  16. },
  17. saoma() {
  18. wx.navigateTo({
  19. url: '/pages/verify/verify',
  20. })
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. let that = this;
  37. if(that.data.code_result != ''){
  38. wx.showLoading({
  39. title: '扫码成功',
  40. mask: true
  41. })
  42. wx.request({
  43. url: api.Orderwrite,
  44. header: {
  45. 'Authorization': wx.getStorageSync('token')
  46. },
  47. data: {
  48. card_number: that.data.code_result,
  49. write_method: 0
  50. },
  51. method: 'POST',
  52. success(res) {
  53. wx.hideLoading()
  54. console.log(res);
  55. if (res.data.code === 1) {
  56. wx.showToast({
  57. title: '核销成功',
  58. mask: true
  59. })
  60. } else {
  61. wx.showToast({
  62. title: res.data.msg,
  63. mask: true,
  64. icon: 'none'
  65. })
  66. }
  67. },
  68. fail(err) {
  69. wx.hideLoading()
  70. wx.showToast({
  71. title: '发起网络请求失败',
  72. icon: 'none',
  73. mask: true
  74. })
  75. },
  76. complete() {
  77. that.setData({
  78. code_result: ''
  79. })
  80. // wx.hideLoading()
  81. }
  82. })
  83. }
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. },
  110. inputCardNumber(e) {
  111. this.setData({
  112. card_number: e.detail.value
  113. })
  114. },
  115. submit() {
  116. let that = this;
  117. if(that.data.card_number == '') {
  118. wx.showToast({
  119. title: '订单核销码未录入',
  120. mask: true,
  121. icon: 'none'
  122. })
  123. return
  124. }
  125. wx.showLoading({
  126. title: '提交中',
  127. mask: true
  128. })
  129. wx.request({
  130. url: api.Orderwrite,
  131. header: {
  132. 'Authorization': wx.getStorageSync('token')
  133. },
  134. data: {
  135. card_number: that.data.card_number,
  136. write_method: 2
  137. },
  138. method: 'POST',
  139. success(res) {
  140. console.log(res);
  141. if (res.data.code === 1) {
  142. wx.showToast({
  143. title: '核销成功',
  144. })
  145. } else {
  146. wx.showToast({
  147. title: res.data.msg,
  148. mask: true,
  149. icon: 'none'
  150. })
  151. }
  152. },
  153. fail(err) {
  154. wx.showToast({
  155. title: '发起网络请求失败',
  156. icon: 'none',
  157. mask: true
  158. })
  159. },
  160. complete() {
  161. wx.hideLoading()
  162. }
  163. })
  164. }
  165. })