<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 cpmService from '../../cpm-service.js'
import components from './_import-components/cpm-improve-rect-problem-form-import'

export default {
  name: 'CpmImproveRectProblemForm',
  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((r) => {})
    },
    // 保存
    saveForm() {
      this.$refs.docform.saveBtnClick()
    },
    close(flag) {
      window.close()
    },
    initDaF(array) {
      if (array) {
        array.attrFD.keepHiddenCell = false
      }
      if (this.flag) {
        setTimeout(() => {
          this.$refs.docform.setFieldValue('BASE_INFO', 'true')
          this.$refs.docform.setFieldValue('SUPPORT_LIST', 'true')
        }, 1000)
        this.flag = false
      }
      return array
    },
  },
}
</script>

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