抖音小程序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.

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