C端小程序
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.

116 lines
2.8 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 || !code.replace(/\s*/g, "")) {
  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. that.exchange({ detail: { value: num } })
  41. },
  42. fail: (res) => {
  43. console.log(res, 'fail');
  44. }
  45. })
  46. },
  47. checkPhoneStatus: function (password, formId) {
  48. let that = this;
  49. Http.get({
  50. url: config.api.checkPhoneStatus,
  51. data: {}
  52. })
  53. .then(res => {
  54. that.getCouponOrderByPassword(password, formId);
  55. })
  56. .catch(err => {
  57. if (err.code == 11005) {
  58. /**
  59. * 手机号没有授权,将值传到用户手机号授权的页面
  60. *
  61. */
  62. wx.redirectTo({
  63. url: "/pages/getphoneInfo/index",
  64. })
  65. } else {
  66. wx.showToast({
  67. title: err.message,
  68. icon: 'none',
  69. duration: 2500
  70. })
  71. }
  72. })
  73. },
  74. getCouponOrderByPassword(password, formId) {
  75. let that = this;
  76. Http.post({
  77. url: config.api.getCouponOrderByPassword,
  78. data: {
  79. password: password,
  80. formId: formId
  81. }
  82. })
  83. .then(res => {
  84. wx.showModal({
  85. title: '兑换成功',
  86. content: '消费卡已发放到"我的卡包"',
  87. showCancel: true,
  88. cancelText: "知道了",
  89. cancelColor: '',
  90. confirmText: "去查看",
  91. confirmColor: '#FD832D',
  92. success: function (res) {
  93. if (res.cancel) {
  94. //点击取消,默认隐藏弹框
  95. } else {
  96. wx.redirectTo({
  97. url: '/pages/cardorder/index/index',
  98. })
  99. }
  100. },
  101. fail: function (res) { },//接口调用失败的回调函数
  102. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  103. })
  104. })
  105. .catch(err => {
  106. wx.showToast({
  107. title: err.message,
  108. icon: 'none',
  109. duration: 2000
  110. })
  111. })
  112. }
  113. })