<template>
  <div>
    <sd-webflow ref="flow" :removed-tabs="['sdRelatedDoc']">
      <template v-slot:form="{ model, fields }">
        <table>
          <colgroup style="width:160px"></colgroup>
          <colgroup></colgroup>
          <colgroup style="width:160px"></colgroup>
          <colgroup></colgroup>
          <tr>
            <!-- 报告年度 -->
            <sd-form-item-td name="reportYear" :colspan="3">
              <a-date-picker
                v-model="model.reportYear"
                mode="year"
                picker="YYYY"
                format="YYYY"
                :allow-clear="false"
                placeholder="选择年度"
                :input-read-only="true"
                :value="year"
                :open="endOpen"
                @panelChange="yearChange"
                @openChange="handleEndOpenChange"
              ></a-date-picker>
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 报告名称 -->
            <sd-form-item-td name="title" v-show="initData(model)"/>
            <!-- 报告文号 -->
            <sd-form-item-td name="reportNumber" />
          </tr>
          <tr>
            <!-- 报告类型 -->
            <sd-form-item-td name="reportType" />
            <!-- 文书编号 -->
            <sd-form-item-td name="docNumber" />
          </tr>
          <tr>
            <!-- 报告内容 -->
            <sd-form-item-td name="reportDesc" :colspan="3">
              <a-textarea v-model="model.reportDesc" :auto-size="{ maxRows: 3, minRows: 3 }" />
            </sd-form-item-td>
          </tr>
          <tr>
            <!-- 创建人 -->
            <sd-form-item-td name="creatorName" />
            <!-- 编制日期 -->
            <sd-form-item-td name="creationTime" />
          </tr>
          <tr>
            <!-- 创建单位 -->
            <sd-form-item-td name="createDeptName" />
          </tr>
          <tr>
            <!-- 附件 -->
            <sd-form-item-td name="attachment" :colspan="3">
              <template v-slot:read-and-edit="{ editable }">
                <sd-attachment
                  v-model="model.attachment"
                  :group-id="JSON.parse(fields.attachment.value).value"
                  :read-only="!editable"
                ></sd-attachment>
              </template>
            </sd-form-item-td>
          </tr>
        </table>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import moment from 'moment'
import components from './_import-components/risk-report-form-import'
export default {
  name: 'RiskReportForm',
  metaInfo: {
    title: '风险报告',
  },
  components,
  data() {
    return {
      year: null,
      endOpen: false,
      flag:true,
    }
  },
  mounted() {},
  methods: {
    initData(model){
      if(this.flag){
        this.flag = false
        if(!model.reportYear){
          model.reportYear = moment(new Date()).format('YYYY')
        }
        
      }
      return true
    },
    handleEndOpenChange(open) {
      this.endOpen = open
    },
    yearChange(value) {
      this.year = value
      this.$refs.flow.setFieldValue('reportYear', value.format('YYYY'))
      if (document.getElementsByClassName('ant-calendar-picker-container').length > 0) {
        document.getElementsByClassName('ant-calendar-picker-container')[0].style.display = 'none'
      }
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
