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.

595 lines
18 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const imgurl = require("../../utils/imgurl");
  3. const config = require("../../config/config");
  4. let app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tenantData: wx.getStorageSync('tenantData')?JSON.parse(wx.getStorageSync('tenantData')):[]
  11. },
  12. bindPickerChange(options) {
  13. console.log('picker发送选择改变,携带值为', options.tenantId, this.data.tenantData)
  14. let selectIndex = 0;
  15. this.data.tenantData.map((item, index) => {
  16. if (options.tenantId == item.tenantId) {
  17. selectIndex = index;
  18. wx.setStorageSync('tenantId', item.tenantId)
  19. }
  20. })
  21. console.log()
  22. let param = {
  23. tenantId: this.data.tenantData[selectIndex].parentTenantId,
  24. subTenantId: this.data.tenantData[selectIndex].tenantId
  25. }
  26. this.checkAble = true;
  27. wx.showLoading({
  28. title: '切换中...',
  29. })
  30. Http.post({
  31. url: config.api.selectMall,
  32. data: param
  33. }).then(res => {
  34. wx.setStorageSync('tenantId', this.data.tenantData[selectIndex].tenantId)
  35. wx.hideLoading();
  36. wx.showToast({
  37. title: '切换成功!',
  38. icon: 'success',
  39. duration: 2000
  40. })
  41. wx.reLaunch({
  42. url: '/index/index',
  43. })
  44. })
  45. .catch(err => {
  46. wx.showModal({
  47. title: '提示',
  48. content: err.message,
  49. showCancel: false,
  50. success: function (res) {
  51. // 重启首页
  52. if (res.confirm) {
  53. wx.reLaunch({
  54. url: '/pages/index/index',
  55. })
  56. }
  57. }
  58. })
  59. this.alphaClick();
  60. })
  61. },
  62. goContinue(options){
  63. let that = this;
  64. wx.showToast({
  65. title: '加载中',
  66. icon: "loading",
  67. duration: 2000
  68. })
  69. /**
  70. * 根据接收到的参数的值,判断跳转到哪个页面
  71. */
  72. if (options && options.type) {
  73. app.globalData.type = options.type;
  74. }
  75. if (decodeURIComponent(options.scene) == "undefined") {
  76. that.setData({
  77. scene: 0
  78. })
  79. app.globalData.scene = 0;
  80. } else {
  81. that.setData({
  82. scene: decodeURIComponent(options.scene)
  83. });
  84. app.globalData.scene = decodeURIComponent(options.scene)
  85. that.setData({
  86. newArr: this.data.scene.split(':')
  87. })
  88. //// 大屏-二维码-start
  89. if (this.data.newArr[0] == 'JC') {
  90. // 跳转券详情
  91. options.couponChannelId = this.data.newArr[1];
  92. } else if (this.data.newArr[0] == 'JG') {
  93. // 跳转拼团详情
  94. options.couponChannelId = this.data.newArr[1];
  95. options.path = 'daping'
  96. } else if (this.data.newArr[0] == 't') {
  97. // 普通二维码
  98. options.type = this.data.newArr[1];
  99. app.globalData.type = options.type;
  100. if (options.type == 'cd') {
  101. options.couponChannelId = this.data.newArr[2];
  102. } else if (options.type == 'bd') {
  103. options.bt = this.data.newArr[2];
  104. options.id = this.data.newArr[3];
  105. } else if (options.type == 'gm') {
  106. options.id = this.data.newArr[2];
  107. } else if (options.type == 'sd') {
  108. options.couponChannelId = this.data.newArr[2];
  109. } else if (options.type == 'td') {
  110. // 专题活动页
  111. options.id = this.data.newArr[2];
  112. } else if (options.type == 'md') {
  113. // 门店详情
  114. options.id = this.data.newArr[2];
  115. } else if (options.type == 'ra') {
  116. //活动详情
  117. options.id = this.data.newArr[2];
  118. } else if (options.type == 'si') {
  119. //活动签到
  120. options.id = this.data.newArr[2];
  121. }
  122. }
  123. }
  124. wx.setStorageSync('options', JSON.stringify(options))
  125. wx.setStorageSync('imgurl', imgurl);
  126. if (app.globalData.token) {
  127. this.updateUserInfo();
  128. if (options.couponChannelId || options.orderId || options.id) {
  129. that.userStatus(options);
  130. } else {
  131. that.userStatus();
  132. }
  133. } else {
  134. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  135. // 所以此处加入 callback 以防止这种情况
  136. app.tokenCallback = token => {
  137. this.updateUserInfo();
  138. if (options.couponChannelId || options.orderId || options.id) {
  139. that.userStatus(options);
  140. } else {
  141. that.userStatus();
  142. }
  143. }
  144. }
  145. },
  146. /**
  147. * 生命周期函数--监听页面加载
  148. */
  149. onLoad: function(options) {
  150. let that = this;
  151. console.log(options, wx.getStorageSync('tenantData'),1112222);
  152. if (options.tenantId){
  153. this.bindPickerChange(options);
  154. }else{
  155. this.goContinue(options);
  156. }
  157. },
  158. /**
  159. * 检查用户的状态
  160. */
  161. userStatus: function(options) {
  162. var that = this;
  163. if (options && (options.couponChannelId || options.orderId || options.id)) {
  164. that.checkuserstatus(options);
  165. } else {
  166. that.checkuserstatus();
  167. }
  168. },
  169. /**
  170. * 获取手机信息
  171. */
  172. updateUserInfo() {
  173. wx.getSystemInfo({
  174. success: function (res) {
  175. Http.post({
  176. url: config.api.updateUserInfo,
  177. data: {
  178. systemInfo: JSON.stringify(res)
  179. }
  180. }).then(res => {
  181. console.log(res)
  182. })
  183. }
  184. })
  185. },
  186. checkuserstatus(options) {
  187. let that = this;
  188. Http.get({
  189. url: config.api.checkUserStatus,
  190. data: {
  191. token: app.globalData.token
  192. }
  193. })
  194. .then(res => {
  195. //参与拼团
  196. if (options && options.orderGroupId) {
  197. wx.redirectTo({
  198. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  199. })
  200. }
  201. //来自大屏的跳转拼团券详情
  202. else if (options && options.couponChannelId && options.path == 'daping') {
  203. /**
  204. * 主要是为了拿couponId
  205. */
  206. Http.get({
  207. url: config.api.couponDetail,
  208. data: {
  209. couponChannelId: options.couponChannelId
  210. }
  211. }).then(res => {
  212. let data = res.data;
  213. wx.redirectTo({
  214. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  215. })
  216. })
  217. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  218. // 转赠判断
  219. if (options.cuserId) {
  220. wx.redirectTo({
  221. 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}`,
  222. })
  223. } else {
  224. // 跳转普通券/消费卡/限时秒杀/砍价详情
  225. wx.redirectTo({
  226. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  227. })
  228. }
  229. }
  230. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  231. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  232. wx.redirectTo({
  233. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  234. })
  235. }
  236. // 游戏页面
  237. else if (options && options.id && app.globalData.type == 'gm') {
  238. that.getGameOne(app.globalData.token, options.id)
  239. }
  240. // 报名活动页面
  241. else if (options && options.id && app.globalData.type == 'ra') {
  242. wx.redirectTo({
  243. url: `/pages/radetail/index?id=${options.id}`,
  244. })
  245. }
  246. //活动签到
  247. else if (options && options.id && app.globalData.type == 'si') {
  248. wx.redirectTo({
  249. url: `/pages/acSignIn/index?id=${options.id}`,
  250. })
  251. }
  252. // 宣传页详情
  253. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  254. if (options.bt == '2') {
  255. // 自由图文
  256. wx.redirectTo({
  257. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  258. })
  259. } else {
  260. // 标准格式
  261. wx.redirectTo({
  262. url: `/pages/bannerdetail/index?id=${options.id}`,
  263. })
  264. }
  265. }
  266. // 专题
  267. else if (options && options.id && app.globalData.type == 'td') {
  268. wx.redirectTo({
  269. url: `/pages/topicDetail/index?id=${options.id}`
  270. });
  271. }
  272. // 门店详情
  273. else if (options && options.id && app.globalData.type == 'md') {
  274. wx.redirectTo({
  275. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  276. });
  277. }
  278. // 参与砍价
  279. else if (options && options.orderId) {
  280. wx.redirectTo({
  281. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  282. })
  283. }
  284. // 我的
  285. else if (app.globalData.type == 'uc') {
  286. wx.switchTab({
  287. url: '/index/user'
  288. });
  289. }
  290. // 积分
  291. else if (app.globalData.type == 'jf') {
  292. wx.redirectTo({
  293. url: '/pages/integralmall/index'
  294. });
  295. }
  296. // 首页
  297. else if (app.globalData.type == 'in') {
  298. wx.switchTab({
  299. url: '/index/index'
  300. });
  301. }
  302. // 停车
  303. else if (app.globalData.type == 'pc') {
  304. // 停车
  305. wx.switchTab({
  306. url: '/index/passCar'
  307. });
  308. }
  309. // 我的券包
  310. else if (app.globalData.type == 'mc') {
  311. // 我的券包
  312. wx.redirectTo({
  313. url: '/pages/couponorder/index/index'
  314. });
  315. }
  316. // 我的订单
  317. else if (app.globalData.type == 'mo') {
  318. // 我的订单
  319. wx.redirectTo({
  320. url: '/pages/order/index/index?id=all'
  321. });
  322. }
  323. // 我的卡包
  324. else if (app.globalData.type == 'ca') {
  325. // 我的卡包
  326. wx.redirectTo({
  327. url: '/pages/cardorder/index/index'
  328. });
  329. }
  330. // 特享礼遇
  331. else if (app.globalData.type == 'sc') {
  332. // 特享礼遇
  333. wx.redirectTo({
  334. url: '/pages/specialcourtesy/specialcourtesy'
  335. });
  336. }
  337. // 限时秒杀
  338. else if (app.globalData.type == 'rb') {
  339. // 限时秒杀
  340. wx.redirectTo({
  341. url: '/pages/rushToBuy/index'
  342. })
  343. }
  344. // 砍价专场
  345. else if (app.globalData.type == 'bl') {
  346. // 砍价专场
  347. wx.redirectTo({
  348. url: '/pages/bargain/bargain'
  349. })
  350. }
  351. // 我的砍价
  352. else if (app.globalData.type == 'mb') {
  353. // 我的砍价
  354. wx.redirectTo({
  355. url: '/pages/bargain/bargain?from=myhtml'
  356. })
  357. }
  358. // 拼团专场
  359. else if (app.globalData.type == 'sl') {
  360. // 拼团专场
  361. wx.redirectTo({
  362. url: '/pages/spellGroup/spellGroup'
  363. })
  364. }
  365. // 我的拼团
  366. else if (app.globalData.type == 'ms') {
  367. // 我的拼团
  368. wx.redirectTo({
  369. url: '/pages/spellGroup/spellGroup?from=myhtml'
  370. })
  371. }
  372. // 消费卡
  373. else if (app.globalData.type == 'dc') {
  374. // 消费卡
  375. wx.redirectTo({
  376. url: '/pages/discountCardList/discountCardList'
  377. })
  378. }
  379. // 门店
  380. else if (app.globalData.type == 'ml') {
  381. wx.switchTab({
  382. url: '/index/searchbar'
  383. })
  384. }
  385. // 兑换
  386. else if (app.globalData.type == 'ec') {
  387. wx.redirectTo({
  388. url: '/pages/exchange/exchange'
  389. })
  390. }
  391. // 通过分享进入的门店详情
  392. else if (options && options.id && options.frommd == 'md') {
  393. wx.redirectTo({
  394. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  395. });
  396. } else {
  397. // 主页
  398. wx.switchTab({
  399. url: '/index/index'
  400. })
  401. }
  402. })
  403. .catch(err => {
  404. console.log(err)
  405. if (err.code == 11004) {
  406. // 用户昵称未授权
  407. if (options && options.orderGroupId) {
  408. wx.redirectTo({
  409. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  410. })
  411. }
  412. /**
  413. * spellGroup
  414. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  415. * 注意:拼团券和普通券是两个页面
  416. */
  417. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  418. wx.redirectTo({
  419. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  420. })
  421. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  422. wx.redirectTo({
  423. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  424. })
  425. } else if (options && options.couponChannelId && options.cuserId) {
  426. /**
  427. * 转赠判断
  428. */
  429. wx.redirectTo({
  430. 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}`
  431. })
  432. } else if (options && options.orderId) {
  433. wx.redirectTo({
  434. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  435. })
  436. }
  437. // 通过分享进入的门店详情
  438. else if (options && options.id && options.frommd == 'md') {
  439. wx.redirectTo({
  440. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  441. });
  442. }// 门店详情
  443. else if (options && options.id && app.globalData.type == 'md') {
  444. wx.redirectTo({
  445. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  446. });
  447. } else if (app.globalData.type == 'uc') {
  448. wx.switchTab({
  449. url: '/index/user'
  450. });
  451. }
  452. // 积分
  453. else if (app.globalData.type == 'jf') {
  454. wx.redirectTo({
  455. url: '/pages/integralmall/index'
  456. });
  457. }
  458. // 首页
  459. else if (app.globalData.type == 'in') {
  460. wx.switchTab({
  461. url: '/index/index'
  462. });
  463. }
  464. // 停车
  465. else if (app.globalData.type == 'pc') {
  466. // 停车
  467. wx.switchTab({
  468. url: '/index/passCar'
  469. });
  470. }
  471. // 我的券包
  472. else if (app.globalData.type == 'mc') {
  473. // 我的券包
  474. wx.redirectTo({
  475. url: '/pages/couponorder/index/index'
  476. });
  477. }
  478. // 我的订单
  479. else if (app.globalData.type == 'mo') {
  480. // 我的订单
  481. wx.redirectTo({
  482. url: '/pages/order/index/index?id=all'
  483. });
  484. }
  485. // 我的卡包
  486. else if (app.globalData.type == 'ca') {
  487. // 我的卡包
  488. wx.redirectTo({
  489. url: '/pages/cardorder/index/index'
  490. });
  491. }
  492. // 特享礼遇
  493. else if (app.globalData.type == 'sc') {
  494. // 特享礼遇
  495. wx.redirectTo({
  496. url: '/pages/specialcourtesy/specialcourtesy'
  497. });
  498. }
  499. // 限时秒杀
  500. else if (app.globalData.type == 'rb') {
  501. // 限时秒杀
  502. wx.redirectTo({
  503. url: '/pages/rushToBuy/index'
  504. })
  505. }
  506. // 砍价专场
  507. else if (app.globalData.type == 'bl') {
  508. // 砍价专场
  509. wx.redirectTo({
  510. url: '/pages/bargain/bargain'
  511. })
  512. }
  513. // 我的砍价
  514. else if (app.globalData.type == 'mb') {
  515. // 我的砍价
  516. wx.redirectTo({
  517. url: '/pages/bargain/bargain?from=myhtml'
  518. })
  519. }
  520. // 拼团专场
  521. else if (app.globalData.type == 'sl') {
  522. // 拼团专场
  523. wx.redirectTo({
  524. url: '/pages/spellGroup/spellGroup'
  525. })
  526. }
  527. // 我的拼团
  528. else if (app.globalData.type == 'ms') {
  529. wx.redirectTo({
  530. url: '/pages/spellGroup/spellGroup?from=myhtml'
  531. })
  532. }
  533. // 消费卡
  534. else if (app.globalData.type == 'dc') {
  535. // 消费卡
  536. wx.redirectTo({
  537. url: '/pages/discountCardList/discountCardList'
  538. })
  539. }
  540. // 兑换
  541. else if (app.globalData.type == 'ec') {
  542. wx.redirectTo({
  543. url: '/pages/exchange/exchange'
  544. })
  545. }
  546. // 门店
  547. else if (app.globalData.type == 'ml') {
  548. wx.switchTab({
  549. url: '/index/searchbar'
  550. })
  551. } else {
  552. wx.switchTab({
  553. url: '/index/index',
  554. })
  555. }
  556. }
  557. })
  558. },
  559. getGameOne: function(token, id) {
  560. let _this = this;
  561. Http.get({
  562. url: config.api.getOneGame,
  563. data: {
  564. token: token,
  565. id: id
  566. }
  567. }).then(res => {
  568. wx.redirectTo({
  569. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  570. })
  571. })
  572. .catch(err => {
  573. wx.showModal({
  574. title: '提示',
  575. content: err.message,
  576. showCancel: false,
  577. success: function(res) {
  578. // 如果游戏下架或者找不到,重启首页
  579. if (res.confirm) {
  580. wx.reLaunch({
  581. url: '/pages/index/index',
  582. })
  583. }
  584. }
  585. })
  586. this.alphaClick();
  587. })
  588. },
  589. })