抖音c端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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