<script lang="ts" setup>
import {Page, useVbenModal} from '@vben/common-ui';

import {message} from 'ant-design-vue';

import {passwordModalForm} from '#/layouts/config/form.ts'
import {useVbenForm} from "#/adapter/form";
import {updatePassword} from "#/views/system/admin/api";

const [Form, formApi] = useVbenForm(passwordModalForm);
const [Modal, modalApi] = useVbenModal({
  fullscreenButton: false,
  draggable: true,
  onCancel() {
    modalApi.close();
  },
  onConfirm: async () => {
    formApi.validate().then(async (e: any) => {
      if (e.valid) {
        const values = await formApi.getValues();
        modalApi.setState({loading: true, confirmLoading: true});
        updatePassword(values).then(() => {
          modalApi.close();
          message.success('修改成功，请重新登录');
        })
          .finally(() => {
            modalApi.setState({loading: false, confirmLoading: false});
          });
      }
    });
    await formApi.validateAndSubmitForm();
  },
});
</script>

<template>
  <!--  <Modal class="w-[60%]" title="西（中成）药列表">-->
  <Modal class="w-[60%]" title="修改密码">
    <Page>
      <Form/>
    </Page>
  </Modal>
</template>
<style lang="scss"></style>
