<template>
  <div class="body">
    <div class="body-center">
      <root-unit
        v-for="(item, i) in templateInfo"
        :unit="item"
        :key="item.id"
        :setUnit="(v: any) => changeUnit(i, v)"
      />
    </div>
  </div>
</template>
<script lang="ts">
// 取本地数据转换函数
import { GO_URLS } from "cqk-sy-ui";
import { Property, Unit } from "../newEditTemplate/types2";
import RootUnit from "../newEditTemplate/RootUnit.vue";
import { formatTemplateApi2Local } from "./Template";
import { defineComponent } from "vue";
import { $ajax } from "@/service";
import { __VLS_types_PropertyType } from "./index.vue.__VLS_script";

export default defineComponent({
  components: {
    RootUnit,
  },
  props: {
    systemTemplateId: { type: Number, default: 0 },
    isActive: { type: Boolean, default: true },
  },
  data() {
    return {
      templateInfo: [] as Unit[],
    };
  },
  created() {
    this.obtainTemplateInformation();
  },
  methods: {
    changeUnit(
      i: any,
      v: {
        // 取本地数据转换函数
        id: string;
        title: string;
        children: (
          | any
          | {
              id: string;
              label: string;
              key: string;
              type: __VLS_types_PropertyType;
              options: string[];
              value: string | string[];
              parent: any;
              data?:
                | { value: string; format: string; type: string }
                | undefined;
            }
        )[];
        parent: any | null;
        type: __VLS_types_PropertyType;
        addInputChildren: (label: string) => void;
        changeChild2Unit: (child: Property) => Unit;
      }
    ) {
      this.templateInfo[i] = v;
    },
    returnTemplate(val: string) {
      this.$emit("returnTemplate", val);
    },
    //  查询模板
    async obtainTemplateInformation() {
      //   获取个人模板||获取系统模板
      // let url = "";
      // if (this.isActive) {
      //   url = URLS.SYS_TMPL_GET;
      // } else {
      //   url = URLS.TEMPLATE_DETAIL;
      // }
      const data = await $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="scss" scoped>
:deep(.root_unit) {
  pointer-events: none;
  .input-box {
    input {
      width: 500px;
    }
  }
  .date-picker {
    width: 500px;
  }
}

.body {
  background: rgba(255, 255, 255, 1);
  border-radius: 10px;
  .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: 400px;
    overflow: auto;
  }
}
</style>
