抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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