<template>
  <div class="service_info apaas_button" v-if="data">
    <div class="service_title">
      <span class="service_name" v-text="data.app_name"></span>
      <span class="service_access_info">
        <img :src="require('@/assets/imgs/icon_liulan.png')" />
        <span v-text="'浏览次数：' + data.view_count"></span>
      </span>
      <span class="service_access_info">
        <img :src="require('@/assets/imgs/icon_huoqu.png')" />
        <span v-text="'部署次数：' + data.deploy_times"></span>
      </span>
    </div>
    <div class="main_container">
      <div class="main_container-left">
        <img :src="data.logo" width="100%" />
      </div>
      <div class="main_container-right">
        <ul class="service_base_info">
          <li>
            <span>应用开发者：</span>
            <span v-text="data.username"> </span>
          </li>
          <li>
            <span>应用类型：</span>
            <span v-html="data.type_name"></span>
          </li>
          <li>
            <span>业务领域：</span>
            <span v-text="data.ywly_name"></span>
          </li>
          <li>
            <span>上线时间：</span>
            <span v-text="data.create_date"></span>
          </li>
        </ul>
        <div class="and_wid">
          <div class="dbn_wkdn">
            价&nbsp;&nbsp;格：
            <span class="ndwa_indowa"> {{ data.price * duration }} </span>
            <span class="kfdf_jffa">金币</span>
          </div>
          <div class="nmd_kwd">
            月售：
            <span class="ndwa_dn"> {{ data.sale }} 笔 </span>
            <img src="@/assets/imgs/shop_ic_star.png" class="dwin_diwa" />
            <span class="dn_wjd"> {{ data.star }} </span>
          </div>
        </div>
        <div class="commodity_information">
          <span>规&emsp;&emsp;格：</span>
          <div class="btn_container_ddaw">
              {{ data.price }} 金币/月
          </div>
        </div>
        <div class="commodity_information">
          <span>购买时长：</span>
          <div class="btn_container">
            <el-input-number
              v-model="duration"
              :min="1"
              :disabled="actionDisabled"
            ></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: {
    data: {
      type: Object,
      default: () => null,
    },
  },
  data: () => ({
    specifications: [
      {
        name: "1.申请获取应用镜像部署权限",
        value: 1,
      },
      {
        name: "2.申请获取应用二次开发权限（需要先行升级为开发者用户）",
        value: 2,
      },
    ],
    specificationID: 1,
    duration: 1,
  }),
  computed: {
    actionDisabled() {
      return this.specifications.length == 0;
    },
  },
  methods: {
    changeSpecification({ value }) {
      this.specificationID = value;
    },
    addToCart() {
      // console.log("addToCart");

      this.$http
        .post("/apaas/serviceapp/v3/shopcart/add", {
          service_id: 0, // 0表示不是服务
          app_id: parseFloat(this.data.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.data.app_id),
          spec_id: this.specificationID,
          duration: 1,
          duration_unit: 1,
        },
      });
    },
  },
};
</script>
</script>

<style scoped>
.service_info {
  padding: 35px 20px 40px;
  background-color: #fff;
  margin-bottom: 20px;
}
.main_container {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-top: 25px;
}
.main_container-left {
  width: 270px;
  padding: 3px;
  background-color: #f9fafc;
  margin-right: 30px;
  font-size: 0;
  position: relative;
}
.main_container-left img {
  width: 100%;
}
.main_container-left > .map_view {
  position: absolute;
  right: 3px;
  bottom: 3px;
}
.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;
  flex-grow: 1;
}
.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: 19px;
  margin-right: 5px;
}
.service_base_info {
  padding: 25px 20px;
  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,
.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 {
  border-width: 2px;
}
.commodity_information > .btn_container > .el-button,
.commodity_information > .btn_container > .el-input-number {
  margin: 0 20px 15px 0;
}
.btn_container_ddaw {
  line-height: 40px;
  margin-left: 5px;
}
.commodity_action {
  margin-top: 60px;
  text-align: right;
}
.commodity_action > .el-button {
  width: 220px;
  margin-left: 20px;
  font-size: 16px;
}
.and_wid {
  background-color: #f9fafc;
  border-radius: 8px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  align-items: center;
}
.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;
}
.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;
}
</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;
}
</style>
