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.

571 lines
18 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. console.log("我是中转页面")
  16. let that = this;
  17. console.log(options);
  18. wx.showToast({
  19. title: '加载中',
  20. icon: "loading",
  21. duration: 2000
  22. })
  23. /**
  24. * 根据接收到的参数的值,判断跳转到哪个页面
  25. */
  26. if (options && options.type) {
  27. app.globalData.type = options.type;
  28. }
  29. if (decodeURIComponent(options.scene) == "undefined") {
  30. that.setData({
  31. scene: 0
  32. })
  33. app.globalData.scene = 0;
  34. } else {
  35. that.setData({
  36. scene: decodeURIComponent(options.scene)
  37. });
  38. app.globalData.scene = decodeURIComponent(options.scene)
  39. that.setData({
  40. newArr: this.data.scene.split(':')
  41. })
  42. //// 大屏-二维码-start
  43. if (this.data.newArr[0] == 'JC') {
  44. // 跳转券详情
  45. options.couponChannelId = this.data.newArr[1];
  46. } else if (this.data.newArr[0] == 'JG') {
  47. // 跳转拼团详情
  48. options.couponChannelId = this.data.newArr[1];
  49. options.path = 'daping'
  50. } else if (this.data.newArr[0] == 't') {
  51. // 普通二维码
  52. options.type = this.data.newArr[1];
  53. app.globalData.type = options.type;
  54. if (options.type == 'cd') {
  55. options.couponChannelId = this.data.newArr[2];
  56. } else if (options.type == 'bd') {
  57. options.bt = this.data.newArr[2];
  58. options.id = this.data.newArr[3];
  59. } else if (options.type == 'gm') {
  60. options.id = this.data.newArr[2];
  61. } else if (options.type == 'sd') {
  62. options.couponChannelId = this.data.newArr[2];
  63. } else if (options.type == 'td') {
  64. // 专题活动页
  65. options.id = this.data.newArr[2];
  66. } else if (options.type == 'md') {
  67. // 门店详情
  68. options.id = this.data.newArr[2];
  69. } else if (options.type == 'ra') {
  70. //活动详情
  71. options.id = this.data.newArr[2];
  72. } else if (options.type == 'si') {
  73. //活动签到
  74. options.id = this.data.newArr[2];
  75. } else if (options.type == 'wj') {
  76. options.id = this.data.newArr[2];
  77. }
  78. }
  79. }
  80. wx.setStorageSync('options', JSON.stringify(options))
  81. wx.setStorageSync('imgurl', imgurl);
  82. if (app.globalData.token) {
  83. this.updateUserInfo();
  84. if (options.couponChannelId || options.orderId || options.id) {
  85. that.userStatus(options);
  86. } else {
  87. that.userStatus();
  88. }
  89. } else {
  90. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  91. // 所以此处加入 callback 以防止这种情况
  92. app.tokenCallback = token => {
  93. this.updateUserInfo();
  94. if (options.couponChannelId || options.orderId || options.id) {
  95. that.userStatus(options);
  96. } else {
  97. that.userStatus();
  98. }
  99. }
  100. }
  101. },
  102. /**
  103. * 检查用户的状态
  104. */
  105. userStatus: function(options) {
  106. var that = this;
  107. if (options && (options.couponChannelId || options.orderId || options.id)) {
  108. that.checkuserstatus(options);
  109. } else {
  110. that.checkuserstatus();
  111. }
  112. },
  113. /**
  114. * 获取手机信息
  115. */
  116. updateUserInfo() {
  117. wx.getSystemInfo({
  118. success: function (res) {
  119. Http.post({
  120. url: config.api.updateUserInfo,
  121. data: {
  122. systemInfo: JSON.stringify(res)
  123. }
  124. }).then(res => {
  125. console.log(res)
  126. })
  127. }
  128. })
  129. },
  130. checkuserstatus(options) {
  131. let that = this;
  132. Http.get({
  133. url: config.api.checkUserStatus,
  134. data: {
  135. token: app.globalData.token
  136. }
  137. })
  138. .then(res => {
  139. // res = JSON.parse('{"code":11004,"message":"用户昵称未授权,请跳转到用户昵称授权页!","data":{}}')
  140. //参与拼团
  141. if (options && options.orderGroupId) {
  142. wx.redirectTo({
  143. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  144. })
  145. }
  146. //来自大屏的跳转拼团券详情
  147. else if (options && options.couponChannelId && options.path == 'daping') {
  148. /**
  149. * 主要是为了拿couponId
  150. */
  151. Http.get({
  152. url: config.api.couponDetail,
  153. data: {
  154. couponChannelId: options.couponChannelId
  155. }
  156. }).then(res => {
  157. let data = res.data;
  158. wx.redirectTo({
  159. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  160. })
  161. })
  162. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  163. console.log(3333333333333333)
  164. // 转赠判断
  165. if (options.cuserId) {
  166. wx.redirectTo({
  167. 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}`,
  168. })
  169. } else {
  170. // 跳转普通券/消费卡/限时秒杀/砍价详情
  171. wx.redirectTo({
  172. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  173. })
  174. }
  175. }
  176. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  177. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  178. wx.redirectTo({
  179. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  180. })
  181. }
  182. // 游戏页面
  183. else if (options && options.id && app.globalData.type == 'gm') {
  184. that.getGameOne(app.globalData.token, options.id)
  185. }
  186. // 报名活动页面
  187. else if (options && options.id && app.globalData.type == 'ra') {
  188. wx.redirectTo({
  189. url: `/pages/radetail/index?id=${options.id}`,
  190. })
  191. }
  192. //活动签到
  193. else if (options && options.id && app.globalData.type == 'si') {
  194. wx.redirectTo({
  195. url: `/pages/acSignIn/index?id=${options.id}`,
  196. })
  197. }
  198. //答题问卷
  199. else if (options && options.id && app.globalData.type == 'wj') {
  200. wx.redirectTo({
  201. url: `/pages/questionnaire/questionnaire?id=${options.id}`,
  202. })
  203. }
  204. // 宣传页详情
  205. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  206. if (options.bt == '2') {
  207. // 自由图文
  208. wx.redirectTo({
  209. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  210. })
  211. } else {
  212. // 标准格式
  213. wx.redirectTo({
  214. url: `/pages/bannerdetail/index?id=${options.id}`,
  215. })
  216. }
  217. }
  218. // 专题
  219. else if (options && options.id && app.globalData.type == 'td') {
  220. wx.redirectTo({
  221. url: `/pages/topicDetail/index?id=${options.id}`
  222. });
  223. }
  224. // 门店详情
  225. else if (options && options.id && app.globalData.type == 'md') {
  226. wx.redirectTo({
  227. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  228. });
  229. }
  230. // 参与砍价
  231. else if (options && options.orderId) {
  232. wx.redirectTo({
  233. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  234. })
  235. }
  236. // 我的
  237. else if (app.globalData.type == 'uc') {
  238. wx.switchTab({
  239. url: '/index/user'
  240. });
  241. }
  242. // 积分
  243. else if (app.globalData.type == 'jf') {
  244. wx.redirectTo({
  245. url: '/pages/integralmall/index'
  246. });
  247. }
  248. // 首页
  249. else if (app.globalData.type == 'in') {
  250. wx.switchTab({
  251. url: '/index/index'
  252. });
  253. }
  254. // 停车
  255. else if (app.globalData.type == 'pc') {
  256. // 停车
  257. wx.switchTab({
  258. url: '/index/passCar'
  259. });
  260. }
  261. // 我的券包
  262. else if (app.globalData.type == 'mc') {
  263. // 我的券包
  264. wx.redirectTo({
  265. url: '/pages/couponorder/index/index'
  266. });
  267. }
  268. // 我的订单
  269. else if (app.globalData.type == 'mo') {
  270. // 我的订单
  271. wx.redirectTo({
  272. url: '/pages/order/index/index?id=all'
  273. });
  274. }
  275. // 我的卡包
  276. else if (app.globalData.type == 'ca') {
  277. // 我的卡包
  278. wx.redirectTo({
  279. url: '/pages/cardorder/index/index'
  280. });
  281. }
  282. // 特享礼遇
  283. else if (app.globalData.type == 'sc') {
  284. // 特享礼遇
  285. wx.redirectTo({
  286. url: '/pages/specialcourtesy/specialcourtesy'
  287. });
  288. }
  289. // 限时秒杀
  290. else if (app.globalData.type == 'rb') {
  291. // 限时秒杀
  292. wx.redirectTo({
  293. url: '/pages/rushToBuy/index'
  294. })
  295. }
  296. // 砍价专场
  297. else if (app.globalData.type == 'bl') {
  298. // 砍价专场
  299. wx.redirectTo({
  300. url: '/pages/bargain/bargain'
  301. })
  302. }
  303. // 我的砍价
  304. else if (app.globalData.type == 'mb') {
  305. // 我的砍价
  306. wx.redirectTo({
  307. url: '/pages/bargain/bargain?from=myhtml'
  308. })
  309. }
  310. // 拼团专场
  311. else if (app.globalData.type == 'sl') {
  312. // 拼团专场
  313. wx.redirectTo({
  314. url: '/pages/spellGroup/spellGroup'
  315. })
  316. }
  317. // 我的拼团
  318. else if (app.globalData.type == 'ms') {
  319. // 我的拼团
  320. wx.redirectTo({
  321. url: '/pages/spellGroup/spellGroup?from=myhtml'
  322. })
  323. }
  324. // 消费卡
  325. else if (app.globalData.type == 'dc') {
  326. // 消费卡
  327. wx.redirectTo({
  328. url: '/pages/discountCardList/discountCardList'
  329. })
  330. }
  331. //直播
  332. else if (app.globalData.type == 'zb') {
  333. wx.redirectTo({
  334. url: `/pages2/live/livelist/index`
  335. });
  336. }
  337. //活动日历
  338. else if (app.globalData.type == 'arl') {
  339. wx.redirectTo({
  340. url: `/pages/dateLsit/dateLsit`
  341. });
  342. }
  343. //每日签到
  344. else if (app.globalData.type == 'qd') {
  345. wx.redirectTo({
  346. url: `/pages/activityCalendar/activityCalendar`
  347. });
  348. }
  349. // 门店
  350. else if (app.globalData.type == 'ml') {
  351. wx.switchTab({
  352. url: '/index/searchbar'
  353. })
  354. }
  355. // 兑换
  356. else if (app.globalData.type == 'ec') {
  357. wx.redirectTo({
  358. url: '/pages/exchange/exchange'
  359. })
  360. }
  361. // 通过分享进入的门店详情
  362. else if (options && options.id && options.frommd == 'md') {
  363. wx.redirectTo({
  364. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  365. });
  366. } else {
  367. // 主页
  368. wx.switchTab({
  369. url: '/index/index'
  370. })
  371. }
  372. })
  373. .catch(err => {
  374. console.log(err)
  375. if (err.code == 11004) {
  376. // 用户昵称未授权
  377. if (options && options.orderGroupId) {
  378. wx.redirectTo({
  379. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  380. })
  381. }
  382. /**
  383. * spellGroup
  384. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  385. * 注意:拼团券和普通券是两个页面
  386. */
  387. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  388. wx.redirectTo({
  389. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  390. })
  391. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  392. wx.redirectTo({
  393. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  394. })
  395. } else if (options && options.couponChannelId && options.cuserId) {
  396. /**
  397. * 转赠判断
  398. */
  399. wx.redirectTo({
  400. 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}`
  401. })
  402. } else if (options && options.orderId) {
  403. wx.redirectTo({
  404. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  405. })
  406. }
  407. // 报名活动页面
  408. else if (options && options.id && app.globalData.type == 'ra') {
  409. wx.redirectTo({
  410. url: `/pages/radetail/index?id=${options.id}`,
  411. })
  412. }
  413. // 通过分享进入的门店详情
  414. else if (options && options.id && options.frommd == 'md') {
  415. wx.redirectTo({
  416. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  417. });
  418. }// 门店详情
  419. else if (options && options.id && app.globalData.type == 'md') {
  420. wx.redirectTo({
  421. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  422. });
  423. } else if (app.globalData.type == 'uc') {
  424. wx.switchTab({
  425. url: '/index/user'
  426. });
  427. }
  428. // 积分
  429. else if (app.globalData.type == 'jf') {
  430. wx.redirectTo({
  431. url: '/pages/integralmall/index'
  432. });
  433. }
  434. // 首页
  435. else if (app.globalData.type == 'in') {
  436. wx.switchTab({
  437. url: '/index/index'
  438. });
  439. }
  440. // 停车
  441. else if (app.globalData.type == 'pc') {
  442. // 停车
  443. wx.switchTab({
  444. url: '/index/passCar'
  445. });
  446. }
  447. // 我的券包
  448. else if (app.globalData.type == 'mc') {
  449. // 我的券包
  450. wx.redirectTo({
  451. url: '/pages/couponorder/index/index'
  452. });
  453. }
  454. // 我的订单
  455. else if (app.globalData.type == 'mo') {
  456. // 我的订单
  457. wx.redirectTo({
  458. url: '/pages/order/index/index?id=all'
  459. });
  460. }
  461. // 我的卡包
  462. else if (app.globalData.type == 'ca') {
  463. // 我的卡包
  464. wx.redirectTo({
  465. url: '/pages/cardorder/index/index'
  466. });
  467. }
  468. // 特享礼遇
  469. else if (app.globalData.type == 'sc') {
  470. // 特享礼遇
  471. wx.redirectTo({
  472. url: '/pages/specialcourtesy/specialcourtesy'
  473. });
  474. }
  475. // 限时秒杀
  476. else if (app.globalData.type == 'rb') {
  477. // 限时秒杀
  478. wx.redirectTo({
  479. url: '/pages/rushToBuy/index'
  480. })
  481. }
  482. // 砍价专场
  483. else if (app.globalData.type == 'bl') {
  484. // 砍价专场
  485. wx.redirectTo({
  486. url: '/pages/bargain/bargain'
  487. })
  488. }
  489. // 我的砍价
  490. else if (app.globalData.type == 'mb') {
  491. // 我的砍价
  492. wx.redirectTo({
  493. url: '/pages/bargain/bargain?from=myhtml'
  494. })
  495. }
  496. // 拼团专场
  497. else if (app.globalData.type == 'sl') {
  498. // 拼团专场
  499. wx.redirectTo({
  500. url: '/pages/spellGroup/spellGroup'
  501. })
  502. }
  503. // 我的拼团
  504. else if (app.globalData.type == 'ms') {
  505. wx.redirectTo({
  506. url: '/pages/spellGroup/spellGroup?from=myhtml'
  507. })
  508. }
  509. // 消费卡
  510. else if (app.globalData.type == 'dc') {
  511. // 消费卡
  512. wx.redirectTo({
  513. url: '/pages/discountCardList/discountCardList'
  514. })
  515. }
  516. // 兑换
  517. else if (app.globalData.type == 'ec') {
  518. wx.redirectTo({
  519. url: '/pages/exchange/exchange'
  520. })
  521. }
  522. // 门店
  523. else if (app.globalData.type == 'ml') {
  524. wx.switchTab({
  525. url: '/index/searchbar'
  526. })
  527. } else {
  528. wx.switchTab({
  529. url: '/index/index',
  530. })
  531. }
  532. }
  533. })
  534. },
  535. getGameOne: function(token, id) {
  536. let _this = this;
  537. Http.get({
  538. url: config.api.getOneGame,
  539. data: {
  540. token: token,
  541. id: id
  542. }
  543. }).then(res => {
  544. wx.redirectTo({
  545. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  546. })
  547. })
  548. .catch(err => {
  549. wx.showModal({
  550. title: '提示',
  551. content: err.message,
  552. showCancel: false,
  553. success: function(res) {
  554. // 如果游戏下架或者找不到,重启首页
  555. if (res.confirm) {
  556. wx.reLaunch({
  557. url: '/pages/index/index',
  558. })
  559. }
  560. }
  561. })
  562. this.alphaClick();
  563. })
  564. },
  565. })