抖音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.

1478 line
38 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 + 60) + "px"
  6. const navigationBarHeight1 = (getApp().statusBarHeight + 50) + "px"
  7. const Http = require("../utils/HttpBasics");
  8. const imgurl = require("../utils/imgurl");
  9. const config = require("../config/config");
  10. const QR = require("../utils/memberqrcode.js");
  11. const util = require("../utils/util");
  12. const bgColor = require("../utils/bgColor.js")
  13. let app = getApp();
  14. Page({
  15. data: {
  16. userAvatarUrl: '',
  17. userName: '',
  18. // aa: (app.statusBarHeight + 60) + "rpx",
  19. noDataFlag: false,
  20. busineKye: 0,
  21. businePageNum: 1,
  22. credit: 0,
  23. businessList: [], //优选好物导航
  24. businessData: [], //优选好物数据
  25. topicObj2: null, //欢乐城首页限时抢购
  26. topicObj3: null, //欢乐城首页砍价
  27. topicObj4: null, //欢乐城首页拼团
  28. topicObj5: null, //欢乐城首页消费卡
  29. topicObj6: null, //欢乐城首页积分商城
  30. specialLsit: [], //欢乐城首页专题
  31. marketName: "", //商场名称
  32. mouldType: null,
  33. navLineHeight: ((app.statusBarHeight + app.statusBarHeight) + 50) + "px",
  34. navImgHeight: (((app.statusBarHeight + app.statusBarHeight) + 34) / 2) + "px",
  35. huanlechengImgurl: "https://formall.oss-accelerate.aliyuncs.com/cimg/v20211214/",
  36. // mch_id: mch_id,
  37. goUrl: "", //商圈跳转链接
  38. accreditFlag: 1, //1是未授权微信且未授权手机号 2授权了微信 没授权手机号 3微信和手机号都授权了
  39. // businessSwitch: businessSwitch,
  40. typeLsit: {},
  41. showLocationIf: true,
  42. // ifStoreApp: ifStoreApp,
  43. navigationBarTitle: '首页',
  44. navigationBarHeight,
  45. navigationBarHeight1,
  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. currentMall: '富茂广场',
  118. shopList: [],
  119. mallTenantId: tt.getStorageSync('mallTenantId') || '',
  120. index: tt.getStorageSync('mallIndex') || 0,
  121. locateData: {}
  122. },
  123. getCongig() { //获取小程序是否开通授权手机号
  124. Http.get({
  125. url: config.api.getConfig,
  126. data: {
  127. key: "douyinPhoneStatus"
  128. }
  129. }).then(res => {
  130. app.globalData.ifCongPh = res.data ? res.data : 1
  131. }).catch(err => {
  132. app.globalData.ifCongPh = 1
  133. })
  134. },
  135. mallSync() {
  136. this.setData({
  137. mallTenantId: tt.getStorageSync('mallTenantId') || '',
  138. index: tt.getStorageSync('mallIndex') || 0,
  139. })
  140. },
  141. getsubMallList() {
  142. Http.get({
  143. url: '/mall/subMall?isAll=1',
  144. }).then(res => {
  145. this.setData({
  146. shopList: res.data,
  147. mallTenantId: tt.getStorageSync('mallTenantId') || res.data[0].tenantId
  148. });
  149. if (!tt.getStorageSync('mallTenantId') && res.data.length > 1) {
  150. tt.setStorageSync('mallTenantId', res.data[0].tenantId)
  151. tt.setStorageSync('mallIndex', 0)
  152. }
  153. }).catch(err => {
  154. console.log(err, 'err');
  155. })
  156. },
  157. bindPickerChange(e) {
  158. const index = e.detail.value
  159. const mallTenantId = this.data.shopList[index].tenantId
  160. tt.setStorageSync('mallTenantId', mallTenantId)
  161. tt.setStorageSync('mallIndex', index)
  162. this.setData({
  163. index: index,
  164. mallTenantId: mallTenantId,
  165. });
  166. this.getBannerlist();
  167. this.getBusinessList()
  168. this.getCouponChannelList(0)
  169. },
  170. getBusineData(e) {
  171. this.setData({
  172. businePageNum: 1,
  173. busineKye: e.detail,
  174. noDataFlag: false,
  175. })
  176. this.getCouponChannelList(e.detail)
  177. },
  178. getBusinessList() { //获取优选导航
  179. Http.get({
  180. url: config.api.businessList,
  181. data: {
  182. filter: 2,
  183. mallTenantId: this.data.mallTenantId,
  184. }
  185. }).then(res => {
  186. this.setData({
  187. businessList: [{
  188. id: 0,
  189. title: "全部",
  190. type: 1
  191. }].concat(res.data)
  192. });
  193. }).catch(err => {
  194. tt.showModal({
  195. title: '提示',
  196. content: err.message ? err.message : err.data,
  197. showCancel: false
  198. })
  199. })
  200. },
  201. getCouponChannelList(key) {
  202. if (this.data.noDataFlag) {
  203. return
  204. }
  205. tt.showLoading({
  206. title: "加载中"
  207. });
  208. let param = {}
  209. if (key == 0) {
  210. param = {
  211. pageNum: this.data.businePageNum,
  212. pageSize: 6,
  213. targetAd: 101,
  214. mallTenantId: this.data.mallTenantId,
  215. }
  216. } else {
  217. param = {
  218. pageNum: this.data.businePageNum,
  219. pageSize: 6,
  220. business: key,
  221. targetAd: 101,
  222. mallTenantId: this.data.mallTenantId,
  223. }
  224. }
  225. Http.get({
  226. url: config.api.couponChannelList,
  227. data: param
  228. }).then(res => {
  229. if (res.data.list && res.data.list.length != 0) {
  230. let tempLsit = this.data.businessData
  231. let data = res.data.list
  232. data.map(item => {
  233. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  234. let str = item.salePriceStr.split('.')
  235. item.salePriceStrQ = str[0]
  236. item.salePriceStrH = str[1]
  237. }
  238. item.sale = item.inventory - item.remainInventory
  239. })
  240. if (this.data.businePageNum > 1) {
  241. this.setData({
  242. businessData: [...tempLsit, ...data]
  243. })
  244. } else {
  245. this.setData({
  246. businessData: data
  247. })
  248. }
  249. } else {
  250. this.setData({
  251. noDataFlag: true
  252. })
  253. }
  254. tt.hideLoading();
  255. }).catch(err => {
  256. tt.hideLoading();
  257. tt.showModal({
  258. title: '提示',
  259. content: err.message ? err.message : err.data,
  260. showCancel: false
  261. })
  262. })
  263. },
  264. goPage(e) {
  265. let obj = e.currentTarget.dataset.obj
  266. console.log(obj, "obj")
  267. if (obj.linkType == 1) {
  268. if (obj.linkUrl == "/pages/game/index") {
  269. this.gotogame()
  270. } else {
  271. tt.navigateTo({
  272. url: obj.linkUrl,
  273. })
  274. }
  275. //小程序内部跳转
  276. } else if (obj.linkType == 2) {
  277. //跳转到外部小程序
  278. tt.navigateToMiniProgram({
  279. appId: obj.outLinkAppid,
  280. path: obj.linkUrl ? obj.linkUrl : '',
  281. fail: err => {
  282. tt.showModal({
  283. title: '提示',
  284. content: err,
  285. showCancel: false
  286. })
  287. }
  288. })
  289. }
  290. },
  291. //获取按钮列表
  292. getModule() {
  293. Http.get({
  294. url: config.api.wxCustomizeModule
  295. }).then(res => {
  296. this.setData({
  297. moduleList: res.data,
  298. })
  299. }).catch(err => {
  300. if (err.status != 404)
  301. tt.showModal({
  302. title: '提示',
  303. content: err.message ? err.message : err.data,
  304. showCancel: false
  305. })
  306. })
  307. },
  308. //判断用户是否授权
  309. uesrInfo() {
  310. Http.get({
  311. url: config.api.checkUserStatus,
  312. data: {
  313. token: app.globalData.token
  314. }
  315. }).then(res => {
  316. Http.get({
  317. url: config.api.checkPhoneStatus
  318. }).then(res => { //全部授权
  319. this.setData({
  320. accreditFlag: 3
  321. })
  322. }).catch(err => {
  323. if (err.code == 11005) { //未授权手机号
  324. this.setData({
  325. accreditFlag: 2
  326. })
  327. } else {
  328. tt.showToast({
  329. title: err.message,
  330. icon: 'none',
  331. duration: 2000,
  332. mask: false
  333. });
  334. }
  335. })
  336. }).catch(err => {
  337. if (err.code == 11004) { //未授权微信
  338. this.setData({
  339. accreditFlag: 1
  340. })
  341. } else {
  342. tt.showToast({
  343. title: err.message,
  344. icon: 'none',
  345. duration: 2000,
  346. mask: false
  347. });
  348. }
  349. })
  350. },
  351. //获取当前广场名
  352. //跳转到每日签到
  353. goSign() {
  354. tt.navigateTo({
  355. url: '/pages/activityCalendar/activityCalendar',
  356. })
  357. },
  358. //活动日历
  359. goCalendar() {
  360. tt.navigateTo({
  361. url: '/pages/dateLsit/dateLsit',
  362. })
  363. },
  364. //跳转到其他广场列表
  365. goSquareList() {
  366. if (this.data.isShowSqare) {
  367. tt.navigateTo({
  368. url: '/pages/location/location',
  369. })
  370. }
  371. },
  372. goLive() {
  373. tt.navigateTo({
  374. url: '/pages2/live/livelist/index',
  375. })
  376. },
  377. alphaClick1: function (even) {
  378. var animation = tt.createAnimation({})
  379. animation.opacity(0).step({
  380. duration: 2000
  381. })
  382. this.setData({
  383. alphaData: animation.export()
  384. })
  385. },
  386. alphaClick: function (even) {
  387. var animation = tt.createAnimation({})
  388. animation.opacity(0).step({
  389. duration: 2000
  390. })
  391. this.setData({
  392. alphaData1: animation.export()
  393. })
  394. },
  395. // 我的卡包
  396. mycard: function () {
  397. tt.navigateTo({
  398. url: '/pages/cardorder/index/index',
  399. })
  400. },
  401. //我的券包
  402. mycoupon: function () {
  403. tt.navigateTo({
  404. url: '/pages/couponorder/index/index',
  405. })
  406. },
  407. gotoSpellGroup: function () {
  408. tt.navigateTo({
  409. url: '/pages/spellGroup/spellGroup',
  410. })
  411. },
  412. qrcode: function () {
  413. var that = this;
  414. let memberId = that.data.memberId;
  415. if (memberId) {
  416. tt.navigateTo({
  417. url: '/pages/specialcourtesy/specialcourtesy'
  418. })
  419. }
  420. },
  421. //跳往限时秒杀
  422. gotoRushBuy: function () {
  423. tt.navigateTo({
  424. url: '/pages/rushToBuy/index',
  425. })
  426. },
  427. swiperChange: function (e) {
  428. this.setData({
  429. swiperCurrent: e.detail.current
  430. });
  431. },
  432. gotogame: function () {
  433. let that = this;
  434. if (!that.data.showIf) {
  435. tt.showToast({
  436. title: '暂无游戏频道',
  437. icon: "none",
  438. duration: 3000
  439. })
  440. } else {
  441. Http.get({
  442. url: config.api.checkUserStatus,
  443. data: {
  444. token: app.globalData.token
  445. }
  446. }).then(res1 => {
  447. app.globalData.type = 'gm'
  448. Http.get({
  449. url: config.api.checkPhoneStatus,
  450. data: {}
  451. }).then(res => {
  452. var data = {
  453. couponChannelId: "" + that.data.couponChannelId,
  454. couponId: "" + that.data.couponId
  455. };
  456. if (that.data.couponChannelId == null) {
  457. var data = {
  458. couponId: "" + that.data.couponId
  459. };
  460. }
  461. tt.redirectTo({
  462. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  463. })
  464. }).catch(err => {
  465. if (err.code == 11005) {
  466. // 用户手机未授权
  467. /**
  468. * 将值传到用户手机号授权的页面
  469. *
  470. */
  471. app.globalData.skipUrl = '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  472. app.globalData.skip = 'redirectTo'
  473. tt.redirectTo({
  474. url: "/pages/getphoneInfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  475. });
  476. } else if (err.code == 11006) {
  477. // 用户手机已加密
  478. tt.redirectTo({
  479. url: "/pages/phoneinput/phoneinput?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  480. });
  481. } else {
  482. tt.showToast({
  483. title: err.message,
  484. icon: 'none',
  485. duration: 2000,
  486. mask: false
  487. });
  488. }
  489. })
  490. }).catch(err => {
  491. if (err.code == 11004) { //未授权微信
  492. app.globalData.type = 'gm'
  493. tt.redirectTo({
  494. url: "/pages/getuserinfo/index?path=index&url=" + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  495. });
  496. } else {
  497. tt.showToast({
  498. title: err.message,
  499. icon: 'none',
  500. duration: 2000,
  501. mask: false
  502. });
  503. }
  504. })
  505. }
  506. },
  507. mySpecial: function () {
  508. console.log("special");
  509. tt.navigateTo({
  510. url: '/pages/specialcourtesy/specialcourtesy',
  511. })
  512. },
  513. //是否属于集团
  514. ifShowSqare() {
  515. if (tt.getStorageSync("squareList")) {
  516. this.setData({
  517. isShowSqare: true
  518. })
  519. } else {
  520. this.setData({
  521. isShowSqare: false
  522. })
  523. }
  524. },
  525. /**
  526. * 获取全局样式
  527. */
  528. getType() {
  529. Http.get({
  530. url: config.api.setType,
  531. data: {
  532. mouldType: app.globalData.mouldType
  533. }
  534. }).then(res => {
  535. const {
  536. code,
  537. data
  538. } = res
  539. if (code == 200) {
  540. app.globalData.typeLsit = data
  541. this.setData({
  542. typeLsit: data,
  543. })
  544. }
  545. })
  546. },
  547. /**
  548. * 生命周期函数--监听页面初次渲染完成
  549. */
  550. onLoad: function (options) {
  551. let that = this;
  552. let optionss;
  553. let openId = tt.getStorageSync('openId')
  554. if (tt.getStorageSync('options')) {
  555. optionss = JSON.parse(tt.getStorageSync('options'));
  556. }
  557. if (options.played == "true") {
  558. that.setData({
  559. played: true
  560. })
  561. }
  562. if (optionss && optionss.couponChannelId || optionss && optionss.orderId) {
  563. that.setData({
  564. optionsData: optionss
  565. })
  566. that.getWeapNote(optionss.couponChannelId, optionss.orderId);
  567. } else {
  568. that.getWeapNote()
  569. }
  570. //获取条形码
  571. // util.barcode("barcode", optionss.quancode, 510, 100);
  572. // console.log(Http.headers.token, "?")
  573. this.getLocation()
  574. },
  575. /**
  576. * 获得经纬度
  577. */
  578. getLocation() {
  579. let that = this;
  580. tt.getLocation({
  581. type: "wgs84",
  582. // isHighAccuracy: true,
  583. success: function (res) {
  584. console.log(res, 'getLocation')
  585. const locateData = {
  586. latitude: res.latitude,
  587. longitude: res.longitude,
  588. }
  589. that.setData({
  590. locateData: locateData
  591. })
  592. if (res && res.longitude && res.latitude) {
  593. Http.post({
  594. url: config.api.updateLBS,
  595. data: {
  596. latitude: res.latitude,
  597. longitude: res.longitude,
  598. city: res.city
  599. }
  600. }).then(res => {
  601. console.log(res, 9999)
  602. })
  603. }
  604. },
  605. fail: error => {
  606. console.log(error);
  607. },
  608. complete: finish => {
  609. const latitudeNow = that.data.locateData.latitude
  610. const longitudeNow = that.data.locateData.longitude
  611. const mallLocationArr = []
  612. let index = 0
  613. that.data.shopList.forEach(item => {
  614. const obj = {
  615. latitude: item.latitude,
  616. longitude: item.longitude,
  617. mallTenantId: item.tenantId,
  618. index: index
  619. }
  620. mallLocationArr.push(obj)
  621. index++
  622. })
  623. const isBest = []
  624. mallLocationArr.forEach(item => {
  625. const num = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude)
  626. isBest.push(num.distance_str)
  627. })
  628. console.log(isBest, 'isBest');
  629. const winer = isBest.bubbleSort()
  630. console.log(winer, 'winer');
  631. }
  632. })
  633. },
  634. /**
  635. * @description:根据经纬度计算距离
  636. * @param {*} locationInfo (lat1, lng1, lat2, lng2)
  637. * @return: distanceObj: { distance , distance_str }
  638. */
  639. getDistances(lat1, lng1, lat2, lng2) {
  640. function rad(d) {
  641. return d * Math.PI / 180.0;
  642. }
  643. var radLat1 = rad(lat1);
  644. var radLat2 = rad(lat2);
  645. var a = radLat1 - radLat2;
  646. var b = rad(lng1) - rad(lng2);
  647. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  648. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  649. s = s * 6378.137;
  650. s = Math.round(s * 10000) / 10000;
  651. var distance = s;
  652. var distance_str = "";
  653. if (parseInt(distance) >= 1) {
  654. distance_str = distance.toFixed(2) + "km";
  655. } else {
  656. distance_str = (distance * 1000).toFixed(2) + "m";
  657. }
  658. let objData = {
  659. distance: distance,
  660. distance_str: distance_str
  661. }
  662. return objData
  663. },
  664. onShow: function () {
  665. this.mallSync()
  666. console.log(app.globalData.mouldType, "mouldType")
  667. // tt.requestSubscribeMessage({
  668. // tmplIds: [], // 需要填入开放平台申请的模版id,支持最多3个同类型模版
  669. // success(res) {
  670. // //订阅成功
  671. // console.log("订阅成功", res);
  672. // },
  673. // fail(error) {
  674. // //订阅失败
  675. // console.log("订阅失败, 错误详情: ", error);
  676. // tt.showToast({
  677. // title: "订阅失败",
  678. // icon: "fail",
  679. // });
  680. // },
  681. // complete(res) {
  682. // //订阅完成
  683. // console.log("tt.requestSubscribeMessage API调用完成: ", res);
  684. // },
  685. // });
  686. this.setData({
  687. mouldType: app.globalData.mouldType,
  688. marketName: app.globalData.marketName,
  689. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  690. })
  691. // this.uesrInfo()
  692. this.ifShowSqare();
  693. if (tt.getStorageSync("squareList") && tt.getStorageSync("selectedMall")) {
  694. // var temp = tt.getStorageSync("squareList").filter(item => item.tenantId == tt.getStorageSync("selectedMall"))[0].name
  695. // this.setData({
  696. // squareName: temp
  697. // })
  698. }
  699. if (typeof this.getTabBar === 'function' &&
  700. this.getTabBar()) {
  701. this.getTabBar().setData({
  702. selected: 0,
  703. })
  704. }
  705. let that = this;
  706. that.setData({
  707. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  708. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  709. })
  710. /**
  711. * couponNum 是否有普通的优惠券购买
  712. * couponNum2 是否有新买的消费卡
  713. */
  714. let num = tt.getStorageSync('couponNum');
  715. let num1 = tt.getStorageSync('couponNum2');
  716. // if (num == 'couponNum' || num1 == 'couponNum2') {
  717. // tt.showTabBarRedDot({
  718. // index: 3
  719. // })
  720. // } else {
  721. // tt.hideTabBarRedDot({
  722. // index: 3
  723. // })
  724. // }
  725. if (app.globalData.score) {
  726. that.setData({
  727. fistLogin: app.globalData.score
  728. })
  729. }
  730. // 如果有游戏
  731. setTimeout(function () {
  732. that.alphaClick();
  733. }, 8000)
  734. // 如果有广告
  735. setTimeout(function () {
  736. that.alphaClick1();
  737. }, 8000)
  738. },
  739. getmemberId: function (token) {
  740. let that = this;
  741. Http.get({
  742. url: config.api.getScore,
  743. data: {
  744. token: token
  745. }
  746. }).then(res => {
  747. if (res.data.avatarUrl || res.data.nickName) {
  748. app.globalData.avatarUrl = res.data.avatarUrl
  749. app.globalData.nickName = res.data.nickName
  750. }
  751. that.setData({
  752. levelName: res.data.levelName,
  753. upgradePercent: res.data.upgradePercent,
  754. upgradeScore: res.data.upgradeScore,
  755. memberId: res.data.id,
  756. credit: res.data.credit,
  757. userAvatarUrl: res.data.avatarUrl ? res.data.avatarUrl : '',
  758. userName: res.data.nickName ? res.data.nickName : '',
  759. })
  760. })
  761. .catch(err => {
  762. tt.showModal({
  763. title: '提示',
  764. content: err.message,
  765. showCancel: false
  766. })
  767. })
  768. },
  769. gotoChengzhangzhi: function () {
  770. tt.navigateTo({
  771. url: '/pages/czdetail/czdetail',
  772. })
  773. },
  774. goIntegralmall() {
  775. tt.navigateTo({
  776. url: '/pages/integralmall/index',
  777. })
  778. },
  779. gotoBargain: function () {
  780. tt.navigateTo({
  781. url: '/pages/bargain/bargain',
  782. })
  783. },
  784. gotoSpellGroup: function () {
  785. tt.navigateTo({
  786. url: '/pages/spellGroup/spellGroup',
  787. })
  788. },
  789. gotoCard: function () {
  790. tt.navigateTo({
  791. url: '/pages/discountCardList/discountCardList',
  792. })
  793. },
  794. // gotoGame: function () {
  795. // tt.navigateTo({
  796. // url: '/pages/game/index',
  797. // })
  798. // },
  799. gotoJfsc: function () {
  800. tt.navigateTo({
  801. url: '/pages/integralmall/index',
  802. })
  803. },
  804. /**
  805. *
  806. * @param {code,page}
  807. * 子组件向父组件传值
  808. */
  809. onGetCode: function (e) {
  810. this.setData({
  811. code: e.detail.val,
  812. page: e.detail.pageNum,
  813. });
  814. console.log(e.detail.val)
  815. console.log(e.detail.pageNum)
  816. },
  817. getWeapNote: function (couponChannelId, couponId, orderId) {
  818. var that = this;
  819. if (app.globalData.token) {
  820. that.getsubMallList()
  821. // 登录
  822. console.log(app.globalData.token)
  823. that.getCongig() //获取小程序是否开通授权手机号
  824. that.setData({
  825. mouldType: app.globalData.mouldType,
  826. marketName: app.globalData.marketName,
  827. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  828. })
  829. //获取首页按钮 抖音暂时屏蔽
  830. // that.getModule()
  831. that.getmemberId(app.globalData.token);
  832. that.getBannerlist();
  833. // if (that.data.mouldType == 0) { //富茂原版
  834. // that.topicShow();
  835. // that.getxsList();
  836. // } else if (that.data.mouldType == 1) { //欢乐城模板
  837. // }
  838. that.getShowList()
  839. that.topicShowall(2);
  840. that.topicShowall(3);
  841. that.topicShowall(4);
  842. that.topicShowall(5);
  843. that.topicShowall(6);
  844. that.getBusinessList();
  845. that.getCouponChannelList(0)
  846. that.getsubMallList()
  847. that.getType()
  848. that.uesrInfo()
  849. // that.getLocation();
  850. that.getMallInfo(app.globalData.token);
  851. if (app.couponChannelListCallback) {
  852. app.couponChannelListCallback(app.globalData.token);
  853. }
  854. if (app.couponListCallback) {
  855. app.couponListCallback(app.globalData.token);
  856. }
  857. if (app.businessListCallback) {
  858. app.businessListCallback(app.globalData.token);
  859. }
  860. Http.get({
  861. url: config.api.getWeapNote,
  862. data: {
  863. appId: app.globalData.appId,
  864. }
  865. })
  866. .then(res => {
  867. console.log(33333333333)
  868. console.log(app.globalData.token)
  869. console.log(res)
  870. console.log(33333333333)
  871. // that.getGameOne(app.globalData.token)
  872. // that.getStaticGame(app.globalData.token)
  873. that.getGg(app.globalData.token)
  874. let weapNote = JSON.parse(res.data.weapNote);
  875. that.setData({
  876. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  877. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  878. })
  879. })
  880. .catch(err => {
  881. // that.getGameOne(app.globalData.token)
  882. // that.getStaticGame(app.globalData.token)
  883. that.getGg(app.globalData.token)
  884. tt.showModal({
  885. title: "提示",
  886. content: err.message,
  887. showCancel: false
  888. });
  889. });
  890. } else {
  891. app.tokenCallback = token => {
  892. that.getsubMallList()
  893. // 登录
  894. console.log(app.globalData.token)
  895. that.getCongig() //获取小程序是否开通授权手机号
  896. that.setData({
  897. mouldType: app.globalData.mouldType,
  898. marketName: app.globalData.marketName,
  899. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  900. })
  901. //获取首页按钮 抖音暂时屏蔽
  902. // that.getModule()
  903. that.getmemberId(app.globalData.token);
  904. that.getBannerlist();
  905. // if (that.data.mouldType == 0) { //富茂原版
  906. // that.topicShow();
  907. // that.getxsList();
  908. // } else if (that.data.mouldType == 1) { //欢乐城模板
  909. // }
  910. that.getShowList()
  911. that.topicShowall(2);
  912. that.topicShowall(3);
  913. that.topicShowall(4);
  914. that.topicShowall(5);
  915. that.topicShowall(6);
  916. that.getBusinessList();
  917. that.getCouponChannelList(0)
  918. that.getType()
  919. that.uesrInfo()
  920. // that.getLocation();
  921. that.getMallInfo(app.globalData.token);
  922. if (app.couponChannelListCallback) {
  923. app.couponChannelListCallback(app.globalData.token);
  924. }
  925. if (app.couponListCallback) {
  926. app.couponListCallback(app.globalData.token);
  927. }
  928. if (app.businessListCallback) {
  929. app.businessListCallback(app.globalData.token);
  930. }
  931. Http.get({
  932. url: config.api.getWeapNote,
  933. data: {
  934. appId: app.globalData.appId,
  935. }
  936. })
  937. .then(res => {
  938. console.log(33333333333)
  939. console.log(app.globalData.token)
  940. console.log(res)
  941. console.log(33333333333)
  942. // that.getGameOne(app.globalData.token)
  943. // that.getStaticGame(app.globalData.token)
  944. that.getGg(app.globalData.token)
  945. let weapNote = JSON.parse(res.data.weapNote);
  946. that.setData({
  947. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  948. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  949. })
  950. })
  951. .catch(err => {
  952. // that.getGameOne(app.globalData.token)
  953. // that.getStaticGame(app.globalData.token)
  954. that.getGg(app.globalData.token)
  955. tt.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. tt.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. plat: 3,
  1088. mallTenantId: tt.getStorageSync('mallTenantId') || ""
  1089. }
  1090. }).then(res => {
  1091. that.getmemberId(app.globalData.token);
  1092. // that.checkUserCarStatus();
  1093. that.setData({
  1094. list: res.data.list
  1095. });
  1096. })
  1097. .catch(err => {
  1098. that.getmemberId(app.globalData.token);
  1099. // that.checkUserCarStatus();
  1100. });
  1101. },
  1102. //获取欢乐城专题
  1103. getShowList() {
  1104. Http.get({
  1105. url: config.api.showList
  1106. }).then(res => {
  1107. let tempData = res.data
  1108. tempData.map(item1 => {
  1109. if (item1.couponList) {
  1110. item1.couponList.map(item2 => {
  1111. if (item2.salePriceStr && item2.salePriceStr.indexOf('.') != -1) {
  1112. let str = item2.salePriceStr.split('.')
  1113. item2.salePriceStrQ = str[0]
  1114. item2.salePriceStrH = str[1]
  1115. }
  1116. })
  1117. }
  1118. })
  1119. this.setData({
  1120. specialLsit: res.data ? res.data : []
  1121. })
  1122. }).catch(err => {
  1123. tt.showToast({
  1124. title: err.message ? err.message : err.data,
  1125. icon: 'none',
  1126. duration: 2000,
  1127. mask: false
  1128. });
  1129. })
  1130. },
  1131. /**
  1132. * topicType=2 限时抢购
  1133. * topicType=3 砍价
  1134. * topicType=4 拼团
  1135. * topicType=5 消费卡
  1136. * topicType=6 积分商城
  1137. */
  1138. topicShowall(topicType) {
  1139. Http.get({
  1140. url: config.api.topicShow,
  1141. data: {
  1142. topicType
  1143. }
  1144. }).then(res => {
  1145. let data = res.data
  1146. if (data.couponList != null && data.couponList.length > 0) {
  1147. data.couponList.map(item => {
  1148. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  1149. let str = item.salePriceStr.split('.')
  1150. item.salePriceStrQ = str[0]
  1151. item.salePriceStrH = str[1]
  1152. }
  1153. })
  1154. }
  1155. if (topicType == 2) {
  1156. let tempData = data
  1157. this.setData({
  1158. topicObj2: data
  1159. })
  1160. } else if (topicType == 3) {
  1161. this.setData({
  1162. topicObj3: data
  1163. })
  1164. } else if (topicType == 4) {
  1165. this.setData({
  1166. topicObj4: data
  1167. })
  1168. } else if (topicType == 5) {
  1169. this.setData({
  1170. topicObj5: data
  1171. })
  1172. } else if (topicType == 6) {
  1173. this.setData({
  1174. topicObj6: data
  1175. })
  1176. }
  1177. }).catch(err => {
  1178. tt.showToast({
  1179. title: err.message ? err.message : err.data,
  1180. icon: 'none',
  1181. duration: 2000,
  1182. mask: false
  1183. });
  1184. })
  1185. },
  1186. // 专题显示
  1187. topicShow: function () {
  1188. let that = this;
  1189. Http.get({
  1190. url: config.api.topicShow,
  1191. data: {
  1192. token: app.globalData.token
  1193. }
  1194. }).then(res => {
  1195. if (res && res.data) {
  1196. that.setData({
  1197. name: res.data.name,
  1198. cover: res.data.cover,
  1199. id: res.data.id,
  1200. showTopic: true
  1201. })
  1202. } else {
  1203. that.setData({
  1204. showTopic: false
  1205. })
  1206. }
  1207. })
  1208. .catch(err => {
  1209. console.log(err);
  1210. })
  1211. },
  1212. gotoTopic() {
  1213. tt.navigateTo({
  1214. url: `/pages/topicDetail/index?id=${this.data.id}`
  1215. })
  1216. },
  1217. /**
  1218. * 检查用户是否有车
  1219. */
  1220. // checkUserCarStatus: function() {
  1221. // var that = this;
  1222. // Http.get({
  1223. // url: config.api.userCarCount,
  1224. // data: {}
  1225. // }).then(res => {
  1226. // if (res.data > 0) {
  1227. // // 用户名下有车
  1228. // app.globalData.phone = res.data.phone;
  1229. // app.globalData.supportCar = true;
  1230. // // 共同登录
  1231. // that.userCarLogin();
  1232. // }
  1233. // });
  1234. // },
  1235. /**
  1236. * car共同登录
  1237. */
  1238. // userCarLogin: function() {
  1239. // var that = this;
  1240. // if (!app.globalData.carLogin) {
  1241. // // 共同登录
  1242. // Http.post({
  1243. // url: config.api.carInit,
  1244. // data: {
  1245. // phone: app.globalData.phone
  1246. // }
  1247. // }).then(res => {
  1248. // app.globalData.carLogin = true;
  1249. // app.globalData.parkVendor = res.data.vendor;
  1250. // if (res.data.token != "undefined") {
  1251. // app.globalData.etcpToken = res.data.token;
  1252. // }
  1253. // });
  1254. // }
  1255. // },
  1256. /**
  1257. * 获取用户信息
  1258. */
  1259. // getUserInfo: function() {
  1260. // // 获取用户信息
  1261. // tt.getSetting({
  1262. // success: res => {
  1263. // if (res.authSetting["scope.userInfo"]) {
  1264. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  1265. // tt.getUserInfo({
  1266. // success: res => {
  1267. // // 可以将 res 发送给后台解码出 unionId
  1268. // }
  1269. // });
  1270. // }
  1271. // }
  1272. // });
  1273. // },
  1274. gotoBargain: function () {
  1275. tt.navigateTo({
  1276. url: '/pages/bargain/bargain'
  1277. })
  1278. },
  1279. //限时抢购的详情页面
  1280. gotodetail: function (e) {
  1281. tt.navigateTo({
  1282. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.couponchannelid
  1283. }&couponId=${e.currentTarget.dataset.couponid}`
  1284. });
  1285. },
  1286. //浮层广告
  1287. getGg: function (token) {
  1288. let that = this
  1289. Http.get({
  1290. url: config.api.getGg,
  1291. data: {
  1292. token: token,
  1293. appId: app.globalData.appId,
  1294. openId: "" // tt.getStorageSync('openId')
  1295. }
  1296. }).then(res => {
  1297. console.log(res)
  1298. if (res.data.id) {
  1299. that.setData({
  1300. showGg: true,
  1301. })
  1302. console.log(that.data.showGg, 1111111111111)
  1303. } else {
  1304. that.setData({
  1305. showGg: false
  1306. })
  1307. // that.getGameOne(app.globalData.token)
  1308. console.log(that.data.showGg, 222222222222222222)
  1309. }
  1310. that.setData({
  1311. ggdata: res.data
  1312. })
  1313. })
  1314. .catch(err => {
  1315. this.setData({
  1316. showGg: false
  1317. })
  1318. // that.getGameOne(app.globalData.token)
  1319. that.alphaClick1();
  1320. })
  1321. },
  1322. /**
  1323. * 刷新
  1324. */
  1325. onPullDownRefresh: function (e) {
  1326. tt.showLoading({
  1327. title: "加载中..."
  1328. });
  1329. let that = this;
  1330. that.setData({
  1331. topicObj2: null, //欢乐城首页限时抢购
  1332. topicObj3: null, //欢乐城首页砍价
  1333. topicObj4: null, //欢乐城首页拼团
  1334. topicObj5: null, //欢乐城首页消费卡
  1335. topicObj6: null, //欢乐城首页积分商城
  1336. specialLsit: null, //专题
  1337. })
  1338. // that.getWeapNote();
  1339. that.setData({
  1340. page: 1
  1341. })
  1342. if (that.data.optionsData != null && (that.data.optionsData.couponChannelId || that.data.optionsData.orderId)) {
  1343. that.getWeapNote(that.data.optionsData.couponChannelId, that.data.optionsData.orderId);
  1344. } else {
  1345. that.getWeapNote()
  1346. }
  1347. if (that.selectComponent("#lists")) {
  1348. if (that.data.code == 0 || that.data.code == undefined) {
  1349. that.selectComponent("#lists").getList(0, 1, "refresh");
  1350. tt.stopPullDownRefresh();
  1351. } else {
  1352. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  1353. tt.stopPullDownRefresh();
  1354. };
  1355. that.selectComponent("#hot").getList();
  1356. }
  1357. // 砍价下拉刷新
  1358. // that.selectComponent("#bargain").getList();
  1359. // that.selectComponent("#spellGroup").getList();
  1360. // that.selectComponent("#rushtobyCard").getList();
  1361. //爆款专区下拉刷新
  1362. that.getxsList();
  1363. that.topicShow();
  1364. setTimeout(function () {
  1365. tt.hideLoading();
  1366. tt.stopPullDownRefresh();
  1367. }, 1600);
  1368. },
  1369. //加载更多
  1370. onReachBottom: function () {
  1371. console.log("我到底了")
  1372. let that = this;
  1373. that.data.page++;
  1374. that.setData({
  1375. page: that.data.page,
  1376. businePageNum: that.data.businePageNum + 1
  1377. });
  1378. console.log("加载更多页数" + that.data.page, );
  1379. console.log("加载更多key" + that.data.code);
  1380. // if (that.data.mouldType == 0) { //富茂源模板
  1381. // //父组件获得子组件的方法
  1382. // //如果code == 0
  1383. // if (that.data.code == 0 || that.data.code == undefined) {
  1384. // that.selectComponent("#lists").getList(0, that.data.page);
  1385. // } else {
  1386. // that.selectComponent("#lists").getList(that.data.code, that.data.page);
  1387. // }
  1388. // } else if (that.data.mouldType == 1) {
  1389. // }
  1390. this.getCouponChannelList(that.data.busineKye)
  1391. },
  1392. // 用户点击右上角分享
  1393. onShareAppMessage: function () {
  1394. app.globalData.previewFlag = true
  1395. return {
  1396. path: "/pages/index/index",
  1397. title: this.data.weappShareTitle,
  1398. imageUrl: this.data.weappShareCoverImg,
  1399. success: function (res) {
  1400. tt.showToast({
  1401. title: "分享成功",
  1402. duration: 1000,
  1403. icon: "success"
  1404. });
  1405. }
  1406. };
  1407. }
  1408. });
  1409. Array.prototype.bubbleSort = function () {
  1410. for (let i = 0; i < this.length - 1; i += 1) {
  1411. for (let j = 0; j < this.length - 1 - i; j += 1) {
  1412. if (this[j] > this[j + 1]) {
  1413. const temp = this[j];
  1414. this[j] = this[j + 1];
  1415. this[j + 1] = temp;
  1416. }
  1417. }
  1418. }
  1419. }