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.

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