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.

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