CheckDetail.vue 4.75 KB
<template>
  <BasicDrawer
    @register="register"
    v-bind="$attrs"
    showFooter
    title="字段编辑权限申请"
    width="60%"
    :isDetail="true"
    @ok="handleSubmit"
    :showDetailBack="false"
    okText="申请"
    ><input />
    <div>
      <h3>基本信息</h3>
      <BasicForm @register="registerForm" />
      <h3>利润分析</h3>
      <BasicForm @register="registerProfitForm" />
      <h3>项目报告书</h3>
      <BasicForm @register="registerReportForm" />
    </div>
    <!-- <template #titleToolbar> <a-button type="primary"> 申请编辑权限 </a-button></template> -->

    <!-- <template #appendFooter>
      <a-button type="primary" @click="onGoFormDetail"> 返回编辑</a-button>
    </template> -->
  </BasicDrawer>
</template>
<script lang="ts">
  import { defineComponent, reactive, ref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { orderAuth } from '/@/api/project/order';

  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { FIELDS_BASE_INFO, FIELDS_PROFIT_INFO, FIELDS_REPORT_INFO } from './tableData';

  const getSchema = (fields) =>
    fields.map((item) => ({
      field: `${item.field}`,
      dataIndex: `${item.field}`,
      label: item.label,
      component: 'Switch',
      componentProps: {
        checkedValue: 'UN_LOCKED',
        unCheckedValue: 'LOCKED',
      },
      colProps: {
        span: 6,
      },
    }));

  export default defineComponent({
    components: { BasicDrawer, BasicForm },
    props: {
      onGoFormDetail: {
        type: Function,
      },
    },
    setup() {
      const id = ref('');
      const schemas = getSchema(FIELDS_BASE_INFO);
      const profitSchemas = getSchema(FIELDS_PROFIT_INFO);
      const reportSchemas = getSchema(FIELDS_REPORT_INFO);
      const [registerForm, { getFieldsValue }] = useForm({
        labelWidth: 120,
        schemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const [registerProfitForm, { getFieldsValue: getProfitFieldsValue }] = useForm({
        labelWidth: 120,
        schemas: profitSchemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const [registerReportForm, { getFieldsValue: getReportFieldsValue }] = useForm({
        labelWidth: 120,
        schemas: reportSchemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const lockFields = reactive({});
      const [register, { closeDrawer }] = useDrawerInner((data) => {
        Object.assign(lockFields, data.lockFields);
        id.value = data.id;
      });

      const handleSubmit = async () => {
        const baseFieldValues = getFieldsValue();
        const profitFieldValues = getProfitFieldsValue();
        const reportFieldValues = getReportFieldsValue();

        FIELDS_BASE_INFO.map(
          ({ field }) =>
            (baseFieldValues[field] =
              baseFieldValues[field] === 'UN_LOCKED' ? 'UN_LOCKED' : 'LOCKED'),
        );

        FIELDS_REPORT_INFO.map(
          ({ field }) =>
            (reportFieldValues[field] =
              reportFieldValues[field] === 'UN_LOCKED' ? 'UN_LOCKED' : 'LOCKED'),
        );

        FIELDS_PROFIT_INFO.map(
          ({ field }) =>
            (profitFieldValues[field] =
              profitFieldValues[field] === 'UN_LOCKED' ? 'UN_LOCKED' : 'LOCKED'),
        );

        // !isEmpty(baseFieldValues) &&
        //   Object.keys(baseFieldValues.baseFields)?.map((key) => {
        //     baseFieldValues.baseFields[key] = baseFieldValues.baseFields[key]
        //       ? 'UN_LOCKED'
        //       : 'LOCKED';
        //   });

        // !isEmpty(profitFieldValues) &&
        //   Object.keys(profitFieldValues.profitAnalysisFields).map((key) => {
        //     profitFieldValues.profitAnalysisFields[key] = profitFieldValues.profitAnalysisFields[
        //       key
        //     ]
        //       ? 'UN_LOCKED'
        //       : 'LOCKED';
        //   });

        // !isEmpty(reportFieldValues) &&
        //   Object.keys(reportFieldValues.reportFields).map((key) => {
        //     reportFieldValues.reportFields[key] = reportFieldValues.reportFields[key]
        //       ? 'UN_LOCKED'
        //       : 'LOCKED';
        //   });

        const values = Object.assign(
          { orderId: id.value },
          { baseFields: baseFieldValues },
          { profitAnalysisFields: profitFieldValues },
          { reportFields: reportFieldValues },
        );
        await orderAuth(values);
        closeDrawer();
      };
      return {
        register,
        schemas,
        registerForm,
        registerProfitForm,
        registerReportForm,
        handleSubmit,
      };
    },
  });
</script>