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

385 行
12 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. const config = require("../../config/config");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {},
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function(options) {
  15. let that = this;
  16. console.log(options)
  17. wx.showToast({
  18. title: '加载中',
  19. icon: "loading",
  20. duration: 2000
  21. })
  22. /**
  23. * 根据接收到的参数的值,判断跳转到哪个页面
  24. */
  25. if (options && options.type) {
  26. app.globalData.type = options.type;
  27. }
  28. if (decodeURIComponent(options.scene) == "undefined") {
  29. that.setData({
  30. scene: 0
  31. })
  32. app.globalData.scene = 0;
  33. } else {
  34. that.setData({
  35. scene: decodeURIComponent(options.scene)
  36. });
  37. app.globalData.scene = decodeURIComponent(options.scene)
  38. that.setData({
  39. newArr: this.data.scene.split(':')
  40. })
  41. //// 大屏-二维码-start
  42. if (this.data.newArr[0] == 'JC') {
  43. // 跳转券详情
  44. options.couponChannelId = this.data.newArr[1];
  45. } else if (this.data.newArr[0] == 'JG') {
  46. // 跳转拼团详情
  47. options.couponChannelId = this.data.newArr[1];
  48. options.path = 'daping'
  49. } else if (this.data.newArr[0] == 't') {
  50. // 普通二维码
  51. options.type = this.data.newArr[1];
  52. app.globalData.type = options.type;
  53. if (options.type == 'cd') {
  54. options.couponChannelId = this.data.newArr[2];
  55. } else if (options.type == 'bd') {
  56. options.bt = this.data.newArr[2];
  57. options.id = this.data.newArr[3];
  58. } else if (options.type == 'gm') {
  59. options.id = this.data.newArr[2];
  60. } else if (options.type == 'sd') {
  61. options.couponChannelId = this.data.newArr[2];
  62. } else if (options.type == 'td') {
  63. // 专题活动页
  64. options.id = this.data.newArr[2];
  65. } else if (options.type == 'md') {
  66. // 门店详情
  67. options.id = this.data.newArr[2];
  68. }
  69. }
  70. }
  71. wx.setStorageSync('options', JSON.stringify(options))
  72. wx.setStorageSync('imgurl', imgurl);
  73. if (app.globalData.token) {
  74. if (options.couponChannelId || options.orderId || options.id) {
  75. that.userStatus(options);
  76. } else {
  77. that.userStatus();
  78. }
  79. } else {
  80. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  81. // 所以此处加入 callback 以防止这种情况
  82. app.tokenCallback = token => {
  83. if (options.couponChannelId || options.orderId || options.id) {
  84. that.userStatus(options);
  85. } else {
  86. that.userStatus();
  87. }
  88. }
  89. }
  90. },
  91. /**
  92. * 检查用户的状态
  93. */
  94. userStatus: function(options) {
  95. var that = this;
  96. if (options && (options.couponChannelId || options.orderId || options.id)) {
  97. that.checkuserstatus(options);
  98. } else {
  99. that.checkuserstatus();
  100. }
  101. },
  102. checkuserstatus(options) {
  103. let that = this;
  104. Http.get({
  105. url: config.api.checkUserStatus,
  106. data: {
  107. token:app.globalData.token
  108. }
  109. })
  110. .then(res => {
  111. //参与拼团
  112. if (options && options.orderGroupId) {
  113. wx.redirectTo({
  114. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  115. })
  116. }
  117. //来自大屏的跳转拼团券详情
  118. else if (options && options.couponChannelId && options.path == 'daping') {
  119. /**
  120. * 主要是为了拿couponId
  121. */
  122. Http.get({
  123. url: config.api.couponDetail,
  124. data: {
  125. couponChannelId: options.couponChannelId
  126. }
  127. }).then(res => {
  128. let data = res.data;
  129. wx.redirectTo({
  130. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  131. })
  132. })
  133. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  134. // 转赠判断
  135. if (options.cuserId) {
  136. wx.redirectTo({
  137. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`,
  138. })
  139. } else {
  140. // 跳转普通券/消费卡/限时秒杀/砍价详情
  141. wx.redirectTo({
  142. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  143. })
  144. }
  145. }
  146. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  147. else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) {
  148. wx.redirectTo({
  149. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  150. })
  151. }
  152. // 游戏页面
  153. else if (options && options.id && app.globalData.type == 'gm') {
  154. that.getGameOne(app.globalData.token, options.id)
  155. }
  156. // 宣传页详情
  157. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  158. if (options.bt == '2') {
  159. // 自由图文
  160. wx.redirectTo({
  161. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  162. })
  163. } else {
  164. // 标准格式
  165. wx.redirectTo({
  166. url: `/pages/bannerdetail/index?id=${options.id}`,
  167. })
  168. }
  169. }
  170. // 专题
  171. else if (options && options.id && app.globalData.type == 'td') {
  172. wx.redirectTo({
  173. url: `/pages/topicDetail/index?id=${options.id}`
  174. });
  175. }
  176. // 门店详情
  177. else if (options && options.id && app.globalData.type == 'md') {
  178. wx.redirectTo({
  179. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  180. });
  181. }
  182. // 参与砍价
  183. else if (options && options.orderId) {
  184. wx.redirectTo({
  185. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  186. })
  187. }
  188. // 我的
  189. else if (app.globalData.type == 'uc') {
  190. wx.switchTab({
  191. url: '/pages/user/index'
  192. });
  193. }
  194. // 积分
  195. else if (app.globalData.type == 'jf') {
  196. wx.redirectTo({
  197. url: '/pages/integralmall/index'
  198. });
  199. }
  200. // 首页
  201. else if (app.globalData.type == 'in') {
  202. wx.switchTab({
  203. url: '/pages/main/index'
  204. });
  205. }
  206. // 停车
  207. else if (app.globalData.type == 'pc') {
  208. // 停车
  209. wx.switchTab({
  210. url: '/pages/passCar/passCar'
  211. });
  212. }
  213. // 我的券包
  214. else if (app.globalData.type == 'mc') {
  215. // 我的券包
  216. wx.redirectTo({
  217. url: '/pages/couponorder/index/index'
  218. });
  219. }
  220. // 我的订单
  221. else if (app.globalData.type == 'mo') {
  222. // 我的订单
  223. wx.redirectTo({
  224. url: '/pages/order/index/index?id=all'
  225. });
  226. }
  227. // 我的卡包
  228. else if (app.globalData.type == 'ca') {
  229. // 我的卡包
  230. wx.redirectTo({
  231. url: '/pages/cardorder/index/index'
  232. });
  233. }
  234. // 特享礼遇
  235. else if (app.globalData.type == 'sc') {
  236. // 特享礼遇
  237. wx.redirectTo({
  238. url: '/pages/specialcourtesy/specialcourtesy'
  239. });
  240. }
  241. // 限时秒杀
  242. else if (app.globalData.type == 'rb') {
  243. // 限时秒杀
  244. wx.redirectTo({
  245. url: '/pages/rushToBuy/index'
  246. })
  247. }
  248. // 砍价专场
  249. else if (app.globalData.type == 'bl') {
  250. // 砍价专场
  251. wx.redirectTo({
  252. url: '/pages/bargain/bargain'
  253. })
  254. }
  255. // 我的砍价
  256. else if (app.globalData.type == 'mb') {
  257. // 我的砍价
  258. wx.redirectTo({
  259. url: '/pages/bargain/bargain?from=myhtml'
  260. })
  261. }
  262. // 拼团专场
  263. else if (app.globalData.type == 'sl') {
  264. // 拼团专场
  265. wx.redirectTo({
  266. url: '/pages/spellGroup/spellGroup'
  267. })
  268. }
  269. // 我的拼团
  270. else if (app.globalData.type == 'ms') {
  271. // 我的拼团
  272. wx.redirectTo({
  273. url: '/pages/spellGroup/spellGroup?from=myhtml'
  274. })
  275. }
  276. // 消费卡
  277. else if (app.globalData.type == 'dc') {
  278. // 消费卡
  279. wx.redirectTo({
  280. url: '/pages/discountCardList/discountCardList'
  281. })
  282. }
  283. // 门店
  284. else if (app.globalData.type == 'ml') {
  285. wx.switchTab({
  286. url: '/pages/index/searchbar/index'
  287. })
  288. }
  289. // 通过分享进入的门店详情
  290. else if (options && options.id && options.frommd == 'md') {
  291. wx.redirectTo({
  292. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  293. });
  294. }else {
  295. // 主页
  296. wx.switchTab({
  297. url: '/pages/main/index'
  298. })
  299. }
  300. })
  301. .catch(err => {
  302. console.log(err)
  303. if (err.code == 11004) {
  304. // 用户昵称未授权
  305. if (options && options.orderGroupId) {
  306. wx.redirectTo({
  307. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  308. })
  309. }
  310. /**
  311. * spellGroup
  312. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  313. * 注意:拼团券和普通券是两个页面
  314. */
  315. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  316. wx.redirectTo({
  317. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  318. })
  319. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  320. wx.redirectTo({
  321. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  322. })
  323. } else if (options && options.couponChannelId && options.cuserId) {
  324. /**
  325. * 转赠判断
  326. */
  327. wx.redirectTo({
  328. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`
  329. })
  330. } else if (options && options.orderId) {
  331. wx.redirectTo({
  332. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  333. })
  334. }
  335. // 通过分享进入的门店详情
  336. else if (options && options.id && options.frommd == 'md') {
  337. wx.redirectTo({
  338. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  339. });
  340. } else {
  341. wx.redirectTo({
  342. url: `/pages/getuserinfo/index`
  343. });
  344. }
  345. }
  346. });
  347. },
  348. getGameOne: function(token, id) {
  349. let _this = this;
  350. Http.get({
  351. url: config.api.getOneGame,
  352. data: {
  353. token: token,
  354. id: id
  355. }
  356. }).then(res => {
  357. wx.redirectTo({
  358. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  359. })
  360. })
  361. .catch(err => {
  362. wx.showModal({
  363. title: '提示',
  364. content: err.message,
  365. showCancel: false,
  366. success: function(res) {
  367. // 如果游戏下架或者找不到,重启首页
  368. if (res.confirm) {
  369. wx.reLaunch({
  370. url: '/pages/index/index',
  371. })
  372. }
  373. }
  374. })
  375. this.alphaClick();
  376. })
  377. },
  378. })