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

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