<template>
  <sd-webflow ref="flow" :validate-form="validForm">
    <template v-slot:form="{ model }">
      <table>
        <tr>
          <sd-form-item-td name="title" :colspan="3" />
        </tr>
        <tr>
          <sd-form-item-td name="type" :colspan="3" />
        </tr>
        <tr>
          <sd-form-item-td :hidden="model.type === '0'" name="returnDate" :colspan="3">
            <a-date-picker
              v-model="model.returnDate"
              format="YYYY-MM-DD"
              :disabled-date="disabledDate"
            />
          </sd-form-item-td>
        </tr>
        <tr>
          <sd-form-item-td name="borrower" />
          <sd-form-item-td name="creationTime" />
        </tr>
      </table>
    </template>
  </sd-webflow>
</template>

<script>
import { Message } from 'ant-design-vue'
import moment from 'moment'
import components from './_import-components/km-knowledge-borrow-import'

export default {
  name: 'KmKnowledgeBorrow',
  metaInfo: {
    title: 'OaKnowledgeBorrow',
  },
  components,
  data() {
    return {}
  },
  methods: {
    validForm() {
      return new Promise((resolve, reject) => {
        let validate = true
        const params = this.$refs.flow.getFieldsValue()
        if (params.type === '1') {
          if (params.returnDate === undefined) {
            validate = false
            Message.warn('请选择归还日期')
          }
        }
        resolve(validate)
      })
    },

    disabledDate(current) {
      return current && current < moment().subtract(1, 'days')
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
