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.

1338 line
34 KiB

  1. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  2. let ifStoreApp = extConfig.attr.ifStoreApp;
  3. let businessSwitch = extConfig.attr.businessSwitch
  4. let mch_id = extConfig.attr.mchId
  5. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  6. const Http = require("../utils/HttpBasics");
  7. const imgurl = require("../utils/imgurl");
  8. const config = require("../config/config");
  9. const QR = require("../utils/memberqrcode.js");
  10. const util = require("../utils/util");
  11. const bgColor = require("../utils/bgColor.js")
  12. let app = getApp();
  13. Page({
  14. data: {
  15. aa: (app.statusBarHeight + 34) + "rpx",
  16. noDataFlag: false,
  17. busineKye: 0,
  18. businePageNum: 1,
  19. credit: 0,
  20. businessList: [], //优选好物导航
  21. businessData: [], //优选好物数据
  22. topicObj2: null, //欢乐城首页限时抢购
  23. topicObj3: null, //欢乐城首页砍价
  24. topicObj4: null, //欢乐城首页拼团
  25. topicObj5: null, //欢乐城首页消费卡
  26. topicObj6: null, //欢乐城首页积分商城
  27. specialLsit: [], //欢乐城首页专题
  28. marketName: "", //商场名称
  29. mouldType: 0,
  30. navLineHeight: ((app.statusBarHeight + app.statusBarHeight) + 44) + "px",
  31. huanlechengImgurl: "https://formall.oss-accelerate.aliyuncs.com/cimg/v20211214/",
  32. mch_id: mch_id,
  33. goUrl: "", //商圈跳转链接
  34. accreditFlag: 1, //1是未授权微信且未授权手机号 2授权了微信 没授权手机号 3微信和手机号都授权了
  35. businessSwitch: businessSwitch,
  36. typeLsit: {},
  37. showLocationIf: true,
  38. ifStoreApp: ifStoreApp,
  39. navigationBarTitle: '首页',
  40. navigationBarHeight,
  41. chengzhangBox: bgColor.colorFirst.main.chengzhangBox,
  42. activeColor: bgColor.colorFirst.main.activeColor,
  43. qg: bgColor.colorFirst.main.qg,
  44. newUrl: "",
  45. cover: "",
  46. kanjia: imgurl.kanjia.url,
  47. pintuan: imgurl.pintuan.url,
  48. xiaofeika: imgurl.xiaofeika.url,
  49. xingyun: imgurl.xingyun.url,
  50. jfshangcheng: imgurl.jfshangcheng.url,
  51. toutiao: imgurl.toutiao.url,
  52. more: imgurl.more.url,
  53. giftHr: imgurl.giftHr.url,
  54. giftHr: imgurl.giftHr.url,
  55. next: imgurl.next.url,
  56. usergift: imgurl.usergift.url,
  57. guanbi1: imgurl.guanbi1.url,
  58. icon0001: imgurl.icon0001.url,
  59. icon0002: imgurl.icon0002.url,
  60. icon0003: imgurl.icon0003.url,
  61. icon0004: imgurl.icon0004.url,
  62. icon0005: imgurl.icon0005.url,
  63. icon0006: imgurl.icon0006.url,
  64. icon0007: imgurl.icon0007.url,
  65. icon0008: imgurl.icon0008.url,
  66. barcode: imgurl.barcode.url,
  67. leftarrows: imgurl.leftarrows.url,
  68. newcard: imgurl.newcard.url,
  69. newseckill: imgurl.newseckill.url,
  70. newbargain: imgurl.newbargain.url,
  71. newgroup: imgurl.newgroup.url,
  72. product: imgurl.product.url,
  73. barginicon: imgurl.barginicon.url,
  74. pintuan: imgurl.pintuan.url,
  75. live: imgurl.live.url,
  76. duihuan: imgurl.duihuan.url,
  77. market: app.globalData.market,
  78. list: [],
  79. xslist: [],
  80. loading: true,
  81. fistLogin: null,
  82. alphaData: null,
  83. alphaData1: null,
  84. swiperCurrent: 0,
  85. title: null,
  86. weappShareTitle: '', //分享标题
  87. weappShareCoverImg: '', //分享图片
  88. desc: null,
  89. scrollTop: 0,
  90. showGame: false,
  91. showTopic: false,
  92. showQg: false,
  93. gamedata: {},
  94. couponId: '', //游戏返回时传回的字段
  95. played: false, //从游戏页面跳回首页返回true
  96. havePlayEd: app.globalData.havePlayEd,
  97. havePlayEd1: app.globalData.havePlayEd1,
  98. staticGamedata: {},
  99. showIf: false,
  100. showPages: false,
  101. display: 'none',
  102. display1: 'none',
  103. optionsData: null,
  104. page: 1, // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  105. openId: '',
  106. showGg: false,
  107. ggdata: {},
  108. liveFlag: 0, //直播按钮显隐标志位
  109. squareName: "", //当前广场
  110. isShowSqare: false,
  111. moduleList: [], //按钮列表
  112. userAvatarUrl: "",
  113. userName: "",
  114. },
  115. getBusineData(e) {
  116. this.setData({
  117. businePageNum: 1,
  118. busineKye: e.detail,
  119. noDataFlag: false,
  120. })
  121. this.getCouponChannelList(e.detail)
  122. },
  123. getBusinessList() { //获取优选导航
  124. Http.get({
  125. url: config.api.businessList,
  126. data: {
  127. filter: 2
  128. }
  129. }).then(res => {
  130. this.setData({
  131. businessList: [{
  132. id: 0,
  133. title: "全部",
  134. type: 1
  135. }].concat(res.data)
  136. });
  137. }).catch(err => {
  138. wx.showModal({
  139. title: '提示',
  140. content: err.message ? err.message : err.data,
  141. showCancel: false
  142. })
  143. })
  144. },
  145. getCouponChannelList(key) {
  146. if (this.data.noDataFlag) {
  147. return
  148. }
  149. wx.showLoading({
  150. title: "加载中"
  151. });
  152. let param = {}
  153. if (key == 0) {
  154. param = {
  155. pageNum: this.data.businePageNum,
  156. pageSize: 6,
  157. targetAd: 1
  158. }
  159. } else {
  160. param = {
  161. pageNum: this.data.businePageNum,
  162. pageSize: 6,
  163. business: key,
  164. targetAd: 1
  165. }
  166. }
  167. Http.get({
  168. url: config.api.couponChannelList,
  169. data: param
  170. }).then(res => {
  171. if (res.data.list&&res.data.list.length != 0) {
  172. let tempLsit = this.data.businessData
  173. let data = res.data.list
  174. data.map(item => {
  175. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  176. let str = item.salePriceStr.split('.')
  177. item.salePriceStrQ = str[0]
  178. item.salePriceStrH = str[1]
  179. }
  180. item.sale = item.inventory - item.remainInventory
  181. })
  182. if (this.data.businePageNum > 1) {
  183. this.setData({
  184. businessData: [...tempLsit, ...data]
  185. })
  186. } else {
  187. this.setData({
  188. businessData: data
  189. })
  190. }
  191. }else{
  192. this.setData({
  193. noDataFlag: true
  194. })
  195. }
  196. wx.hideLoading();
  197. }).catch(err => {
  198. wx.hideLoading();
  199. wx.showModal({
  200. title: '提示',
  201. content: err.message ? err.message : err.data,
  202. showCancel: false
  203. })
  204. })
  205. },
  206. goPage(e) {
  207. let obj = e.currentTarget.dataset.obj
  208. console.log(obj, "obj")
  209. if (obj.linkType == 1) {
  210. if (obj.linkUrl == "/pages/game/index") {
  211. this.gotogame()
  212. } else {
  213. wx.navigateTo({
  214. url: obj.linkUrl,
  215. })
  216. }
  217. //小程序内部跳转
  218. } else if (obj.linkType == 2) {
  219. //跳转到外部小程序
  220. wx.navigateToMiniProgram({
  221. appId: obj.outLinkAppid,
  222. path: obj.linkUrl ? obj.linkUrl : '',
  223. fail: err => {
  224. wx.showModal({
  225. title: '提示',
  226. content: err,
  227. showCancel: false
  228. })
  229. }
  230. })
  231. }
  232. },
  233. //获取按钮列表
  234. getModule() {
  235. Http.get({
  236. url: config.api.wxCustomizeModule
  237. }).then(res => {
  238. this.setData({
  239. moduleList: res.data,
  240. })
  241. }).catch(err => {
  242. if (err.status != 404)
  243. wx.showModal({
  244. title: '提示',
  245. content: err.message ? err.message : err.data,
  246. showCancel: false
  247. })
  248. })
  249. },
  250. //判断用户是否授权
  251. uesrInfo() {
  252. Http.get({
  253. url: config.api.checkUserStatus,
  254. data: {
  255. token: app.globalData.token
  256. }
  257. }).then(res => {
  258. Http.get({
  259. url: config.api.checkPhoneStatus
  260. }).then(res => { //全部授权
  261. this.setData({
  262. accreditFlag: 3
  263. })
  264. }).catch(err => {
  265. if (err.code == 11005) { //未授权手机号
  266. this.setData({
  267. accreditFlag: 2
  268. })
  269. } else {
  270. wx.showToast({
  271. title: err.message,
  272. icon: 'none',
  273. duration: 2000,
  274. mask: false
  275. });
  276. }
  277. })
  278. }).catch(err => {
  279. if (err.code == 11004) { //未授权微信
  280. this.setData({
  281. accreditFlag: 1
  282. })
  283. } else {
  284. wx.showToast({
  285. title: err.message,
  286. icon: 'none',
  287. duration: 2000,
  288. mask: false
  289. });
  290. }
  291. })
  292. },
  293. //获取当前广场名
  294. //跳转到每日签到
  295. goSign() {
  296. wx.navigateTo({
  297. url: '/pages/activityCalendar/activityCalendar',
  298. })
  299. },
  300. //活动日历
  301. goCalendar() {
  302. wx.navigateTo({
  303. url: '/pages/dateLsit/dateLsit',
  304. })
  305. },
  306. //跳转到其他广场列表
  307. goSquareList() {
  308. if (this.data.isShowSqare) {
  309. wx.navigateTo({
  310. url: '/pages/location/location',
  311. })
  312. }
  313. },
  314. goLive() {
  315. wx.navigateTo({
  316. url: '/pages2/live/livelist/index',
  317. })
  318. },
  319. alphaClick1: function(even) {
  320. var animation = wx.createAnimation({})
  321. animation.opacity(0).step({
  322. duration: 2000
  323. })
  324. this.setData({
  325. alphaData: animation.export()
  326. })
  327. },
  328. alphaClick: function(even) {
  329. var animation = wx.createAnimation({})
  330. animation.opacity(0).step({
  331. duration: 2000
  332. })
  333. this.setData({
  334. alphaData1: animation.export()
  335. })
  336. },
  337. // 我的卡包
  338. mycard: function() {
  339. wx.navigateTo({
  340. url: '/pages/cardorder/index/index',
  341. })
  342. },
  343. //我的券包
  344. mycoupon: function() {
  345. wx.navigateTo({
  346. url: '/pages/couponorder/index/index',
  347. })
  348. },
  349. gotoSpellGroup: function() {
  350. wx.navigateTo({
  351. url: '/pages/spellGroup/spellGroup',
  352. })
  353. },
  354. qrcode: function() {
  355. var that = this;
  356. let memberId = that.data.memberId;
  357. if (memberId) {
  358. wx.navigateTo({
  359. url: '/pages/specialcourtesy/specialcourtesy'
  360. })
  361. }
  362. },
  363. //跳往限时秒杀
  364. gotoRushBuy: function() {
  365. wx.navigateTo({
  366. url: '/pages/rushToBuy/index',
  367. })
  368. },
  369. swiperChange: function(e) {
  370. this.setData({
  371. swiperCurrent: e.detail.current
  372. });
  373. },
  374. gotogame: function() {
  375. let that = this;
  376. if (!that.data.showIf) {
  377. wx.showToast({
  378. title: '暂无游戏频道',
  379. icon: "none",
  380. duration: 3000
  381. })
  382. } else {
  383. Http.get({
  384. url: config.api.checkUserStatus,
  385. data: {
  386. token: app.globalData.token
  387. }
  388. }).then(res1 => {
  389. app.globalData.type = 'gm'
  390. Http.get({
  391. url: config.api.checkPhoneStatus,
  392. data: {}
  393. }).then(res => {
  394. var data = {
  395. couponChannelId: "" + that.data.couponChannelId,
  396. couponId: "" + that.data.couponId
  397. };
  398. if (that.data.couponChannelId == null) {
  399. var data = {
  400. couponId: "" + that.data.couponId
  401. };
  402. }
  403. wx.redirectTo({
  404. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  405. })
  406. }).catch(err => {
  407. if (err.code == 11005) {
  408. // 用户手机未授权
  409. /**
  410. * 将值传到用户手机号授权的页面
  411. *
  412. */
  413. app.globalData.skipUrl = '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  414. app.globalData.skip = 'redirectTo'
  415. wx.redirectTo({
  416. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  417. });
  418. } else if (err.code == 11006) {
  419. // 用户手机已加密
  420. wx.redirectTo({
  421. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  422. });
  423. } else {
  424. wx.showToast({
  425. title: err.message,
  426. icon: 'none',
  427. duration: 2000,
  428. mask: false
  429. });
  430. }
  431. })
  432. }).catch(err => {
  433. if (err.code == 11004) { //未授权微信
  434. app.globalData.type = 'gm'
  435. wx.redirectTo({
  436. url: "/pages/getuserinfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  437. });
  438. } else {
  439. wx.showToast({
  440. title: err.message,
  441. icon: 'none',
  442. duration: 2000,
  443. mask: false
  444. });
  445. }
  446. })
  447. }
  448. },
  449. mySpecial: function() {
  450. console.log("special");
  451. wx.navigateTo({
  452. url: '/pages/specialcourtesy/specialcourtesy',
  453. })
  454. },
  455. //是否属于集团
  456. ifShowSqare() {
  457. if (wx.getStorageSync("squareList")) {
  458. this.setData({
  459. isShowSqare: true
  460. })
  461. } else {
  462. this.setData({
  463. isShowSqare: false
  464. })
  465. }
  466. },
  467. /**
  468. * 获取全局样式
  469. */
  470. getType() {
  471. Http.get({
  472. url: config.api.setType,
  473. data: {
  474. mouldType: app.globalData.mouldType
  475. }
  476. }).then(res => {
  477. const {
  478. code,
  479. data
  480. } = res
  481. if (code == 200) {
  482. app.globalData.typeLsit = data
  483. this.setData({
  484. typeLsit: data,
  485. })
  486. }
  487. })
  488. },
  489. /**
  490. * 生命周期函数--监听页面初次渲染完成
  491. */
  492. onLoad: function(options) {
  493. this.setData({
  494. mouldType: app.globalData.mouldType,
  495. marketName: app.globalData.marketName,
  496. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  497. })
  498. let that = this;
  499. let optionss;
  500. //获取首页按钮
  501. that.getModule()
  502. let openId = wx.getStorageSync('openId')
  503. if (wx.getStorageSync('options')) {
  504. optionss = JSON.parse(wx.getStorageSync('options'));
  505. }
  506. if (options.played == "true") {
  507. that.setData({
  508. played: true
  509. })
  510. }
  511. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  512. that.setData({
  513. optionsData: optionss
  514. })
  515. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  516. } else {
  517. that.getWeapNote()
  518. }
  519. //获取条形码
  520. // util.barcode("barcode", optionss.quancode, 510, 100);
  521. // console.log(Http.headers.token, "?")
  522. },
  523. /**
  524. * 获得经纬度
  525. */
  526. getLocation() {
  527. let that = this;
  528. wx.getLocation({
  529. type: "wgs84",
  530. success: function(res) {
  531. console.log(res, 9999)
  532. if (res && res.longitude && res.latitude) {
  533. Http.post({
  534. url: config.api.updateLBS,
  535. data: {
  536. latitude: res.latitude,
  537. longitude: res.longitude
  538. }
  539. }).then(res => {
  540. console.log(res, 9999)
  541. })
  542. }
  543. },
  544. fail: error => {
  545. console.log(error);
  546. }
  547. })
  548. },
  549. onUnload() {
  550. // wx.removeStorageSync('squareList')
  551. },
  552. // 初始换底部导航栏
  553. setTabStyle: function() {
  554. this.getTabBar().setData({
  555. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  556. list: [{
  557. "pagePath": "/index/index",
  558. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  559. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  560. "text": "首页"
  561. },
  562. {
  563. "pagePath": "/index/searchbar",
  564. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  565. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  566. "text": "门店"
  567. },
  568. {
  569. "pagePath": "/index/passCar",
  570. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  571. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  572. "text": "停车"
  573. },
  574. {
  575. "pagePath": "/index/user",
  576. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  577. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  578. "text": "我的"
  579. }
  580. ],
  581. })
  582. },
  583. onShow: function() {
  584. console.log(app.globalData.mouldType, "mouldType")
  585. if (app.globalData.token) {
  586. this.getmemberId(app.globalData.token);
  587. } else {
  588. app.tokenCallback = token => {
  589. this.getmemberId(app.globalData.token);
  590. }
  591. }
  592. this.setData({
  593. mouldType: app.globalData.mouldType,
  594. marketName: app.globalData.marketName,
  595. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  596. })
  597. this.uesrInfo()
  598. if (businessSwitch) {
  599. let openId = wx.getStorageSync("openId")
  600. this.setData({
  601. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  602. })
  603. }
  604. if (JSON.stringify(app.globalData.styleLsit) != "{}") {
  605. this.setTabStyle()
  606. }
  607. this.ifShowSqare();
  608. if (wx.getStorageSync("squareList") && wx.getStorageSync("selectedMall")) {
  609. var temp = wx.getStorageSync("squareList").filter(item => item.tenantId == wx.getStorageSync("selectedMall"))[0].name
  610. this.setData({
  611. squareName: temp
  612. })
  613. }
  614. if (typeof this.getTabBar === 'function' &&
  615. this.getTabBar()) {
  616. this.getTabBar().setData({
  617. selected: 0,
  618. })
  619. }
  620. let that = this;
  621. that.setData({
  622. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  623. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  624. })
  625. /**
  626. * couponNum 是否有普通的优惠券购买
  627. * couponNum2 是否有新买的消费卡
  628. */
  629. let num = wx.getStorageSync('couponNum');
  630. let num1 = wx.getStorageSync('couponNum2');
  631. // if (num == 'couponNum' || num1 == 'couponNum2') {
  632. // wx.showTabBarRedDot({
  633. // index: 3
  634. // })
  635. // } else {
  636. // wx.hideTabBarRedDot({
  637. // index: 3
  638. // })
  639. // }
  640. if (app.globalData.score) {
  641. that.setData({
  642. fistLogin: app.globalData.score
  643. })
  644. }
  645. // 如果有游戏
  646. setTimeout(function() {
  647. that.alphaClick();
  648. }, 8000)
  649. // 如果有广告
  650. setTimeout(function() {
  651. that.alphaClick1();
  652. }, 8000)
  653. },
  654. getmemberId: function(token) {
  655. let that = this;
  656. Http.get({
  657. url: config.api.getScore,
  658. data: {
  659. token: token
  660. }
  661. }).then(res => {
  662. if (res.data.avatarUrl && res.data.nickName){
  663. app.globalData.userAvatarUrl = res.data.avatarUrl,
  664. app.globalData.userName = res.data.nickName
  665. }
  666. that.setData({
  667. levelName: res.data.levelName,
  668. upgradePercent: res.data.upgradePercent,
  669. upgradeScore: res.data.upgradeScore,
  670. memberId: res.data.id,
  671. credit: res.data.credit,
  672. userAvatarUrl: res.data.avatarUrl,
  673. userName: res.data.nickName,
  674. })
  675. })
  676. .catch(err => {
  677. wx.showModal({
  678. title: '提示',
  679. content: err.message,
  680. showCancel: false
  681. })
  682. })
  683. },
  684. gotoChengzhangzhi: function() {
  685. wx.navigateTo({
  686. url: '/pages/czdetail/czdetail',
  687. })
  688. },
  689. goIntegralmall() {
  690. wx.navigateTo({
  691. url: '/pages/integralmall/index',
  692. })
  693. },
  694. gotoBargain: function() {
  695. wx.navigateTo({
  696. url: '/pages/bargain/bargain',
  697. })
  698. },
  699. gotoSpellGroup: function() {
  700. wx.navigateTo({
  701. url: '/pages/spellGroup/spellGroup',
  702. })
  703. },
  704. gotoCard: function() {
  705. wx.navigateTo({
  706. url: '/pages/discountCardList/discountCardList',
  707. })
  708. },
  709. // gotoGame: function () {
  710. // wx.navigateTo({
  711. // url: '/pages/game/index',
  712. // })
  713. // },
  714. gotoJfsc: function() {
  715. wx.navigateTo({
  716. url: '/pages/integralmall/index',
  717. })
  718. },
  719. /**
  720. *
  721. * @param {code,page}
  722. * 子组件向父组件传值
  723. */
  724. onGetCode: function(e) {
  725. this.setData({
  726. code: e.detail.val,
  727. page: e.detail.pageNum,
  728. });
  729. console.log(e.detail.val)
  730. console.log(e.detail.pageNum)
  731. },
  732. getWeapNote: function(couponChannelId, couponId, orderId) {
  733. var that = this;
  734. if (app.globalData.token) {
  735. // 登录
  736. console.log(app.globalData.token)
  737. that.getmemberId(app.globalData.token);
  738. that.getBannerlist();
  739. if (that.data.mouldType == 0) { //富茂原版
  740. that.topicShow();
  741. that.getxsList();
  742. } else if (that.data.mouldType == 1) { //欢乐城模板
  743. that.getShowList()
  744. that.topicShowall(2);
  745. that.topicShowall(3);
  746. that.topicShowall(4);
  747. that.topicShowall(5);
  748. that.topicShowall(6);
  749. that.getBusinessList();
  750. that.getCouponChannelList(0)
  751. }
  752. that.getType()
  753. // that.uesrInfo()
  754. that.getLocation();
  755. that.getMallInfo(app.globalData.token);
  756. if (app.couponChannelListCallback) {
  757. app.couponChannelListCallback(app.globalData.token);
  758. }
  759. if (app.couponListCallback) {
  760. app.couponListCallback(app.globalData.token);
  761. }
  762. if (app.businessListCallback) {
  763. app.businessListCallback(app.globalData.token);
  764. }
  765. Http.get({
  766. url: config.api.getWeapNote,
  767. data: {
  768. appId: config.weapp.AppId,
  769. }
  770. })
  771. .then(res => {
  772. console.log(33333333333)
  773. console.log(app.globalData.token)
  774. console.log(res)
  775. console.log(33333333333)
  776. // that.getGameOne(app.globalData.token)
  777. that.getStaticGame(app.globalData.token)
  778. that.getGg(app.globalData.token)
  779. let weapNote = JSON.parse(res.data.weapNote);
  780. that.setData({
  781. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  782. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  783. })
  784. })
  785. .catch(err => {
  786. // that.getGameOne(app.globalData.token)
  787. that.getStaticGame(app.globalData.token)
  788. that.getGg(app.globalData.token)
  789. wx.showModal({
  790. title: "提示",
  791. content: err.message,
  792. showCancel: false
  793. });
  794. });
  795. } else {
  796. app.tokenCallback = token => {
  797. // 登录
  798. console.log(app.globalData.token)
  799. that.getmemberId(app.globalData.token);
  800. that.getBannerlist();
  801. if (that.data.mouldType == 0) { //富茂原版
  802. that.topicShow();
  803. that.getxsList();
  804. } else if (that.data.mouldType == 1) { //欢乐城模板
  805. that.getShowList()
  806. that.topicShowall(2);
  807. that.topicShowall(3);
  808. that.topicShowall(4);
  809. that.topicShowall(5);
  810. that.topicShowall(6);
  811. that.getBusinessList();
  812. that.getCouponChannelList(0)
  813. }
  814. that.getType()
  815. // that.uesrInfo()
  816. that.getLocation();
  817. that.getMallInfo(app.globalData.token);
  818. if (app.couponChannelListCallback) {
  819. app.couponChannelListCallback(app.globalData.token);
  820. }
  821. if (app.couponListCallback) {
  822. app.couponListCallback(app.globalData.token);
  823. }
  824. if (app.businessListCallback) {
  825. app.businessListCallback(app.globalData.token);
  826. }
  827. Http.get({
  828. url: config.api.getWeapNote,
  829. data: {
  830. appId: config.weapp.AppId,
  831. }
  832. })
  833. .then(res => {
  834. console.log(33333333333)
  835. console.log(app.globalData.token)
  836. console.log(res)
  837. console.log(33333333333)
  838. // that.getGameOne(app.globalData.token)
  839. that.getStaticGame(app.globalData.token)
  840. that.getGg(app.globalData.token)
  841. let weapNote = JSON.parse(res.data.weapNote);
  842. that.setData({
  843. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  844. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  845. })
  846. })
  847. .catch(err => {
  848. // that.getGameOne(app.globalData.token)
  849. that.getStaticGame(app.globalData.token)
  850. that.getGg(app.globalData.token)
  851. wx.showModal({
  852. title: "提示",
  853. content: err.message,
  854. showCancel: false
  855. });
  856. });
  857. }
  858. }
  859. },
  860. getStaticGame(token) {
  861. let _this = this;
  862. Http.get({
  863. url: config.api.getGame,
  864. data: {
  865. triggleAction: 2, // 固定入口
  866. token: token
  867. }
  868. }).then(res => {
  869. if (res.data.id) {
  870. _this.setData({
  871. showIf: true,
  872. newUrl: res.data.imgUrl
  873. })
  874. } else {
  875. _this.setData({
  876. showIf: false
  877. })
  878. }
  879. _this.setData({
  880. staticGamedata: res.data
  881. })
  882. })
  883. .catch(err => {
  884. _this.setData({
  885. showIf: false
  886. })
  887. console.log(err)
  888. })
  889. },
  890. getGameOne: function(token) {
  891. let _this = this;
  892. Http.get({
  893. url: config.api.getGame,
  894. data: {
  895. triggleAction: 1, // 登录触发
  896. token: token
  897. }
  898. }).then(res => {
  899. if (res.data.id) {
  900. _this.setData({
  901. showGame: true,
  902. })
  903. } else {
  904. _this.setData({
  905. showGame: false
  906. })
  907. }
  908. _this.setData({
  909. gamedata: res.data
  910. })
  911. })
  912. .catch(err => {
  913. _this.setData({
  914. showGame: false
  915. })
  916. this.alphaClick();
  917. })
  918. },
  919. /**
  920. * mallinfo
  921. */
  922. getMallInfo: function(token) {
  923. let that = this;
  924. Http.get({
  925. url: config.api.getMallInfo,
  926. data: {
  927. token: token,
  928. }
  929. }).then(res => {
  930. that.setData({
  931. liveFlag: res.data.liveSupport,
  932. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  933. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  934. });
  935. console.log(that.data.liveFlag, "||||")
  936. })
  937. .catch(err => {
  938. // 不需要错误提示
  939. });
  940. },
  941. //获取限时抢购列表
  942. getxsList() {
  943. let that = this;
  944. Http.get({
  945. url: config.api.couponChannelList,
  946. data: {
  947. pageNum: 1,
  948. pageSize: 3,
  949. targetAd: 2
  950. }
  951. }).then(res => {
  952. if (res && res.data.total > 0) {
  953. that.setData({
  954. xslist: res.data.list,
  955. showQg: true
  956. });
  957. } else {
  958. that.setData({
  959. showQg: false
  960. })
  961. }
  962. })
  963. .catch(err => {
  964. console.log(err)
  965. wx.showToast({
  966. title: err.message,
  967. icon: 'none',
  968. duration: 2000,
  969. mask: false
  970. });
  971. })
  972. },
  973. /**
  974. * banner
  975. */
  976. getBannerlist: function() {
  977. let that = this;
  978. Http.get({
  979. url: config.api.bannerlist,
  980. data: {
  981. pageNum: 1,
  982. pageSize: 7
  983. }
  984. }).then(res => {
  985. that.getmemberId(app.globalData.token);
  986. // that.checkUserCarStatus();
  987. that.setData({
  988. list: res.data.list
  989. });
  990. })
  991. .catch(err => {
  992. that.getmemberId(app.globalData.token);
  993. // that.checkUserCarStatus();
  994. });
  995. },
  996. //获取欢乐城专题
  997. getShowList() {
  998. Http.get({
  999. url: config.api.showList
  1000. }).then(res => {
  1001. let tempData = res.data
  1002. tempData.map(item1 => {
  1003. if (item1.couponList) {
  1004. item1.couponList.map(item2 => {
  1005. if (item2.salePriceStr && item2.salePriceStr.indexOf('.') != -1) {
  1006. let str = item2.salePriceStr.split('.')
  1007. item2.salePriceStrQ = str[0]
  1008. item2.salePriceStrH = str[1]
  1009. }
  1010. })
  1011. }
  1012. })
  1013. this.setData({
  1014. specialLsit: res.data ? res.data : []
  1015. })
  1016. }).catch(err => {
  1017. wx.showToast({
  1018. title: err.message ? err.message : err.data,
  1019. icon: 'none',
  1020. duration: 2000,
  1021. mask: false
  1022. });
  1023. })
  1024. },
  1025. /**
  1026. * topicType=2 限时抢购
  1027. * topicType=3 砍价
  1028. * topicType=4 拼团
  1029. * topicType=5 消费卡
  1030. * topicType=6 积分商城
  1031. */
  1032. topicShowall(topicType) {
  1033. Http.get({
  1034. url: config.api.topicShow,
  1035. data: {
  1036. topicType
  1037. }
  1038. }).then(res => {
  1039. let data = res.data
  1040. if (data.couponList != null && data.couponList.length > 0) {
  1041. data.couponList.map(item => {
  1042. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  1043. let str = item.salePriceStr.split('.')
  1044. item.salePriceStrQ = str[0]
  1045. item.salePriceStrH = str[1]
  1046. }
  1047. })
  1048. }
  1049. if (topicType == 2) {
  1050. let tempData = data
  1051. this.setData({
  1052. topicObj2: data
  1053. })
  1054. } else if (topicType == 3) {
  1055. this.setData({
  1056. topicObj3: data
  1057. })
  1058. } else if (topicType == 4) {
  1059. this.setData({
  1060. topicObj4: data
  1061. })
  1062. } else if (topicType == 5) {
  1063. this.setData({
  1064. topicObj5: data
  1065. })
  1066. } else if (topicType == 6) {
  1067. this.setData({
  1068. topicObj6: data
  1069. })
  1070. }
  1071. }).catch(err => {
  1072. wx.showToast({
  1073. title: err.message ? err.message : err.data,
  1074. icon: 'none',
  1075. duration: 2000,
  1076. mask: false
  1077. });
  1078. })
  1079. },
  1080. // 专题显示
  1081. topicShow: function() {
  1082. let that = this;
  1083. Http.get({
  1084. url: config.api.topicShow,
  1085. data: {
  1086. token: app.globalData.token
  1087. }
  1088. }).then(res => {
  1089. if (res && res.data) {
  1090. that.setData({
  1091. name: res.data.name,
  1092. cover: res.data.cover,
  1093. id: res.data.id,
  1094. showTopic: true
  1095. })
  1096. } else {
  1097. that.setData({
  1098. showTopic: false
  1099. })
  1100. }
  1101. })
  1102. .catch(err => {
  1103. console.log(err);
  1104. })
  1105. },
  1106. gotoTopic() {
  1107. wx.navigateTo({
  1108. url: `/pages/topicDetail/index?id=${this.data.id}`
  1109. })
  1110. },
  1111. /**
  1112. * 检查用户是否有车
  1113. */
  1114. // checkUserCarStatus: function() {
  1115. // var that = this;
  1116. // Http.get({
  1117. // url: config.api.userCarCount,
  1118. // data: {}
  1119. // }).then(res => {
  1120. // if (res.data > 0) {
  1121. // // 用户名下有车
  1122. // app.globalData.phone = res.data.phone;
  1123. // app.globalData.supportCar = true;
  1124. // // 共同登录
  1125. // that.userCarLogin();
  1126. // }
  1127. // });
  1128. // },
  1129. /**
  1130. * car共同登录
  1131. */
  1132. // userCarLogin: function() {
  1133. // var that = this;
  1134. // if (!app.globalData.carLogin) {
  1135. // // 共同登录
  1136. // Http.post({
  1137. // url: config.api.carInit,
  1138. // data: {
  1139. // phone: app.globalData.phone
  1140. // }
  1141. // }).then(res => {
  1142. // app.globalData.carLogin = true;
  1143. // app.globalData.parkVendor = res.data.vendor;
  1144. // if (res.data.token != "undefined") {
  1145. // app.globalData.etcpToken = res.data.token;
  1146. // }
  1147. // });
  1148. // }
  1149. // },
  1150. /**
  1151. * 获取用户信息
  1152. */
  1153. // getUserInfo: function() {
  1154. // // 获取用户信息
  1155. // wx.getSetting({
  1156. // success: res => {
  1157. // if (res.authSetting["scope.userInfo"]) {
  1158. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  1159. // wx.getUserInfo({
  1160. // success: res => {
  1161. // // 可以将 res 发送给后台解码出 unionId
  1162. // }
  1163. // });
  1164. // }
  1165. // }
  1166. // });
  1167. // },
  1168. gotoBargain: function() {
  1169. wx.navigateTo({
  1170. url: '/pages/bargain/bargain'
  1171. })
  1172. },
  1173. //限时抢购的详情页面
  1174. gotodetail: function(e) {
  1175. wx.navigateTo({
  1176. url: `/pages/coupon/detail/index?couponChannelId=${
  1177. e.currentTarget.dataset.couponchannelid
  1178. }&couponId=${e.currentTarget.dataset.couponid}`
  1179. });
  1180. },
  1181. //浮层广告
  1182. getGg: function(token) {
  1183. let that = this
  1184. Http.get({
  1185. url: config.api.getGg,
  1186. data: {
  1187. token: token,
  1188. appId: config.weapp.AppId,
  1189. openId: "" // wx.getStorageSync('openId')
  1190. }
  1191. }).then(res => {
  1192. console.log(res)
  1193. if (res.data.id) {
  1194. that.setData({
  1195. showGg: true,
  1196. })
  1197. console.log(that.data.showGg, 1111111111111)
  1198. } else {
  1199. that.setData({
  1200. showGg: false
  1201. })
  1202. that.getGameOne(app.globalData.token)
  1203. console.log(that.data.showGg, 222222222222222222)
  1204. }
  1205. that.setData({
  1206. ggdata: res.data
  1207. })
  1208. })
  1209. .catch(err => {
  1210. this.setData({
  1211. showGg: false
  1212. })
  1213. that.getGameOne(app.globalData.token)
  1214. that.alphaClick1();
  1215. })
  1216. },
  1217. /**
  1218. * 刷新
  1219. */
  1220. onPullDownRefresh: function(e) {
  1221. this.setData({
  1222. topicObj2: null, //欢乐城首页限时抢购
  1223. topicObj3: null, //欢乐城首页砍价
  1224. topicObj4: null, //欢乐城首页拼团
  1225. topicObj5: null, //欢乐城首页消费卡
  1226. topicObj6: null, //欢乐城首页积分商城
  1227. })
  1228. let that = this;
  1229. // that.getWeapNote();
  1230. that.setData({
  1231. page: 1
  1232. })
  1233. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  1234. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  1235. } else {
  1236. this.getWeapNote()
  1237. }
  1238. if (that.selectComponent("#lists")) {
  1239. if (that.data.code == 0 || that.data.code == undefined) {
  1240. that.selectComponent("#lists").getList(0, 1, "refresh");
  1241. wx.stopPullDownRefresh();
  1242. } else {
  1243. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  1244. wx.stopPullDownRefresh();
  1245. };
  1246. that.selectComponent("#hot").getList();
  1247. }
  1248. // 砍价下拉刷新
  1249. // that.selectComponent("#bargain").getList();
  1250. // that.selectComponent("#spellGroup").getList();
  1251. // that.selectComponent("#rushtobyCard").getList();
  1252. wx.stopPullDownRefresh();
  1253. //爆款专区下拉刷新
  1254. that.getxsList();
  1255. that.topicShow();
  1256. },
  1257. //加载更多
  1258. onReachBottom: function() {
  1259. console.log("我到底了")
  1260. let that = this;
  1261. that.data.page++;
  1262. that.setData({
  1263. page: that.data.page,
  1264. businePageNum: that.data.businePageNum + 1
  1265. });
  1266. console.log("加载更多页数" + that.data.page, );
  1267. console.log("加载更多key" + that.data.code);
  1268. if (that.data.mouldType == 0) { //富茂源模板
  1269. //父组件获得子组件的方法
  1270. //如果code == 0
  1271. if (that.data.code == 0 || that.data.code == undefined) {
  1272. that.selectComponent("#lists").getList(0, that.data.page);
  1273. } else {
  1274. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  1275. }
  1276. } else if (that.data.mouldType == 1) {
  1277. this.getCouponChannelList(that.data.busineKye)
  1278. }
  1279. },
  1280. // 用户点击右上角分享
  1281. onShareAppMessage: function() {
  1282. app.globalData.previewFlag = true
  1283. return {
  1284. path: "/pages/index/index",
  1285. title: this.data.weappShareTitle,
  1286. imageUrl: this.data.weappShareCoverImg,
  1287. success: function(res) {
  1288. wx.showToast({
  1289. title: "分享成功",
  1290. duration: 1000,
  1291. icon: "success"
  1292. });
  1293. }
  1294. };
  1295. }
  1296. });