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.

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