C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

420 rader
14 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. wx.showToast({
  17. title: '加载中',
  18. icon: "loading",
  19. duration: 2000
  20. })
  21. /**
  22. * 根据接收到的参数的值,判断跳转到哪个页面
  23. */
  24. if (options && options.type) {
  25. app.globalData.type = options.type;
  26. }
  27. if (decodeURIComponent(options.scene) == "undefined") {
  28. that.setData({
  29. scene: 0
  30. })
  31. app.globalData.scene = 0;
  32. } else {
  33. that.setData({
  34. scene: decodeURIComponent(options.scene)
  35. });
  36. app.globalData.scene = decodeURIComponent(options.scene)
  37. that.setData({
  38. newArr: this.data.scene.split(':')
  39. })
  40. //// 大屏-二维码-start
  41. if (this.data.newArr[0] == 'JC') {
  42. // 跳转券详情
  43. options.couponChannelId = this.data.newArr[1];
  44. } else if (this.data.newArr[0] == 'JG') {
  45. // 跳转拼团详情
  46. options.couponChannelId = this.data.newArr[1];
  47. options.path = 'daping'
  48. } else if (this.data.newArr[0] == 't') {
  49. // 普通二维码
  50. options.type = this.data.newArr[1];
  51. app.globalData.type = options.type;
  52. if (options.type == 'cd') {
  53. options.couponChannelId = this.data.newArr[2];
  54. } else if (options.type == 'bd') {
  55. options.bt = this.data.newArr[2];
  56. options.id = this.data.newArr[3];
  57. } else if (options.type == 'gm') {
  58. options.id = this.data.newArr[2];
  59. } else if (options.type == 'sd') {
  60. options.couponChannelId = this.data.newArr[2];
  61. } else if (options.type == 'td') {
  62. // 专题活动页
  63. options.id = this.data.newArr[2];
  64. } else if (options.type == 'md') {
  65. // 门店详情
  66. options.id = this.data.newArr[2];
  67. } else if (options.type == 'ra') {
  68. //活动详情
  69. options.id = this.data.newArr[2];
  70. } else if (options.type == 'si') {
  71. //活动签到
  72. options.id = this.data.newArr[2];
  73. }
  74. }
  75. }
  76. wx.setStorageSync('options', JSON.stringify(options))
  77. wx.setStorageSync('imgurl', imgurl);
  78. if (app.globalData.token) {
  79. this.updateUserInfo();
  80. if (options.couponChannelId || options.orderId || options.id) {
  81. that.userStatus(options);
  82. } else {
  83. that.userStatus();
  84. }
  85. } else {
  86. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  87. // 所以此处加入 callback 以防止这种情况
  88. app.tokenCallback = token => {
  89. this.updateUserInfo();
  90. if (options.couponChannelId || options.orderId || options.id) {
  91. that.userStatus(options);
  92. } else {
  93. that.userStatus();
  94. }
  95. }
  96. }
  97. },
  98. /**
  99. * 检查用户的状态
  100. */
  101. userStatus: function(options) {
  102. var that = this;
  103. if (options && (options.couponChannelId || options.orderId || options.id)) {
  104. that.checkuserstatus(options);
  105. } else {
  106. that.checkuserstatus();
  107. }
  108. },
  109. /**
  110. * 获取手机信息
  111. */
  112. updateUserInfo() {
  113. wx.getSystemInfo({
  114. success: function (res) {
  115. Http.post({
  116. url: config.api.updateUserInfo,
  117. data: {
  118. systemInfo: JSON.stringify(res)
  119. }
  120. }).then(res => {
  121. console.log(res)
  122. })
  123. }
  124. })
  125. },
  126. checkuserstatus(options) {
  127. let that = this;
  128. Http.get({
  129. url: config.api.checkUserStatus,
  130. data: {
  131. token:app.globalData.token
  132. }
  133. })
  134. .then(res => {
  135. //参与拼团
  136. if (options && options.orderGroupId) {
  137. wx.redirectTo({
  138. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  139. })
  140. }
  141. //来自大屏的跳转拼团券详情
  142. else if (options && options.couponChannelId && options.path == 'daping') {
  143. /**
  144. * 主要是为了拿couponId
  145. */
  146. Http.get({
  147. url: config.api.couponDetail,
  148. data: {
  149. couponChannelId: options.couponChannelId
  150. }
  151. }).then(res => {
  152. let data = res.data;
  153. wx.redirectTo({
  154. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  155. })
  156. })
  157. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  158. // 转赠判断
  159. if (options.cuserId) {
  160. wx.redirectTo({
  161. 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}`,
  162. })
  163. } else {
  164. // 跳转普通券/消费卡/限时秒杀/砍价详情
  165. wx.redirectTo({
  166. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  167. })
  168. }
  169. }
  170. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  171. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup) ){
  172. wx.redirectTo({
  173. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  174. })
  175. }
  176. // 游戏页面
  177. else if (options && options.id && app.globalData.type == 'gm') {
  178. that.getGameOne(app.globalData.token, options.id)
  179. }
  180. // 报名活动页面
  181. else if (options && options.id && app.globalData.type == 'ra') {
  182. wx.redirectTo({
  183. url: `/pages/radetail/index?id=${options.id}`,
  184. })
  185. }
  186. //活动签到
  187. else if (options && options.id && app.globalData.type == 'si') {
  188. wx.redirectTo({
  189. url: `/pages/acSignIn/index?id=${options.id}`,
  190. })
  191. }
  192. // 宣传页详情
  193. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  194. if (options.bt == '2') {
  195. // 自由图文
  196. wx.redirectTo({
  197. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  198. })
  199. } else {
  200. // 标准格式
  201. wx.redirectTo({
  202. url: `/pages/bannerdetail/index?id=${options.id}`,
  203. })
  204. }
  205. }
  206. // 专题
  207. else if (options && options.id && app.globalData.type == 'td') {
  208. wx.redirectTo({
  209. url: `/pages/topicDetail/index?id=${options.id}`
  210. });
  211. }
  212. // 门店详情
  213. else if (options && options.id && app.globalData.type == 'md') {
  214. wx.redirectTo({
  215. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  216. });
  217. }
  218. // 参与砍价
  219. else if (options && options.orderId) {
  220. wx.redirectTo({
  221. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  222. })
  223. }
  224. // 我的
  225. else if (app.globalData.type == 'uc') {
  226. wx.switchTab({
  227. url: '/pages/user/index'
  228. });
  229. }
  230. // 积分
  231. else if (app.globalData.type == 'jf') {
  232. wx.redirectTo({
  233. url: '/pages/integralmall/index'
  234. });
  235. }
  236. // 首页
  237. else if (app.globalData.type == 'in') {
  238. wx.switchTab({
  239. url: '/pages/main/index'
  240. });
  241. }
  242. // 停车
  243. else if (app.globalData.type == 'pc') {
  244. // 停车
  245. wx.switchTab({
  246. url: '/pages/passCar/passCar'
  247. });
  248. }
  249. // 我的券包
  250. else if (app.globalData.type == 'mc') {
  251. // 我的券包
  252. wx.redirectTo({
  253. url: '/pages/couponorder/index/index'
  254. });
  255. }
  256. // 我的订单
  257. else if (app.globalData.type == 'mo') {
  258. // 我的订单
  259. wx.redirectTo({
  260. url: '/pages/order/index/index?id=all'
  261. });
  262. }
  263. // 我的卡包
  264. else if (app.globalData.type == 'ca') {
  265. // 我的卡包
  266. wx.redirectTo({
  267. url: '/pages/cardorder/index/index'
  268. });
  269. }
  270. // 特享礼遇
  271. else if (app.globalData.type == 'sc') {
  272. // 特享礼遇
  273. wx.redirectTo({
  274. url: '/pages/specialcourtesy/specialcourtesy'
  275. });
  276. }
  277. // 限时秒杀
  278. else if (app.globalData.type == 'rb') {
  279. // 限时秒杀
  280. wx.redirectTo({
  281. url: '/pages/rushToBuy/index'
  282. })
  283. }
  284. // 砍价专场
  285. else if (app.globalData.type == 'bl') {
  286. // 砍价专场
  287. wx.redirectTo({
  288. url: '/pages/bargain/bargain'
  289. })
  290. }
  291. // 我的砍价
  292. else if (app.globalData.type == 'mb') {
  293. // 我的砍价
  294. wx.redirectTo({
  295. url: '/pages/bargain/bargain?from=myhtml'
  296. })
  297. }
  298. // 拼团专场
  299. else if (app.globalData.type == 'sl') {
  300. // 拼团专场
  301. wx.redirectTo({
  302. url: '/pages/spellGroup/spellGroup'
  303. })
  304. }
  305. // 我的拼团
  306. else if (app.globalData.type == 'ms') {
  307. // 我的拼团
  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: '/pages/index/searchbar/index'
  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: '/pages/main/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 {
  377. wx.switchTab({
  378. url: '/index/index',
  379. })
  380. }
  381. }
  382. })
  383. },
  384. getGameOne: function(token, id) {
  385. let _this = this;
  386. Http.get({
  387. url: config.api.getOneGame,
  388. data: {
  389. token: token,
  390. id: id
  391. }
  392. }).then(res => {
  393. wx.redirectTo({
  394. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  395. })
  396. })
  397. .catch(err => {
  398. wx.showModal({
  399. title: '提示',
  400. content: err.message,
  401. showCancel: false,
  402. success: function(res) {
  403. // 如果游戏下架或者找不到,重启首页
  404. if (res.confirm) {
  405. wx.reLaunch({
  406. url: '/pages/index/index',
  407. })
  408. }
  409. }
  410. })
  411. this.alphaClick();
  412. })
  413. },
  414. })