<template>
  <audit-form-top-banner>
    <sd-detail-form
      ref="docform"
      form-id="iamArchivesMaintain"
      page-id="audit/archives/iamArchivesMaintain"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      :class="$style.form"
      :read-only="readOnly"
      @close="close(true)"
    >
      <template v-slot="{ model, fields }">
        <table>
          <tr>
            <td style="border:none;padding-left:5px">
              <audit-advanced-group
                :expand="templateExpand"
                :expand-str="'templateExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="templateExpand">
          <tr>
            <!-- 项目名称 -->
            <sd-form-item-td name="projectName">{{ model.projectName }}</sd-form-item-td>
            <!-- 档案编号 -->
            <sd-form-item-td name="archivesCode">{{ model.archivesCode }}</sd-form-item-td>
          </tr>
          <tr>
            <!-- 档案类型 -->
            <sd-form-item-td name="archivesType" :colspan="3">
              <span v-if="model.archivesType === 'SYSTEM_FILE'">系统档案</span>
              <span v-if="model.archivesType === 'HISTORY_FILE'">历史档案</span>
              <span v-if="model.archivesType === 'OFFLINE_FILE'">线下档案</span></sd-form-item-td
            >
          </tr>
          <tr>
            <!-- 简要描述 -->
            <sd-form-item-td name="brieflyDesc" :colspan="3"
              >{{ model.brieflyDesc }}
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 案卷状态 -->
            <sd-form-item-td name="fileState" :colspan="3">
              <span v-if="model.fileState === 'FILING'" :value="'FILING'"> 立卷</span>
              <span v-if="model.fileState === 'STAY_FILE'" :value="'STAY_FILE'"> 待归档</span>
              <span v-if="model.fileState === 'ALREADY_FILE'" :value="'ALREADY_FILE'">已归档</span>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 最后修改时间 -->
            <sd-form-item-td name="lastModifiedTime">{{ model.lastModifiedTime }} </sd-form-item-td>
            <!-- 归档日期 -->
            <sd-form-item-td name="filingDate">{{ format(model.filingDate) }} </sd-form-item-td>
          </tr>
          <tr>
            <!-- 编制人员 -->
            <sd-form-item-td name="creatorName">{{ model.creatorName }} </sd-form-item-td>
            <!-- 编制日期 -->
            <sd-form-item-td name="creationTime">{{ model.creationTime }} </sd-form-item-td>
          </tr>
        </table>

        <table>
          <tr>
            <td style="border:none;padding-left:5px">
              <audit-advanced-group
                :expand="expandA"
                :expand-str="'expandA'"
                :group-label="'案卷信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="expandA">
          <AuditArchivesTree
            :columns="childAJColumns"
            form-id="iamDossierData"
            page-id="audit/archives/iamDossierData"
            :treeparams="{
              configId: '22',
            }"
            :change="treechange"
            :dossierId="dossierId"
          >
          </AuditArchivesTree>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import TableColumnTypes from '@/common/services/table-column-types'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import AuditArchivesTree from '../archives/audit-archives-tree'
import components from './_import-components/audit-archives-view-import'

export default {
  name: 'AuditArchivesView',
  metaInfo: {
    title: '档案管理',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
    AuditArchivesTree,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      treeId: '',
      expandA: true,
      saveFlag: true,
      readOnly: true,
      templateExpand: true,
      childAJColumns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
        },
        { dataIndex: 'id', sdHidden: true },

        {
          title: '文件名称',
          dataIndex: 'docTitle',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '编制人员',
          dataIndex: 'creatorName',
        },
        {
          title: '编制日期',
          dataIndex: 'creationTime',
          defaultSortOrder: 'descend', // 没有点击任何排序列时，默认的排序列
          sdRender: TableColumnTypes.dateTime,
        },
      ],

      recordId: '',
      dossierId: '',
    }
  },
  created() {
    if (this.$route.query.record) {
      this.recordId = this.$route.query.record
    }
    if (this.$route.query.dossierId) {
      this.dossierId = this.$route.query.dossierId
    }
  },
  methods: {
    add0(m) {
      return m < 10 ? '0' + m : m
    },
    format(shijianchuo) {
      // shijianchuo是整数，否则要parseInt转换
      var time = new Date(shijianchuo)
      var y = time.getFullYear()
      var m = time.getMonth() + 1
      var d = time.getDate()
      return y + '-' + this.add0(m) + '-' + this.add0(d)
    },

    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    treechange(id) {
      this.treeId = id
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
</style>
