<template>
  <el-dialog v-model="visible" title="查看">
    <el-descriptions :column="1" border>
      <el-descriptions-item :label="labelName">
        {{ info.REMARKS }}
      </el-descriptions-item>
      <el-descriptions-item label="规程属性">
        {{
          info.CATEGORY_LIST.map((item) => item.CATEGORY_NAME)
            .filter(Boolean)
            .join("、")
        }}
      </el-descriptions-item>
      <el-descriptions-item label="类型">
        {{
          info.TYPES.map((item) => item.CATEGORY_NAME)
            .filter(Boolean)
            .join("、")
        }}
      </el-descriptions-item>
      <el-descriptions-item label="国民经济行业类型">
        {{
          info.SPECIFICATION_TYPES.map((item) => item.CATEGORY_NAME)
            .filter(Boolean)
            .join("、")
        }}
      </el-descriptions-item>
      <el-descriptions-item label="上传时间">
        {{ info.UPLOAD_TIME }}
      </el-descriptions-item>
      <el-descriptions-item label="上传人">
        {{ info.UPLOAD_USER_NAME }}
      </el-descriptions-item>
      <el-descriptions-item label="标签">
        {{
          info.labels
            .map((item) => item.NAME)
            .filter(Boolean)
            .join("、")
        }}
      </el-descriptions-item>
      <el-descriptions-item label="文件">
        {{ getFileName(info.PATH) }}
        <el-button
          type="primary"
          class="ml-10"
          @click="useDownloadFile(info.PATH)"
        >
          下载
        </el-button>
      </el-descriptions-item>
      <el-descriptions-item label="文件内容">
        <div v-html="info.TEXT_INFO" />
        <el-button v-if="info.TEXT_INFO" type="primary" @click="fnExport">
          导出WORD
        </el-button>
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <el-button @click="visible = false">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { useVModel } from "@vueuse/core";
import { getFileName } from "@/assets/js/utils.js";
import useDownloadFile from "@/assets/js/useDownloadFile.js";

const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
    default: false,
  },
  info: {
    type: Object,
    required: true,
    default: () => ({}),
  },
  labelName: {
    type: String,
    required: true,
    default: "",
  },
});
const emits = defineEmits(["update:visible"]);
const visible = useVModel(props, "visible", emits);
const fnExport = () => {
  window.location.href =
    import.meta.env[import.meta.env.DEV ? "VITE_PROXY" : "VITE_BASE_URL"] +
    "/textLibrary/exportWord?BUS_TEXT_LIBRARY_ID=" +
    props.info.BUS_TEXT_LIBRARY_ID;
};
</script>

<style scoped lang="scss"></style>
