<template>
  <a-card>
    <sd-detail-form
      v-show="showForm"
      ref="docform"
      page-id="onl:00788856205141a18048cfb8b01b07e7"
      :record-id="id"
      :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="formData.pageFormData"></sd-form-by-builder>
            </td>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </a-card>
</template>

<script>
import { message } from '@/common/one-ui'
import axios from '@/common/services/axios-instance'
import components from './_import-components/law-work-bench-config-import'

export default {
  name: 'LawWorkBenchConfig',
  metaInfo: {
    title: 'LawWorkBenchConfig',
  },
  components: {
    ...components,
  },
  data() {
    return {
      showForm: false,
      id: this.$route.query.id ? this.$route.query.id : '',
    }
  },
  mounted() {
    const ini = setInterval(() => {
      if (
        this.$refs.docform &&
        (this.$refs.docform.$refs.form || this.$refs.docform.$refs.sdForm)
      ) {
        clearInterval(ini)
        axios({
          method: 'post',
          url: 'api/xcoa-mobile/v1/iam-page/businessList',
          data: {
            columns: 'LAW_CASE_SHOW,LAW_DISPUTE_SHOW',
            expressions: [],
            formId: 'onlhead:00788856205141a18048cfb8b01b07e7',
            maxResults: 10,
            startPosition: 0,
          },
        }).then((res) => {
          if (res.data.data.length > 0) {
            const showCase = res.data.data[0].LAW_CASE_SHOW === '显示' ? '1' : '0'
            const showDispute = res.data.data[0].LAW_DISPUTE_SHOW === '显示' ? '1' : '0'
            this.$refs.docform.setFieldValue('LAW_CASE_SHOW', showCase)
            this.$refs.docform.setFieldValue('LAW_DISPUTE_SHOW', showDispute)
            this.id = res.data.data[0].id
          } else {
            this.$refs.docform.setFieldValue('LAW_CASE_SHOW', '0')
            this.$refs.docform.setFieldValue('LAW_DISPUTE_SHOW', '0')
          }
          this.showForm = true
        })
      }
    }, 100)
  },
  methods: {
    saved(t) {
      const idobj = t.pageFormData.pageFieldInfos.find((i) => i.name === 'id').value
      this.id = idobj
      message.success({ content: '保存成功！' }, 1)
    },
    // 保存
    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>
