抖音c端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1494 lines
39 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)
  627. })
  628. console.log(isBest, 'isBest');
  629. const winer = this.bloob(isBest)
  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(num) {
  641. return num * 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. bloob(arr) {
  665. const tempArr = arr
  666. for (let i = 0; i < tempArr.length - 1; i++) {
  667. for (let j = 0; j < tempArr.length - 1 - i; j++) {
  668. if (tempArr[j] > tempArr[j + 1]) {
  669. let temp = tempArr[j];
  670. tempArr[j] = tempArr[j + 1];
  671. tempArr[j + 1] = temp;
  672. }
  673. }
  674. }
  675. return tempArr
  676. },
  677. onShow: function () {
  678. this.mallSync()
  679. console.log(app.globalData.mouldType, "mouldType")
  680. // tt.requestSubscribeMessage({
  681. // tmplIds: [], // 需要填入开放平台申请的模版id,支持最多3个同类型模版
  682. // success(res) {
  683. // //订阅成功
  684. // console.log("订阅成功", res);
  685. // },
  686. // fail(error) {
  687. // //订阅失败
  688. // console.log("订阅失败, 错误详情: ", error);
  689. // tt.showToast({
  690. // title: "订阅失败",
  691. // icon: "fail",
  692. // });
  693. // },
  694. // complete(res) {
  695. // //订阅完成
  696. // console.log("tt.requestSubscribeMessage API调用完成: ", res);
  697. // },
  698. // });
  699. this.setData({
  700. mouldType: app.globalData.mouldType,
  701. marketName: app.globalData.marketName,
  702. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  703. })
  704. // this.uesrInfo()
  705. this.ifShowSqare();
  706. if (tt.getStorageSync("squareList") && tt.getStorageSync("selectedMall")) {
  707. // var temp = tt.getStorageSync("squareList").filter(item => item.tenantId == tt.getStorageSync("selectedMall"))[0].name
  708. // this.setData({
  709. // squareName: temp
  710. // })
  711. }
  712. if (typeof this.getTabBar === 'function' &&
  713. this.getTabBar()) {
  714. this.getTabBar().setData({
  715. selected: 0,
  716. })
  717. }
  718. let that = this;
  719. that.setData({
  720. havePlayEd: app.globalData.havePlayEd ? app.globalData.havePlayEd : false,
  721. havePlayEd1: app.globalData.havePlayEd1 ? app.globalData.havePlayEd1 : false
  722. })
  723. /**
  724. * couponNum 是否有普通的优惠券购买
  725. * couponNum2 是否有新买的消费卡
  726. */
  727. let num = tt.getStorageSync('couponNum');
  728. let num1 = tt.getStorageSync('couponNum2');
  729. // if (num == 'couponNum' || num1 == 'couponNum2') {
  730. // tt.showTabBarRedDot({
  731. // index: 3
  732. // })
  733. // } else {
  734. // tt.hideTabBarRedDot({
  735. // index: 3
  736. // })
  737. // }
  738. if (app.globalData.score) {
  739. that.setData({
  740. fistLogin: app.globalData.score
  741. })
  742. }
  743. // 如果有游戏
  744. setTimeout(function () {
  745. that.alphaClick();
  746. }, 8000)
  747. // 如果有广告
  748. setTimeout(function () {
  749. that.alphaClick1();
  750. }, 8000)
  751. },
  752. getmemberId: function (token) {
  753. let that = this;
  754. Http.get({
  755. url: config.api.getScore,
  756. data: {
  757. token: token
  758. }
  759. }).then(res => {
  760. if (res.data.avatarUrl || res.data.nickName) {
  761. app.globalData.avatarUrl = res.data.avatarUrl
  762. app.globalData.nickName = res.data.nickName
  763. }
  764. that.setData({
  765. levelName: res.data.levelName,
  766. upgradePercent: res.data.upgradePercent,
  767. upgradeScore: res.data.upgradeScore,
  768. memberId: res.data.id,
  769. credit: res.data.credit,
  770. userAvatarUrl: res.data.avatarUrl ? res.data.avatarUrl : '',
  771. userName: res.data.nickName ? res.data.nickName : '',
  772. })
  773. })
  774. .catch(err => {
  775. tt.showModal({
  776. title: '提示',
  777. content: err.message,
  778. showCancel: false
  779. })
  780. })
  781. },
  782. gotoChengzhangzhi: function () {
  783. tt.navigateTo({
  784. url: '/pages/czdetail/czdetail',
  785. })
  786. },
  787. goIntegralmall() {
  788. tt.navigateTo({
  789. url: '/pages/integralmall/index',
  790. })
  791. },
  792. gotoBargain: function () {
  793. tt.navigateTo({
  794. url: '/pages/bargain/bargain',
  795. })
  796. },
  797. gotoSpellGroup: function () {
  798. tt.navigateTo({
  799. url: '/pages/spellGroup/spellGroup',
  800. })
  801. },
  802. gotoCard: function () {
  803. tt.navigateTo({
  804. url: '/pages/discountCardList/discountCardList',
  805. })
  806. },
  807. // gotoGame: function () {
  808. // tt.navigateTo({
  809. // url: '/pages/game/index',
  810. // })
  811. // },
  812. gotoJfsc: function () {
  813. tt.navigateTo({
  814. url: '/pages/integralmall/index',
  815. })
  816. },
  817. /**
  818. *
  819. * @param {code,page}
  820. * 子组件向父组件传值
  821. */
  822. onGetCode: function (e) {
  823. this.setData({
  824. code: e.detail.val,
  825. page: e.detail.pageNum,
  826. });
  827. console.log(e.detail.val)
  828. console.log(e.detail.pageNum)
  829. },
  830. getWeapNote: function (couponChannelId, couponId, orderId) {
  831. var that = this;
  832. if (app.globalData.token) {
  833. that.getsubMallList()
  834. // 登录
  835. console.log(app.globalData.token)
  836. that.getCongig() //获取小程序是否开通授权手机号
  837. that.setData({
  838. mouldType: app.globalData.mouldType,
  839. marketName: app.globalData.marketName,
  840. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  841. })
  842. //获取首页按钮 抖音暂时屏蔽
  843. // that.getModule()
  844. that.getmemberId(app.globalData.token);
  845. that.getBannerlist();
  846. // if (that.data.mouldType == 0) { //富茂原版
  847. // that.topicShow();
  848. // that.getxsList();
  849. // } else if (that.data.mouldType == 1) { //欢乐城模板
  850. // }
  851. that.getShowList()
  852. that.topicShowall(2);
  853. that.topicShowall(3);
  854. that.topicShowall(4);
  855. that.topicShowall(5);
  856. that.topicShowall(6);
  857. that.getBusinessList();
  858. that.getCouponChannelList(0)
  859. that.getsubMallList()
  860. that.getType()
  861. that.uesrInfo()
  862. // that.getLocation();
  863. that.getMallInfo(app.globalData.token);
  864. if (app.couponChannelListCallback) {
  865. app.couponChannelListCallback(app.globalData.token);
  866. }
  867. if (app.couponListCallback) {
  868. app.couponListCallback(app.globalData.token);
  869. }
  870. if (app.businessListCallback) {
  871. app.businessListCallback(app.globalData.token);
  872. }
  873. Http.get({
  874. url: config.api.getWeapNote,
  875. data: {
  876. appId: app.globalData.appId,
  877. }
  878. })
  879. .then(res => {
  880. console.log(33333333333)
  881. console.log(app.globalData.token)
  882. console.log(res)
  883. console.log(33333333333)
  884. // that.getGameOne(app.globalData.token)
  885. // that.getStaticGame(app.globalData.token)
  886. that.getGg(app.globalData.token)
  887. let weapNote = JSON.parse(res.data.weapNote);
  888. that.setData({
  889. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  890. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  891. })
  892. })
  893. .catch(err => {
  894. // that.getGameOne(app.globalData.token)
  895. // that.getStaticGame(app.globalData.token)
  896. that.getGg(app.globalData.token)
  897. tt.showModal({
  898. title: "提示",
  899. content: err.message,
  900. showCancel: false
  901. });
  902. });
  903. } else {
  904. app.tokenCallback = token => {
  905. that.getsubMallList()
  906. // 登录
  907. console.log(app.globalData.token)
  908. that.getCongig() //获取小程序是否开通授权手机号
  909. that.setData({
  910. mouldType: app.globalData.mouldType,
  911. marketName: app.globalData.marketName,
  912. activeColor: app.globalData.mouldType == 1 ? "#E9D0AA" : bgColor.colorFirst.main.activeColor
  913. })
  914. //获取首页按钮 抖音暂时屏蔽
  915. // that.getModule()
  916. that.getmemberId(app.globalData.token);
  917. that.getBannerlist();
  918. // if (that.data.mouldType == 0) { //富茂原版
  919. // that.topicShow();
  920. // that.getxsList();
  921. // } else if (that.data.mouldType == 1) { //欢乐城模板
  922. // }
  923. that.getShowList()
  924. that.topicShowall(2);
  925. that.topicShowall(3);
  926. that.topicShowall(4);
  927. that.topicShowall(5);
  928. that.topicShowall(6);
  929. that.getBusinessList();
  930. that.getCouponChannelList(0)
  931. that.getType()
  932. that.uesrInfo()
  933. // that.getLocation();
  934. that.getMallInfo(app.globalData.token);
  935. if (app.couponChannelListCallback) {
  936. app.couponChannelListCallback(app.globalData.token);
  937. }
  938. if (app.couponListCallback) {
  939. app.couponListCallback(app.globalData.token);
  940. }
  941. if (app.businessListCallback) {
  942. app.businessListCallback(app.globalData.token);
  943. }
  944. Http.get({
  945. url: config.api.getWeapNote,
  946. data: {
  947. appId: app.globalData.appId,
  948. }
  949. })
  950. .then(res => {
  951. console.log(33333333333)
  952. console.log(app.globalData.token)
  953. console.log(res)
  954. console.log(33333333333)
  955. // that.getGameOne(app.globalData.token)
  956. // that.getStaticGame(app.globalData.token)
  957. that.getGg(app.globalData.token)
  958. let weapNote = JSON.parse(res.data.weapNote);
  959. that.setData({
  960. // desc: weapNote.firstpage.desc?weapNote.firstpage.desc:"",
  961. // title: weapNote.firstpage.title?weapNote.firstpage.title:'',
  962. })
  963. })
  964. .catch(err => {
  965. // that.getGameOne(app.globalData.token)
  966. // that.getStaticGame(app.globalData.token)
  967. that.getGg(app.globalData.token)
  968. tt.showModal({
  969. title: "提示",
  970. content: err.message,
  971. showCancel: false
  972. });
  973. });
  974. }
  975. }
  976. },
  977. getStaticGame(token) {
  978. let _this = this;
  979. Http.get({
  980. url: config.api.getGame,
  981. data: {
  982. triggleAction: 2, // 固定入口
  983. token: token
  984. }
  985. }).then(res => {
  986. if (res.data.id) {
  987. _this.setData({
  988. showIf: true,
  989. newUrl: res.data.imgUrl
  990. })
  991. } else {
  992. _this.setData({
  993. showIf: false
  994. })
  995. }
  996. _this.setData({
  997. staticGamedata: res.data
  998. })
  999. })
  1000. .catch(err => {
  1001. _this.setData({
  1002. showIf: false
  1003. })
  1004. console.log(err)
  1005. })
  1006. },
  1007. getGameOne: function (token) {
  1008. let _this = this;
  1009. Http.get({
  1010. url: config.api.getGame,
  1011. data: {
  1012. triggleAction: 1, // 登录触发
  1013. token: token
  1014. }
  1015. }).then(res => {
  1016. if (res.data.id) {
  1017. _this.setData({
  1018. showGame: true,
  1019. })
  1020. } else {
  1021. _this.setData({
  1022. showGame: false
  1023. })
  1024. }
  1025. _this.setData({
  1026. gamedata: res.data
  1027. })
  1028. })
  1029. .catch(err => {
  1030. _this.setData({
  1031. showGame: false
  1032. })
  1033. this.alphaClick();
  1034. })
  1035. },
  1036. /**
  1037. * mallinfo
  1038. */
  1039. getMallInfo: function (token) {
  1040. let that = this;
  1041. Http.get({
  1042. url: config.api.getMallInfo,
  1043. data: {
  1044. token: token,
  1045. }
  1046. }).then(res => {
  1047. that.setData({
  1048. liveFlag: res.data.liveSupport,
  1049. weappShareTitle: res.data.weappShareTitle ? res.data.weappShareTitle : null,
  1050. weappShareCoverImg: res.data.weappShareCoverImg ? res.data.weappShareCoverImg : null,
  1051. });
  1052. console.log(that.data.liveFlag, "||||")
  1053. })
  1054. .catch(err => {
  1055. // 不需要错误提示
  1056. });
  1057. },
  1058. //获取限时抢购列表
  1059. getxsList() {
  1060. let that = this;
  1061. Http.get({
  1062. url: config.api.couponChannelList,
  1063. data: {
  1064. pageNum: 1,
  1065. pageSize: 3,
  1066. targetAd: 2
  1067. }
  1068. }).then(res => {
  1069. if (res && res.data.total > 0) {
  1070. that.setData({
  1071. xslist: res.data.list,
  1072. showQg: true
  1073. });
  1074. } else {
  1075. that.setData({
  1076. showQg: false
  1077. })
  1078. }
  1079. })
  1080. .catch(err => {
  1081. console.log(err)
  1082. tt.showToast({
  1083. title: err.message,
  1084. icon: 'none',
  1085. duration: 2000,
  1086. mask: false
  1087. });
  1088. })
  1089. },
  1090. /**
  1091. * banner
  1092. */
  1093. getBannerlist: function () {
  1094. let that = this;
  1095. Http.get({
  1096. url: config.api.bannerlist,
  1097. data: {
  1098. pageNum: 1,
  1099. pageSize: 7,
  1100. plat: 3,
  1101. mallTenantId: tt.getStorageSync('mallTenantId') || ""
  1102. }
  1103. }).then(res => {
  1104. that.getmemberId(app.globalData.token);
  1105. // that.checkUserCarStatus();
  1106. that.setData({
  1107. list: res.data.list
  1108. });
  1109. })
  1110. .catch(err => {
  1111. that.getmemberId(app.globalData.token);
  1112. // that.checkUserCarStatus();
  1113. });
  1114. },
  1115. //获取欢乐城专题
  1116. getShowList() {
  1117. Http.get({
  1118. url: config.api.showList
  1119. }).then(res => {
  1120. let tempData = res.data
  1121. tempData.map(item1 => {
  1122. if (item1.couponList) {
  1123. item1.couponList.map(item2 => {
  1124. if (item2.salePriceStr && item2.salePriceStr.indexOf('.') != -1) {
  1125. let str = item2.salePriceStr.split('.')
  1126. item2.salePriceStrQ = str[0]
  1127. item2.salePriceStrH = str[1]
  1128. }
  1129. })
  1130. }
  1131. })
  1132. this.setData({
  1133. specialLsit: res.data ? res.data : []
  1134. })
  1135. }).catch(err => {
  1136. tt.showToast({
  1137. title: err.message ? err.message : err.data,
  1138. icon: 'none',
  1139. duration: 2000,
  1140. mask: false
  1141. });
  1142. })
  1143. },
  1144. /**
  1145. * topicType=2 限时抢购
  1146. * topicType=3 砍价
  1147. * topicType=4 拼团
  1148. * topicType=5 消费卡
  1149. * topicType=6 积分商城
  1150. */
  1151. topicShowall(topicType) {
  1152. Http.get({
  1153. url: config.api.topicShow,
  1154. data: {
  1155. topicType
  1156. }
  1157. }).then(res => {
  1158. let data = res.data
  1159. if (data.couponList != null && data.couponList.length > 0) {
  1160. data.couponList.map(item => {
  1161. if (item.salePriceStr && item.salePriceStr.indexOf('.') != -1) {
  1162. let str = item.salePriceStr.split('.')
  1163. item.salePriceStrQ = str[0]
  1164. item.salePriceStrH = str[1]
  1165. }
  1166. })
  1167. }
  1168. if (topicType == 2) {
  1169. let tempData = data
  1170. this.setData({
  1171. topicObj2: data
  1172. })
  1173. } else if (topicType == 3) {
  1174. this.setData({
  1175. topicObj3: data
  1176. })
  1177. } else if (topicType == 4) {
  1178. this.setData({
  1179. topicObj4: data
  1180. })
  1181. } else if (topicType == 5) {
  1182. this.setData({
  1183. topicObj5: data
  1184. })
  1185. } else if (topicType == 6) {
  1186. this.setData({
  1187. topicObj6: data
  1188. })
  1189. }
  1190. }).catch(err => {
  1191. tt.showToast({
  1192. title: err.message ? err.message : err.data,
  1193. icon: 'none',
  1194. duration: 2000,
  1195. mask: false
  1196. });
  1197. })
  1198. },
  1199. // 专题显示
  1200. topicShow: function () {
  1201. let that = this;
  1202. Http.get({
  1203. url: config.api.topicShow,
  1204. data: {
  1205. token: app.globalData.token
  1206. }
  1207. }).then(res => {
  1208. if (res && res.data) {
  1209. that.setData({
  1210. name: res.data.name,
  1211. cover: res.data.cover,
  1212. id: res.data.id,
  1213. showTopic: true
  1214. })
  1215. } else {
  1216. that.setData({
  1217. showTopic: false
  1218. })
  1219. }
  1220. })
  1221. .catch(err => {
  1222. console.log(err);
  1223. })
  1224. },
  1225. gotoTopic() {
  1226. tt.navigateTo({
  1227. url: `/pages/topicDetail/index?id=${this.data.id}`
  1228. })
  1229. },
  1230. /**
  1231. * 检查用户是否有车
  1232. */
  1233. // checkUserCarStatus: function() {
  1234. // var that = this;
  1235. // Http.get({
  1236. // url: config.api.userCarCount,
  1237. // data: {}
  1238. // }).then(res => {
  1239. // if (res.data > 0) {
  1240. // // 用户名下有车
  1241. // app.globalData.phone = res.data.phone;
  1242. // app.globalData.supportCar = true;
  1243. // // 共同登录
  1244. // that.userCarLogin();
  1245. // }
  1246. // });
  1247. // },
  1248. /**
  1249. * car共同登录
  1250. */
  1251. // userCarLogin: function() {
  1252. // var that = this;
  1253. // if (!app.globalData.carLogin) {
  1254. // // 共同登录
  1255. // Http.post({
  1256. // url: config.api.carInit,
  1257. // data: {
  1258. // phone: app.globalData.phone
  1259. // }
  1260. // }).then(res => {
  1261. // app.globalData.carLogin = true;
  1262. // app.globalData.parkVendor = res.data.vendor;
  1263. // if (res.data.token != "undefined") {
  1264. // app.globalData.etcpToken = res.data.token;
  1265. // }
  1266. // });
  1267. // }
  1268. // },
  1269. /**
  1270. * 获取用户信息
  1271. */
  1272. // getUserInfo: function() {
  1273. // // 获取用户信息
  1274. // tt.getSetting({
  1275. // success: res => {
  1276. // if (res.authSetting["scope.userInfo"]) {
  1277. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  1278. // tt.getUserInfo({
  1279. // success: res => {
  1280. // // 可以将 res 发送给后台解码出 unionId
  1281. // }
  1282. // });
  1283. // }
  1284. // }
  1285. // });
  1286. // },
  1287. gotoBargain: function () {
  1288. tt.navigateTo({
  1289. url: '/pages/bargain/bargain'
  1290. })
  1291. },
  1292. //限时抢购的详情页面
  1293. gotodetail: function (e) {
  1294. tt.navigateTo({
  1295. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.couponchannelid
  1296. }&couponId=${e.currentTarget.dataset.couponid}`
  1297. });
  1298. },
  1299. //浮层广告
  1300. getGg: function (token) {
  1301. let that = this
  1302. Http.get({
  1303. url: config.api.getGg,
  1304. data: {
  1305. token: token,
  1306. appId: app.globalData.appId,
  1307. openId: "" // tt.getStorageSync('openId')
  1308. }
  1309. }).then(res => {
  1310. console.log(res)
  1311. if (res.data.id) {
  1312. that.setData({
  1313. showGg: true,
  1314. })
  1315. console.log(that.data.showGg, 1111111111111)
  1316. } else {
  1317. that.setData({
  1318. showGg: false
  1319. })
  1320. // that.getGameOne(app.globalData.token)
  1321. console.log(that.data.showGg, 222222222222222222)
  1322. }
  1323. that.setData({
  1324. ggdata: res.data
  1325. })
  1326. })
  1327. .catch(err => {
  1328. this.setData({
  1329. showGg: false
  1330. })
  1331. // that.getGameOne(app.globalData.token)
  1332. that.alphaClick1();
  1333. })
  1334. },
  1335. /**
  1336. * 刷新
  1337. */
  1338. onPullDownRefresh: function (e) {
  1339. tt.showLoading({
  1340. title: "加载中..."
  1341. });
  1342. let that = this;
  1343. that.setData({
  1344. topicObj2: null, //欢乐城首页限时抢购
  1345. topicObj3: null, //欢乐城首页砍价
  1346. topicObj4: null, //欢乐城首页拼团
  1347. topicObj5: null, //欢乐城首页消费卡
  1348. topicObj6: null, //欢乐城首页积分商城
  1349. specialLsit: null, //专题
  1350. })
  1351. // that.getWeapNote();
  1352. that.setData({
  1353. page: 1
  1354. })
  1355. if (that.data.optionsData != null && (that.data.optionsData.couponChannelId || that.data.optionsData.orderId)) {
  1356. that.getWeapNote(that.data.optionsData.couponChannelId, that.data.optionsData.orderId);
  1357. } else {
  1358. that.getWeapNote()
  1359. }
  1360. if (that.selectComponent("#lists")) {
  1361. if (that.data.code == 0 || that.data.code == undefined) {
  1362. that.selectComponent("#lists").getList(0, 1, "refresh");
  1363. tt.stopPullDownRefresh();
  1364. } else {
  1365. that.selectComponent("#lists").getList(that.data.code, 1, "refresh");
  1366. tt.stopPullDownRefresh();
  1367. };
  1368. that.selectComponent("#hot").getList();
  1369. }
  1370. // 砍价下拉刷新
  1371. // that.selectComponent("#bargain").getList();
  1372. // that.selectComponent("#spellGroup").getList();
  1373. // that.selectComponent("#rushtobyCard").getList();
  1374. //爆款专区下拉刷新
  1375. that.getxsList();
  1376. that.topicShow();
  1377. setTimeout(function () {
  1378. tt.hideLoading();
  1379. tt.stopPullDownRefresh();
  1380. }, 1600);
  1381. },
  1382. //加载更多
  1383. onReachBottom: function () {
  1384. console.log("我到底了")
  1385. let that = this;
  1386. that.data.page++;
  1387. that.setData({
  1388. page: that.data.page,
  1389. businePageNum: that.data.businePageNum + 1
  1390. });
  1391. console.log("加载更多页数" + that.data.page, );
  1392. console.log("加载更多key" + that.data.code);
  1393. // if (that.data.mouldType == 0) { //富茂源模板
  1394. // //父组件获得子组件的方法
  1395. // //如果code == 0
  1396. // if (that.data.code == 0 || that.data.code == undefined) {
  1397. // that.selectComponent("#lists").getList(0, that.data.page);
  1398. // } else {
  1399. // that.selectComponent("#lists").getList(that.data.code, that.data.page);
  1400. // }
  1401. // } else if (that.data.mouldType == 1) {
  1402. // }
  1403. this.getCouponChannelList(that.data.busineKye)
  1404. },
  1405. // 用户点击右上角分享
  1406. onShareAppMessage: function () {
  1407. app.globalData.previewFlag = true
  1408. return {
  1409. path: "/pages/index/index",
  1410. title: this.data.weappShareTitle,
  1411. imageUrl: this.data.weappShareCoverImg,
  1412. success: function (res) {
  1413. tt.showToast({
  1414. title: "分享成功",
  1415. duration: 1000,
  1416. icon: "success"
  1417. });
  1418. }
  1419. };
  1420. }
  1421. });
  1422. Array.prototype.bubbleSort = function () {
  1423. for (let i = 0; i < this.length - 1; i += 1) {
  1424. for (let j = 0; j < this.length - 1 - i; j += 1) {
  1425. if (this[j] > this[j + 1]) {
  1426. const temp = this[j];
  1427. this[j] = this[j + 1];
  1428. this[j + 1] = temp;
  1429. }
  1430. }
  1431. }
  1432. }