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

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