<template>
  <audit-form-top-banner :handel-save-form="saveForm" @handelSaveForm="saveForm">
    <sd-detail-form
      ref="docform"
      :class="$style.form"
      form-id="spicDesensitize"
      page-id="audit/spicdesensitize/spicDesensitize"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      @saved="saved"
      @close="close(true)"
    >
      <template v-slot="{ model, fields }">
        <table>
          <audit-advanced-group group-label="基本信息"> </audit-advanced-group>
        </table>

        <table>
          <tr>
            <sd-form-item-td name="title" :colspan="3" />
          </tr>
        </table>

        <table>
          <tr
            ><td :colspan="4">
              <sd-form-item name="sensitiveWordConfiguration" :label="null">
                <template v-slot:read-and-edit="{ editable }">
                  <audit-advanced-group
                    :expand="sensitiveWordExpand"
                    :expand-str="'sensitiveWordExpand'"
                    :group-label="'敏感词'"
                    @changedClick="changedClick"
                  >
                    <template>
                      <sd-child-table
                        ref="sensitiveWord"
                        :class="$style.deptPlanChild"
                        v-model="model.sensitiveWordConfiguration"
                        label=""
                        :read-only="!editable"
                        :sequence-column="true"
                        :fields="Array.from(fields.sensitiveWordConfiguration.attr.dync)"
                        :columns="columns"
                        :flagpage="true"
                        @change="changeNum"
                      >
                        <!-- input-form 表示这部分是子表组件的form插槽 -->
                        <template v-slot:form="{ model, fields }">
                          <table style="width: 80%">
                            <tr>
                              <sd-form-item-td name="name" :colspan="3" />
                            </tr>
                          </table>
                        </template>
                      </sd-child-table>
                    </template>
                  </audit-advanced-group>
                </template> </sd-form-item
            ></td>
          </tr>
        </table>

        <!-- <table>
          <sd-form-item label="" name="sensitiveWordConfiguration">
            <audit-advanced-group group-label="敏感词配置">
              <xm-child-table
                v-model="model.sensitiveWordConfiguration"
                :hide-pagination="hidePagination"
                :columns="columns"
                :fields="
                  [
                    {
                      caption: '序号',
                      name: 'sortNum',
                      dataType: 'sortNum',
                    },
                  ].concat(Array.from(fields.sensitiveWordConfiguration.attr.dync).slice(0, 2))
                "
              >
              </xm-child-table>
            </audit-advanced-group>
          </sd-form-item>
        </table> -->
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import { Message, Modal } from 'ant-design-vue'
import debounce from 'lodash.debounce'
import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '@product/iam/components/audit-form-top-banner'
import auditAdvancedGroup from '@product/iam/components/audit-advanced-group.vue'
import xmChildTable from '@product/iam/components/xm-child-table'
import components from './_import-components/xm-spic-desensitize-config-form-import'

export default {
  name: 'XmSpicDesensitizeConfigForm',
  metaInfo: {
    title: '脱敏关键词配置',
  },
  components: {
    ...components,
    auditFormTopBanner,
    auditAdvancedGroup,
    // xmChildTable,
  },
  data() {
    return {
      sensitiveWordExpand: true,
      mainId: '',
      columns: [
        {
          title: '序号',
          dataIndex: 'sortNum',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        { dataIndex: 'mainId', sdHidden: true },
        {
          title: '关键词',
          dataIndex: 'name',
        },
      ],
    }
  },
  created() {
    setTimeout(() => {
      // 當前ID
      if (this.$route.query.record !== '' || this.$route.query.record !== undefined) {
        this.mainId = this.$route.query.record
      }
    }, 1000)
  },
  methods: {
    saveForm() {
      this.$refs.docform.saveBtnClick()
      // this.$refs.docform.validateFields().then(() => {
      //   Message.success('保存成功').then(() => {
      //     this.$refs.docform.saveBtnClick()
      //   })
      // })
    },
    saved() {
      Message.success('保存成功', 1).then((res) => {
        this.close(true)
      })
      // this.close(true)
    },
    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    changeNum(data) {
      data.forEach((item, index) => {
        item.sortNum = index + 1
      })
    },
  },
}
</script>

<style module lang="scss">
@import '@/webflow/sd-flow-form.scss';
</style>
