<template>
  <BlockRadius
    :borRadius="8"
    :paddingNum="32"
    class="service_info apaas_button"
    v-if="datas"
  >
    <div class="main_container">
      <div class="main_container-left">
        <img
          :src="datas.logo"
          width="100%"
        />
      </div>
      <div class="main_container-right">
        <div class="service_title">
          <span
            class="service_name"
            v-text="datas.app_name"
          ></span>
          <div style="margin-right:auto">
            <span class="service_access_info1">
              <img :src="require('@/assets/imgs/icon_liulan.png')" />
              <span v-text="datas.view_count + '次浏览'"></span>
            </span>
            <span class="service_access_info1">
              <img :src="require('@/assets/imgs/icon_huoqu.png')" />
              <span v-text="'本月' + datas.apply_times + '次获取'"></span>
            </span>
          </div>
          <span class="service_access_info">
            <el-button
              class="service_now_buy"
              @click="applyImmediately"
            >
              立即申请
            </el-button>
          </span>
          <span class="service_access_info">
            <el-button
              class="service_add_cart"
              @click="addToCart"
            >
              加入申请单
            </el-button>
          </span>
        </div>
        <div class="baseInfo_box">
          <tr class="flex_3">
            <td>部署来源：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.online_state_name"
                placement="top-start"
              >
                <span>{{datas.online_state_name}}</span>
              </el-tooltip>
            </td>
            <td>业务领域：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.ywly_name"
                placement="top-start"
              >
                <span>{{datas.ywly_name}}</span>
              </el-tooltip>
            </td>
            <td>应用类型：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.type_name"
                placement="top-start"
              >
                <span>{{datas.type_name}}</span>
              </el-tooltip>
            </td>
          </tr>
          <tr class="flex_3">
            <td>提供组织：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.organization_name"
                placement="top-start"
              >
                <span>{{datas.organization_name}}</span>
              </el-tooltip>
            </td>
            <td>联系人：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.username"
                placement="top-start"
              >
                <span>{{datas.username}}</span>
              </el-tooltip>
            </td>
            <td>联系方式：
              <el-tooltip
                class="item"
                effect="dark"
                :content="datas.phone"
                placement="top-start"
              >
                <span>{{datas.phone}}</span>
              </el-tooltip>
            </td>
          </tr>
          <tr class="flex_3">
            <td>上线时间：
              <el-tooltip
                class="item"
                effect="dark"
                :content="helper.dateStringTransform(datas.create_date)"
                placement="top-start"
              >
                <span>{{helper.dateStringTransform(datas.create_date)}}</span>
              </el-tooltip>
            </td>
          </tr>
        </div>
      </div>
    </div>
  </BlockRadius>
</template>

<script>
import BlockRadius from "@/components/general/block-radius";
import helper from "@/services/helper.js";
export default {
  components: {
    BlockRadius,
  },
  props: {
    datas: {
      type: Object,
      default: () => null,
    },
  },
  data: () => ({
    helper,
    specifications: [
      {
        name: "1.申请获取应用镜像部署权限",
        value: 1,
      },
      {
        name: "2.申请获取应用二次开发权限（需要先行升级为开发者用户）",
        value: 2,
      },
    ],
    specificationID: 1,
    duration: 1,
  }),
  watch: {},
  computed: {
    actionDisabled() {
      return this.specifications.length == 0;
    },
  },
  methods: {
    changeSpecification({ value }) {
      this.specificationID = value;
    },
    addToCart() {
      // console.log("addToCart");
      console.log(this.datas);
      this.$http
        .post("/apaas/serviceapp/v3/shopcart/add", {
          service_id: 0, // 0表示不是服务
          app_id: parseFloat(this.datas.app_id),
          spec_id: this.specificationID,
          duration: 1,
          duration_method: 1,
          is_subscribe: 0, // 是否订阅
        })
        .then(({ data }) => {
          if (data.success == 1) {
            this.$message({
              message: data.errMsg,
              type: "success",
            });
            this.$store.commit("setMenuCartState");
          } else {
            this.$message({
              message: data.errMsg,
              type: "warning",
            });
          }
        })
        .catch((error) => {
          this.$message({
            message: `添加申请单失败`,
            type: "warning",
          });
        });
    },
    applyImmediately() {
      // console.log("applyImmediately");

      this.$router.push({
        path: "/shop/shop_car_apply",
        query: {
          app_id: parseFloat(this.datas.app_id),
          spec_id: this.specificationID,
          duration: 1,
          duration_unit: 1,
        },
      });
    },
  },
};
</script>

<style scoped>
.main_container {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 8px 8px 0;
}
.main_container-left {
  width: 200px;
  height: 200px;
  padding: 2px;
  background-color: #f6f7fb;
  font-size: 0;
  position: relative;
}
.main_container-left img {
  width: 100%;
  height: 100%;
  border-radius: 6px;
}
.main_container-left > .map_view {
  position: absolute;
  right: 3px;
  bottom: 3px;
}
.main_container-right {
  width: 896px;
}
.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;
  margin-right: 36px;
}
.service_title > .service_type {
  flex-shrink: 0;
  height: 24px;
  padding: 0 12px;
  border: 1px solid #5362ee;
  background-color: #5362ee;
  border-radius: 4px;
  font-size: 12px;
  color: #fff;
  line-height: 22px;
  margin-left: 10px;
}

.service_title > .service_access_info {
  flex-shrink: 0;
  font-size: 14px;
  color: #58617a;
  margin-left: 20px;
}
.service_access_info1 {
  margin-right: 16px;
}
.service_title > .service_access_info > * {
  display: inline-block;
  vertical-align: middle;
}
.service_title > .service_access_info > img {
  width: 12px;
  margin-right: 5px;
}
.baseInfo_box {
  width: 100%;
  margin-top: 16px;
}
.baseInfo_box .flex_3 {
  display: flex;
  width: 100%;
  height: 32px;
  line-height: 32px;
  margin-bottom: 16px;
}
.baseInfo_box .flex_3 td {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.service_base_info {
  padding: 18px;
  background-color: #f9fafc;
  border-radius: 8px;
}
.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,
.guige_title {
  color: #8890a7;
  width: 100px;
  margin-right: 20px;
  text-align: right;
}
.service_base_info > li > span:nth-child(2) {
  color: #242c43;
}
.commodity_information {
  margin-top: 16px;
}
.commodity_information > span:nth-child(2) {
  color: #58617a;
}
.commodity_information > span:first-child {
  line-height: 36px;
}
.commodity_information > .commodity_text {
  flex-grow: 1;
  padding: 8px 18px;
  background-color: #f9fafc;
  border-radius: 5px;
}
.commodity_information > .btn_container {
  margin-bottom: -15px;
}
.commodity_information > .btn_container > .el-button {
  border-width: 2px;
}
.commodity_information > .btn_container > .el-button,
.commodity_information > .btn_container > .el-input-number {
  margin: 0 20px 15px 0;
}
.spec_btn {
  height: 36px;
  padding: 7px 18px 6px;
  background-color: #ffffff;
  border-radius: 6px;
  border: solid 1px #dcdfe6;
  font-size: 14px;
  line-height: 20px;
  color: #58617a;
  margin-right: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.spec_btn_act {
  height: 36px;
  padding: 7px 18px 6px;
  background-color: #515fe7;
  border-radius: 6px;
  border: solid 1px #515fe7;
  font-size: 14px;
  line-height: 20px;
  color: #f4f7fc;
  margin-right: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.spec_btn:hover {
  background-color: #f2f5fe;
  border: solid 1px #c3caf8;
  color: #58617a;
}
.commodity_action {
  margin-top: 16px;
  margin-left: 120px;
}
.dbn_wkdn {
  color: #8890a7;
  font-size: 14px;
}
.ndwa_indowa {
  color: #e56600;
  font-size: 26px;
  font-weight: bold;
}
.kfdf_jffa {
  color: #e56600;
  font-size: 14px;
}
.nmd_kwd {
  color: #8890a7;
}
.ndwa_dn {
  color: #242c43;
}
.dn_wjd {
  color: #ea7d19;
  font-size: 18px;
  position: relative;
  font-weight: bold;
}
.dwin_diwa {
  width: 14px;
  height: 14px;
  margin-left: 20px;
  margin-right: 4px;
  position: relative;
}
.dn_wjd::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 16px;
  background-color: #e3e5ef;
  top: 5px;
  left: -35px;
}
.service_add_cart {
  width: 104px;
  height: 28px;
  background-color: #fcefd6;
  border-radius: 6px;
  color: #e56600;
  font-size: 14px;
  border: none;
  padding: 0;
  text-align: center;
  line-height: 28px;
}
.service_now_buy {
  width: 88px;
  height: 28px;
  background-color: #e56600;
  border: solid 1px #e56600;
  border-radius: 6px;
  color: #fcefd6;
  font-size: 14px;
  padding: 0;
  text-align: center;
  line-height: 28px;
}
.tags {
  display: inline-block;
  margin-left: 8px;
  height: 24px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  line-height: 24px;
  border-radius: 4px;
  position: relative;
  top: 1px;
  flex-shrink: 0;
  margin-right: auto;
}
.map_service {
  background-color: #626de9;
  border: solid 1px #626de9;
  color: #fff;
}
.shared {
  background-color: #e7fdfc;
  border: solid 1px #8bd6d0;
  color: #25bdb1;
}
.restricted {
  background-color: #fffee8;
  border: solid 1px #e4c884;
  color: #ef9433;
}
.sensitive {
  background-color: #ffefef;
  border: solid 1px #d7a4a9;
  color: #e15260;
}
.des_p {
  color: #8890a7;
  font-size: 14px;
  margin-top: 8px;
  margin-bottom: 12px;
}
.jiage_d {
  background: url("~@/assets/imgs/img_bg_jiage.png");
  width: 896px;
  height: 72px;
  margin-bottom: 16px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.spec_des {
  margin-left: 128px;
  color: rgba(88, 97, 122, 0.5);
  font-size: 14px;
  line-height: 14px;
  margin-top: 8px;
}
</style>

<style>
.service_info.apaas_button .el-button--primary {
  color: #fff;
  background-color: #515fe7;
  border-color: #515fe7;
}
.service_info .el-input-number .el-input-number__decrease {
  top: 2px;
  left: 2px;
  width: 38px;
  line-height: 36px;
  border-radius: 8px 0 0 8px;
  border-right-width: 2px;
}
.service_info .el-input-number .el-input-number__increase {
  top: 2px;
  right: 2px;
  width: 38px;
  line-height: 36px;
  border-radius: 0 8px 8px 0;
  border-left-width: 2px;
}
.service_info .el-input-number .el-input__inner {
  border-width: 2px;
}
.service_info .el-input-number {
  width: 128px;
}
.service_info .el-input-number .el-input-number__decrease {
  top: 1px;
  left: 1px;
  line-height: 34px;
  border-radius: 5px 0 0 5px;
  border-right-width: 1px;
}
.service_info .el-input-number .el-input-number__increase {
  top: 1px;
  right: 1px;
  line-height: 34px;
  border-radius: 0 5px 5px 0;
  border-left-width: 1px;
}
.service_info .el-input-number .el-input__inner {
  border-width: 1px;
  height: 36px;
  line-height: 36px;
}
.service_info .el-input-number {
  width: 128px;
  line-height: 36px;
}
.service_info
  .el-input-number__decrease:hover:not(.is-disabled)
  ~ .el-input
  .el-input__inner:not(.is-disabled),
.el-input-number__increase:hover:not(.is-disabled)
  ~ .el-input
  .el-input__inner:not(.is-disabled) {
  border-color: #515fe7;
}
.service_info .el-input__inner:focus {
  border-color: #515fe7;
}
.service_info .el-input-number__decrease:hover,
.el-input-number__increase:hover {
  color: #515fe7;
}
</style>
