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.

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