抖音c端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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