<template>
  <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
    <sd-detail-form
      ref="docform"
      :page-id="this.$route.query.pageId ? this.$route.query.pageId : null"
      :record-id="this.id"
      :read-only="false"
      :class="[$style.form]"
      @close="close(true)"
      @saved="saved"
    >
      <template v-slot="{ formData, model, fields }">
        <table :class="$style.detailForm">
          <tr>
            <td colspan="4" style="border:none">
              <sd-form-by-builder :form-data="initDaF(formData.pageFormData)"></sd-form-by-builder>
            </td>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import { message } from '@/common/one-ui'
import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
import components from './_import-components/cpm-committee-form-import'

export default {
  name: 'CpmCommitteeForm',
  metaInfo: {
    title: '委员会专题纪要',
  },
  components: {
    ...components,
    auditFormTopBanner,
  },
  data() {
    return {
      initialled: false,
      id: this.$route.query.id ? this.$route.query.id : '',
      flag: true,
    }
  },
  methods: {
    saved(t) {
      const idobj = t.pageFormData.pageFieldInfos.find((i) => i.name === 'id').value
      this.id = idobj
      const id = this.$route.params.id ? this.$route.params.id : this.$route.query.id
      if (id === null || id === undefined || id === '') {
        let path = this.$route.fullPath
        path = path.replace('?id=&pageId', '?id=' + this.id + '&pageId')
        window.location.href = '#' + path
      }
      message.success({ content: '保存成功！' }, 1).then(() => {})
    },
    // 保存
    saveForm() {
      this.$refs.docform.saveBtnClick()
    },
    close(flag) {
      window.close()
    },
    initDaF(array) {
      if (array) {
        array.attrFD.keepHiddenCell = false
      }
      return array
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
@import '@/webflow/sd-flow-form.scss';
.detailForm {
  width: 100% !important;
  margin: 0;
  :global(.sd-form-table) {
    width: 90% !important;
  }
}
</style>
