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.

402 lines
13 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. if (options.couponChannelId || options.orderId || options.id) {
  80. that.userStatus(options);
  81. } else {
  82. that.userStatus();
  83. }
  84. } else {
  85. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  86. // 所以此处加入 callback 以防止这种情况
  87. app.tokenCallback = token => {
  88. if (options.couponChannelId || options.orderId || options.id) {
  89. that.userStatus(options);
  90. } else {
  91. that.userStatus();
  92. }
  93. }
  94. }
  95. },
  96. /**
  97. * 检查用户的状态
  98. */
  99. userStatus: function(options) {
  100. var that = this;
  101. if (options && (options.couponChannelId || options.orderId || options.id)) {
  102. that.checkuserstatus(options);
  103. } else {
  104. that.checkuserstatus();
  105. }
  106. },
  107. checkuserstatus(options) {
  108. let that = this;
  109. Http.get({
  110. url: config.api.checkUserStatus,
  111. data: {
  112. token:app.globalData.token
  113. }
  114. })
  115. .then(res => {
  116. //参与拼团
  117. if (options && options.orderGroupId) {
  118. wx.redirectTo({
  119. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  120. })
  121. }
  122. //来自大屏的跳转拼团券详情
  123. else if (options && options.couponChannelId && options.path == 'daping') {
  124. /**
  125. * 主要是为了拿couponId
  126. */
  127. Http.get({
  128. url: config.api.couponDetail,
  129. data: {
  130. couponChannelId: options.couponChannelId
  131. }
  132. }).then(res => {
  133. let data = res.data;
  134. wx.redirectTo({
  135. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  136. })
  137. })
  138. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  139. // 转赠判断
  140. if (options.cuserId) {
  141. wx.redirectTo({
  142. 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}`,
  143. })
  144. } else {
  145. // 跳转普通券/消费卡/限时秒杀/砍价详情
  146. wx.redirectTo({
  147. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  148. })
  149. }
  150. }
  151. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  152. else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) {
  153. wx.redirectTo({
  154. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  155. })
  156. }
  157. // 游戏页面
  158. else if (options && options.id && app.globalData.type == 'gm') {
  159. that.getGameOne(app.globalData.token, options.id)
  160. }
  161. // 报名活动页面
  162. else if (options && options.id && app.globalData.type == 'ra') {
  163. wx.redirectTo({
  164. url: `/pages/radetail/index?id=${options.id}`,
  165. })
  166. }
  167. //活动签到
  168. else if (options && options.id && app.globalData.type == 'si') {
  169. wx.redirectTo({
  170. url: `/pages/acSignIn/index?id=${options.id}`,
  171. })
  172. }
  173. // 宣传页详情
  174. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  175. if (options.bt == '2') {
  176. // 自由图文
  177. wx.redirectTo({
  178. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  179. })
  180. } else {
  181. // 标准格式
  182. wx.redirectTo({
  183. url: `/pages/bannerdetail/index?id=${options.id}`,
  184. })
  185. }
  186. }
  187. // 专题
  188. else if (options && options.id && app.globalData.type == 'td') {
  189. wx.redirectTo({
  190. url: `/pages/topicDetail/index?id=${options.id}`
  191. });
  192. }
  193. // 门店详情
  194. else if (options && options.id && app.globalData.type == 'md') {
  195. wx.redirectTo({
  196. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  197. });
  198. }
  199. // 参与砍价
  200. else if (options && options.orderId) {
  201. wx.redirectTo({
  202. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  203. })
  204. }
  205. // 我的
  206. else if (app.globalData.type == 'uc') {
  207. wx.switchTab({
  208. url: '/pages/user/index'
  209. });
  210. }
  211. // 积分
  212. else if (app.globalData.type == 'jf') {
  213. wx.redirectTo({
  214. url: '/pages/integralmall/index'
  215. });
  216. }
  217. // 首页
  218. else if (app.globalData.type == 'in') {
  219. wx.switchTab({
  220. url: '/pages/main/index'
  221. });
  222. }
  223. // 停车
  224. else if (app.globalData.type == 'pc') {
  225. // 停车
  226. wx.switchTab({
  227. url: '/pages/passCar/passCar'
  228. });
  229. }
  230. // 我的券包
  231. else if (app.globalData.type == 'mc') {
  232. // 我的券包
  233. wx.redirectTo({
  234. url: '/pages/couponorder/index/index'
  235. });
  236. }
  237. // 我的订单
  238. else if (app.globalData.type == 'mo') {
  239. // 我的订单
  240. wx.redirectTo({
  241. url: '/pages/order/index/index?id=all'
  242. });
  243. }
  244. // 我的卡包
  245. else if (app.globalData.type == 'ca') {
  246. // 我的卡包
  247. wx.redirectTo({
  248. url: '/pages/cardorder/index/index'
  249. });
  250. }
  251. // 特享礼遇
  252. else if (app.globalData.type == 'sc') {
  253. // 特享礼遇
  254. wx.redirectTo({
  255. url: '/pages/specialcourtesy/specialcourtesy'
  256. });
  257. }
  258. // 限时秒杀
  259. else if (app.globalData.type == 'rb') {
  260. // 限时秒杀
  261. wx.redirectTo({
  262. url: '/pages/rushToBuy/index'
  263. })
  264. }
  265. // 砍价专场
  266. else if (app.globalData.type == 'bl') {
  267. // 砍价专场
  268. wx.redirectTo({
  269. url: '/pages/bargain/bargain'
  270. })
  271. }
  272. // 我的砍价
  273. else if (app.globalData.type == 'mb') {
  274. // 我的砍价
  275. wx.redirectTo({
  276. url: '/pages/bargain/bargain?from=myhtml'
  277. })
  278. }
  279. // 拼团专场
  280. else if (app.globalData.type == 'sl') {
  281. // 拼团专场
  282. wx.redirectTo({
  283. url: '/pages/spellGroup/spellGroup'
  284. })
  285. }
  286. // 我的拼团
  287. else if (app.globalData.type == 'ms') {
  288. // 我的拼团
  289. wx.redirectTo({
  290. url: '/pages/spellGroup/spellGroup?from=myhtml'
  291. })
  292. }
  293. // 消费卡
  294. else if (app.globalData.type == 'dc') {
  295. // 消费卡
  296. wx.redirectTo({
  297. url: '/pages/discountCardList/discountCardList'
  298. })
  299. }
  300. // 门店
  301. else if (app.globalData.type == 'ml') {
  302. wx.switchTab({
  303. url: '/pages/index/searchbar/index'
  304. })
  305. }
  306. // 通过分享进入的门店详情
  307. else if (options && options.id && options.frommd == 'md') {
  308. wx.redirectTo({
  309. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  310. });
  311. }else {
  312. // 主页
  313. wx.switchTab({
  314. url: '/pages/main/index'
  315. })
  316. }
  317. })
  318. .catch(err => {
  319. console.log(err)
  320. if (err.code == 11004) {
  321. // 用户昵称未授权
  322. if (options && options.orderGroupId) {
  323. wx.redirectTo({
  324. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  325. })
  326. }
  327. /**
  328. * spellGroup
  329. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  330. * 注意:拼团券和普通券是两个页面
  331. */
  332. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  333. wx.redirectTo({
  334. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  335. })
  336. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  337. wx.redirectTo({
  338. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  339. })
  340. } else if (options && options.couponChannelId && options.cuserId) {
  341. /**
  342. * 转赠判断
  343. */
  344. wx.redirectTo({
  345. 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}`
  346. })
  347. } else if (options && options.orderId) {
  348. wx.redirectTo({
  349. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  350. })
  351. }
  352. // 通过分享进入的门店详情
  353. else if (options && options.id && options.frommd == 'md') {
  354. wx.redirectTo({
  355. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  356. });
  357. } else {
  358. wx.redirectTo({
  359. url: `/pages/getuserinfo/index`
  360. });
  361. }
  362. }
  363. });
  364. },
  365. getGameOne: function(token, id) {
  366. let _this = this;
  367. Http.get({
  368. url: config.api.getOneGame,
  369. data: {
  370. token: token,
  371. id: id
  372. }
  373. }).then(res => {
  374. wx.redirectTo({
  375. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  376. })
  377. })
  378. .catch(err => {
  379. wx.showModal({
  380. title: '提示',
  381. content: err.message,
  382. showCancel: false,
  383. success: function(res) {
  384. // 如果游戏下架或者找不到,重启首页
  385. if (res.confirm) {
  386. wx.reLaunch({
  387. url: '/pages/index/index',
  388. })
  389. }
  390. }
  391. })
  392. this.alphaClick();
  393. })
  394. },
  395. })