抖音c端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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