<template>
  <Page :left="leftFuns">
    <TenantForm ref="formIns"/>
  </Page>
</template>

<script lang="ts" setup>
import Page from '@/components/page/Page.vue'
import Nav from '@/common/router/nav.ts'
import Toast from '@/components/toast'
import TenantForm from '@/pages/sys/tenant/tenant-form/TenantForm.vue'
import TenantApi from '@/pages/sys/tenant/tenant-api.ts'

const formIns = ref<InstanceType<typeof TenantForm> | null>(null)

const leftFuns = computed<PageTypes.Fun[]>(() => {
  return [
    {
      title: '查看列表',
      mode: 'text',
      icon: 'view-list',
      onClick() {
        Nav.open('tenant')
      }
    },
    {
      title: '提交',
      mode: 'text',
      icon: 'check',
      onClick() {
        const value = formIns.value!.getValue()
        if (value == null) return
        const toastId = Toast.loading('正在提交')
        TenantApi.add(value)
            .then(_ => {
              Toast.success('添加成功')
              formIns.value!.reset()
            })
            .catch(_ => {
              Toast.error('添加失败')
            })
            .finally(() => {
              Toast.close(toastId)
            })
      }
    },
  ]
})

</script>

<style lang="stylus" scoped>
</style>
