EnterpriseInfo.vue 2.16 KB
<template>
  <div class="card">
    <Card :bordered="false" class="card"> <BasicForm @register="registerForm" /></Card>
    <Loading v-bind="compState" />
    <a-button
      @click="handleUpdateInfo"
      size="large"
      type="primary"
      style="margin-top: 20px; background-color: #2950f7; border-radius: 5px"
      >更新基本信息</a-button
    >
  </div>
</template>

<script lang="ts">
  import { defineComponent, onMounted, ref } from 'vue';
  import { Card } from 'ant-design-vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { schemas } from '../config/enterPriseInfo.config';
  import { getEnterPriseDetail, updateEnterPriseDetail } from '/@/api/oem/index';
  import { Loading } from '/@/components/Loading';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    components: {
      Card,
      BasicForm,
      Loading,
    },
    setup() {
      const compState = ref({
        absolute: false,
        loading: false,
        tip: '拼命加载中...',
      });
      const [registerForm, { getFieldsValue, setFieldsValue }] = useForm({
        labelWidth: 80,
        schemas,
        showResetButton: false,
        showSubmitButton: false,
        wrapperCol: {
          span: 10,
        },
      });
      const { createMessage } = useMessage();
      const handleUpdateInfo = async () => {
        try {
          compState.value.loading = true;
          const fieldsValue = getFieldsValue();
          await updateEnterPriseDetail({
            ...fieldsValue,
            codeProv: fieldsValue.nameProv,
            codeCity: fieldsValue.nameCity,
            codeCoun: fieldsValue.nameCoun,
            codeTown: fieldsValue.nameTown,
          });
          compState.value.loading = false;
          createMessage.success('更新信息成功');
        } catch (e) {
          createMessage.error('更新信息失败');
        }
      };
      onMounted(async () => {
        const res = await getEnterPriseDetail();
        setFieldsValue(res);
      });

      return {
        registerForm,
        compState,
        handleUpdateInfo,
      };
    },
  });
</script>

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