C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1450 行
38 KiB

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