<template>
  <BlockRadius
    :borRadius="8"
    :paddingNum="32"
    class="service_info apaas_button"
    v-if="data"
  >
    <div class="main_container">
      <div
        class="main_container-left"
        v-if="data.cover"
      >
        <img
          :src="data.cover"
          width="100%"
          v-if="!(data.type == 'workflow' && data.workflows_id != 0) || !(data.type === 'Map Service')"
        />
        <workflows-view
          :isShop="true"
          :id="parseInt(data.workflows_id)"
          :hideDetail="true"
          v-if="data.type == 'workflow' && data.workflows_id != 0"
        ></workflows-view>
        <map-view
          v-if="data.type === 'Map Service'"
          :id="data.portal_id"
        ></map-view>
        <process-view
          :id="parseInt(data.workflows_id)"
          v-if="data.type == 'workflow' && data.workflows_id != 0"
        ></process-view>
      </div>
      <div class="main_container-right">
        <div class="service_title">
          <span class="service_name">
            {{ data.name }}
            <span v-if="data.version && data.version != ''">
              ( {{ data.version }} )
            </span>
          </span>
          <span
            class="service_type"
            v-if="data.type"
            v-text="data.type"
          ></span>
          <span
            v-if="data.openness == 1"
            class="tags shared"
          >共享</span>
          <span
            v-else-if="data.openness == 2"
            class="tags restricted"
          >
            受限
          </span>
          <span
            v-else
            class="tags sensitive"
          >敏感</span>
          <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="baseInfo.fwlx"
                placement="top-start"
              >
                <span>{{baseInfo.fwlx}}</span>
              </el-tooltip>
            </td>
            <td>
              服务领域：
              <el-tooltip
                class="item"
                effect="dark"
                :content="baseInfo.fwly"
                placement="top-start"
              >

                <span>{{baseInfo.fwly}}</span>
              </el-tooltip>
            </td>
            <td>
              提供组织：
              <el-tooltip
                class="item"
                effect="dark"
                :content="baseInfo.tgzz"
                placement="top-start"
              >

                <span>{{baseInfo.tgzz}}</span>
              </el-tooltip>
            </td>
          </tr>
          <tr class="flex_3">
            <td>
              联系人：
              <el-tooltip
                class="item"
                effect="dark"
                :content="baseInfo.lxr"
                placement="top-start"
              >

                <span>{{baseInfo.lxr}}</span>
              </el-tooltip>
            </td>
            <td>
              联系方式：
              <el-tooltip
                class="item"
                effect="dark"
                :content="baseInfo.lxfs"
                placement="top-start"
              >

                <span>{{baseInfo.lxfs}}</span>
              </el-tooltip>
            </td>
            <td>
              发布时间：
              <el-tooltip
                class="item"
                effect="dark"
                :content="helper.dateStringTransform(baseInfo.fbsj)"
                placement="top-start"
              >

                <span>{{helper.dateStringTransform(baseInfo.fbsj)}}</span>
              </el-tooltip>
            </td>
          </tr>
          <tr class="flex_3">
            <td>
              最近更新时间：
              <el-tooltip
                class="item"
                effect="dark"
                :content="helper.dateStringTransform(baseInfo.zjgxsj)"
                placement="top-start"
              >

                <span>{{helper.dateStringTransform(baseInfo.zjgxsj)}}</span>
              </el-tooltip>
            </td>
            <td>
              服务描述：
              <el-tooltip
                class="item"
                effect="dark"
                :content="baseInfo.fwms"
                placement="top-start"
              >
                <span>{{baseInfo.fwms}}</span>
              </el-tooltip>
            </td>
            <td></td>
          </tr>
        </div>

      </div>
    </div>
  </BlockRadius>
</template>

<script>
import helper from "@/services/helper.js";
import MapView from "./map-view";
import workflowsView from "@/components/work-flow/workflows-view";
import processView from "@/components/service-info/process-view";
import BlockRadius from "@/components/general/block-radius";

export default {
  components: {
    MapView,
    workflowsView,
    processView,
    BlockRadius,
  },
  props: {
    data: {
      type: Object,
      default: () => null,
    },
  },
  data: () => ({
    helper,
    types: [],
    type: 1, // 购买方式 1：按月，2：按年
    specification: {}, // 规格
    duration: 1, // 时长
    showTime: false,
    baseInfo: {
      fwlx: "",
      fwly: "",
      tgzz: "",
      lxr: "",
      lxfs: "",
      fbsj: "",
      zjgxsj: "",
      fwms: "",
    },
  }),
  computed: {},
  watch: {},
  methods: {
    getBaseInfo() {
      let data = { ...this.data };
      this.baseInfo.fwlx =
        data.data_service_type && data.data_service_type.length > 0
          ? data.data_service_type.join(" ")
          : "";
      this.baseInfo.fwly = data.sectors_name;
      this.baseInfo.tgzz = data.organization_name;
      this.baseInfo.lxr = data.user_name;
      this.baseInfo.lxfs = data.phone;
      this.baseInfo.fbsj = data.create_time;
      this.baseInfo.zjgxsj = data.update_date;
      this.baseInfo.fwms = data.descript;
    },
    dateTransform(datestr = "") {
      return helper.dateStringTransform(datestr);
    },
    changeSpecification(specification, type) {
      this.specification = specification;
      if (type == 0) {
        this.showTime = false;
      } else if (type == 1) {
        this.showTime = true;
      }
    },
    changeType({ value }) {
      this.type = value;
    },
    addToCart() {
      // console.log("addToCart");
      if(this.$store.state.userInfo){
        this.$http
          .post("/apaas/serviceapp/v3/shopcart/add", {
            service_id: parseFloat(this.data.service_id),
            app_id: 0, // 0表示不是应用
            spec_id: this.specification.id, // 规格id
            duration: this.duration, // 申请时长
            duration_method: this.type, // 计时方式 按年 按月
            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",
            });
          });
      }else{
        window.location.href = "/iam/login/#/login?ReturnUrl=" + encodeURIComponent(window.location.href);
      }
    },
    applyImmediately() {
      if(this.$store.state.userInfo){
        this.$router.push({
          path: "/shop/shop_car_apply",
          query: {
            service_id: parseFloat(this.data.service_id),
            spec_id: this.specification.id,
            spcs_type: this.specification.spcs_type,
            duration: this.duration,
            duration_unit: this.type,
          },
        });
      }else{
        window.location.href = "/iam/login/#/login?ReturnUrl=" + encodeURIComponent(window.location.href);
      }
    },
  },
  created() {
    this.getBaseInfo();
  },
};
</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 > .workflows-view {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
}
.main_container-left > .map_view {
  position: absolute;
  right: 1px;
  bottom: 2px;
}
.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;
}
.service_title > .service_type {
  flex-shrink: 0;
  height: 22px;
  padding: 0 7px;
  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;
}
.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;
  height: 38px;
}
.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: #242c43;
  font-size: 14px;
}
.ndwa_indowa {
  color: #e56600;
  font-size: 32px;
  font-weight: bold;
  margin: 0 8px 0 20px;
}
.kfdf_jffa {
  color: #e56600;
  font-size: 14px;
  position: relative;
  bottom: 6px;
}
.nmd_kwd {
  color: #242c43;
}
.ndwa_dn {
  color: #242c43;
}
.dn_wjd {
  color: #ea7d19;
  font-size: 20px;
  position: relative;
  font-weight: bold;
}
.dwin_diwa {
  width: 14px;
  height: 14px;
  margin-left: 42px;
  margin-right: 4px;
  position: relative;
}
.dn_wjd::after {
  content: "";
  position: absolute;
  width: 1px;
  height: 14px;
  background-color: #eccb8a;
  top: 8px;
  left: -44px;
}
.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: 22px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 500;
  line-height: 22px;
  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 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.gnekg_fwf {
  position: relative;
  bottom: 6px;
}
.spec_des {
  margin-left: 128px;
  color: rgba(88, 97, 122, 0.5);
  font-size: 12px;
  line-height: 14px;
  margin-top: 8px;
}
.bgnerighur {
  position: relative;
  bottom: 1px;
}
</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: 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>
