C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1431 líneas
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. if (this.data.isShowSqare) {
  326. wx.navigateTo({
  327. url: '/pages/location/location',
  328. })
  329. }
  330. },
  331. goLive() {
  332. wx.navigateTo({
  333. url: '/pages2/live/livelist/index',
  334. })
  335. },
  336. alphaClick1: function (even) {
  337. var animation = wx.createAnimation({})
  338. animation.opacity(0).step({
  339. duration: 2000
  340. })
  341. this.setData({
  342. alphaData: animation.export()
  343. })
  344. },
  345. alphaClick: function (even) {
  346. var animation = wx.createAnimation({})
  347. animation.opacity(0).step({
  348. duration: 2000
  349. })
  350. this.setData({
  351. alphaData1: animation.export()
  352. })
  353. },
  354. // 我的卡包
  355. mycard: function () {
  356. wx.navigateTo({
  357. url: '/pages/cardorder/index/index',
  358. })
  359. },
  360. //我的券包
  361. mycoupon: function () {
  362. wx.navigateTo({
  363. url: '/pages/couponorder/index/index',
  364. })
  365. },
  366. gotoSpellGroup: function () {
  367. wx.navigateTo({
  368. url: '/pages/spellGroup/spellGroup',
  369. })
  370. },
  371. qrcode: function () {
  372. var that = this;
  373. let memberId = that.data.memberId;
  374. if (memberId) {
  375. wx.navigateTo({
  376. url: '/pages/specialcourtesy/specialcourtesy'
  377. })
  378. }
  379. },
  380. //跳往限时秒杀
  381. gotoRushBuy: function () {
  382. wx.navigateTo({
  383. url: '/pages/rushToBuy/index',
  384. })
  385. },
  386. swiperChange: function (e) {
  387. this.setData({
  388. swiperCurrent: e.detail.current
  389. });
  390. },
  391. gotogame: function () {
  392. let that = this;
  393. if (!that.data.showIf) {
  394. wx.showToast({
  395. title: '暂无游戏频道',
  396. icon: "none",
  397. duration: 3000
  398. })
  399. } else {
  400. Http.get({
  401. url: config.api.checkUserStatus,
  402. data: {
  403. token: app.globalData.token
  404. }
  405. }).then(res1 => {
  406. app.globalData.type = 'gm'
  407. Http.get({
  408. url: config.api.checkPhoneStatus,
  409. data: {}
  410. }).then(res => {
  411. var data = {
  412. couponChannelId: "" + that.data.couponChannelId,
  413. couponId: "" + that.data.couponId
  414. };
  415. if (that.data.couponChannelId == null) {
  416. var data = {
  417. couponId: "" + that.data.couponId
  418. };
  419. }
  420. wx.redirectTo({
  421. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  422. })
  423. }).catch(err => {
  424. if (err.code == 11005) {
  425. // 用户手机未授权
  426. /**
  427. * 将值传到用户手机号授权的页面
  428. *
  429. */
  430. app.globalData.skipUrl = '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  431. app.globalData.skip = 'redirectTo'
  432. wx.redirectTo({
  433. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  434. });
  435. } else if (err.code == 11006) {
  436. // 用户手机已加密
  437. wx.redirectTo({
  438. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  439. });
  440. } else {
  441. wx.showToast({
  442. title: err.message,
  443. icon: 'none',
  444. duration: 2000,
  445. mask: false
  446. });
  447. }
  448. })
  449. }).catch(err => {
  450. if (err.code == 11004) { //未授权微信
  451. app.globalData.type = 'gm'
  452. wx.redirectTo({
  453. url: "/pages/getuserinfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  454. });
  455. } else {
  456. wx.showToast({
  457. title: err.message,
  458. icon: 'none',
  459. duration: 2000,
  460. mask: false
  461. });
  462. }
  463. })
  464. }
  465. },
  466. mySpecial: function () {
  467. console.log("special");
  468. wx.navigateTo({
  469. url: '/pages/specialcourtesy/specialcourtesy',
  470. })
  471. },
  472. //是否属于集团
  473. ifShowSqare() {
  474. if (wx.getStorageSync("squareList")) {
  475. this.setData({
  476. isShowSqare: true
  477. })
  478. } else {
  479. this.setData({
  480. isShowSqare: false
  481. })
  482. }
  483. },
  484. /**
  485. * 获取全局样式
  486. */
  487. getType() {
  488. Http.get({
  489. url: config.api.setType,
  490. data: {
  491. mouldType: app.globalData.mouldType
  492. }
  493. }).then(res => {
  494. const {
  495. code,
  496. data
  497. } = res
  498. if (code == 200) {
  499. app.globalData.typeLsit = data
  500. this.setData({
  501. typeLsit: data,
  502. })
  503. }
  504. })
  505. },
  506. /**
  507. * 生命周期函数--监听页面初次渲染完成
  508. */
  509. onLoad: function (options) {
  510. console.log("onLoad--")
  511. this.setData({
  512. mouldType: app.globalData.mouldType,
  513. marketName: app.globalData.marketName,
  514. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  515. })
  516. let that = this;
  517. let optionss;
  518. //获取首页按钮
  519. that.getModule()
  520. let openId = wx.getStorageSync('openId')
  521. if (wx.getStorageSync('options')) {
  522. optionss = JSON.parse(wx.getStorageSync('options'));
  523. }
  524. if (options.played == "true") {
  525. that.setData({
  526. played: true
  527. })
  528. }
  529. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  530. that.setData({
  531. optionsData: optionss
  532. })
  533. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  534. } else {
  535. that.getWeapNote()
  536. }
  537. //获取条形码
  538. // util.barcode("barcode", optionss.quancode, 510, 100);
  539. // console.log(Http.headers.token, "?")
  540. },
  541. /**
  542. * 获得经纬度
  543. */
  544. // getLocation() {
  545. // let that = this;
  546. // wx.getLocation({
  547. // type: "wgs84",
  548. // success: function(res) {
  549. // console.log(res, 9999)
  550. // if (res && res.longitude && res.latitude) {
  551. // Http.post({
  552. // url: config.api.updateLBS,
  553. // data: {
  554. // latitude: res.latitude,
  555. // longitude: res.longitude
  556. // }
  557. // }).then(res => {
  558. // console.log(res, 9999)
  559. // })
  560. // }
  561. // },
  562. // fail: error => {
  563. // console.log(error);
  564. // }
  565. // })
  566. // },
  567. onUnload() {
  568. // wx.removeStorageSync('squareList')
  569. },
  570. // 初始换底部导航栏
  571. setTabStyle: function () {
  572. this.getTabBar().setData({
  573. selectedColor: `${app.globalData.styleLsit.t_in_std.styleClass}`,
  574. list: [{
  575. "pagePath": "/index/index",
  576. "iconPath": `${app.globalData.styleLsit.t_in.icon}`,
  577. "selectedIconPath": `${app.globalData.styleLsit.t_in_std.icon}`,
  578. "text": "首页"
  579. },
  580. {
  581. "pagePath": "/index/searchbar",
  582. "iconPath": `${app.globalData.styleLsit.t_md.icon}`,
  583. "selectedIconPath": `${app.globalData.styleLsit.t_md_std.icon}`,
  584. "text": "门店"
  585. },
  586. {
  587. "pagePath": "/index/passCar",
  588. "iconPath": `${app.globalData.styleLsit.t_tc.icon}`,
  589. "selectedIconPath": `${app.globalData.styleLsit.t_tc_std.icon}`,
  590. "text": "停车"
  591. },
  592. {
  593. "pagePath": "/index/user",
  594. "iconPath": `${app.globalData.styleLsit.t_uc.icon}`,
  595. "selectedIconPath": `${app.globalData.styleLsit.t_uc_std.icon}`,
  596. "text": "我的"
  597. }
  598. ],
  599. })
  600. },
  601. onShow: function () {
  602. console.log("onShow--")
  603. console.log(app.globalData.mouldType, "mouldType")
  604. if (app.globalData.token) {
  605. this.getmemberId(app.globalData.token);
  606. } else {
  607. app.tokenCallback = token => {
  608. this.getmemberId(app.globalData.token);
  609. }
  610. }
  611. this.setData({
  612. mouldType: app.globalData.mouldType,
  613. marketName: app.globalData.marketName,
  614. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  615. })
  616. this.uesrInfo()
  617. if (businessSwitch) {
  618. let openId = wx.getStorageSync("openId")
  619. this.setData({
  620. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  621. })
  622. }
  623. if (JSON.stringify(app.globalData.styleLsit) != "{}") {
  624. this.setTabStyle()
  625. }
  626. this.ifShowSqare();
  627. if (wx.getStorageSync("squareList") && wx.getStorageSync("selectedMall")) {
  628. var temp = wx.getStorageSync("squareList").filter(item => item.tenantId == wx.getStorageSync("selectedMall"))[0].name
  629. this.setData({
  630. squareName: temp
  631. })
  632. }
  633. if (typeof this.getTabBar === 'function' &&
  634. this.getTabBar()) {
  635. this.getTabBar().setData({
  636. selected: 0,
  637. })
  638. }
  639. let that = this;
  640. that.setData({
  641. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  642. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  643. })
  644. /**
  645. * couponNum 是否有普通的优惠券购买
  646. * couponNum2 是否有新买的消费卡
  647. */
  648. let num = wx.getStorageSync('couponNum');
  649. let num1 = wx.getStorageSync('couponNum2');
  650. // if (num == 'couponNum' || num1 == 'couponNum2') {
  651. // wx.showTabBarRedDot({
  652. // index: 3
  653. // })
  654. // } else {
  655. // wx.hideTabBarRedDot({
  656. // index: 3
  657. // })
  658. // }
  659. if (app.globalData.score) {
  660. that.setData({
  661. fistLogin: app.globalData.score
  662. })
  663. }
  664. // 如果有游戏
  665. setTimeout(function () {
  666. that.alphaClick();
  667. }, 8000)
  668. // 如果有广告
  669. setTimeout(function () {
  670. that.alphaClick1();
  671. }, 8000)
  672. },
  673. getmemberId: function (token) {
  674. let that = this;
  675. Http.get({
  676. url: config.api.getScore,
  677. data: {
  678. token: token
  679. }
  680. }).then(res => {
  681. if (res.data.avatarUrl && res.data.nickName) {
  682. app.globalData.userAvatarUrl = res.data.avatarUrl,
  683. app.globalData.userName = res.data.nickName
  684. }
  685. that.setData({
  686. levelName: res.data.levelName,
  687. upgradePercent: res.data.upgradePercent,
  688. upgradeScore: res.data.upgradeScore,
  689. memberId: res.data.id,
  690. credit: res.data.credit,
  691. userAvatarUrl: res.data.avatarUrl,
  692. userName: res.data.nickName,
  693. })
  694. })
  695. .catch(err => {
  696. wx.showModal({
  697. title: '提示',
  698. content: err.message,
  699. showCancel: false
  700. })
  701. })
  702. },
  703. gotoChengzhangzhi: function () {
  704. wx.navigateTo({
  705. url: '/pages/czdetail/czdetail',
  706. })
  707. },
  708. goIntegralmall() {
  709. wx.navigateTo({
  710. url: '/pages/integralmall/index',
  711. })
  712. },
  713. gotoBargain: function () {
  714. wx.navigateTo({
  715. url: '/pages/bargain/bargain',
  716. })
  717. },
  718. gotoSpellGroup: function () {
  719. wx.navigateTo({
  720. url: '/pages/spellGroup/spellGroup',
  721. })
  722. },
  723. gotoCard: function () {
  724. wx.navigateTo({
  725. url: '/pages/discountCardList/discountCardList',
  726. })
  727. },
  728. // gotoGame: function () {
  729. // wx.navigateTo({
  730. // url: '/pages/game/index',
  731. // })
  732. // },
  733. gotoJfsc: function () {
  734. wx.navigateTo({
  735. url: '/pages/integralmall/index',
  736. })
  737. },
  738. /**
  739. *
  740. * @param {code,page}
  741. * 子组件向父组件传值
  742. */
  743. onGetCode: function (e) {
  744. this.setData({
  745. code: e.detail.val,
  746. page: e.detail.pageNum,
  747. });
  748. console.log(e.detail.val)
  749. console.log(e.detail.pageNum)
  750. },
  751. getWeapNote: function (couponChannelId, couponId, orderId) {
  752. var that = this;
  753. if (app.globalData.token) {
  754. // 登录
  755. console.log(app.globalData.token)
  756. that.getmemberId(app.globalData.token);
  757. that.getBannerlist();
  758. if (that.data.mouldType == 0) { //富茂原版
  759. that.topicShow();
  760. that.getxsList();
  761. } else if (that.data.mouldType == 1) { //欢乐城模板
  762. that.getShowList()
  763. that.topicShowall(2);
  764. that.topicShowall(3);
  765. that.topicShowall(4);
  766. that.topicShowall(5);
  767. that.topicShowall(6);
  768. that.getBusinessList();
  769. that.getCouponChannelList(0)
  770. }
  771. that.getType()
  772. // that.uesrInfo()
  773. // that.getLocation();
  774. that.getMallInfo(app.globalData.token);
  775. if (app.couponChannelListCallback) {
  776. app.couponChannelListCallback(app.globalData.token);
  777. }
  778. if (app.couponListCallback) {
  779. app.couponListCallback(app.globalData.token);
  780. }
  781. if (app.businessListCallback) {
  782. app.businessListCallback(app.globalData.token);
  783. }
  784. Http.get({
  785. url: config.api.getWeapNote,
  786. data: {
  787. appId: config.weapp.AppId,
  788. }
  789. })
  790. .then(res => {
  791. console.log(33333333333)
  792. console.log(app.globalData.token)
  793. console.log(res)
  794. console.log(33333333333)
  795. // that.getGameOne(app.globalData.token)
  796. that.getStaticGame(app.globalData.token)
  797. that.getGg(app.globalData.token)
  798. that.getPrivacySetting()
  799. let weapNote = JSON.parse(res.data.weapNote);
  800. that.setData({
  801. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  802. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  803. })
  804. })
  805. .catch(err => {
  806. // that.getGameOne(app.globalData.token)
  807. that.getStaticGame(app.globalData.token)
  808. that.getGg(app.globalData.token)
  809. wx.showModal({
  810. title: "提示",
  811. content: err.message,
  812. showCancel: false
  813. });
  814. });
  815. } else {
  816. app.tokenCallback = token => {
  817. // 登录
  818. console.log(app.globalData.token)
  819. that.getmemberId(app.globalData.token);
  820. that.getBannerlist();
  821. if (that.data.mouldType == 0) { //富茂原版
  822. that.topicShow();
  823. that.getxsList();
  824. } else if (that.data.mouldType == 1) { //欢乐城模板
  825. that.getShowList()
  826. that.topicShowall(2);
  827. that.topicShowall(3);
  828. that.topicShowall(4);
  829. that.topicShowall(5);
  830. that.topicShowall(6);
  831. that.getBusinessList();
  832. that.getCouponChannelList(0)
  833. }
  834. that.getType()
  835. // that.uesrInfo()
  836. // that.getLocation();
  837. that.getMallInfo(app.globalData.token);
  838. if (app.couponChannelListCallback) {
  839. app.couponChannelListCallback(app.globalData.token);
  840. }
  841. if (app.couponListCallback) {
  842. app.couponListCallback(app.globalData.token);
  843. }
  844. if (app.businessListCallback) {
  845. app.businessListCallback(app.globalData.token);
  846. }
  847. Http.get({
  848. url: config.api.getWeapNote,
  849. data: {
  850. appId: config.weapp.AppId,
  851. }
  852. })
  853. .then(res => {
  854. console.log(33333333333)
  855. console.log(app.globalData.token)
  856. console.log(res)
  857. console.log(33333333333)
  858. // that.getGameOne(app.globalData.token)
  859. that.getStaticGame(app.globalData.token)
  860. that.getGg(app.globalData.token)
  861. let weapNote = JSON.parse(res.data.weapNote);
  862. that.getPrivacySetting()
  863. that.setData({
  864. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  865. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  866. })
  867. })
  868. .catch(err => {
  869. // that.getGameOne(app.globalData.token)
  870. that.getStaticGame(app.globalData.token)
  871. that.getGg(app.globalData.token)
  872. wx.showModal({
  873. title: "提示",
  874. content: err.message,
  875. showCancel: false
  876. });
  877. });
  878. }
  879. }
  880. },
  881. getStaticGame(token) {
  882. let _this = this;
  883. Http.get({
  884. url: config.api.getGame,
  885. data: {
  886. triggleAction: 2, // 固定入口
  887. token: token
  888. }
  889. }).then(res => {
  890. if (res.data.id) {
  891. _this.setData({
  892. showIf: true,
  893. newUrl: res.data.imgUrl
  894. })
  895. } else {
  896. _this.setData({
  897. showIf: false
  898. })
  899. }
  900. _this.setData({
  901. staticGamedata: res.data
  902. })
  903. })
  904. .catch(err => {
  905. _this.setData({
  906. showIf: false
  907. })
  908. console.log(err)
  909. })
  910. },
  911. getGameOne: function (token) {
  912. let _this = this;
  913. Http.get({
  914. url: config.api.getGame,
  915. data: {
  916. triggleAction: 1, // 登录触发
  917. token: token
  918. }
  919. }).then(res => {
  920. if (res.data.id) {
  921. _this.setData({
  922. showGame: true,
  923. })
  924. } else {
  925. _this.setData({
  926. showGame: false
  927. })
  928. }
  929. _this.setData({
  930. gamedata: res.data
  931. })
  932. })
  933. .catch(err => {
  934. _this.setData({
  935. showGame: false
  936. })
  937. this.alphaClick();
  938. })
  939. },
  940. /**
  941. * mallinfo
  942. */
  943. getMallInfo: function (token) {
  944. let that = this;
  945. Http.get({
  946. url: config.api.getMallInfo,
  947. data: {
  948. token: token,
  949. }
  950. }).then(res => {
  951. that.setData({
  952. liveFlag: res.data.liveSupport,
  953. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  954. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  955. });
  956. console.log(that.data.liveFlag, "||||")
  957. })
  958. .catch(err => {
  959. // 不需要错误提示
  960. });
  961. },
  962. //获取限时抢购列表
  963. getxsList() {
  964. let that = this;
  965. Http.get({
  966. url: config.api.couponChannelList,
  967. data: {
  968. pageNum: 1,
  969. pageSize: 3,
  970. targetAd: 2
  971. }
  972. }).then(res => {
  973. if (res && res.data.total > 0) {
  974. that.setData({
  975. xslist: res.data.list,
  976. showQg: true
  977. });
  978. } else {
  979. that.setData({
  980. showQg: false
  981. })
  982. }
  983. })
  984. .catch(err => {
  985. console.log(err)
  986. wx.showToast({
  987. title: err.message,
  988. icon: 'none',
  989. duration: 2000,
  990. mask: false
  991. });
  992. })
  993. },
  994. /**
  995. * banner
  996. */
  997. getBannerlist: function () {
  998. let that = this;
  999. Http.get({
  1000. url: config.api.bannerlist,
  1001. data: {
  1002. pageNum: 1,
  1003. pageSize: 7
  1004. }
  1005. }).then(res => {
  1006. that.getmemberId(app.globalData.token);
  1007. // that.checkUserCarStatus();
  1008. that.setData({
  1009. list: res.data.list
  1010. });
  1011. })
  1012. .catch(err => {
  1013. that.getmemberId(app.globalData.token);
  1014. // that.checkUserCarStatus();
  1015. });
  1016. },
  1017. //获取欢乐城专题
  1018. getShowList() {
  1019. Http.get({
  1020. url: config.api.showList
  1021. }).then(res => {
  1022. let tempData = res.data
  1023. tempData.map(item1 => {
  1024. if (item1.couponList) {
  1025. item1.couponList.map(item2 => {
  1026. if (item2.salePriceStr && item2.salePriceStr.indexOf('.') != -1) {
  1027. let str = item2.salePriceStr.split('.')
  1028. item2.salePriceStrQ = str[0]
  1029. item2.salePriceStrH = str[1]
  1030. }
  1031. })
  1032. }
  1033. })
  1034. this.setData({
  1035. specialLsit: res.data ? res.data : []
  1036. })
  1037. }).catch(err => {
  1038. wx.showToast({
  1039. title: err.message ? err.message : err.data,
  1040. icon: 'none',
  1041. duration: 2000,
  1042. mask: false
  1043. });
  1044. })
  1045. },
  1046. /**
  1047. * topicType=2 限时抢购
  1048. * topicType=3 砍价
  1049. * topicType=4 拼团
  1050. * topicType=5 消费卡
  1051. * topicType=6 积分商城
  1052. */
  1053. topicShowall(topicType) {
  1054. Http.get({
  1055. url: config.api.topicShow,
  1056. data: {
  1057. topicType
  1058. }
  1059. }).then(res => {
  1060. let data = res.data
  1061. if (data.couponList != null && data.couponList.length > 0) {
  1062. data.couponList.map(item => {
  1063. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  1064. let str = item.salePriceStr.split('.')
  1065. item.salePriceStrQ = str[0]
  1066. item.salePriceStrH = str[1]
  1067. }
  1068. })
  1069. }
  1070. if (topicType == 2) {
  1071. let tempData = data
  1072. this.setData({
  1073. topicObj2: data
  1074. })
  1075. } else if (topicType == 3) {
  1076. this.setData({
  1077. topicObj3: data
  1078. })
  1079. } else if (topicType == 4) {
  1080. this.setData({
  1081. topicObj4: data
  1082. })
  1083. } else if (topicType == 5) {
  1084. this.setData({
  1085. topicObj5: data
  1086. })
  1087. } else if (topicType == 6) {
  1088. this.setData({
  1089. topicObj6: data
  1090. })
  1091. }
  1092. }).catch(err => {
  1093. wx.showToast({
  1094. title: err.message ? err.message : err.data,
  1095. icon: 'none',
  1096. duration: 2000,
  1097. mask: false
  1098. });
  1099. })
  1100. },
  1101. // 专题显示
  1102. topicShow: function () {
  1103. let that = this;
  1104. Http.get({
  1105. url: config.api.topicShow,
  1106. data: {
  1107. token: app.globalData.token
  1108. }
  1109. }).then(res => {
  1110. if (res && res.data) {
  1111. that.setData({
  1112. name: res.data.name,
  1113. cover: res.data.cover,
  1114. id: res.data.id,
  1115. showTopic: true
  1116. })
  1117. } else {
  1118. that.setData({
  1119. showTopic: false
  1120. })
  1121. }
  1122. })
  1123. .catch(err => {
  1124. console.log(err);
  1125. })
  1126. },
  1127. gotoTopic() {
  1128. wx.navigateTo({
  1129. url: `/pages/topicDetail/index?id=${this.data.id}`
  1130. })
  1131. },
  1132. clickPrivacy(e) {
  1133. },
  1134. closePrivacy() {
  1135. this.setData({
  1136. showPrivacy: false
  1137. })
  1138. },
  1139. getPrivacySetting() {
  1140. const canIUsePrivacy = wx.canIUse('getPrivacySetting')
  1141. console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
  1142. if (canIUsePrivacy) {
  1143. wx.getPrivacySetting({
  1144. success: res => {
  1145. console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  1146. if (res.needAuthorization) {
  1147. // 需要弹出隐私协议
  1148. this.setData({
  1149. showPrivacy: true
  1150. })
  1151. } else {
  1152. // this.setData({
  1153. // showPrivacy: true
  1154. // })
  1155. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  1156. // wx.getUserProfile()
  1157. // wx.chooseMedia()
  1158. // wx.getClipboardData()
  1159. // wx.startRecord()
  1160. // this.setData({
  1161. // showPrivacy: true
  1162. // })
  1163. }
  1164. },
  1165. fail: () => { },
  1166. complete: () => { }
  1167. })
  1168. }
  1169. },
  1170. handleAgreePrivacyAuthorization() {
  1171. console.log('Privacy Agreed!');
  1172. this.setData({
  1173. showPrivacy: false
  1174. })
  1175. // 用户同意隐私协议事件回调
  1176. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  1177. // wx.getUserProfile()
  1178. // wx.chooseMedia()
  1179. // wx.getClipboardData()
  1180. // wx.startRecord()
  1181. },
  1182. handleOpenPrivacyContract() {
  1183. // 打开隐私协议页面
  1184. wx.openPrivacyContract({
  1185. success: () => {
  1186. // this.setData({
  1187. // showPrivacy: false
  1188. // })
  1189. }, // 打开成功
  1190. fail: () => { }, // 打开失败
  1191. complete: () => { }
  1192. })
  1193. },
  1194. /**
  1195. * 检查用户是否有车
  1196. */
  1197. // checkUserCarStatus: function() {
  1198. // var that = this;
  1199. // Http.get({
  1200. // url: config.api.userCarCount,
  1201. // data: {}
  1202. // }).then(res => {
  1203. // if (res.data > 0) {
  1204. // // 用户名下有车
  1205. // app.globalData.phone = res.data.phone;
  1206. // app.globalData.supportCar = true;
  1207. // // 共同登录
  1208. // that.userCarLogin();
  1209. // }
  1210. // });
  1211. // },
  1212. /**
  1213. * car共同登录
  1214. */
  1215. // userCarLogin: function() {
  1216. // var that = this;
  1217. // if (!app.globalData.carLogin) {
  1218. // // 共同登录
  1219. // Http.post({
  1220. // url: config.api.carInit,
  1221. // data: {
  1222. // phone: app.globalData.phone
  1223. // }
  1224. // }).then(res => {
  1225. // app.globalData.carLogin = true;
  1226. // app.globalData.parkVendor = res.data.vendor;
  1227. // if (res.data.token != "undefined") {
  1228. // app.globalData.etcpToken = res.data.token;
  1229. // }
  1230. // });
  1231. // }
  1232. // },
  1233. /**
  1234. * 获取用户信息
  1235. */
  1236. // getUserInfo: function() {
  1237. // // 获取用户信息
  1238. // wx.getSetting({
  1239. // success: res => {
  1240. // if (res.authSetting["scope.userInfo"]) {
  1241. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  1242. // wx.getUserInfo({
  1243. // success: res => {
  1244. // // 可以将 res 发送给后台解码出 unionId
  1245. // }
  1246. // });
  1247. // }
  1248. // }
  1249. // });
  1250. // },
  1251. gotoBargain: function () {
  1252. wx.navigateTo({
  1253. url: '/pages/bargain/bargain'
  1254. })
  1255. },
  1256. //限时抢购的详情页面
  1257. gotodetail: function (e) {
  1258. wx.navigateTo({
  1259. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.couponchannelid
  1260. }&couponId=${e.currentTarget.dataset.couponid}`
  1261. });
  1262. },
  1263. //浮层广告
  1264. getGg: function (token) {
  1265. let that = this
  1266. Http.get({
  1267. url: config.api.getGg,
  1268. data: {
  1269. token: token,
  1270. appId: config.weapp.AppId,
  1271. openId: "" // wx.getStorageSync('openId')
  1272. }
  1273. }).then(res => {
  1274. console.log(res)
  1275. if (res.data.id) {
  1276. that.setData({
  1277. showGg: true,
  1278. })
  1279. console.log(that.data.showGg, 1111111111111)
  1280. } else {
  1281. that.setData({
  1282. showGg: false
  1283. })
  1284. that.getGameOne(app.globalData.token)
  1285. console.log(that.data.showGg, 222222222222222222)
  1286. }
  1287. that.setData({
  1288. ggdata: res.data
  1289. })
  1290. })
  1291. .catch(err => {
  1292. this.setData({
  1293. showGg: false
  1294. })
  1295. that.getGameOne(app.globalData.token)
  1296. that.alphaClick1();
  1297. })
  1298. },
  1299. /**
  1300. * 刷新
  1301. */
  1302. onPullDownRefresh: function (e) {
  1303. this.setData({
  1304. topicObj2: null, //欢乐城首页限时抢购
  1305. topicObj3: null, //欢乐城首页砍价
  1306. topicObj4: null, //欢乐城首页拼团
  1307. topicObj5: null, //欢乐城首页消费卡
  1308. topicObj6: null, //欢乐城首页积分商城
  1309. })
  1310. let that = this;
  1311. // that.getWeapNote();
  1312. that.setData({
  1313. page: 1
  1314. })
  1315. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  1316. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  1317. } else {
  1318. this.getWeapNote()
  1319. }
  1320. if (that.selectComponent("#lists")) {
  1321. if (that.data.code == 0 || that.data.code == undefined) {
  1322. that.selectComponent("#lists").getList(0, 1, "refresh");
  1323. wx.stopPullDownRefresh();
  1324. } else {
  1325. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  1326. wx.stopPullDownRefresh();
  1327. };
  1328. that.selectComponent("#hot").getList();
  1329. }
  1330. // 砍价下拉刷新
  1331. // that.selectComponent("#bargain").getList();
  1332. // that.selectComponent("#spellGroup").getList();
  1333. // that.selectComponent("#rushtobyCard").getList();
  1334. wx.stopPullDownRefresh();
  1335. //爆款专区下拉刷新
  1336. that.getxsList();
  1337. that.topicShow();
  1338. },
  1339. //加载更多
  1340. onReachBottom: function () {
  1341. console.log("我到底了")
  1342. let that = this;
  1343. that.data.page++;
  1344. that.setData({
  1345. page: that.data.page,
  1346. businePageNum: that.data.businePageNum + 1
  1347. });
  1348. console.log("加载更多页数" + that.data.page,);
  1349. console.log("加载更多key" + that.data.code);
  1350. if (that.data.mouldType == 0) { //富茂源模板
  1351. //父组件获得子组件的方法
  1352. //如果code == 0
  1353. if (that.data.code == 0 || that.data.code == undefined) {
  1354. that.selectComponent("#lists").getList(0, that.data.page);
  1355. } else {
  1356. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  1357. }
  1358. } else if (that.data.mouldType == 1) {
  1359. this.getCouponChannelList(that.data.busineKye)
  1360. }
  1361. },
  1362. // 用户点击右上角分享
  1363. onShareAppMessage: function () {
  1364. app.globalData.previewFlag = true
  1365. return {
  1366. path: "/pages/index/index",
  1367. title: this.data.weappShareTitle,
  1368. imageUrl: this.data.weappShareCoverImg,
  1369. success: function (res) {
  1370. wx.showToast({
  1371. title: "分享成功",
  1372. duration: 1000,
  1373. icon: "success"
  1374. });
  1375. }
  1376. };
  1377. }
  1378. });