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.

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