抖音c端

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