<template>
  <div class="sevice_info" v-if="serviceData">
    <div class="service_title">
      <span class="service_name" v-text="serviceData.name"></span>
      <span
        class="service_type"
        v-if="serviceData.type"
        v-text="serviceData.type"
      ></span>
      <span class="service_level" v-text="serviceData.openLevel"></span>
      <span class="service_access_info">
        <img :src="require('@/assets/imgs/icon_liulan.png')" />
        <span v-text="'浏览次数：' + serviceData.viewCount"></span>
      </span>
      <span class="service_access_info">
        <img :src="require('@/assets/imgs/icon_huoqu.png')" />
        <span v-text="'获取次数：' + serviceData.acquireCount"></span>
      </span>
    </div>
    <div class="main_container">
      <div class="main_container-left" v-if="serviceData.img">
        <img :src="serviceData.img" width="460" />
      </div>
      <div class="main_container-right">
        <ul class="service_base_info">
          <li>
            <span>提供机构：</span>
            <span v-text="serviceData.providedBy"> </span>
          </li>
          <li>
            <span>发布时间：</span>
            <span v-text="serviceData.publishTime"></span>
          </li>
          <li>
            <span>更新时间：</span>
            <span v-text="serviceData.updatedTime"></span>
          </li>
          <li>
            <span>数据领域：</span>
            <span v-text="serviceData.dataField"></span>
          </li>
          <li>
            <span>服务类型：</span>
            <span v-html="serviceData.serviceType.join('&emsp;')"></span>
          </li>
          <li>
            <span>资源摘要：</span>
            <span v-text="serviceData.resourceSummary"></span>
          </li>
        </ul>
        <div class="commodity_information">
          <span>规&emsp;&emsp;格：</span>
          <div class="btn_container">
            <el-button
              v-for="(item, index) in serviceData.specifications"
              :key="'specifications_' + index"
              :type="
                item.value === commodityData.specification
                  ? 'primary'
                  : 'default'
              "
              @click="changeSpecification(item)"
            >
              {{ item.name }}
            </el-button>
          </div>
        </div>
        <div class="commodity_information">
          <span>规格说明：</span>
          <span class="commodity_text" v-text="specificationDescription"></span>
        </div>
        <div class="commodity_information">
          <span>购买方式：</span>
          <div class="btn_container">
            <el-button
              v-for="(item, index) in serviceData.ways"
              v-text="item.name"
              :key="'way_' + index"
              :type="item.value === commodityData.way ? 'primary' : 'default'"
              @click="changeWay(item)"
            >
            </el-button>
          </div>
        </div>
        <div class="commodity_information">
          <span>购买时长：</span>
          <div class="btn_container">
            <el-input-number
              v-model="commodityData.duration"
              :min="1"
              :max="12"
            ></el-input-number>
          </div>
        </div>
        <div class="commodity_action">
          <el-button type="warning" plain @click="addToCart">
            加入购物车
          </el-button>
          <el-button type="warning" @click="applyImmediately">
            立即申请
          </el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    serviceData: {
      type: Object,
      default: () => null,
    },
  },
  data: () => ({
    commodityData: {
      specification: 0,
      way: 0,
      duration: 1,
    },
  }),
  computed: {
    specificationDescription() {
      let obj =
        this.serviceData.specifications[this.commodityData.specification] || {};
      return obj.description || "";
    },
  },
  methods: {
    changeSpecification({ value }) {
      this.commodityData.specification = value;
    },
    changeWay({ value }) {
      this.commodityData.way = value;
    },
    addToCart() {
      console.log("addToCart");
      console.log(this.commodityData);
    },
    applyImmediately() {
      console.log("applyImmediately");
      console.log(this.commodityData);
    },
  },
};
</script>

<style scoped>
.sevice_info {
  padding: 20px;
  background-color: #fff;
  margin-bottom: 20px;
}
.main_container {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-top: 25px;
}
.main_container-left {
  padding: 3px;
  background-color: #f9fafc;
  margin-right: 30px;
}
.main_container-right {
  flex-grow: 1;
}
.service_title {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.service_title > .service_name {
  font-size: 22px;
  font-weight: bold;
  color: #0d1847;
  line-height: 36px;
}
.service_title > .service_type {
  flex-shrink: 0;
  height: 24px;
  padding: 0 12px;
  border: 1px solid #5362ee;
  background-color: #5362ee;
  border-radius: 12px;
  font-size: 12px;
  color: #fff;
  line-height: 22px;
  margin-left: 10px;
}
.service_title > .service_level {
  flex-shrink: 0;
  height: 24px;
  padding: 0 12px;
  border: 1px solid #25bdb1;
  border-radius: 12px;
  font-size: 12px;
  color: #25bdb1;
  line-height: 22px;
  margin-left: 10px;
  margin-right: auto;
}
.service_title > .service_access_info {
  flex-shrink: 0;
  font-size: 14px;
  color: #58617a;
  margin-left: 20px;
}
.service_title > .service_access_info > * {
  display: inline-block;
  vertical-align: middle;
}
.service_title > .service_access_info > img {
  width: 15px;
  margin-right: 5px;
}
.service_base_info {
  padding: 18px;
  background-color: #f9fafc;
}
.service_base_info > li,
.commodity_information {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  font-size: 14px;
  color: #242c43;
  line-height: 20px;
}
.service_base_info > li:not(:first-child) {
  margin-top: 18px;
}
.service_base_info > li > span:first-child,
.commodity_information > span:first-child {
  flex-shrink: 0;
  white-space: nowrap;
  color: #8890a7;
}
.service_base_info > li > span:nth-child(2) {
  color: #242c43;
}
.commodity_information {
  margin-top: 30px;
}
.commodity_information > span:nth-child(2) {
  color: #58617a;
}
.commodity_information > span:first-child {
  line-height: 40px;
}
.commodity_information > .commodity_text {
  flex-grow: 1;
  padding: 13px 18px;
  background-color: #f9fafc;
  border-radius: 5px;
}
.commodity_information > .btn_container {
  margin-bottom: -15px;
}
.commodity_information > .btn_container > .el-button,
.commodity_information > .btn_container > .el-input-number {
  margin: 0 20px 15px 0;
}
.commodity_action {
  margin-top: 50px;
  text-align: right;
}
.commodity_action > .el-button {
  width: 220px;
  margin-left: 20px;
}
.sevice_info .el-button--primary {
  background-color: #515fe7;
  border-color: #515fe7;
}
.sevice_info .el-button--warning.is-plain {
  background-color: #fcefd6;
  border-color: #fac266;
  color: #e56600;
}
.sevice_info .el-button--warning {
  background-color: #e56600;
  border-color: #e56600;
}
</style>
