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.

249 line
7.1 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. var config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. var app = getApp();
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. canIUse: wx.canIUse("button.open-type.getPhoneNumber"),
  9. couponChannelId: "",
  10. path: null,
  11. paramData: null,
  12. signActivity: "",
  13. mineFlag: null,
  14. skipUrl: 0,
  15. fillIndentId: "",
  16. couponId: "",
  17. // skip: app.globalData.skip
  18. },
  19. onLoad: function(options) {
  20. var that = this;
  21. console.log(options.skipUrl, "options.skipUrl")
  22. if (options.skipUrl) {
  23. that.setData({
  24. skipUrl: options.skipUrl
  25. })
  26. }
  27. that.setData({
  28. path: options.path
  29. })
  30. that.setData({
  31. paramData: options
  32. })
  33. if (options && options.fillIndentId && options.couponId) {
  34. that.setData({
  35. fillIndentId: options.fillIndentId,
  36. couponId: options.couponId
  37. })
  38. }
  39. if (options && options.couponChannelId) {
  40. that.setData({
  41. couponChannelId: options.couponChannelId
  42. });
  43. }
  44. if (options && options.mineFlag) {
  45. that.setData({
  46. mineFlag: options.mineFlag
  47. })
  48. }
  49. if (options && options.signActivity) {
  50. that.setData({
  51. signActivity: options.signActivity
  52. });
  53. }
  54. Http.get({
  55. url: config.api.marketicon,
  56. data: {
  57. appId: config.weapp.AppId
  58. }
  59. }).then(res => {
  60. that.setData({
  61. mallImgUrl: res.data.mallImgUrl
  62. });
  63. wx.setNavigationBarTitle({
  64. title: res.data.mallName
  65. })
  66. })
  67. .catch(err => {
  68. wx.showToast({
  69. title: err.errMsg,
  70. icon: 'none',
  71. duration: 2000,
  72. mask: false
  73. });
  74. })
  75. },
  76. onShow: function() {
  77. wx.checkSession({
  78. success() {
  79. //session_key 未过期,并且在本生命周期一直有效
  80. },
  81. fail() {
  82. // session_key 已经失效,需要重新执行登录流程
  83. console.log("session_key 过期")
  84. wx.login({
  85. success: (res) => {
  86. if (res.code) {
  87. let usrdata = {
  88. appId: config.weapp.AppId,
  89. code: res.code,
  90. }
  91. Http.post({
  92. url: config.api.login,
  93. data: usrdata
  94. }).then(res => {
  95. Http.setToken(res.data.token);
  96. app.globalData.token = res.data.token;
  97. })
  98. }
  99. }
  100. })
  101. }
  102. })
  103. },
  104. backHome: function() {
  105. wx.switchTab({
  106. url: '/index/index',
  107. })
  108. },
  109. getPhoneNumber: function(e) {
  110. var that = this;
  111. var iv = e.detail.iv;
  112. var encryptedData = e.detail.encryptedData;
  113. Http.post({
  114. url: config.api.getUserPhone,
  115. data: {
  116. encryptedData: encryptedData,
  117. iv: iv
  118. }
  119. }).then(res => {
  120. // debugger
  121. app.globalData.phone = res.data.phone;
  122. if (that.data.skipUrl == '1') {
  123. console.log(app.globalData.skip, app.globalData.skipUrl, "跳转地址")
  124. if (app.globalData.skip == 'redirectTo') {
  125. wx.redirectTo({
  126. url: app.globalData.skipUrl,
  127. })
  128. return;
  129. } else if (app.globalData.skip == 'navigateTo') {
  130. wx.navigateTo({
  131. url: app.globalData.skipUrl,
  132. })
  133. return;
  134. } else if (app.globalData.skip == 'reLaunch') {
  135. wx.reLaunch({
  136. url: app.globalData.skipUrl,
  137. })
  138. return;
  139. } else if (app.globalData.skip == 'switchTab') {
  140. wx.switchTab({
  141. url: app.globalData.skipUrl,
  142. })
  143. return;
  144. }
  145. }
  146. //线上配送
  147. if (that.data.path == "fi") {
  148. wx.redirectTo({
  149. url: `/pages/fillIndent/fillIndent?id=${that.data.fillIndentId}&couponId=${that.data.couponId}`
  150. })
  151. }
  152. // 来着问卷
  153. if (that.data.path == "wj") {
  154. wx.redirectTo({
  155. url: `/pages/questionnaire/questionnaire?id=${that.data.wjId}`
  156. })
  157. return;
  158. }
  159. /**a
  160. * 来自我的
  161. */
  162. if (that.data.path == 'main') {
  163. wx.switchTab({
  164. url: `/index/user`
  165. })
  166. return;
  167. }
  168. /**
  169. * 来自积分兑换
  170. */
  171. if (that.data.path == 'jifen') {
  172. wx.redirectTo({
  173. url: `/pages/integralmall/payIntegcoupondetail/index?couponChannelId=${that.data.paramData.couponChannelId}&couponId=${that.data.paramData.couponId}`
  174. })
  175. return;
  176. }
  177. /**
  178. * 来自拼团详情
  179. */
  180. if (that.data.path == 'spell') {
  181. if (that.data.paramData.avatarUrl) {
  182. wx.redirectTo({
  183. url: `/pages/joinFrDpell/index?couponId=${that.data.paramData.couponId}&orderGroupId=${that.data.paramData.orderGroupId}&couponChannelId=${that.data.paramData.couponChannelId}&orderId=${that.data.paramData.orderId}&avatarUrl=${that.data.paramData.avatarUrl}&nickName=${that.data.paramData.nickName}`
  184. })
  185. } else {
  186. wx.redirectTo({
  187. url: `/pages/spellGroup/mySpellGroup/index?couponId=${that.data.paramData.couponId}&couponChannelId=${that.data.paramData.couponChannelId}`
  188. })
  189. }
  190. return;
  191. }
  192. /**
  193. * fromId若存在来自卡转赠
  194. */
  195. if (that.data.path == 'index' && !that.data.paramData.cuserId) {
  196. wx.redirectTo({
  197. url: "/pages/game/index?url=" + that.data.paramData.url + "&id=" + that.data.paramData.id + "&gameId=" + that.data.paramData.gameId,
  198. })
  199. } else if (that.data.path == 'index' && that.data.paramData.cuserId) {
  200. wx.redirectTo({
  201. url: "/pages/coupon/detail/index?cuserId=" + that.data.paramData.cuserId + '&couponChannelId=' + that.data.paramData.couponChannelId + '&coverImg=' + that.data.paramData.coverImg + '&avatarUrl=' + that.data.paramData.avatarUrl + '&userName=' + that.data.paramData.userName + '&couponOrderId=' + that.data.paramData.couponOrderId + "&updateDate=" + that.data.paramData.updateDate
  202. })
  203. }
  204. /**
  205. * 活动报名
  206. */
  207. else if (that.data.signActivity) {
  208. wx.redirectTo({
  209. url: `/pages/radetail/joinActivity/edit?activityId=${that.data.signActivity}`
  210. })
  211. } else if (that.data.mineFlag == 'mine') {
  212. wx.switchTab({
  213. url: '/index/user'
  214. });
  215. } else if (that.data.mineFlag == 'index') {
  216. wx.switchTab({
  217. url: '/index/index'
  218. });
  219. } else {
  220. wx.showToast({
  221. title: res.data.msg,
  222. icon: "success",
  223. success: function(res) {
  224. if (that.data.couponChannelId) {
  225. wx.redirectTo({
  226. url: "/pages/coupon/detail/index?couponChannelId=" + that.data.couponChannelId + "&flag=pay"
  227. })
  228. } else {
  229. wx.switchTab({
  230. url: '/index/passCar',
  231. })
  232. }
  233. }
  234. });
  235. }
  236. }).catch(err => {
  237. wx.showToast({
  238. title: err.message,
  239. icon: 'none',
  240. duration: 2000,
  241. mask: false
  242. });
  243. })
  244. },
  245. });