<template>
  <div class="p-4">
    <BasicForm @register="register" @submit="handleSubmit" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { clean } from '/@/api/staff/list';
  // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  export default defineComponent({
    components: {
      BasicForm,
    },
    setup() {
      const { t } = useI18n();
      const { createMessage } = useMessage();
      const schemas: FormSchema[] = [
        {
          field: 'userName',
          component: 'Input',
          label: '手机号',
          colProps: {
            span: 8,
          },
          componentProps: {
            // type:"number"
          },
          rules: [
            {
              required: true,
              // @ts-ignore
              validator: async (rule, value) => {
                var reg_tel =
                  /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                // var reg = /\S+@\S+\.\S+/;
                if (!value) {
                  /* eslint-disable-next-line */

                  return Promise.reject(t('common.phone'));
                }
                if (!reg_tel.test(value)) {
                  /* eslint-disable-next-line */
                  return Promise.reject(t('common.phoneError'));
                }
                return Promise.resolve();
              },
              trigger: 'change',
            },
          ],
        },
      ];
      const [register, { setProps, validate, resetFields }] = useForm({
        labelWidth: 120,
        schemas,
        actionColOptions: {
          span: 4,
        },
        submitButtonOptions: {
          text: '清除状态',
        },
      });
      async function handleSubmit() {
        let data = await validate();
        await clean({ userName: data.userName }); //
        createMessage.success(t('common.optSuccess'));
        setTimeout(() => resetFields(), 500);
      }
      return {
        handleSubmit,
        setProps,
        register,
      };
    },
  });
</script>
