<template>
  <div class="body">
    <div class="body-top">
      <span class="body-top__left" @click="returnTemplate('Return')"
        >返回模板</span
      >
      预览
      <span class="body-top__right" @click="returnTemplate('Use')">使用</span>
    </div>
    <!-- 预览部分 -->
    <div class="body-center">
      <root-unit v-for="item in templateInfo" :unit="item" :key="item.id" />
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
import { GO_URLS } from "@/config/URLS";
import { Unit } from "@/plugins/types2";
// 取本地数据转换函数
import { formatTemplateApi2Local } from "@/plugins/Template";
import RootUnit from "@/components/editTemplate/RootUnit.vue";
@Component({
  components: {
    RootUnit,
  },
})
export default class preview extends Vue {
  @Prop({ type: Number, default: 0 }) systemTemplateId!: 0;
  @Prop({ type: Boolean, default: true }) isActive!: boolean;
  public templateInfo: Unit[] = [];
  //   周期函数
  public created() {
    this.obtainTemplateInformation();
    // if (this.systemTemplateId) {
    // this.templateInfo = formatTemplateApi2Local(JSON.parse(this.detail));
    // }
  }
  //   返回模板
  public returnTemplate(val: string) {
    this.$emit("returnTemplate", val);
  }
  //  查询模板
  public async obtainTemplateInformation() {
    //   获取个人模板||获取系统模板
    // let url = "";
    // if (this.isActive) {
    //   url = URLS.SYS_TMPL_GET;
    // } else {
    //   url = URLS.TEMPLATE_DETAIL;
    // }
    const data = await this.$ajax({
      type: "get",
      params: {
        id: this.systemTemplateId,
      },
      url: GO_URLS.getSystemTemplate,
    });
    if (data && data.data.detail) {
      this.templateInfo = formatTemplateApi2Local(JSON.parse(data.data.detail));
    }
  }
}
</script>
<style lang="less" scoped>
/deep/.root_unit {
  pointer-events: none;
  .input-box {
    input {
      width: 500px;
    }
  }
  .date-picker {
    width: 500px;
  }
}

.body {
  width: 932px;
  height: 640px;
  background: rgba(255, 255, 255, 1);
  border-radius: 10px;
  // pointer-events: none;
  .body-top {
    height: 68px;
    line-height: 68px;
    text-align: center;
    border-bottom: 1px solid #e9e9e9;
    font-size: 22px;
    font-weight: 500;
    color: rgba(53, 53, 53, 1);
    .body-top__right,
    .body-top__left {
      width: 90px;
      height: 40px;
      background: rgba(239, 239, 239, 1);
      border-radius: 4px;
      line-height: 40px;
      font-size: 14px;
      text-align: center;
      font-weight: 400;
      color: rgba(41, 41, 41, 1);
      margin-top: 14px;
      cursor: pointer;
    }
    .body-top__left {
      float: left;
      margin-left: 24px;
    }
    .body-top__right {
      float: right;
      margin-right: 24px;
    }
  }
  .body-center {
    height: 571px;
    width: 100%;
    // pointer-events: none;
    border-radius: 0 0 10px 10px;
    overflow-y: auto;
    padding-left: 18px;
    padding-top: 20px;
  }
}
</style>