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. businessList: [], //优选好物导航
  26. businessData: [], //优选好物数据
  27. topicObj2: null, //欢乐城首页限时抢购
  28. topicObj3: null, //欢乐城首页砍价
  29. topicObj4: null, //欢乐城首页拼团
  30. topicObj5: null, //欢乐城首页消费卡
  31. topicObj6: null, //欢乐城首页积分商城
  32. specialLsit: [], //欢乐城首页专题
  33. marketName: "", //商场名称
  34. mouldType: 0,
  35. navLineHeight: ((app.statusBarHeight + app.statusBarHeight) + 44) + "px",
  36. huanlechengImgurl: "https://formall.oss-accelerate.aliyuncs.com/cimg/v20211214/",
  37. mch_id: mch_id,
  38. goUrl: "", //商圈跳转链接
  39. accreditFlag: 1, //1:未授权微信且未授权手机号,2:授权了微信没授权手机号,3:微信和手机号都授权了
  40. businessSwitch: businessSwitch,
  41. typeLsit: {},
  42. showLocationIf: true,
  43. ifStoreApp: ifStoreApp,
  44. navigationBarTitle: '首页',
  45. navigationBarHeight,
  46. chengzhangBox: bgColor.colorFirst.main.chengzhangBox,
  47. activeColor: bgColor.colorFirst.main.activeColor,
  48. qg: bgColor.colorFirst.main.qg,
  49. newUrl: "",
  50. cover: "",
  51. kanjia: imgurl.kanjia.url,
  52. pintuan: imgurl.pintuan.url,
  53. xiaofeika: imgurl.xiaofeika.url,
  54. xingyun: imgurl.xingyun.url,
  55. jfshangcheng: imgurl.jfshangcheng.url,
  56. toutiao: imgurl.toutiao.url,
  57. more: imgurl.more.url,
  58. giftHr: imgurl.giftHr.url,
  59. giftHr: imgurl.giftHr.url,
  60. next: imgurl.next.url,
  61. usergift: imgurl.usergift.url,
  62. guanbi1: imgurl.guanbi1.url,
  63. icon0001: imgurl.icon0001.url,
  64. icon0002: imgurl.icon0002.url,
  65. icon0003: imgurl.icon0003.url,
  66. icon0004: imgurl.icon0004.url,
  67. icon0005: imgurl.icon0005.url,
  68. icon0006: imgurl.icon0006.url,
  69. icon0007: imgurl.icon0007.url,
  70. icon0008: imgurl.icon0008.url,
  71. barcode: imgurl.barcode.url,
  72. leftarrows: imgurl.leftarrows.url,
  73. newcard: imgurl.newcard.url,
  74. newseckill: imgurl.newseckill.url,
  75. newbargain: imgurl.newbargain.url,
  76. newgroup: imgurl.newgroup.url,
  77. product: imgurl.product.url,
  78. barginicon: imgurl.barginicon.url,
  79. pintuan: imgurl.pintuan.url,
  80. live: imgurl.live.url,
  81. duihuan: imgurl.duihuan.url,
  82. market: app.globalData.market,
  83. list: [],
  84. xslist: [],
  85. loading: true,
  86. fistLogin: null,
  87. alphaData: null,
  88. alphaData1: null,
  89. swiperCurrent: 0,
  90. title: null,
  91. weappShareTitle: '', //分享标题
  92. weappShareCoverImg: '', //分享图片
  93. desc: null,
  94. scrollTop: 0,
  95. showGame: false,
  96. showTopic: false,
  97. showQg: false,
  98. gamedata: {},
  99. couponId: '', //游戏返回时传回的字段
  100. played: false, //从游戏页面跳回首页返回true
  101. havePlayEd: app.globalData.havePlayEd,
  102. havePlayEd1: app.globalData.havePlayEd1,
  103. staticGamedata: {},
  104. showIf: false,
  105. showPages: false,
  106. display: 'none',
  107. display1: 'none',
  108. optionsData: null,
  109. page: 1, // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  110. openId: '',
  111. showGg: false,
  112. ggdata: {},
  113. liveFlag: 0, //直播按钮显隐标志位
  114. squareName: "", //当前广场
  115. isShowSqare: false,
  116. moduleList: [], //按钮列表
  117. userAvatarUrl: "",
  118. userName: "",
  119. showPrivacy: false,
  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. console.log(openId, 'openId');
  699. this.setData({
  700. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}&member_status=${1}`
  701. })
  702. } else {
  703. this.setData({
  704. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  705. })
  706. }
  707. }
  708. // console.log(JSON.stringify(app.globalData.styleLsit), "styleLsit")
  709. this.ifShowSqare();
  710. if (wx.getStorageSync("squareList") && wx.getStorageSync("selectedMall")) {
  711. var temp = wx.getStorageSync("squareList").filter(item => item.tenantId == wx.getStorageSync("selectedMall"))[0].name
  712. this.setData({
  713. squareName: temp
  714. })
  715. }
  716. if (typeof this.getTabBar === 'function' &&
  717. this.getTabBar()) {
  718. this.getTabBar().setData({
  719. selected: 0,
  720. })
  721. }
  722. let that = this;
  723. that.setData({
  724. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  725. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  726. })
  727. /**
  728. * couponNum 是否有普通的优惠券购买
  729. * couponNum2 是否有新买的消费卡
  730. */
  731. let num = wx.getStorageSync('couponNum');
  732. let num1 = wx.getStorageSync('couponNum2');
  733. // if (num == 'couponNum' || num1 == 'couponNum2') {
  734. // wx.showTabBarRedDot({
  735. // index: 3
  736. // })
  737. // } else {
  738. // wx.hideTabBarRedDot({
  739. // index: 3
  740. // })
  741. // }
  742. if (app.globalData.score) {
  743. that.setData({
  744. fistLogin: app.globalData.score
  745. })
  746. }
  747. // 如果有游戏
  748. setTimeout(function () {
  749. that.alphaClick();
  750. }, 8000)
  751. // 如果有广告
  752. setTimeout(function () {
  753. that.alphaClick1();
  754. }, 8000)
  755. },
  756. getmemberId: function (token) {
  757. let that = this;
  758. Http.get({
  759. url: config.api.getScore,
  760. data: {
  761. token: token
  762. }
  763. }).then(res => {
  764. if (res.data.avatarUrl && res.data.nickName) {
  765. app.globalData.userAvatarUrl = res.data.avatarUrl,
  766. app.globalData.userName = res.data.nickName
  767. }
  768. that.setData({
  769. levelName: res.data.levelName,
  770. upgradePercent: res.data.upgradePercent,
  771. upgradeScore: res.data.upgradeScore,
  772. memberId: res.data.id,
  773. credit: res.data.credit,
  774. userAvatarUrl: res.data.avatarUrl ? res.data.avatarUrl : '',
  775. userName: res.data.nickName ? res.data.nickName : '',
  776. })
  777. })
  778. .catch(err => {
  779. wx.showModal({
  780. title: '提示',
  781. content: err.message,
  782. showCancel: false
  783. })
  784. })
  785. },
  786. gotoChengzhangzhi: function () {
  787. wx.navigateTo({
  788. url: '/pages/czdetail/czdetail',
  789. })
  790. },
  791. goIntegralmall() {
  792. wx.navigateTo({
  793. url: '/pages/integralmall/index',
  794. })
  795. },
  796. gotoBargain: function () {
  797. wx.navigateTo({
  798. url: '/pages/bargain/bargain',
  799. })
  800. },
  801. gotoSpellGroup: function () {
  802. wx.navigateTo({
  803. url: '/pages/spellGroup/spellGroup',
  804. })
  805. },
  806. gotoCard: function () {
  807. wx.navigateTo({
  808. url: '/pages/discountCardList/discountCardList',
  809. })
  810. },
  811. // gotoGame: function () {
  812. // wx.navigateTo({
  813. // url: '/pages/game/index',
  814. // })
  815. // },
  816. gotoJfsc: function () {
  817. wx.navigateTo({
  818. url: '/pages/integralmall/index',
  819. })
  820. },
  821. /**
  822. *
  823. * @param {code,page}
  824. * 子组件向父组件传值
  825. */
  826. onGetCode: function (e) {
  827. this.setData({
  828. code: e.detail.val,
  829. page: e.detail.pageNum,
  830. });
  831. console.log(e.detail.val)
  832. console.log(e.detail.pageNum)
  833. },
  834. getWeapNote: function (couponChannelId, couponId, orderId) {
  835. var that = this;
  836. if (app.globalData.token) {
  837. // 登录
  838. that.setTabStyle()
  839. that.getmemberId(app.globalData.token);
  840. that.getBannerlist();
  841. if (that.data.mouldType == 0) { //富茂原版
  842. that.topicShow();
  843. that.getxsList();
  844. } else if (that.data.mouldType == 1) { //欢乐城模板
  845. that.getShowList()
  846. that.topicShowall(2);
  847. that.topicShowall(3);
  848. that.topicShowall(4);
  849. that.topicShowall(5);
  850. that.topicShowall(6);
  851. that.getBusinessList();
  852. that.getCouponChannelList(0)
  853. }
  854. that.getType()
  855. // that.uesrInfo()
  856. // that.getLocation();
  857. that.getMallInfo(app.globalData.token);
  858. if (app.couponChannelListCallback) {
  859. app.couponChannelListCallback(app.globalData.token);
  860. }
  861. if (app.couponListCallback) {
  862. app.couponListCallback(app.globalData.token);
  863. }
  864. if (app.businessListCallback) {
  865. app.businessListCallback(app.globalData.token);
  866. }
  867. Http.get({
  868. url: config.api.getWeapNote,
  869. data: {
  870. appId: config.weapp.AppId,
  871. }
  872. })
  873. .then(res => {
  874. console.log(33333333333)
  875. console.log(app.globalData.token)
  876. console.log(res)
  877. console.log(33333333333)
  878. // that.getGameOne(app.globalData.token)
  879. that.getStaticGame(app.globalData.token)
  880. that.getGg(app.globalData.token)
  881. let weapNote = JSON.parse(res.data.weapNote);
  882. that.setData({
  883. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  884. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  885. })
  886. // that.getPrivacySetting()
  887. })
  888. .catch(err => {
  889. // that.getGameOne(app.globalData.token)
  890. that.getStaticGame(app.globalData.token)
  891. that.getGg(app.globalData.token)
  892. wx.showModal({
  893. title: "提示",
  894. content: err.message,
  895. showCancel: false
  896. });
  897. });
  898. } else {
  899. app.tokenCallback = token => {
  900. // 登录
  901. that.setTabStyle()
  902. that.getmemberId(app.globalData.token);
  903. that.getBannerlist();
  904. if (that.data.mouldType == 0) { //富茂原版
  905. that.topicShow();
  906. that.getxsList();
  907. } else if (that.data.mouldType == 1) { //欢乐城模板
  908. that.getShowList()
  909. that.topicShowall(2);
  910. that.topicShowall(3);
  911. that.topicShowall(4);
  912. that.topicShowall(5);
  913. that.topicShowall(6);
  914. that.getBusinessList();
  915. that.getCouponChannelList(0)
  916. }
  917. that.getType()
  918. // that.uesrInfo()
  919. // that.getLocation();
  920. that.getMallInfo(app.globalData.token);
  921. if (app.couponChannelListCallback) {
  922. app.couponChannelListCallback(app.globalData.token);
  923. }
  924. if (app.couponListCallback) {
  925. app.couponListCallback(app.globalData.token);
  926. }
  927. if (app.businessListCallback) {
  928. app.businessListCallback(app.globalData.token);
  929. }
  930. Http.get({
  931. url: config.api.getWeapNote,
  932. data: {
  933. appId: config.weapp.AppId,
  934. }
  935. })
  936. .then(res => {
  937. console.log(33333333333)
  938. console.log(app.globalData.token)
  939. console.log(res)
  940. console.log(33333333333)
  941. // that.getGameOne(app.globalData.token)
  942. that.getStaticGame(app.globalData.token)
  943. that.getGg(app.globalData.token)
  944. let weapNote = JSON.parse(res.data.weapNote);
  945. that.setData({
  946. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  947. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  948. })
  949. // that.getPrivacySetting()
  950. })
  951. .catch(err => {
  952. // that.getGameOne(app.globalData.token)
  953. that.getStaticGame(app.globalData.token)
  954. that.getGg(app.globalData.token)
  955. wx.showModal({
  956. title: "提示",
  957. content: err.message,
  958. showCancel: false
  959. });
  960. });
  961. }
  962. }
  963. },
  964. getStaticGame(token) {
  965. let _this = this;
  966. Http.get({
  967. url: config.api.getGame,
  968. data: {
  969. triggleAction: 2, // 固定入口
  970. token: token
  971. }
  972. }).then(res => {
  973. if (res.data.id) {
  974. _this.setData({
  975. showIf: true,
  976. newUrl: res.data.imgUrl
  977. })
  978. } else {
  979. _this.setData({
  980. showIf: false
  981. })
  982. }
  983. _this.setData({
  984. staticGamedata: res.data
  985. })
  986. })
  987. .catch(err => {
  988. _this.setData({
  989. showIf: false
  990. })
  991. console.log(err)
  992. })
  993. },
  994. getGameOne: function (token) {
  995. let _this = this;
  996. Http.get({
  997. url: config.api.getGame,
  998. data: {
  999. triggleAction: 1, // 登录触发
  1000. token: token
  1001. }
  1002. }).then(res => {
  1003. if (res.data.id) {
  1004. _this.setData({
  1005. showGame: true,
  1006. })
  1007. } else {
  1008. _this.setData({
  1009. showGame: false
  1010. })
  1011. }
  1012. _this.setData({
  1013. gamedata: res.data
  1014. })
  1015. })
  1016. .catch(err => {
  1017. _this.setData({
  1018. showGame: false
  1019. })
  1020. this.alphaClick();
  1021. })
  1022. },
  1023. /**
  1024. * mallinfo
  1025. */
  1026. getMallInfo: function (token) {
  1027. let that = this;
  1028. Http.get({
  1029. url: config.api.getMallInfo,
  1030. data: {
  1031. token: token,
  1032. }
  1033. }).then(res => {
  1034. that.setData({
  1035. liveFlag: res.data.liveSupport,
  1036. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  1037. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  1038. });
  1039. console.log(that.data.liveFlag, "||||")
  1040. })
  1041. .catch(err => {
  1042. // 不需要错误提示
  1043. });
  1044. },
  1045. //获取限时抢购列表
  1046. getxsList() {
  1047. let that = this;
  1048. Http.get({
  1049. url: config.api.couponChannelList,
  1050. data: {
  1051. pageNum: 1,
  1052. pageSize: 3,
  1053. targetAd: 2
  1054. }
  1055. }).then(res => {
  1056. if (res && res.data.total > 0) {
  1057. that.setData({
  1058. xslist: res.data.list,
  1059. showQg: true
  1060. });
  1061. } else {
  1062. that.setData({
  1063. showQg: false
  1064. })
  1065. }
  1066. })
  1067. .catch(err => {
  1068. console.log(err)
  1069. wx.showToast({
  1070. title: err.message,
  1071. icon: 'none',
  1072. duration: 2000,
  1073. mask: false
  1074. });
  1075. })
  1076. },
  1077. /**
  1078. * banner
  1079. */
  1080. getBannerlist: function () {
  1081. let that = this;
  1082. Http.get({
  1083. url: config.api.bannerlist,
  1084. data: {
  1085. pageNum: 1,
  1086. pageSize: 7
  1087. }
  1088. }).then(res => {
  1089. that.getmemberId(app.globalData.token);
  1090. // that.checkUserCarStatus();
  1091. that.setData({
  1092. list: res.data.list
  1093. });
  1094. })
  1095. .catch(err => {
  1096. that.getmemberId(app.globalData.token);
  1097. // that.checkUserCarStatus();
  1098. });
  1099. },
  1100. //获取欢乐城专题
  1101. getShowList() {
  1102. Http.get({
  1103. url: config.api.showList
  1104. }).then(res => {
  1105. let tempData = res.data
  1106. tempData.map(item1 => {
  1107. if (item1.couponList) {
  1108. item1.couponList.map(item2 => {
  1109. if (item2.salePriceStr && item2.salePriceStr.indexOf('.') != -1) {
  1110. let str = item2.salePriceStr.split('.')
  1111. item2.salePriceStrQ = str[0]
  1112. item2.salePriceStrH = str[1]
  1113. }
  1114. })
  1115. }
  1116. })
  1117. this.setData({
  1118. specialLsit: res.data ? res.data : []
  1119. })
  1120. }).catch(err => {
  1121. wx.showToast({
  1122. title: err.message ? err.message : err.data,
  1123. icon: 'none',
  1124. duration: 2000,
  1125. mask: false
  1126. });
  1127. })
  1128. },
  1129. /**
  1130. * topicType=2 限时抢购
  1131. * topicType=3 砍价
  1132. * topicType=4 拼团
  1133. * topicType=5 消费卡
  1134. * topicType=6 积分商城
  1135. */
  1136. topicShowall(topicType) {
  1137. Http.get({
  1138. url: config.api.topicShow,
  1139. data: {
  1140. topicType
  1141. }
  1142. }).then(res => {
  1143. let data = res.data
  1144. if (data.couponList != null && data.couponList.length > 0) {
  1145. data.couponList.map(item => {
  1146. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  1147. let str = item.salePriceStr.split('.')
  1148. item.salePriceStrQ = str[0]
  1149. item.salePriceStrH = str[1]
  1150. }
  1151. })
  1152. }
  1153. if (topicType == 2) {
  1154. let tempData = data
  1155. this.setData({
  1156. topicObj2: data
  1157. })
  1158. } else if (topicType == 3) {
  1159. this.setData({
  1160. topicObj3: data
  1161. })
  1162. } else if (topicType == 4) {
  1163. this.setData({
  1164. topicObj4: data
  1165. })
  1166. } else if (topicType == 5) {
  1167. this.setData({
  1168. topicObj5: data
  1169. })
  1170. } else if (topicType == 6) {
  1171. this.setData({
  1172. topicObj6: data
  1173. })
  1174. }
  1175. }).catch(err => {
  1176. wx.showToast({
  1177. title: err.message ? err.message : err.data,
  1178. icon: 'none',
  1179. duration: 2000,
  1180. mask: false
  1181. });
  1182. })
  1183. },
  1184. // 专题显示
  1185. topicShow: function () {
  1186. let that = this;
  1187. Http.get({
  1188. url: config.api.topicShow,
  1189. data: {
  1190. token: app.globalData.token
  1191. }
  1192. }).then(res => {
  1193. if (res && res.data) {
  1194. that.setData({
  1195. name: res.data.name,
  1196. cover: res.data.cover,
  1197. id: res.data.id,
  1198. showTopic: true
  1199. })
  1200. } else {
  1201. that.setData({
  1202. showTopic: false
  1203. })
  1204. }
  1205. })
  1206. .catch(err => {
  1207. console.log(err);
  1208. })
  1209. },
  1210. gotoTopic() {
  1211. wx.navigateTo({
  1212. url: `/pages/topicDetail/index?id=${this.data.id}`
  1213. })
  1214. },
  1215. /**
  1216. * 检查用户是否有车
  1217. */
  1218. // checkUserCarStatus: function() {
  1219. // var that = this;
  1220. // Http.get({
  1221. // url: config.api.userCarCount,
  1222. // data: {}
  1223. // }).then(res => {
  1224. // if (res.data > 0) {
  1225. // // 用户名下有车
  1226. // app.globalData.phone = res.data.phone;
  1227. // app.globalData.supportCar = true;
  1228. // // 共同登录
  1229. // that.userCarLogin();
  1230. // }
  1231. // });
  1232. // },
  1233. /**
  1234. * car共同登录
  1235. */
  1236. // userCarLogin: function() {
  1237. // var that = this;
  1238. // if (!app.globalData.carLogin) {
  1239. // // 共同登录
  1240. // Http.post({
  1241. // url: config.api.carInit,
  1242. // data: {
  1243. // phone: app.globalData.phone
  1244. // }
  1245. // }).then(res => {
  1246. // app.globalData.carLogin = true;
  1247. // app.globalData.parkVendor = res.data.vendor;
  1248. // if (res.data.token != "undefined") {
  1249. // app.globalData.etcpToken = res.data.token;
  1250. // }
  1251. // });
  1252. // }
  1253. // },
  1254. /**
  1255. * 获取用户信息
  1256. */
  1257. // getUserInfo: function() {
  1258. // // 获取用户信息
  1259. // wx.getSetting({
  1260. // success: res => {
  1261. // if (res.authSetting["scope.userInfo"]) {
  1262. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  1263. // wx.getUserInfo({
  1264. // success: res => {
  1265. // // 可以将 res 发送给后台解码出 unionId
  1266. // }
  1267. // });
  1268. // }
  1269. // }
  1270. // });
  1271. // },
  1272. gotoBargain: function () {
  1273. wx.navigateTo({
  1274. url: '/pages/bargain/bargain'
  1275. })
  1276. },
  1277. //限时抢购的详情页面
  1278. gotodetail: function (e) {
  1279. wx.navigateTo({
  1280. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.couponchannelid
  1281. }&couponId=${e.currentTarget.dataset.couponid}`
  1282. });
  1283. },
  1284. //浮层广告
  1285. getGg: function (token) {
  1286. let that = this
  1287. Http.get({
  1288. url: config.api.getGg,
  1289. data: {
  1290. token: token,
  1291. appId: config.weapp.AppId,
  1292. openId: "" // wx.getStorageSync('openId')
  1293. }
  1294. }).then(res => {
  1295. console.log(res)
  1296. if (res.data.id) {
  1297. that.setData({
  1298. showGg: true,
  1299. })
  1300. console.log(that.data.showGg, 1111111111111)
  1301. } else {
  1302. that.setData({
  1303. showGg: false
  1304. })
  1305. that.getGameOne(app.globalData.token)
  1306. console.log(that.data.showGg, 222222222222222222)
  1307. }
  1308. that.setData({
  1309. ggdata: res.data
  1310. })
  1311. })
  1312. .catch(err => {
  1313. this.setData({
  1314. showGg: false
  1315. })
  1316. that.getGameOne(app.globalData.token)
  1317. that.alphaClick1();
  1318. })
  1319. },
  1320. /**
  1321. * 刷新
  1322. */
  1323. onPullDownRefresh: function (e) {
  1324. this.setData({
  1325. topicObj2: null, //欢乐城首页限时抢购
  1326. topicObj3: null, //欢乐城首页砍价
  1327. topicObj4: null, //欢乐城首页拼团
  1328. topicObj5: null, //欢乐城首页消费卡
  1329. topicObj6: null, //欢乐城首页积分商城
  1330. })
  1331. let that = this;
  1332. // that.getWeapNote();
  1333. that.setData({
  1334. page: 1
  1335. })
  1336. if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) {
  1337. this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId);
  1338. } else {
  1339. this.getWeapNote()
  1340. }
  1341. if (that.selectComponent("#lists")) {
  1342. if (that.data.code == 0 || that.data.code == undefined) {
  1343. that.selectComponent("#lists").getList(0, 1, "refresh");
  1344. wx.stopPullDownRefresh();
  1345. } else {
  1346. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  1347. wx.stopPullDownRefresh();
  1348. };
  1349. that.selectComponent("#hot").getList();
  1350. }
  1351. // 砍价下拉刷新
  1352. // that.selectComponent("#bargain").getList();
  1353. // that.selectComponent("#spellGroup").getList();
  1354. // that.selectComponent("#rushtobyCard").getList();
  1355. wx.stopPullDownRefresh();
  1356. //爆款专区下拉刷新
  1357. that.getxsList();
  1358. that.topicShow();
  1359. },
  1360. //加载更多
  1361. onReachBottom: function () {
  1362. console.log("我到底了")
  1363. let that = this;
  1364. that.data.page++;
  1365. that.setData({
  1366. page: that.data.page,
  1367. businePageNum: that.data.businePageNum + 1
  1368. });
  1369. console.log("加载更多页数" + that.data.page);
  1370. console.log("加载更多key" + that.data.code);
  1371. if (that.data.mouldType == 0) { //富茂源模板
  1372. //父组件获得子组件的方法
  1373. //如果code == 0
  1374. if (that.data.code == 0 || that.data.code == undefined) {
  1375. that.selectComponent("#lists").getList(0, that.data.page);
  1376. } else {
  1377. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  1378. }
  1379. } else if (that.data.mouldType == 1) {
  1380. this.getCouponChannelList(that.data.busineKye)
  1381. }
  1382. },
  1383. // 用户点击右上角分享
  1384. onShareAppMessage: function () {
  1385. app.globalData.previewFlag = true
  1386. return {
  1387. path: "/pages/index/index",
  1388. title: this.data.weappShareTitle,
  1389. imageUrl: this.data.weappShareCoverImg,
  1390. success: function (res) {
  1391. wx.showToast({
  1392. title: "分享成功",
  1393. duration: 1000,
  1394. icon: "success"
  1395. });
  1396. }
  1397. };
  1398. }
  1399. });