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.

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