C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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