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.

570 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. 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. console.log(3333333333333333)
  163. // 转赠判断
  164. if (options.cuserId) {
  165. wx.redirectTo({
  166. 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}`,
  167. })
  168. } else {
  169. // 跳转普通券/消费卡/限时秒杀/砍价详情
  170. wx.redirectTo({
  171. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  172. })
  173. }
  174. }
  175. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  176. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  177. wx.redirectTo({
  178. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  179. })
  180. }
  181. // 游戏页面
  182. else if (options && options.id && app.globalData.type == 'gm') {
  183. that.getGameOne(app.globalData.token, options.id)
  184. }
  185. // 报名活动页面
  186. else if (options && options.id && app.globalData.type == 'ra') {
  187. wx.redirectTo({
  188. url: `/pages/radetail/index?id=${options.id}`,
  189. })
  190. }
  191. //活动签到
  192. else if (options && options.id && app.globalData.type == 'si') {
  193. wx.redirectTo({
  194. url: `/pages/acSignIn/index?id=${options.id}`,
  195. })
  196. }
  197. //答题问卷
  198. else if (options && options.id && app.globalData.type == 'wj') {
  199. wx.redirectTo({
  200. url: `/pages/questionnaire/questionnaire?id=${options.id}`,
  201. })
  202. }
  203. // 宣传页详情
  204. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  205. if (options.bt == '2') {
  206. // 自由图文
  207. wx.redirectTo({
  208. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  209. })
  210. } else {
  211. // 标准格式
  212. wx.redirectTo({
  213. url: `/pages/bannerdetail/index?id=${options.id}`,
  214. })
  215. }
  216. }
  217. // 专题
  218. else if (options && options.id && app.globalData.type == 'td') {
  219. wx.redirectTo({
  220. url: `/pages/topicDetail/index?id=${options.id}`
  221. });
  222. }
  223. // 门店详情
  224. else if (options && options.id && app.globalData.type == 'md') {
  225. wx.redirectTo({
  226. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  227. });
  228. }
  229. // 参与砍价
  230. else if (options && options.orderId) {
  231. wx.redirectTo({
  232. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  233. })
  234. }
  235. // 我的
  236. else if (app.globalData.type == 'uc') {
  237. wx.switchTab({
  238. url: '/index/user'
  239. });
  240. }
  241. // 积分
  242. else if (app.globalData.type == 'jf') {
  243. wx.redirectTo({
  244. url: '/pages/integralmall/index'
  245. });
  246. }
  247. // 首页
  248. else if (app.globalData.type == 'in') {
  249. wx.switchTab({
  250. url: '/index/index'
  251. });
  252. }
  253. // 停车
  254. else if (app.globalData.type == 'pc') {
  255. // 停车
  256. wx.switchTab({
  257. url: '/index/passCar'
  258. });
  259. }
  260. // 我的券包
  261. else if (app.globalData.type == 'mc') {
  262. // 我的券包
  263. wx.redirectTo({
  264. url: '/pages/couponorder/index/index'
  265. });
  266. }
  267. // 我的订单
  268. else if (app.globalData.type == 'mo') {
  269. // 我的订单
  270. wx.redirectTo({
  271. url: '/pages/order/index/index?id=all'
  272. });
  273. }
  274. // 我的卡包
  275. else if (app.globalData.type == 'ca') {
  276. // 我的卡包
  277. wx.redirectTo({
  278. url: '/pages/cardorder/index/index'
  279. });
  280. }
  281. // 特享礼遇
  282. else if (app.globalData.type == 'sc') {
  283. // 特享礼遇
  284. wx.redirectTo({
  285. url: '/pages/specialcourtesy/specialcourtesy'
  286. });
  287. }
  288. // 限时秒杀
  289. else if (app.globalData.type == 'rb') {
  290. // 限时秒杀
  291. wx.redirectTo({
  292. url: '/pages/rushToBuy/index'
  293. })
  294. }
  295. // 砍价专场
  296. else if (app.globalData.type == 'bl') {
  297. // 砍价专场
  298. wx.redirectTo({
  299. url: '/pages/bargain/bargain'
  300. })
  301. }
  302. // 我的砍价
  303. else if (app.globalData.type == 'mb') {
  304. // 我的砍价
  305. wx.redirectTo({
  306. url: '/pages/bargain/bargain?from=myhtml'
  307. })
  308. }
  309. // 拼团专场
  310. else if (app.globalData.type == 'sl') {
  311. // 拼团专场
  312. wx.redirectTo({
  313. url: '/pages/spellGroup/spellGroup'
  314. })
  315. }
  316. // 我的拼团
  317. else if (app.globalData.type == 'ms') {
  318. // 我的拼团
  319. wx.redirectTo({
  320. url: '/pages/spellGroup/spellGroup?from=myhtml'
  321. })
  322. }
  323. // 消费卡
  324. else if (app.globalData.type == 'dc') {
  325. // 消费卡
  326. wx.redirectTo({
  327. url: '/pages/discountCardList/discountCardList'
  328. })
  329. }
  330. //直播
  331. else if (app.globalData.type == 'zb') {
  332. wx.redirectTo({
  333. url: `/pages2/live/livelist/index`
  334. });
  335. }
  336. //活动日历
  337. else if (app.globalData.type == 'arl') {
  338. wx.redirectTo({
  339. url: `/pages/dateLsit/dateLsit`
  340. });
  341. }
  342. //每日签到
  343. else if (app.globalData.type == 'qd') {
  344. wx.redirectTo({
  345. url: `/pages/activityCalendar/activityCalendar`
  346. });
  347. }
  348. // 门店
  349. else if (app.globalData.type == 'ml') {
  350. wx.switchTab({
  351. url: '/index/searchbar'
  352. })
  353. }
  354. // 兑换
  355. else if (app.globalData.type == 'ec') {
  356. wx.redirectTo({
  357. url: '/pages/exchange/exchange'
  358. })
  359. }
  360. // 通过分享进入的门店详情
  361. else if (options && options.id && options.frommd == 'md') {
  362. wx.redirectTo({
  363. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  364. });
  365. } else {
  366. // 主页
  367. wx.switchTab({
  368. url: '/index/index'
  369. })
  370. }
  371. })
  372. .catch(err => {
  373. console.log(err)
  374. if (err.code == 11004) {
  375. // 用户昵称未授权
  376. if (options && options.orderGroupId) {
  377. wx.redirectTo({
  378. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  379. })
  380. }
  381. /**
  382. * spellGroup
  383. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  384. * 注意:拼团券和普通券是两个页面
  385. */
  386. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  387. wx.redirectTo({
  388. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  389. })
  390. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  391. wx.redirectTo({
  392. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  393. })
  394. } else if (options && options.couponChannelId && options.cuserId) {
  395. /**
  396. * 转赠判断
  397. */
  398. wx.redirectTo({
  399. 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}`
  400. })
  401. } else if (options && options.orderId) {
  402. wx.redirectTo({
  403. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  404. })
  405. }
  406. // 报名活动页面
  407. else if (options && options.id && app.globalData.type == 'ra') {
  408. wx.redirectTo({
  409. url: `/pages/radetail/index?id=${options.id}`,
  410. })
  411. }
  412. // 通过分享进入的门店详情
  413. else if (options && options.id && options.frommd == 'md') {
  414. wx.redirectTo({
  415. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  416. });
  417. }// 门店详情
  418. else if (options && options.id && app.globalData.type == 'md') {
  419. wx.redirectTo({
  420. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  421. });
  422. } else if (app.globalData.type == 'uc') {
  423. wx.switchTab({
  424. url: '/index/user'
  425. });
  426. }
  427. // 积分
  428. else if (app.globalData.type == 'jf') {
  429. wx.redirectTo({
  430. url: '/pages/integralmall/index'
  431. });
  432. }
  433. // 首页
  434. else if (app.globalData.type == 'in') {
  435. wx.switchTab({
  436. url: '/index/index'
  437. });
  438. }
  439. // 停车
  440. else if (app.globalData.type == 'pc') {
  441. // 停车
  442. wx.switchTab({
  443. url: '/index/passCar'
  444. });
  445. }
  446. // 我的券包
  447. else if (app.globalData.type == 'mc') {
  448. // 我的券包
  449. wx.redirectTo({
  450. url: '/pages/couponorder/index/index'
  451. });
  452. }
  453. // 我的订单
  454. else if (app.globalData.type == 'mo') {
  455. // 我的订单
  456. wx.redirectTo({
  457. url: '/pages/order/index/index?id=all'
  458. });
  459. }
  460. // 我的卡包
  461. else if (app.globalData.type == 'ca') {
  462. // 我的卡包
  463. wx.redirectTo({
  464. url: '/pages/cardorder/index/index'
  465. });
  466. }
  467. // 特享礼遇
  468. else if (app.globalData.type == 'sc') {
  469. // 特享礼遇
  470. wx.redirectTo({
  471. url: '/pages/specialcourtesy/specialcourtesy'
  472. });
  473. }
  474. // 限时秒杀
  475. else if (app.globalData.type == 'rb') {
  476. // 限时秒杀
  477. wx.redirectTo({
  478. url: '/pages/rushToBuy/index'
  479. })
  480. }
  481. // 砍价专场
  482. else if (app.globalData.type == 'bl') {
  483. // 砍价专场
  484. wx.redirectTo({
  485. url: '/pages/bargain/bargain'
  486. })
  487. }
  488. // 我的砍价
  489. else if (app.globalData.type == 'mb') {
  490. // 我的砍价
  491. wx.redirectTo({
  492. url: '/pages/bargain/bargain?from=myhtml'
  493. })
  494. }
  495. // 拼团专场
  496. else if (app.globalData.type == 'sl') {
  497. // 拼团专场
  498. wx.redirectTo({
  499. url: '/pages/spellGroup/spellGroup'
  500. })
  501. }
  502. // 我的拼团
  503. else if (app.globalData.type == 'ms') {
  504. wx.redirectTo({
  505. url: '/pages/spellGroup/spellGroup?from=myhtml'
  506. })
  507. }
  508. // 消费卡
  509. else if (app.globalData.type == 'dc') {
  510. // 消费卡
  511. wx.redirectTo({
  512. url: '/pages/discountCardList/discountCardList'
  513. })
  514. }
  515. // 兑换
  516. else if (app.globalData.type == 'ec') {
  517. wx.redirectTo({
  518. url: '/pages/exchange/exchange'
  519. })
  520. }
  521. // 门店
  522. else if (app.globalData.type == 'ml') {
  523. wx.switchTab({
  524. url: '/index/searchbar'
  525. })
  526. } else {
  527. wx.switchTab({
  528. url: '/index/index',
  529. })
  530. }
  531. }
  532. })
  533. },
  534. getGameOne: function(token, id) {
  535. let _this = this;
  536. Http.get({
  537. url: config.api.getOneGame,
  538. data: {
  539. token: token,
  540. id: id
  541. }
  542. }).then(res => {
  543. wx.redirectTo({
  544. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  545. })
  546. })
  547. .catch(err => {
  548. wx.showModal({
  549. title: '提示',
  550. content: err.message,
  551. showCancel: false,
  552. success: function(res) {
  553. // 如果游戏下架或者找不到,重启首页
  554. if (res.confirm) {
  555. wx.reLaunch({
  556. url: '/pages/index/index',
  557. })
  558. }
  559. }
  560. })
  561. this.alphaClick();
  562. })
  563. },
  564. })