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.

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