抖音小程序C端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1322 lines
34 KiB

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