DrawerEdit.vue 5.85 KB
<template>
  <BasicDrawer
    v-cloakv-bind="$attrs"
    @register="register"
    title="新增邮件发送"
    width="35%"
    showFooter
    @ok="handleSubmit"
    ref="formRef"
    okText="保存"
    :destroyOnClose="true"
    :isDetail="true"
    :showDetailBack="false"
    :mask="false"
    class="z-20"
  >
    <div>
      <BasicForm @register="registerForm" />
    </div>
    <!-- <div>客户编码</div>
    <textarea></textarea> -->
  </BasicDrawer>
</template>
<script lang="ts" setup>
  import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
  import { BasicForm, FormSchema, useForm } from '@/components/Form';
  import { defineComponent, ref, computed, unref, toRaw, reactive } from 'vue';
  import { getEmailList } from '/@/api/sys/config';

  const emit = defineEmits(['success']);
  // const isUpdate = ref(true);
  const schemas: FormSchema[] = [
    {
      field: 'typeValue',
      component: 'Select',
      label: '客户编码',
      componentProps: {
        disabled: 'Select',
      },
      colProps: {
        span: 23,
      },
      defaultValue: '',
    },
    {
      field: 'configSample',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '确认样品确认状态(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'otherSample',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '其他需求样品发送时间(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'bigSample',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '大货样确认意见(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'aitexSgsTest',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: 'AITEX/SGS测试状态(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'barcodeArrival',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '要求包装到货日期(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'latestDc',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '最晚订舱时间(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'endCheckDate',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '尾期验货日期(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'midCheckReport',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '中期验货报告(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'endCheckReport',
      component: 'InputTextArea',
      labelWidth: 250,
      colProps: {
        span: 23,
      },
      label: '尾期验货报告(填写邮箱)',
      rules: [{ required: true }],
    },
    {
      field: 'id',
    },
    {
      field: 'type',
    },
  ];
  const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
    labelWidth: 120,
    schemas,
    layout: 'vertical',
    showActionButtonGroup: false,
    actionColOptions: {
      span: 24,
    },
  });
  const [register, { setDrawerProps, closeDrawer }] = useDrawerInner((data) => {
    // 方式1
    resetFields();
    setDrawerProps({ confirmLoading: false });
    console.log(data.data, 666);
    // setFieldsValue({
    //   settingValue: data.data.settingValue,
    //   enableFlag: data.data.enableFlag,
    //   // settingValue: data.info,
    // });
    setFieldsValue({
      ...toRaw(data.data),
    });
  });
  // function replaceChineseCommas(text: string): string {
  //   // 使用正则表达式替换中文逗号
  //   const replacedText = text.replace(/,/g, ',');
  //   return replacedText;
  // }
  async function getData() {
    const emailAll = await getEmailList({});
    return emailAll;
  }
  interface NewValues {
    id: string;
    type: string;
    typeValue: string;
    configInfos: any[];
  }
  async function handleSubmit() {
    try {
      const values = await validate();
      console.log(values, '5656values1');
      const newValues = ref<NewValues>({
        id: '',
        type: '',
        typeValue: '',
        configInfos: [],
      });
      newValues.value.id = values.id;
      newValues.value.type = values.type;
      newValues.value.typeValue = values.typeValue;
      console.log(newValues.value.id, '5656idwd');
      getData().then((res) => {
        console.log(res, 5656111);
        for (const value1 of res) {
          //循环整个列表,找出编辑行
          if (value1.id == values.id) {
            // test.value = value1;
            newValues.value.configInfos = value1.configInfos;
            console.log(newValues.value, '5656fornewvalue');
            for (const value2 of newValues.value.configInfos) {
              //遍历所有邮件事件
              // console.log(value2, '5656value2');
              for (const value3 in values) {
                //遍历编辑框传递数据
                // console.log(value3, '5656value3');
                if (value2.fieldValue == value3) {
                  const arr: string[] = values[value3].split(/[,|,]/);
                  value2.emails = arr;
                  console.log(value2.emails, '5656value2.emails');
                }
              }
            }
          }
        }
        console.log(newValues.value, 56566);
        emit('success', {
          values: { ...newValues.value },
        });
      });
      setDrawerProps({ confirmLoading: true });
      closeDrawer();
    } finally {
      setDrawerProps({ confirmLoading: false });
    }
  }
</script>