<template>
  <div>
    <sd-webflow ref="flow" :removed-tabs="['sdRelatedDoc']">
      <template v-slot:form="{ model, fields }">
        <table>
          <tr>
            <td style="border: none">
              <audit-advanced-group
                :expand="planExpand"
                :expand-str="'planExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="planExpand">
          <tr v-show="initData()">
            <!-- 隐藏行，用来计算数据 -->
            <!-- 内控计划ID -->
            <sd-form-item-td name="planId" />
          </tr>
          <tr>
            <!-- 报告名称 -->
            <sd-form-item-td name="reportName" />
            <!-- 报告文号 -->
            <sd-form-item-td name="reportNumber" />
          </tr>
          <tr>
            <!-- 被评价单位 -->
            <sd-form-item-td name="evaluatedUnitOpt" :colspan="3">
              <audit-group-picker
                v-model="model.evaluatedUnitOpt"
                :selectclick="selectclick"
                :root-node="rootNode"
              />
            </sd-form-item-td>
          </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="attachment" :colspan="3" />
          </tr>
        </table>
      </template>
    </sd-webflow>
  </div>
</template>

<script>
import auditGroupPicker from '@product/iam/components/picker/audit-group-picker.vue'
import auditAdvancedGroup from '@product/iam/components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '@product/iam/components/audit-advanced-group-mixins'
import iamIcEvaluationReportServices from './iam-ic-evaluation-report-service'
import components from './_import-components/iam-ic-evaluation-report-form-import'
// 修改主子表的首行title名
export default {
  name: 'IamIcEvaluationReportForm',
  metaInfo: {
    title: '内控评价报告',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditGroupPicker,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      rootNode: {},
      childTableKey: 0, // 刷新子表组件
      inited: true,
      planExpand: true,
      FpdwExpand: true,
      expand: true,
      planId: null,
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          width: '50px',
          customRender: (text, record, index) => `${index + 1}`,
        },
        {
          dataIndex: 'unitName',
          title: '单位名称',
          width: '120px',
        },
        { dataIndex: 'unitOpt' },
        {
          title: '联系人',
          dataIndex: 'contactsName',
        },
      ],
      yearArry: [],
      expressions: [],
      externalUnitIds: [],
      isIni: false, // 是否已经初始化
      icEvaluationPlanUnitList: [],
    }
  },
  mounted() {
    // 加载时，记录planId
    if (this.$route.query.extParams.indexOf('planId') !== -1) {
      this.planId = parseFloat(JSON.parse(this.$route.query.extParams).planId)
    }
  },
  methods: {
    selectclick() {
      return false
    },
    initData() {
      // 如果不是起草，则直接退出，不需要获取计划信息了
      if (!this.planId | this.isIni) return false
      this.isIni = true
      // 生成标题
      iamIcEvaluationReportServices.getPlanInfo(this.planId).then((res) => {
        if (res.status === 200) {
          const planTitle = res.data.pageFormData.pageFieldInfos.find((item) => {
            return item.name === 'evaluationName'
          }).value
          this.$refs.flow.setFieldValue('reportName', planTitle + '的内控评价报告')
        }
      })
      // 获取所有被评价单位
      iamIcEvaluationReportServices.getDvaluationDept(parseFloat(this.planId)).then((res) => {
        if (res.status === 200) {
          this.$refs.flow.setFieldValue('evaluatedUnitOpt', res.data)
        }
      })
      return false
    },
    actionBtnClick(evt, { button, FlowData }) {
      if (button.fakeId === 'save' || button.fakeId === 'workflow-push') {
      }
    },
  },
}
</script>

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

.btnselect {
  position: relative;
  top: 4px;
  float: right;
  .batchselect {
    z-index: 100;
    margin-right: 80px;
  }
}
</style>
