C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

113 linhas
2.9 KiB

  1. var config = require("../../config/config.js");
  2. const Http = require("../../utils/HttpBasics");
  3. var app = getApp();
  4. Page({
  5. data: {
  6. canIUse: wx.canIUse("button.open-type.getPhoneNumber"),
  7. couponChannelId: "",
  8. couponId: "",
  9. path:null,
  10. paramData:null
  11. },
  12. onLoad: function (options) {
  13. if(options.path=='index'){
  14. this.path = options.path
  15. }
  16. this.setData({
  17. paramData: options
  18. })
  19. var that = this;
  20. console.log(options);
  21. if (options.couponChannelId && options.couponId) {
  22. that.setData({
  23. couponChannelId: options.couponChannelId,
  24. couponId: options.couponId
  25. });
  26. }
  27. Http.get({
  28. url: config.api.marketicon,
  29. data: {
  30. appId: config.weapp.AppId
  31. }
  32. }).then(res => {
  33. console.log(res.data.mallImgUrl);
  34. that.setData({
  35. mallImgUrl: res.data.mallImgUrl
  36. });
  37. wx.setNavigationBarTitle({
  38. title: res.data.mallName
  39. })
  40. })
  41. .catch(err => {
  42. wx.showToast({
  43. title: err.message,
  44. image: "../../assets/img/fail.png",
  45. duration: 2000,
  46. mask: false
  47. });
  48. })
  49. },
  50. getPhoneNumber: function (e) {
  51. var that = this;
  52. var iv = e.detail.iv;
  53. var encryptedData = e.detail.encryptedData;
  54. Http.post({
  55. url: config.api.getUserPhone,
  56. data: {
  57. encryptedData: encryptedData,
  58. iv: iv
  59. }
  60. }).then(
  61. function (res) {
  62. console.log(res);
  63. console.log("这是用户授权手机号的结果");
  64. console.log(that.data.couponChannelId);
  65. console.log(that.data.couponId);
  66. console.log("这是从立即支付传回来的值 因为用户没有授权手机号");
  67. app.globalData.phone = res.data.phone;
  68. if (that.path == 'index') {
  69. wx.redirectTo({
  70. url: "/pages/game/index?url=" + that.data.paramData.url + "&id=" + that.data.paramData.id + "&gameId=" + that.data.paramData.gameId,
  71. })
  72. } else {
  73. wx.showToast({
  74. title: res.data.msg,
  75. icon: "success",
  76. success: function (res) {
  77. if (that.data.couponChannelId && that.data.couponId) {
  78. wx.redirectTo({
  79. url: "/pages/coupon/detail/index?couponChannelId=" +
  80. that.data.couponChannelId +
  81. "&couponId=" +
  82. that.data.couponId +
  83. "&flag=pay"
  84. })
  85. } else {
  86. wx.switchTab({
  87. url: '/pages/passCar/passCar',
  88. })
  89. }
  90. }
  91. });
  92. }
  93. },
  94. function (error) {
  95. wx.showToast({
  96. title: "请重新授权手机号",
  97. icon: "none"
  98. });
  99. }
  100. )
  101. .catch(err => {
  102. wx.showToast({
  103. title: err.errMsg,
  104. icon: 'none',
  105. duration: 2000,
  106. mask: false
  107. });
  108. })
  109. }
  110. });