<template>
  <audit-form-top-banner :handel-save-form="saveForm" :form-data="mode" @handelSaveForm="saveForm">
    <sd-detail-form
      ref="docform"
      form-id="iamDirectoryDeploy"
      page-id="audit/deploy/iamDirectoryDeploy"
      :record-id="this.$route.query.record ? parseInt(this.$route.query.record) : null"
      :class="$style.form"
      @close="close(true)"
      @saved="saved"
      @sdFormReady="sdFormReady"
    >
      <template v-slot="{ model, fields }">
        <table>
          <tr>
            <td style="border:none;padding-left:5px">
              <audit-advanced-group
                :expand="templateExpand"
                :expand-str="'templateExpand'"
                :group-label="'基本信息'"
                tablestyle="''"
                @changedClick="changedClick"
              ></audit-advanced-group>
            </td>
          </tr>
        </table>

        <table v-show="templateExpand">
          <tr>
            <!-- 目录名称 -->
            <sd-form-item-td name="contentsTitle" />
            <!-- 显示顺序 -->
            <sd-form-item-td name="contentsOrder" />
          </tr>
          <tr>
            <!-- 归辑内容 -->
            <sd-form-item-td name="collectionContent" :colspan="3" />
          </tr>
          <tr>
            <!-- 简要描述 -->
            <sd-form-item-td name="remarks" :colspan="3">
              <a-textarea v-model="model.remarks" />
            </sd-form-item-td>
          </tr>
        </table>
      </template>
    </sd-detail-form>
  </audit-form-top-banner>
</template>

<script>
import axios from '@/common/services/axios-instance'
import { Message } from 'ant-design-vue'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import auditFormTopBanner from '../../components/audit-form-top-banner'
import auditAdvancedGroup from '../../components/audit-advanced-group.vue'
import auditAdvancedGroupMixins from '../../components/audit-advanced-group-mixins'
import components from './_import-components/audit-deploy-form-import'

export default {
  name: 'AuditDeployForm',
  metaInfo: {
    title: '目录配置',
  },
  components: {
    ...components,
    auditAdvancedGroup,
    auditFormTopBanner,
  },
  mixins: [auditAdvancedGroupMixins],
  data() {
    return {
      mode: null,
      saveFlag: true,
      templateExpand: true,
    }
  },

  mounted() {
    setTimeout(() => {
      this.setAddOrder()
    }, 500)
  },
  created() {},
  methods: {
    // 页面加载完成后
    sdFormReady() {
      this.mode = this.$refs.docform.formData.mode
    },
    setAddOrder(model) {
      var id = this.$route.query.record
      const params = {
        id: id,
      }
      axios({
        url: 'api/xcoa-mobile/v1/iamdirectorydeploy/addOrder',
        method: 'post',
        params,
      }).then((res) => {
        this.$refs.docform.setFieldValue('contentsOrder', res.data)
      })
    },

    close(flag) {
      crossWindowWatcher.notifyChange(this.$route.fullPath, flag)
      window.close()
    },
    // 保存
    saveForm() {
      this.$refs.docform.validateFields().then(() => {
        Message.success('保存成功').then(() => {
          this.$refs.docform.saveBtnClick()
        })
      })
    },
    saved() {
      this.close(true)
    },
  },
}
</script>

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