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

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