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.

109 line
2.7 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. exchange:""
  13. },
  14. onLoad(options){
  15. if (options&&options.exchange){
  16. this.setData({
  17. exchange: options.exchange
  18. })
  19. }
  20. },
  21. // 兑换
  22. exchange(e){
  23. let that = this;
  24. let code = e.detail.value.code;
  25. let formId = e.detail.formId;
  26. if (!code || !code.replace(/\s*/g, "")){
  27. wx.showToast({
  28. title: '请输入兑换码',
  29. icon:"none",
  30. duration:2500
  31. })
  32. return;
  33. }
  34. that.checkPhoneStatus(e.detail.value.code,e.detail.formId);
  35. },
  36. checkPhoneStatus: function (password, formId) {
  37. let that = this;
  38. Http.get({
  39. url: config.api.checkPhoneStatus,
  40. data: {}
  41. })
  42. .then(res => {
  43. that.getCouponOrderByPassword(password, formId);
  44. })
  45. .catch(err => {
  46. if (err.code == 11005) {
  47. /**
  48. * 手机号没有授权,将值传到用户手机号授权的页面
  49. *
  50. */
  51. wx.redirectTo({
  52. url: `/pages/getphoneInfo/index?exchange=${password}`,
  53. })
  54. } else {
  55. wx.showToast({
  56. title: err.message,
  57. icon: 'none',
  58. duration: 2500
  59. })
  60. }
  61. })
  62. },
  63. getCouponOrderByPassword(password, formId) {
  64. let that = this;
  65. let passwords;
  66. if(that.data.exchange){
  67. passwords = that.data.exchange
  68. }else{
  69. passwords = password
  70. }
  71. Http.post({
  72. url: config.api.getCouponOrderByPassword,
  73. data: {
  74. password: passwords,
  75. formId: formId
  76. }
  77. })
  78. .then(res => {
  79. wx.showModal({
  80. title: '兑换成功',
  81. content: '消费卡已发放到"我的卡包"',
  82. showCancel: true,
  83. cancelText: "知道了",
  84. cancelColor: '',
  85. confirmText: "去查看",
  86. confirmColor: '#FD832D',
  87. success: function (res) {
  88. if (res.cancel) {
  89. //点击取消,默认隐藏弹框
  90. } else {
  91. wx.redirectTo({
  92. url: '/pages/cardorder/index/index',
  93. })
  94. }
  95. },
  96. fail: function (res) { },//接口调用失败的回调函数
  97. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  98. })
  99. })
  100. .catch(err => {
  101. wx.showToast({
  102. title: err.message,
  103. icon: 'none',
  104. duration: 2000
  105. })
  106. })
  107. }
  108. })