<template>
  <BlockRadius
    :borRadius="8"
    :paddingNum="32"
    class="service_info apaas_button"
    v-if="data"
  >
    <div class="main_container">
      <div class="main_container-left">
        <img :src="data.logo" width="100%" />
      </div>
      <div class="main_container-right">
        <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.apply_times + '次获取'"></span>
          </span>
        </div>
        <p class="des_p">{{ data.yyjj }}</p>
        <div class="jiage_d">
          <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 class="guige_title">规&emsp;&emsp;格：</span>
          <div class="spec_btn_act">申请获取应用镜像部署权限</div>
        </div>
        <div class="spec_des">
          {{ `申请获取应用镜像部署权限，每月${data.price}金币。` }}
        </div>
        <div class="commodity_information">
          <span class="guige_title">购买时长：</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 class="service_now_buy" @click="applyImmediately">
            立即申请
          </el-button>
          <el-button class="service_add_cart" @click="addToCart">
            加入购物车
          </el-button>
        </div>
      </div>
    </div>
  </BlockRadius>
</template>

<script>
import BlockRadius from "@/components/general/block-radius";
export default {
  components: {
    BlockRadius,
  },
  props: {
    datas: {
      type: Object,
      default: () => null,
    },
  },
  data: () => ({
    specifications: [
      {
        name: "1.申请获取应用镜像部署权限",
        value: 1,
      },
      {
        name: "2.申请获取应用二次开发权限（需要先行升级为开发者用户）",
        value: 2,
      },
    ],
    specificationID: 1,
    duration: 1,
    data: {},
  }),
  watch: {
    datas: {
      handler(val) {
        this.data = val;
        console.log(this.data);
      },
      deep: true,
      immediate: true,
    },
  },
  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>
</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: auto;
}
.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_title > .service_access_info > * {
  display: inline-block;
  vertical-align: middle;
}
.service_title > .service_access_info > img {
  width: 12px;
  margin-right: 5px;
}
.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: 192px;
  height: 40px;
  background-color: #fcefd6;
  border-radius: 6px;
  border: solid 1px #fac266;
  color: #e56600;
  font-size: 16px;
}
.service_now_buy {
  width: 192px;
  height: 40px;
  background-color: #e56600;
  border: solid 1px #e56600;
  border-radius: 6px;
  color: #fcefd6;
  font-size: 16px;
  margin-right: 24px;
}
.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;
}
</style>
