<template>
  <div class="services_shop-container">
    <div class="services_shop-carousel">
      <el-carousel height="400px" arrow="never">
        <el-carousel-item v-for="(banner, index) in banners" :key="'banner_' + index">
          <img :src="banner.image_url" width="100%" @click="goto(banner.url)" />
        </el-carousel-item>
      </el-carousel>
      <ul class="services_shop-info">
        <template v-for="(item, index) in servicesShopInfo">
          <li class="info_item" :key="'info_' + index">
            <div class="left-contianer">
              <img :src="item.icon" width="100%" />
            </div>
            <div class="right-container">
              <p v-text="item.name"></p>
              <p>
                <span>{{ helper.numberFormat(item.value, 2) }}</span>
                <span>{{ item.value > 10000 ? "万" : "" }}</span>
              </p>
            </div>
          </li>
          <li class="info_line" :key="'line_' + index" v-if="index + 1 < servicesShopInfo.length"></li>
        </template>
      </ul>
    </div>

    <!-- 热门数据 -->
    <shop-list
      name="热门数据"
      to="/shop/data_service_list/5"
      detail-path="/shop/sjfwDetail/"
      :data="hot_datas"
      :showImg="false"
    ></shop-list>

    <!-- 精品地图 -->
    <shop-list
      name="精品地图"
      to="/shop/space_time_service_list/6"
      detail-path="/shop/skfwDetail/"
      :data="map_datas"
      :showImg="true"
    ></shop-list>

    <!-- 综合应用 -->
    <shop-list
      name="综合应用"
      to="/shop/comprehensive_app_list/21"
      detail-path="/shop/zhfwDetail/"
      :data="comprehensive_datas"
      :showImg="true"
    ></shop-list>
  </div>
</template>

<script>
import shopList from "@/components/shop-list";
import helper from "@/services/helper";

export default {
  components: {
    shopList
  },
  data: () => ({
    banners: null,
    servicesShopInfo: [
      {
        name: "服务总数",
        value: 0,
        icon: require("@/assets/imgs/shop_ic_fuwuzs.png")
      },
      {
        name: "用户总数",
        value: 0,
        icon: require("@/assets/imgs/shop_ic_yonghuzs.png")
      },
      {
        name: "接入机构",
        value: 0,
        icon: require("@/assets/imgs/shop_ic_jierujg.png")
      },
      {
        name: "接入系统",
        value: 0,
        icon: require("@/assets/imgs/shop_ic_jieruxt.png")
      },
      {
        name: "服务请求次数",
        value: 0,
        icon: require("@/assets/imgs/shop_ic_fuwuzs.png")
      }
    ],
    hot_datas: [],
    map_datas: [],
    comprehensive_datas: [],
    helper
  }),
  methods: {
    init(type) {
      this.$api.serviceShop.getFeaturedList({ type }).then(response => {
        if (type == "hotdata") {
          this.hot_datas = response.data.data;
        } else if (type == "hgmap") {
          this.map_datas = response.data.data;
        } else if (type == "zhapp") {
          this.comprehensive_datas = response.data.data;
        }
      });
    },
    getBenner() {
      this.$api.serviceShop.getBenner().then(response => {
        this.banners = response.data.data;
      });
    },
    getGeneralOverview() {
      this.$api.serviceShop.getGeneralOverview().then(response => {
        let data = response.data.data;
        this.servicesShopInfo[0].value = data.service_num;
        this.servicesShopInfo[1].value = data.person_num;
        this.servicesShopInfo[2].value = data.org_num;
        this.servicesShopInfo[3].value = data.system_num;
        this.servicesShopInfo[4].value = data.request_num;
      });
    },
    goto(page) {
      window.location.href = page;
    }
  },
  mounted() {
    this.getBenner();
    this.init("hotdata");
    this.init("hgmap");
    this.init("zhapp");
    this.getGeneralOverview();
  }
};
</script>

<style scoped>
.services_shop-container {
  max-width: 1200px;
  margin: -157px auto 20px;
}
.services_shop-carousel {
  border-radius: 10px;
  overflow: hidden;
}

.services_shop-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 5px;
  background-color: #fff;
}
.services_shop-info > .info_item {
  flex-grow: 1;
  display: inline-flex;
  justify-content: space-between;
  align-items: center;
  height: 125px;
  padding: 10px 10px;
  margin: 0 15px;
  box-sizing: border-box;
}
.services_shop-info .left-container {
  width: 45px;
  flex-shrink: 0;
}
.services_shop-info .right-container {
  flex-grow: 1;
  padding: 0 1.5em;
}
.services_shop-info .right-container > p {
  font-size: 16px;
  color: #58617a;
  line-height: 32px;
  text-align: right;
  position: relative;
  box-sizing: border-box;
}
.services_shop-info .right-container > p:nth-child(2) > span:nth-child(1) {
  font-family: Arial;
  font-size: 24px;
  font-weight: bold;
  color: #242c43;
}
.services_shop-info .right-container > p:nth-child(2) > span:nth-child(2) {
  position: absolute;
  top: 0;
  right: -1.2em;
}
.services_shop-info > .info_line {
  height: 64px;
  border: 1px solid #f2f3f4;
}
</style>

<style>
.services_shop-carousel .el-carousel__button {
  width: 30px;
  height: 5px;
  opacity: 1;
  border-radius: 2px;
}
.services_shop-carousel .is-active .el-carousel__button {
  background-color: #e56600;
}
</style>
