<template>
  <a-card>
    <sd-detail-form
      v-if="showForm"
      ref="docform"
      :record-id="docId"
      :page-id="pageId"
      :class="$style.docform"
      @saved="fwSaved"
    >
      <template>
        <sd-form-item name="kmAdminMember" />
      </template>
    </sd-detail-form>
  </a-card>
</template>

<script>
import { Message } from 'ant-design-vue'
import KmKnowledageService from '../km-knowledage-service'
import components from './_import-components/km-set-km-admin-import'

export default {
  name: 'KmSetKmAdmin',
  metaInfo: {
    title: '设置KM管理员',
  },
  components,
  data() {
    return {
      pageId: 'km/admin/kmAdmin',
      docId: null,
      showForm: false,
    }
  },
  created() {
    this.getFirstDocData()
  },
  methods: {
    // 进来的时候先调用列表接口，然后打开第一条文档，没有的话打开新建的页面
    getFirstDocData() {
      KmKnowledageService.getKmId().then((res) => {
        if (res.data !== -1) {
          this.docId = res.data
          this.showForm = true
        } else {
          this.docId = undefined
          this.showForm = true
        }
      })
    },
    fwSaved() {
      Message.success('保存成功')
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.docform {
  width: 60%;
  margin: 5% auto 0;
  :global(.sd-form-btns-close) {
    display: none;
  }
}
</style>
