C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

126 行
2.9 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px'
  2. const util = require("../../utils/util.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const config = require("../../config/config");
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. code: ""
  13. },
  14. // 兑换
  15. exchange(e) {
  16. console.log(e, 'e');
  17. let that = this;
  18. let code = e.detail.value.code;
  19. let formId = e.detail.formId;
  20. if (!code) {
  21. wx.showToast({
  22. title: '请输入兑换码',
  23. icon: "none",
  24. duration: 2500
  25. })
  26. return;
  27. }
  28. that.checkPhoneStatus(code, formId);
  29. },
  30. goScanCode() {
  31. console.log('scan!!!');
  32. const that = this
  33. wx.scanCode({
  34. success: (res) => {
  35. console.log(res, 'res');
  36. const num = res.result
  37. that.setData({
  38. code: num
  39. })
  40. const e = {
  41. detail:
  42. {
  43. value:
  44. {
  45. code:
  46. num
  47. }
  48. }
  49. }
  50. that.exchange(e)
  51. },
  52. fail: (res) => {
  53. console.log(res, 'fail');
  54. }
  55. })
  56. },
  57. checkPhoneStatus: function (password, formId) {
  58. let that = this;
  59. Http.get({
  60. url: config.api.checkPhoneStatus,
  61. data: {}
  62. })
  63. .then(res => {
  64. that.getCouponOrderByPassword(password, formId);
  65. })
  66. .catch(err => {
  67. if (err.code == 11005) {
  68. /**
  69. * 手机号没有授权,将值传到用户手机号授权的页面
  70. *
  71. */
  72. wx.redirectTo({
  73. url: "/pages/getphoneInfo/index",
  74. })
  75. } else {
  76. wx.showToast({
  77. title: err.message,
  78. icon: 'none',
  79. duration: 2500
  80. })
  81. }
  82. })
  83. },
  84. getCouponOrderByPassword(password, formId) {
  85. let that = this;
  86. Http.post({
  87. url: config.api.getCouponOrderByPassword,
  88. data: {
  89. password: password,
  90. formId: formId
  91. }
  92. })
  93. .then(res => {
  94. wx.showModal({
  95. title: '兑换成功',
  96. content: '消费卡已发放到"我的卡包"',
  97. showCancel: true,
  98. cancelText: "知道了",
  99. cancelColor: '',
  100. confirmText: "去查看",
  101. confirmColor: '#FD832D',
  102. success: function (res) {
  103. if (res.cancel) {
  104. //点击取消,默认隐藏弹框
  105. } else {
  106. wx.redirectTo({
  107. url: '/pages/cardorder/index/index',
  108. })
  109. }
  110. },
  111. fail: function (res) { },//接口调用失败的回调函数
  112. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  113. })
  114. })
  115. .catch(err => {
  116. wx.showToast({
  117. title: err.message,
  118. icon: 'none',
  119. duration: 2000
  120. })
  121. })
  122. }
  123. })