C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

427 строки
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. /**
  17. * 根据接收到的参数的值,判断跳转到哪个页面
  18. */
  19. if (options && options.type) {
  20. app.globalData.type = options.type;
  21. }
  22. if (decodeURIComponent(options.scene) == "undefined") {
  23. that.setData({
  24. scene: 0
  25. });
  26. } else {
  27. that.setData({
  28. scene: decodeURIComponent(options.scene)
  29. });
  30. that.setData({
  31. newArr: this.data.scene.split(':')
  32. })
  33. console.log(this.data.newArr)
  34. //// 大屏-二维码-start
  35. if (this.data.newArr[0] == 'JC') {
  36. // 跳转券详情
  37. options.couponChannelId = this.data.newArr[1];
  38. } else if (this.data.newArr[0] == 'JG') {
  39. // 跳转拼团详情
  40. options.couponChannelId = this.data.newArr[1];
  41. options.path = 'daping'
  42. }
  43. else if (this.data.newArr[0] == 't') {
  44. // 普通二维码
  45. options.type = this.data.newArr[1];
  46. app.globalData.type = options.type;
  47. if(options.type == 'cd') {
  48. options.couponChannelId = this.data.newArr[2];
  49. } else if (options.type == 'bd') {
  50. options.bt = this.data.newArr[2];
  51. options.id = this.data.newArr[3];
  52. } else if (options.type == 'gm') {
  53. options.id = this.data.newArr[2];
  54. } else if (options.type == 'sd') {
  55. options.couponChannelId = this.data.newArr[2];
  56. } else if (options.type == 'td') {
  57. // 专题活动页
  58. options.id = this.data.newArr[2];
  59. }
  60. }
  61. }
  62. wx.showToast({
  63. title: '加载中',
  64. icon: "loading",
  65. duration: 2000
  66. })
  67. wx.setStorageSync('options', JSON.stringify(options))
  68. wx.setStorageSync('imgurl', imgurl)
  69. app.getLocation();
  70. if (options.couponChannelId || options.orderId || options.id) {
  71. that.userLogin(options);
  72. } else {
  73. that.userLogin()
  74. }
  75. },
  76. checkuserstatus(options) {
  77. let that = this;
  78. Http.get({
  79. url: config.api.checkUserStatus,
  80. data: {}
  81. })
  82. .then(res => {
  83. //参与拼团
  84. if (options && options.orderGroupId) {
  85. wx.redirectTo({
  86. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  87. })
  88. return;
  89. }
  90. //来自大屏的跳转拼团券详情
  91. else if (options && options.couponChannelId && options.path == 'daping') {
  92. /**
  93. * 主要是为了拿couponId
  94. */
  95. Http.get({
  96. url: config.api.couponDetail,
  97. data: {
  98. couponChannelId: options.couponChannelId
  99. }
  100. }).then(res => {
  101. let data = res.data;
  102. wx.redirectTo({
  103. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  104. })
  105. });
  106. return;
  107. }
  108. else if (options && options.couponChannelId && !options.spellGroup) {
  109. // 转赠判断
  110. if (options.cuserId){
  111. wx.redirectTo({
  112. 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}`,
  113. })
  114. }else{
  115. // 跳转普通券/消费卡/限时秒杀/砍价详情
  116. wx.redirectTo({
  117. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  118. })
  119. }
  120. }
  121. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  122. else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) {
  123. wx.redirectTo({
  124. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  125. })
  126. }
  127. // 游戏页面
  128. else if (options && options.id && app.globalData.type == 'gm') {
  129. that.getGameOne(app.globalData.token, options.id)
  130. }
  131. // 宣传页详情
  132. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  133. if (options.bt == '2') {
  134. // 自由图文
  135. wx.redirectTo({
  136. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  137. })
  138. } else {
  139. // 标准格式
  140. wx.redirectTo({
  141. url: `/pages/bannerdetail/index?id=${options.id}`,
  142. })
  143. }
  144. }
  145. // 专题
  146. else if (options && options.id && app.globalData.type == 'td'){
  147. wx.redirectTo({
  148. url: `/pages/topicDetail/index?id=${options.id}`
  149. });
  150. }
  151. // 参与砍价
  152. else if (options && options.orderId) {
  153. wx.redirectTo({
  154. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  155. })
  156. }
  157. // 我的
  158. else if (app.globalData.type == 'uc') {
  159. wx.switchTab({
  160. url: '/pages/user/index'
  161. });
  162. }
  163. // 积分
  164. else if (app.globalData.type == 'jf') {
  165. wx.redirectTo({
  166. url: '/pages/integralmall/index'
  167. });
  168. }
  169. // 首页
  170. else if (app.globalData.type == 'in') {
  171. wx.switchTab({
  172. url: '/pages/main/index'
  173. });
  174. }
  175. // 停车
  176. else if (app.globalData.type == 'pc') {
  177. // 停车
  178. wx.switchTab({
  179. url: '/pages/passCar/passCar'
  180. });
  181. }
  182. // 我的券包
  183. else if (app.globalData.type == 'mc') {
  184. // 我的券包
  185. wx.redirectTo({
  186. url: '/pages/couponorder/index/index'
  187. });
  188. }
  189. // 我的订单
  190. else if (app.globalData.type == 'mo') {
  191. // 我的订单
  192. wx.redirectTo({
  193. url: '/pages/order/index/index?id=all'
  194. });
  195. }
  196. // 我的卡包
  197. else if (app.globalData.type == 'ca') {
  198. // 我的卡包
  199. wx.redirectTo({
  200. url: '/pages/cardorder/index/index'
  201. });
  202. }
  203. // 特享礼遇
  204. else if (app.globalData.type == 'sc') {
  205. // 特享礼遇
  206. wx.redirectTo({
  207. url: '/pages/specialcourtesy/specialcourtesy'
  208. });
  209. }
  210. // 限时秒杀
  211. else if (app.globalData.type == 'rb') {
  212. // 限时秒杀
  213. wx.redirectTo({
  214. url: '/pages/rushToBuy/index'
  215. });
  216. }
  217. // 砍价专场
  218. else if (app.globalData.type == 'bl') {
  219. // 砍价专场
  220. wx.redirectTo({
  221. url: '/pages/bargain/bargain'
  222. });
  223. }
  224. // 我的砍价
  225. else if (app.globalData.type == 'mb') {
  226. // 我的砍价
  227. wx.redirectTo({
  228. url: '/pages/bargain/bargain?from=myhtml'
  229. });
  230. }
  231. // 拼团专场
  232. else if (app.globalData.type == 'sl') {
  233. // 拼团专场
  234. wx.redirectTo({
  235. url: '/pages/spellGroup/spellGroup'
  236. });
  237. }
  238. // 我的拼团
  239. else if (app.globalData.type == 'ms') {
  240. // 我的拼团
  241. wx.redirectTo({
  242. url: '/pages/spellGroup/spellGroup?from=myhtml'
  243. });
  244. }
  245. // 消费卡
  246. else if (app.globalData.type == 'dc') {
  247. // 消费卡
  248. wx.redirectTo({
  249. url: '/pages/discountCardList/discountCardList'
  250. });
  251. }
  252. // 门店
  253. else if (app.globalData.type == 'ml') {
  254. // 门店
  255. wx.switchTab({
  256. url: '/pages/index/searchbar/index'
  257. });
  258. } else {
  259. // 主页
  260. wx.switchTab({
  261. url: '/pages/main/index'
  262. });
  263. }
  264. })
  265. .catch(err => {
  266. if (err.code == 11004) {
  267. // 用户昵称未授权
  268. if (options && options.orderGroupId) {
  269. wx.redirectTo({
  270. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  271. })
  272. return;
  273. }
  274. /**
  275. * spellGroup
  276. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  277. * 注意:拼团券和普通券是两个页面
  278. */
  279. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  280. wx.redirectTo({
  281. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  282. });
  283. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  284. wx.redirectTo({
  285. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  286. });
  287. } else if (options && options.couponChannelId && options.cuserId) {
  288. /**
  289. * 转赠判断
  290. */
  291. wx.redirectTo({
  292. 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}`
  293. });
  294. } else if (options && options.orderId) {
  295. wx.redirectTo({
  296. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  297. });
  298. } else {
  299. wx.redirectTo({
  300. url: `/pages/getuserinfo/index`
  301. });
  302. }
  303. }
  304. });
  305. },
  306. /**
  307. * 用户登录
  308. */
  309. userLogin: function (options) {
  310. var that = this;
  311. // 登录
  312. wx.login({
  313. success: ({
  314. code
  315. }) => {
  316. wx.getSystemInfo({
  317. success: function (res) {
  318. that.setData({
  319. systemInfo: JSON.stringify(res)
  320. })
  321. }
  322. })
  323. var usrdata = {
  324. appId: config.weapp.AppId,
  325. code: code,
  326. sceneAddress: app.globalData.sceneAddress,
  327. scene: that.data.scene,
  328. systemInfo: that.data.systemInfo
  329. };
  330. if (app.globalData.locationInfo) {
  331. usrdata = {
  332. appId: config.weapp.AppId,
  333. code: code,
  334. sceneAddress: app.globalData.sceneAddress,
  335. latitude: "" + app.globalData.locationInfo.latitude,
  336. longitude: "" + app.globalData.locationInfo.longitude,
  337. scene: that.data.scene,
  338. systemInfo: that.data.systemInfo
  339. };
  340. }
  341. Http.post({
  342. url: config.api.login,
  343. data: usrdata
  344. })
  345. .then(res => {
  346. that.setData({
  347. showPages: true
  348. })
  349. app.globalData.token = res.data.token;
  350. app.globalData.openId = res.data.openId;
  351. // 初始化websocket
  352. if (extConfig.attr.ifHaveWebSocket == 1) {
  353. app.initSocket();
  354. // 回调发送给自己的消息
  355. app.globalData.socketReceiver = function (e) {
  356. let msgList = that.data.msgList
  357. msgList.push(e)
  358. that.setData({
  359. msgList: msgList
  360. })
  361. }
  362. }
  363. if (res.data && res.data.score) {
  364. if (res.data.score != 0) {
  365. app.globalData.score = res.data.score;
  366. }
  367. }
  368. Http.setToken(res.data.token);
  369. if (options && (options.couponChannelId || options.orderId || options.id)) {
  370. that.checkuserstatus(options);
  371. } else {
  372. that.checkuserstatus();
  373. }
  374. })
  375. .catch(err => {
  376. wx.showModal({
  377. title: '提示',
  378. showCancel: false,
  379. content: '登录失败,请重新尝试',
  380. success: function (res) {
  381. if (res.cancel) {
  382. //点击取消,默认隐藏弹框
  383. } else {
  384. //点击确定
  385. wx.reLaunch({
  386. url: '/pages/index/index',
  387. })
  388. }
  389. }
  390. })
  391. });
  392. }
  393. });
  394. },
  395. getGameOne: function (token, id) {
  396. let _this = this;
  397. Http.get({
  398. url: config.api.getOneGame,
  399. data: {
  400. token: token,
  401. id: id
  402. }
  403. }).then(res => {
  404. wx.redirectTo({
  405. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  406. })
  407. })
  408. .catch(err => {
  409. wx.showModal({
  410. title: '提示',
  411. content: err.message,
  412. showCancel: false,
  413. success:function(res){
  414. // 如果游戏下架或者找不到,重启首页
  415. if (res.confirm){
  416. wx.reLaunch({
  417. url: '/pages/index/index',
  418. })
  419. }
  420. }
  421. })
  422. this.alphaClick();
  423. })
  424. },
  425. })