<template>
<view class="home-page">
  <view class="top-bg-box" @tap="toGuidePage">
    <image src="https://download.cyjyyjy.com/index-top-bg2.png"></image>
  </view>

  <!-- <view class="page-top-box">
    <image src="../../images/home/top-bg.png" class="top-bg"></image>
    <view class="page-title" style="top:{{menuTop}}px;height:{{menuHeight}}px;line-height: {{menuHeight}}px;">禅意云生态</view>
    <view class="top-box-content" style="top: {{CustomBar + menuHeight}}rpx;">
      <view class="search-box acea-row row-between-wrapper">
        <view class="localtion-box acea-row row-middle">
          <image src="../../images/home/localtion.png"></image>
          <text>{{city}}</text>
        </view>
        <view class="search acea-row row-middle">
          <image src="../../images/home/search.png"></image>
          <text>大家都在搜 APP开发</text>
        </view>
        <image class="message-icon" src="../../images/home/message.png"></image>
      </view>
      <view class="home-menu-box">
        <view class="menu-list acea-row row-between">
          <view class="menu-item acea-row row-column row-middle" wx:for="{{menuList}}" wx:key="index">
            <image src="{{item.icon}}"></image>
            <text>{{item.text}}</text>
          </view>
        </view>
      </view>
    </view>
  </view> -->
  <!-- 招商会 -->
  <view class="investment-box">
    <view class="investment-title-box acea-row row-between-wrapper">
      <view class="acea-row">
        <text class="fz32">热门活动</text>
        <view class="hot">热</view>
      </view>
      <!-- <view class="more acea-row row-middle">
        <text>全部</text>
        <image src="/static/images/home/arrow-r.png"></image>
      </view> -->
    </view>
    <view class="investement-list">
      <scroll-view class="scroll-view_H" scroll-x="true">
        <view v-for="(item, index) in recommendActivity" v-if="index < 3" :key="index" class="investment-item" @tap="toActiveDetail" :data-id="item.id">
          <image class="item-bg" :src="item.images" mode="aspectFill"></image>
          <view class="tips-box acea-row row-right">
            <view v-for="(flag, index2) in spl.spl(item.flag)" :key="index2" :class="'tips-item ' + (index2%2 == 0 ? 'bg2' : '' )" v-if="index2 < 3">{{flag}}</view>
          </view>
          <view class="item-info-box acea-row row-column row-center">
            <view class="address-box line1">
              <image src="/static/images/home/localtion.png"></image>
              <text>{{item.address}}</text>
            </view>
            <view class="time-box">
              <image src="/static/images/home/time.png"></image>
              <text>{{item.activityStartTime}}</text>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
  <!-- 尊享福利 -->
  <!-- <view class="welfare-box">
    <view class="welfare-title">尊享福利</view>
    <view class="welfare-list-box">
      <scroll-view class="scroll-view_H" scroll-x="true">
        <view class="welfare-item" wx:for="{{3}}" wx:key="index">
          <view class="item-box acea-row">
            <image src="../../images/home/welfare1.png"></image>
            <view class="welfare-info-box acea-row row-column row-between">
              <view>
                <view class="w-name">保时捷Porsche-Panamera 4S E-Hybrid 行政加长版</view>
                <view class="w-address">武汉光谷保时捷中心</view>
              </view>
              <view>
                <view class="w-price">140万</view>
                <view class="w-oldPrice">市场价约为￥157万</view>
              </view>
            </view>
            <view class="buy-btn">立即抢购</view>
          </view>
          <view class="item-box acea-row">
            <image src="../../images/home/welfare1.png"></image>
            <view class="welfare-info-box acea-row row-column row-between">
              <view>
                <view class="w-name">保时捷Porsche-Panamera 4S E-Hybrid 行政加长版</view>
                <view class="w-address">武汉光谷保时捷中心</view>
              </view>
              <view>
                <view class="w-price">140万</view>
                <view class="w-oldPrice">市场价约为￥157万</view>
              </view>
            </view>
            <view class="buy-btn">立即抢购</view>
          </view>
      data-i  </view>
      </scroll-view>
    </view>
  </view> -->
  <!-- 供需模块 -->
  <view class="demandhall-box">
    <view class="tabs-box acea-row row-around">
      <view :class="'tab-item ' + (active == 1 ? 'tab-item-a' : '')" data-i="1" @tap="tabClick">最新供应</view>
      <view :class="'tab-item ' + (active == 2 ? 'tab-item-a' : '')" data-i="2" @tap="tabClick">需求广场</view>
      <!-- <view class="tab-item {{active == 3 ? 'tab-item-a' : ''}}" data-i="3" bindtap="tabClick">金牌投资人</view> -->
    </view>
    <view class="list-box" v-if="active == 1">
      <view v-for="(item, index) in resourcesList" :key="index" class="item">
        <view class="item-top">
          <view class="project-name line1">{{item.title}}</view>
          <view class="tag">{{item.cname}}</view>
          <view class="desc line2">{{item.detailedDescription}}</view>
          <view class="buy-btn" @tap="toResourcesDetail" :data-id="item.id">了解详情</view>
        </view>
        <view class="company-box acea-row">
          <image :src="item.enterpriseDto.enterpriseLogo" class="logo"></image>
          <view class="company-info acea-row row-column row-between">
            <view class="company-name line1 fz28">{{item.enterpriseDto.enterpriseName}}</view>
            <view class="company-name line2 fz24">{{item.enterpriseDto.enterpriseTitle}}</view>
            <view class="tags-box acea-row">
              <!-- <view class="tag-item fz20">网站建设</view> -->
              <view class="tag-item fz20 bgG">{{item.cname}}</view>
              <!-- <view class="tag-item fz20 bgO">网站建设</view> -->
            </view>
          </view>
          <view class="into-btn acea-row row-center-wrapper" @tap="toCompanyDetail" :data-id="item.enterpriseId">
            <image src="/static/images/home/company-icon.png"></image>
            <text>进入企业</text>
          </view>
        </view>
      </view>
    </view>
    <view class="list-box" v-if="active == 2">
      <view v-for="(item, index) in demandList" :key="index" class="item" @tap="toNeedDetail" :data-id="item.id">
        <view class="item-top">
          <view class="project-name">{{item.title}}</view>
          <view class="desc line2">{{item.detailedDescription}}</view>
          <view class="tags-box tags-box2 acea-row">
              <view class="tag-item fz20">{{item.enterpriseDto.cname}}</view>
              <!-- <view class="tag-item fz20 bgG">网站建设</view>
              <view class="tag-item fz20 bgO">网站建设</view> -->
            </view>
          <view class="price">{{item.capital}}</view>
       </view>
      </view>
    </view>
  </view>
  <view class="to-demandhall acea-row row-center row-middle" @tap="toTab2">
    <text>更多内容去供需大厅</text>
    <image src="/static/images/home/arrow-r.png"></image>
  </view>
  <tabbar :current="currentTabIndex" @click="tabBarClick"></tabbar>
</view>
</template>

<script module="spl" lang="wxs" src="../../utils/subutil.wxs"></script>

<script>
// index.js
// 获取应用实例
const app = getApp();
import util from '../../utils/util';
var QQMapWX = require("../../utils/qqmap-wx-jssdk.min.js");
var qqmapsdk;
import tabbar from "../../tabbarComponent/tabbar";

export default {
  data() {
    return {
      menuList: [
				{
					icon: "/static/images/home/menu1.png",
					text: 'IT制作'
				}, {
					icon: "/static/images/home/menu2.png",
					text: 'logo设计'
				}, {
					icon: "/static/images/home/menu3.png",
					text: '文案策划'
				}, {
					icon: "/static/images/home/menu4.png",
					text: 'app开发'
				}, {
					icon: "/static/images/home/menu5.png",
					text: '装修服务'
				}, {
					icon: "/static/images/home/menu6.png",
					text: '软件定制'
				}, {
					icon: "/static/images/home/menu7.png",
					text: '法律服务'
				}, {
					icon: "/static/images/home/menu8.png",
					text: '小程序'
				}, {
					icon: "/static/images/home/menu9.png",
					text: '网络营销'
				}, {
					icon: "/static/images/home/menu10.png",
					text: '全部分类'
				},
			],
      CustomBar: app.globalData.CustomBar,
      menuHeight: app.globalData.menuHeight,
      navHeight: app.globalData.navHeight,
      menuTop: app.globalData.menuTop,
      active: 1,
      recommendActivity: [],
      demandList: [],
      resourcesList: [],
      province: '',
      city: '',
      cagetoryList: "",
      latitude: "",
      longitude: "",
			currentTabIndex: 0
    };
  },

  components: {
    tabbar
  },
  props: {},
	onShareAppMessage: function(res) {
		return {
			title: '禅易云生态',
			path: '/pages/home/index',
		}
	},
  onLoad() {
		
		uni.hideTabBar();
    // app.globalData.editTabbar();
		this.pagePath = '/pages/home/index'
    this.getCagetoryList();
    qqmapsdk = new QQMapWX({
      key: 'UVEBZ-M3VRS-CO4OH-6F5QZ-X7FB7-SVFOX' //这里自己的key秘钥进行填充

    });
    this.getLocation();
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.getCagetoryList();
  },
  methods: {
		tabBarClick(index){
			// console.log('返回tabBar索引：' + index)
			this.currentTabIndex = index
		},
    toGuidePage() {
      uni.navigateTo({
        url: '/pages/guide/index'
      });
    },

    toActiveDetail(e) {
      let id = e.currentTarget.dataset.id;
      uni.navigateTo({
        url: '/pages/activity/detail/index?id=' + id
      });
    },

    tabClick(e) {
      this.setData({
        active: e.currentTarget.dataset.i
      });
    },

    toTab2() {
      uni.switchTab({
        url: '/pages/demandHall/index'
      });
    },

    getCagetoryList() {
      uni.showNavigationBarLoading();
      app.http('get', 'index').then(res => {
        if (res.data.success) {
          res.data.data.recommendActivity.content.forEach(item => {
            item.activityStartTime = util.getWeek(item.activityStartTime);
          });
          this.setData({
            demandList: res.data.data.demandList,
            resourcesList: res.data.data.resourcesDtos,
            cagetoryList: res.data.data.cagetoryDtos,
            recommendActivity: res.data.data.recommendActivity.content
          }); //隐藏导航条加载动画
          uni.hideNavigationBarLoading(); //停止下拉刷新
          uni.stopPullDownRefresh();
        }
      });
    },

    toResourcesDetail(e) {
      let id = e.currentTarget.dataset.id;
      uni.navigateTo({
        url: '/pages/demandHall/resourcesDetail/index?id=' + id
      });
    },

    toCompanyDetail(e) {
      let id = e.currentTarget.dataset.id;
      uni.navigateTo({
        url: '/pages/demandHall/companyDetail/index?id=' + id
      });
    },

    toNeedDetail(e) {
      let id = e.currentTarget.dataset.id;
      uni.navigateTo({
        url: '/pages/demandHall/needsDetail/index?id=' + id
      });
    },

    getLocation() {
      let vm = this;
      uni.getLocation({
        type: 'wgs84',
        success: function (res) {
          // console.log(JSON.stringify(res))
          var latitude = res.latitude;
          var longitude = res.longitude;
          var speed = res.speed;
          var accuracy = res.accuracy;
          vm.getLocal(latitude, longitude);
        },
        fail: function (res) {
          console.log('fail' + JSON.stringify(res));
        }
      });
    },

    // 获取当前地理位置
    getLocal: function (latitude, longitude) {
      let vm = this;
      qqmapsdk.reverseGeocoder({
        location: {
          latitude: latitude,
          longitude: longitude
        },
        success: function (res) {
          // console.log(JSON.stringify(res));
          let province = res.result.ad_info.province;
          let city = res.result.ad_info.city;
          vm.setData({
            province: province,
            city: city,
            latitude: latitude,
            longitude: longitude
          }); // console.log(city)
        },
        fail: function (res) {
          console.log(res);
        },
        complete: function (res) {// console.log(res);
        }
      });
    }
  }
};
</script>
<style>

.home-page{
  padding-bottom: 190rpx;
}
.top-bg-box{
  width: 750rpx;
  height: 420rpx;
}
.top-bg-box image{
  width: 100%;
  height: 100%;
}
.page-top-box{
  width: 100%;
  height: 598rpx;
  position: relative;
}
.page-title{
  width: 100%;
  color: #fff;
  text-align: center;
  position: relative;
}
.top-bg{
  width: 100%;
  height: 598rpx;
  position: absolute;
}
.top-box-content{
  position: relative;
}
.search-box{
  color: #fff;
  font-size: 32rpx;
  padding: 0 60rpx 0 40rpx;
}
.localtion-box image{
  width: 26rpx;
  height: 31rpx;
  margin-right: 10rpx;
}
.search{
  width: 448rpx;
  height: 68rpx;
  font-size: 28rpx;
  padding: 16rpx 20rpx;
  background: rgba(255, 255, 255, 0.38);
  border-radius: 8rpx;
}
.search image{
  width: 35rpx;
  height: 35rpx;
  margin-right: 16rpx;
}
.message-icon{
  width: 36rpx;
  height: 36rpx;
}
.home-menu-box{
  width: 670rpx;
  height: 286rpx;
  background: #FFFFFF;
  box-shadow: 0px 6rpx 20rpx rgba(151, 69, 34, 0.28);
  border-radius: 12rpx;
  margin: 28rpx auto 0;
  padding: 42rpx;
}
.menu-list{
  color: #1D1D1D;
  font-size: 24rpx;
}
.menu-item{
  width: 20%;
  /* margin-right:16rpx; */
  margin-bottom: 34rpx;
}
.menu-item:nth-child(5n){
  margin-right: 0;
}
.menu-item image{
  width: 52rpx;
  height: 52rpx;
}

.investment-box{
  width: 100%;
  padding: 40rpx 0 0 40rpx;
}
.investment-title-box{
  width: 100%;
  padding-right: 40rpx;
}
.fz32{
  font-size: 32rpx;
  color: #1D1D1D;
}
.hot{
  width: 26rpx;
  height: 26rpx;
  text-align: center;
  line-height: 26rpx;
  background: linear-gradient(147deg, #FB7E4A 0%, #FF5100 100%);
  border-radius: 8rpx 0px 8rpx 0px;
  font-size: 18rpx;
  color: #fff;
  margin-left: 16rpx;
}
.more{
  font-size: 24rpx;
  color: #999999;
}
.more image{
  width: 9rpx;
  height: 16rpx;
  margin-left: 12rpx;
  margin-top: 2rpx;
}
.investement-list{
  width: 100%;
  margin-top: 34rpx;
}
.scroll-view_H{
  white-space: nowrap;
  width: 100%;
}
.investment-item{
  display: inline-block;
  width: 324rpx;
  height: 408rpx;
  margin-right:20rpx;
  box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.16);
  border-radius: 8rpx;
  position: relative;
}
.investment-item .item-bg{
  width: 324rpx;
  height: 408rpx;
  position: absolute;
}
.tips-box{
  position: relative;
  top: 20rpx;
}
.tips-item{
  padding: 6rpx 10rpx;
  line-height: 28rpx;
  font-size: 20rpx;
  color: #fff;
  background: rgba(255, 81, 0, 0.63);
  border-radius: 8rpx;
  margin-right: 14rpx;
}
.bg2{
  background: rgba(255, 170, 0, 0.63);
}
.item-info-box{
  width: 300rpx;
  height: 102rpx;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0px 6rpx 12rpx rgba(0, 0, 0, 0.2);
  border-radius: 8rpx;
  position: absolute;
  bottom: 18rpx;
  left: 50%;
  margin-left: -150rpx;
  font-size: 22rpx;
  color: #404040;
}
.item-info-box image{
  width: 14rpx;
  height: 17rpx;
  margin: 0 12rpx 0 12rpx;
}

.welfare-box{
  width: 100%;
  padding-left: 40rpx;
  margin-top: 52rpx;
}
.welfare-title{
  font-size: 32rpx;
  color: #1D1D1D;
  margin-bottom: 38rpx;
}
.welfare-list-box{
  width: 100%;
}
.welfare-item{
  display: inline-block;
  margin-right: 6rpx;
  padding: 12rpx;
}
.item-box{
  width: 650rpx;
  height: 248rpx;
  background: #FFFFFF;
  box-shadow: 0px 0rpx 12rpx rgba(0, 0, 0, 0.16);
  padding: 22rpx 16rpx;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
  position: relative;
}
.buy-btn{
  width: 144rpx;
  height: 52rpx;
  text-align: center;
  line-height: 52rpx;
  background: linear-gradient(315deg, #FB966C 0%, #FFC2AA 100%);
  border-radius: 12rpx;
  color: #fff;
  font-size: 24rpx;
  position: absolute;
  bottom: 30rpx;
  right: 30rpx;
}
.item-box image{
  width: 198rpx;
  height: 204rpx;
  margin-right: 12rpx;
}
.welfare-info-box{
  width: 394rpx;
}
.w-name{
  width: 390rpx;
  font-size: 28rpx;
  line-height: 40rpx;
  color: #1D1D1D;
  overflow: hidden;
  text-overflow: ellipsis; 
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.w-address{
  font-size: 24rpx;
  line-height: 34rpx;
  color: #707070;
  margin: 8rpx 0 14rpx;
}
.w-price{
  font-size: 28rpx;
  font-weight: bold;
  line-height: 40rpx;
  color: #FF7942;
}
.w-oldPrice{
  font-size: 20rpx;
  color: #BCBCBC;
  text-decoration: line-through;
}

.demandhall-box{
  width: 100%;
  padding: 40rpx;
}
.tabs-box{
  padding-left: 30rpx;
  padding-right: 12rpx;
}
.tab-item{
  font-size: 28rpx;
  color: #9C9C9C;
  padding-bottom: 8rpx;
}
.tab-item-a{
  color: #1D1D1D;
  border-bottom: 4rpx solid #FF7942;
}
.list-box{
  width: 100%;
  margin-top: 36rpx;
}
.item{
  width: 670rpx;
  background: #FFFFFF;
  box-shadow: 0px 6rpx 12rpx rgba(190, 190, 190, 0.3);
  border-radius: 12rpx;
  padding: 28rpx 20rpx 18rpx;
  margin-bottom: 32rpx;
}
.item-top{
  padding-bottom: 24rpx;
  position: relative;
}
.item-top .buy-btn{
  right: 0;
}
.project-name{
  width: 400rpx;
  font-size: 32rpx;
  font-weight: 500;
  line-height: 58rpx;
  color: #1D1D1D;
}
.tags-box2{
  margin-top: 12rpx;
}
.price{
  color: #FF5100;
  font-size: 28rpx;
  position: absolute;
  top: 0;
  right: 0rpx;
}
.tag{
  color: #74BDF7;
  font-size: 20rpx;
  line-height: 28rpx;
  margin: 12rpx 0 20rpx;
}
.desc{
  font-size: 24rpx;
  line-height: 34rpx;
  color: #666666;
  margin-top: 8rpx;
}
.company-box{
  padding-top: 12rpx;
  position: relative;
  border-top: 2rpx solid #ECECEC;
}
.company-box image{
  width: 128rpx;
  height: 128rpx;
  border-radius: 8rpx;
}
.company-info{
	width: calc(100% - 298rpx);
	margin-left: 12rpx;
}
.fz28{
  font-size: 28rpx;
  line-height: 40rpx;
  color: #1D1D1D;
}
.fz24{
  font-size: 24rpx;
  line-height: 34rpx;
}
.fz20{
  font-size: 20rpx;
  line-height: 28rpx;
}
.item-top .buy-btn{
  top: 0;
}
.into-btn{
  font-size: 20rpx;
  color: #FF5100;
  width: 144rpx;
  height: 40rpx;
  border: 1rpx solid #FF5100;
  opacity: 1;
  border-radius: 20rpx;
  position: absolute;
  top: 18rpx;
  right: 0rpx;
}
.into-btn image{
  width: 21rpx;
  height: 19rpx;
  margin-right: 6rpx;
}
.tag-item{
  width: 112rpx;
  height: 36rpx;
  line-height: 34rpx;
  text-align: center;
  border: 1rpx solid #FFAA00;
  color: #FFAA00;
  border-radius: 4rpx;
  margin-right: 8rpx;
}
.bgG{
  border: 1rpx solid #3A9EFA;
  color: #3A9EFA;
}
.bgO{
  border: 1rpx solid #FC9367;
  color: #FC9367;
}
.to-demandhall{
  font-size: 28rpx;
  color: #A7A7A7;
  margin-bottom: 28rpx;
}
.to-demandhall image{
  width: 13rpx;
  height: 23rpx;
  margin-left: 15rpx;
}

</style>