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.

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