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.

596 lines
18 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. tenantData: JSON.parse(wx.getStorageSync('tenantData'))
  12. },
  13. bindPickerChange(options) {
  14. console.log('picker发送选择改变,携带值为', options.tenantId, this.data.tenantData)
  15. let selectIndex = 0;
  16. this.data.tenantData.map((item, index) => {
  17. if (options.tenantId == item.tenantId) {
  18. selectIndex = index;
  19. wx.setStorageSync('tenantId', item.tenantId)
  20. }
  21. })
  22. console.log()
  23. let param = {
  24. tenantId: this.data.tenantData[selectIndex].parentTenantId,
  25. subTenantId: this.data.tenantData[selectIndex].tenantId
  26. }
  27. this.checkAble = true;
  28. wx.showLoading({
  29. title: '切换中...',
  30. })
  31. Http.post({
  32. url: config.api.selectMall,
  33. data: param
  34. }).then(res => {
  35. wx.setStorageSync('tenantId', this.data.tenantData[selectIndex].tenantId)
  36. wx.hideLoading();
  37. wx.showToast({
  38. title: '切换成功!',
  39. icon: 'success',
  40. duration: 2000
  41. })
  42. wx.reLaunch({
  43. url: '/index/index',
  44. })
  45. })
  46. .catch(err => {
  47. wx.showModal({
  48. title: '提示',
  49. content: err.message,
  50. showCancel: false,
  51. success: function (res) {
  52. // 重启首页
  53. if (res.confirm) {
  54. wx.reLaunch({
  55. url: '/pages/index/index',
  56. })
  57. }
  58. }
  59. })
  60. this.alphaClick();
  61. })
  62. },
  63. goContinue(options){
  64. let that = this;
  65. wx.showToast({
  66. title: '加载中',
  67. icon: "loading",
  68. duration: 2000
  69. })
  70. /**
  71. * 根据接收到的参数的值,判断跳转到哪个页面
  72. */
  73. if (options && options.type) {
  74. app.globalData.type = options.type;
  75. }
  76. if (decodeURIComponent(options.scene) == "undefined") {
  77. that.setData({
  78. scene: 0
  79. })
  80. app.globalData.scene = 0;
  81. } else {
  82. that.setData({
  83. scene: decodeURIComponent(options.scene)
  84. });
  85. app.globalData.scene = decodeURIComponent(options.scene)
  86. that.setData({
  87. newArr: this.data.scene.split(':')
  88. })
  89. //// 大屏-二维码-start
  90. if (this.data.newArr[0] == 'JC') {
  91. // 跳转券详情
  92. options.couponChannelId = this.data.newArr[1];
  93. } else if (this.data.newArr[0] == 'JG') {
  94. // 跳转拼团详情
  95. options.couponChannelId = this.data.newArr[1];
  96. options.path = 'daping'
  97. } else if (this.data.newArr[0] == 't') {
  98. // 普通二维码
  99. options.type = this.data.newArr[1];
  100. app.globalData.type = options.type;
  101. if (options.type == 'cd') {
  102. options.couponChannelId = this.data.newArr[2];
  103. } else if (options.type == 'bd') {
  104. options.bt = this.data.newArr[2];
  105. options.id = this.data.newArr[3];
  106. } else if (options.type == 'gm') {
  107. options.id = this.data.newArr[2];
  108. } else if (options.type == 'sd') {
  109. options.couponChannelId = this.data.newArr[2];
  110. } else if (options.type == 'td') {
  111. // 专题活动页
  112. options.id = this.data.newArr[2];
  113. } else if (options.type == 'md') {
  114. // 门店详情
  115. options.id = this.data.newArr[2];
  116. } else if (options.type == 'ra') {
  117. //活动详情
  118. options.id = this.data.newArr[2];
  119. } else if (options.type == 'si') {
  120. //活动签到
  121. options.id = this.data.newArr[2];
  122. }
  123. }
  124. }
  125. wx.setStorageSync('options', JSON.stringify(options))
  126. wx.setStorageSync('imgurl', imgurl);
  127. if (app.globalData.token) {
  128. this.updateUserInfo();
  129. if (options.couponChannelId || options.orderId || options.id) {
  130. that.userStatus(options);
  131. } else {
  132. that.userStatus();
  133. }
  134. } else {
  135. // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回
  136. // 所以此处加入 callback 以防止这种情况
  137. app.tokenCallback = token => {
  138. this.updateUserInfo();
  139. if (options.couponChannelId || options.orderId || options.id) {
  140. that.userStatus(options);
  141. } else {
  142. that.userStatus();
  143. }
  144. }
  145. }
  146. },
  147. /**
  148. * 生命周期函数--监听页面加载
  149. */
  150. onLoad: function(options) {
  151. let that = this;
  152. console.log(options,1112222);
  153. if (options.tenantId){
  154. this.bindPickerChange(options);
  155. }else{
  156. this.goContinue(options);
  157. }
  158. },
  159. /**
  160. * 检查用户的状态
  161. */
  162. userStatus: function(options) {
  163. var that = this;
  164. if (options && (options.couponChannelId || options.orderId || options.id)) {
  165. that.checkuserstatus(options);
  166. } else {
  167. that.checkuserstatus();
  168. }
  169. },
  170. /**
  171. * 获取手机信息
  172. */
  173. updateUserInfo() {
  174. wx.getSystemInfo({
  175. success: function (res) {
  176. Http.post({
  177. url: config.api.updateUserInfo,
  178. data: {
  179. systemInfo: JSON.stringify(res)
  180. }
  181. }).then(res => {
  182. console.log(res)
  183. })
  184. }
  185. })
  186. },
  187. checkuserstatus(options) {
  188. let that = this;
  189. Http.get({
  190. url: config.api.checkUserStatus,
  191. data: {
  192. token: app.globalData.token
  193. }
  194. })
  195. .then(res => {
  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 && options.frommd == 'md') {
  440. wx.redirectTo({
  441. url: `/pages/getuserinfo/index?id=${options.id}&frommd=md`
  442. });
  443. }// 门店详情
  444. else if (options && options.id && app.globalData.type == 'md') {
  445. wx.redirectTo({
  446. url: `/pages/index/searchbar/detail/index?id=${options.id}`
  447. });
  448. } else if (app.globalData.type == 'uc') {
  449. wx.switchTab({
  450. url: '/index/user'
  451. });
  452. }
  453. // 积分
  454. else if (app.globalData.type == 'jf') {
  455. wx.redirectTo({
  456. url: '/pages/integralmall/index'
  457. });
  458. }
  459. // 首页
  460. else if (app.globalData.type == 'in') {
  461. wx.switchTab({
  462. url: '/index/index'
  463. });
  464. }
  465. // 停车
  466. else if (app.globalData.type == 'pc') {
  467. // 停车
  468. wx.switchTab({
  469. url: '/index/passCar'
  470. });
  471. }
  472. // 我的券包
  473. else if (app.globalData.type == 'mc') {
  474. // 我的券包
  475. wx.redirectTo({
  476. url: '/pages/couponorder/index/index'
  477. });
  478. }
  479. // 我的订单
  480. else if (app.globalData.type == 'mo') {
  481. // 我的订单
  482. wx.redirectTo({
  483. url: '/pages/order/index/index?id=all'
  484. });
  485. }
  486. // 我的卡包
  487. else if (app.globalData.type == 'ca') {
  488. // 我的卡包
  489. wx.redirectTo({
  490. url: '/pages/cardorder/index/index'
  491. });
  492. }
  493. // 特享礼遇
  494. else if (app.globalData.type == 'sc') {
  495. // 特享礼遇
  496. wx.redirectTo({
  497. url: '/pages/specialcourtesy/specialcourtesy'
  498. });
  499. }
  500. // 限时秒杀
  501. else if (app.globalData.type == 'rb') {
  502. // 限时秒杀
  503. wx.redirectTo({
  504. url: '/pages/rushToBuy/index'
  505. })
  506. }
  507. // 砍价专场
  508. else if (app.globalData.type == 'bl') {
  509. // 砍价专场
  510. wx.redirectTo({
  511. url: '/pages/bargain/bargain'
  512. })
  513. }
  514. // 我的砍价
  515. else if (app.globalData.type == 'mb') {
  516. // 我的砍价
  517. wx.redirectTo({
  518. url: '/pages/bargain/bargain?from=myhtml'
  519. })
  520. }
  521. // 拼团专场
  522. else if (app.globalData.type == 'sl') {
  523. // 拼团专场
  524. wx.redirectTo({
  525. url: '/pages/spellGroup/spellGroup'
  526. })
  527. }
  528. // 我的拼团
  529. else if (app.globalData.type == 'ms') {
  530. wx.redirectTo({
  531. url: '/pages/spellGroup/spellGroup?from=myhtml'
  532. })
  533. }
  534. // 消费卡
  535. else if (app.globalData.type == 'dc') {
  536. // 消费卡
  537. wx.redirectTo({
  538. url: '/pages/discountCardList/discountCardList'
  539. })
  540. }
  541. // 兑换
  542. else if (app.globalData.type == 'ec') {
  543. wx.redirectTo({
  544. url: '/pages/exchange/exchange'
  545. })
  546. }
  547. // 门店
  548. else if (app.globalData.type == 'ml') {
  549. wx.switchTab({
  550. url: '/index/searchbar'
  551. })
  552. } else {
  553. wx.switchTab({
  554. url: '/index/index',
  555. })
  556. }
  557. }
  558. })
  559. },
  560. getGameOne: function(token, id) {
  561. let _this = this;
  562. Http.get({
  563. url: config.api.getOneGame,
  564. data: {
  565. token: token,
  566. id: id
  567. }
  568. }).then(res => {
  569. wx.redirectTo({
  570. url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId,
  571. })
  572. })
  573. .catch(err => {
  574. wx.showModal({
  575. title: '提示',
  576. content: err.message,
  577. showCancel: false,
  578. success: function(res) {
  579. // 如果游戏下架或者找不到,重启首页
  580. if (res.confirm) {
  581. wx.reLaunch({
  582. url: '/pages/index/index',
  583. })
  584. }
  585. }
  586. })
  587. this.alphaClick();
  588. })
  589. },
  590. })