<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.$route.query.id ? this.$route.query.id : null"
      :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 LawService from '../../law-service'
import components from './_import-components/case-execute-procedure-form-import'

export default {
  name: 'CaseExecuteProcedureForm',
  metaInfo: {
    title: '案件执行程序页面配置',
  },
  components: {
    ...components,
    auditFormTopBanner,
  },
  data() {
    return {
      initialled: false,
      id: null,
      flag: true,
    }
  },
  methods: {
    saved() {
      message.success({ content: '保存成功！' }, 1).then(() => {})
    },
    // 保存
    saveForm() {
      const appCode = this.$refs.docform.getFieldValue('EXECUTE_CODE')
      const id = this.$refs.docform.getFieldValue('id')
        ? this.$refs.docform.getFieldValue('id')
        : -1
      LawService.getCaseExecuteCode(appCode, id).then((res) => {
        if (res.data) {
          message.error('该执行程序已存在请重新选择！')
        } else {
          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>
