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.

602 lines
19 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. console.log(options,77777777)
  196. //参与拼团
  197. if (options && options.orderGroupId) {
  198. wx.redirectTo({
  199. url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  200. })
  201. }
  202. //来自大屏的跳转拼团券详情
  203. else if (options && options.couponChannelId && options.path == 'daping') {
  204. /**
  205. * 主要是为了拿couponId
  206. */
  207. Http.get({
  208. url: config.api.couponDetail,
  209. data: {
  210. couponChannelId: options.couponChannelId
  211. }
  212. }).then(res => {
  213. let data = res.data;
  214. wx.redirectTo({
  215. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}`
  216. })
  217. })
  218. } else if (options && options.couponChannelId && !options.spellGroup && app.globalData.type != 'sd') {
  219. // 转赠判断
  220. if (options.cuserId) {
  221. wx.redirectTo({
  222. 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}`,
  223. })
  224. } else {
  225. // 跳转普通券/消费卡/限时秒杀/砍价详情
  226. wx.redirectTo({
  227. url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`,
  228. })
  229. }
  230. }
  231. // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口)
  232. else if ((options && options.couponChannelId && app.globalData.type == 'sd') || (options && options.couponChannelId && options.spellGroup)) {
  233. wx.redirectTo({
  234. url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`,
  235. })
  236. }
  237. // 游戏页面
  238. else if (options && options.id && app.globalData.type == 'gm') {
  239. that.getGameOne(app.globalData.token, options.id)
  240. }
  241. // 报名活动页面
  242. else if (options && options.id && app.globalData.type == 'ra') {
  243. wx.redirectTo({
  244. url: `/pages/radetail/index?id=${options.id}`,
  245. })
  246. }
  247. //活动签到
  248. else if (options && options.id && app.globalData.type == 'si') {
  249. wx.redirectTo({
  250. url: `/pages/acSignIn/index?id=${options.id}`,
  251. })
  252. }
  253. // 宣传页详情
  254. else if (options && options.bt && options.id && app.globalData.type == 'bd') {
  255. if (options.bt == '2') {
  256. // 自由图文
  257. wx.redirectTo({
  258. url: `/pages/freeBannerDetail/index?id=${options.id}`,
  259. })
  260. } else {
  261. // 标准格式
  262. wx.redirectTo({
  263. url: `/pages/bannerdetail/index?id=${options.id}`,
  264. })
  265. }
  266. }
  267. // 专题
  268. else if (options && options.id && app.globalData.type == 'td') {
  269. wx.redirectTo({
  270. url: `/pages/topicDetail/index?id=${options.id}`
  271. });
  272. }
  273. // 门店详情
  274. else if (options && options.id && app.globalData.type == 'md') {
  275. wx.redirectTo({
  276. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  277. });
  278. }
  279. // 参与砍价
  280. else if (options && options.orderId) {
  281. wx.redirectTo({
  282. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${options.orderId}&from=${"discount"}`,
  283. })
  284. }
  285. // 我的
  286. else if (app.globalData.type == 'uc') {
  287. wx.switchTab({
  288. url: '/index/user'
  289. });
  290. }
  291. // 积分
  292. else if (app.globalData.type == 'jf') {
  293. wx.redirectTo({
  294. url: '/pages/integralmall/index'
  295. });
  296. }
  297. // 首页
  298. else if (app.globalData.type == 'in') {
  299. wx.switchTab({
  300. url: '/index/index'
  301. });
  302. }
  303. // 停车
  304. else if (app.globalData.type == 'pc') {
  305. // 停车
  306. wx.switchTab({
  307. url: '/index/passCar'
  308. });
  309. }
  310. // 我的券包
  311. else if (app.globalData.type == 'mc') {
  312. // 我的券包
  313. wx.redirectTo({
  314. url: '/pages/couponorder/index/index'
  315. });
  316. }
  317. // 我的订单
  318. else if (app.globalData.type == 'mo') {
  319. // 我的订单
  320. wx.redirectTo({
  321. url: '/pages/order/index/index?id=all'
  322. });
  323. }
  324. // 我的卡包
  325. else if (app.globalData.type == 'ca') {
  326. // 我的卡包
  327. wx.redirectTo({
  328. url: '/pages/cardorder/index/index'
  329. });
  330. }
  331. // 特享礼遇
  332. else if (app.globalData.type == 'sc') {
  333. // 特享礼遇
  334. wx.redirectTo({
  335. url: '/pages/specialcourtesy/specialcourtesy'
  336. });
  337. }
  338. // 限时秒杀
  339. else if (app.globalData.type == 'rb') {
  340. // 限时秒杀
  341. wx.redirectTo({
  342. url: '/pages/rushToBuy/index'
  343. })
  344. }
  345. // 砍价专场
  346. else if (app.globalData.type == 'bl') {
  347. // 砍价专场
  348. wx.redirectTo({
  349. url: '/pages/bargain/bargain'
  350. })
  351. }
  352. // 我的砍价
  353. else if (app.globalData.type == 'mb') {
  354. // 我的砍价
  355. wx.redirectTo({
  356. url: '/pages/bargain/bargain?from=myhtml'
  357. })
  358. }
  359. // 拼团专场
  360. else if (app.globalData.type == 'sl') {
  361. // 拼团专场
  362. wx.redirectTo({
  363. url: '/pages/spellGroup/spellGroup'
  364. })
  365. }
  366. // 我的拼团
  367. else if (app.globalData.type == 'ms') {
  368. // 我的拼团
  369. wx.redirectTo({
  370. url: '/pages/spellGroup/spellGroup?from=myhtml'
  371. })
  372. }
  373. // 消费卡
  374. else if (app.globalData.type == 'dc') {
  375. // 消费卡
  376. wx.redirectTo({
  377. url: '/pages/discountCardList/discountCardList'
  378. })
  379. }
  380. // 门店
  381. else if (app.globalData.type == 'ml') {
  382. wx.switchTab({
  383. url: '/index/searchbar'
  384. })
  385. }
  386. // 兑换
  387. else if (app.globalData.type == 'ec') {
  388. wx.redirectTo({
  389. url: '/pages/exchange/exchange'
  390. })
  391. }
  392. // 通过分享进入的门店详情
  393. else if (options && options.id && options.frommd == 'md') {
  394. wx.redirectTo({
  395. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  396. });
  397. } else {
  398. // 主页
  399. wx.switchTab({
  400. url: '/index/index'
  401. })
  402. }
  403. })
  404. .catch(err => {
  405. console.log(err)
  406. if (err.code == 11004) {
  407. // 用户昵称未授权
  408. if (options && options.orderGroupId) {
  409. wx.redirectTo({
  410. url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}`
  411. })
  412. }
  413. /**
  414. * spellGroup
  415. * 区分是通过拼团详情分享过来的还是从普通券分享过来的
  416. * 注意:拼团券和普通券是两个页面
  417. */
  418. if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) {
  419. wx.redirectTo({
  420. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}`
  421. })
  422. } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) {
  423. wx.redirectTo({
  424. url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}`
  425. })
  426. } else if (options && options.couponChannelId && options.cuserId) {
  427. /**
  428. * 转赠判断
  429. */
  430. wx.redirectTo({
  431. 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}`
  432. })
  433. } else if (options && options.orderId) {
  434. wx.redirectTo({
  435. url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}`
  436. })
  437. }
  438. // 专题
  439. else if (options && options.id && app.globalData.type == 'td') {
  440. wx.redirectTo({
  441. url: `/pages/topicDetail/index?id=${options.id}`
  442. });
  443. }
  444. // 通过分享进入的门店详情
  445. else if (options && options.id && options.frommd == 'md') {
  446. wx.redirectTo({
  447. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  448. });
  449. }// 门店详情
  450. else if (options && options.id && app.globalData.type == 'md') {
  451. wx.redirectTo({
  452. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  453. });
  454. } else if (app.globalData.type == 'uc') {
  455. wx.switchTab({
  456. url: '/index/user'
  457. });
  458. }
  459. // 积分
  460. else if (app.globalData.type == 'jf') {
  461. wx.redirectTo({
  462. url: '/pages/integralmall/index'
  463. });
  464. }
  465. // 首页
  466. else if (app.globalData.type == 'in') {
  467. wx.switchTab({
  468. url: '/index/index'
  469. });
  470. }
  471. // 停车
  472. else if (app.globalData.type == 'pc') {
  473. // 停车
  474. wx.switchTab({
  475. url: '/index/passCar'
  476. });
  477. }
  478. // 我的券包
  479. else if (app.globalData.type == 'mc') {
  480. // 我的券包
  481. wx.redirectTo({
  482. url: '/pages/couponorder/index/index'
  483. });
  484. }
  485. // 我的订单
  486. else if (app.globalData.type == 'mo') {
  487. // 我的订单
  488. wx.redirectTo({
  489. url: '/pages/order/index/index?id=all'
  490. });
  491. }
  492. // 我的卡包
  493. else if (app.globalData.type == 'ca') {
  494. // 我的卡包
  495. wx.redirectTo({
  496. url: '/pages/cardorder/index/index'
  497. });
  498. }
  499. // 特享礼遇
  500. else if (app.globalData.type == 'sc') {
  501. // 特享礼遇
  502. wx.redirectTo({
  503. url: '/pages/specialcourtesy/specialcourtesy'
  504. });
  505. }
  506. // 限时秒杀
  507. else if (app.globalData.type == 'rb') {
  508. // 限时秒杀
  509. wx.redirectTo({
  510. url: '/pages/rushToBuy/index'
  511. })
  512. }
  513. // 砍价专场
  514. else if (app.globalData.type == 'bl') {
  515. // 砍价专场
  516. wx.redirectTo({
  517. url: '/pages/bargain/bargain'
  518. })
  519. }
  520. // 我的砍价
  521. else if (app.globalData.type == 'mb') {
  522. // 我的砍价
  523. wx.redirectTo({
  524. url: '/pages/bargain/bargain?from=myhtml'
  525. })
  526. }
  527. // 拼团专场
  528. else if (app.globalData.type == 'sl') {
  529. // 拼团专场
  530. wx.redirectTo({
  531. url: '/pages/spellGroup/spellGroup'
  532. })
  533. }
  534. // 我的拼团
  535. else if (app.globalData.type == 'ms') {
  536. wx.redirectTo({
  537. url: '/pages/spellGroup/spellGroup?from=myhtml'
  538. })
  539. }
  540. // 消费卡
  541. else if (app.globalData.type == 'dc') {
  542. // 消费卡
  543. wx.redirectTo({
  544. url: '/pages/discountCardList/discountCardList'
  545. })
  546. }
  547. // 兑换
  548. else if (app.globalData.type == 'ec') {
  549. wx.redirectTo({
  550. url: '/pages/exchange/exchange'
  551. })
  552. }
  553. // 门店
  554. else if (app.globalData.type == 'ml') {
  555. wx.switchTab({
  556. url: '/index/searchbar'
  557. })
  558. } else {
  559. wx.switchTab({
  560. url: '/index/index',
  561. })
  562. }
  563. }
  564. })
  565. },
  566. getGameOne: function(token, id) {
  567. let _this = this;
  568. Http.get({
  569. url: config.api.getOneGame,
  570. data: {
  571. token: token,
  572. id: id
  573. }
  574. }).then(res => {
  575. wx.redirectTo({
  576. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  577. })
  578. })
  579. .catch(err => {
  580. wx.showModal({
  581. title: '提示',
  582. content: err.message,
  583. showCancel: false,
  584. success: function(res) {
  585. // 如果游戏下架或者找不到,重启首页
  586. if (res.confirm) {
  587. wx.reLaunch({
  588. url: '/pages/index/index',
  589. })
  590. }
  591. }
  592. })
  593. this.alphaClick();
  594. })
  595. },
  596. })