CheckDetail.vue 7.39 KB
<template>
  <BasicDrawer
    @register="register"
    v-bind="$attrs"
    showFooter
    title="字段编辑权限申请"
    width="60%"
    :destroyOnClose="true"
    :isDetail="true"
    @ok="handleSubmit"
    :showDetailBack="false"
    okText="申请"
    ><input />
    <div>
      <template v-if="role === ROLE.ADMIN || role === ROLE.TRACKER">
        <h3>基本信息</h3>
        <BasicForm @register="registerForm" />
      </template>
      <template v-if="role === ROLE.ADMIN || role === ROLE.BUSINESS">
        <h3>利润分析</h3>
        <BasicForm @register="registerProfitForm" />
      </template>
      <template v-if="role === ROLE.ADMIN || role === ROLE.BUSINESS">
        <h3>项目报告书</h3>
        <BasicForm @register="registerReportForm" />
      </template>
      <template v-if="role === ROLE.ADMIN || role === ROLE.TRACKER">
        <h3>跟单信息</h3>
        <BasicForm @register="registerTrackForm" />
      </template>
      <template v-if="role === ROLE.ADMIN || role === ROLE.INSPECT">
        <h3>质量信息</h3>
        <BasicForm @register="registryInspectForm" />
      </template>
    </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 { computed, defineComponent, reactive, ref } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { orderAuth } from '/@/api/project/order';
  import { ROLE } from './type.d';

  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import {
    FIELDS_BASE_INFO,
    FIELDS_INSPECTION_INFO,
    FIELDS_PROFIT_INFO,
    FIELDS_REPORT_INFO,
    FIELDS_TRACK_STAGE_INFO,
  } from './tableData';
  import { useUserStoreWithOut } from '/@/store/modules/user';

  const userStore = useUserStoreWithOut();
  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,
        },
      }))
      .filter(
        (item) =>
          item.field !== 'packetPrice' &&
          item.field !== 'exchangeRate' &&
          item.field !== 'profitRate',
      );

  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 inspecSchemas = getSchema(FIELDS_INSPECTION_INFO);
      const trackSchemas = getSchema(FIELDS_TRACK_STAGE_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 [registryInspectForm, { getFieldsValue: getInspectFieldsValue }] = useForm({
        labelWidth: 120,
        schemas: inspecSchemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const [registerTrackForm, { getFieldsValue: getTrackFieldsValue }] = useForm({
        labelWidth: 120,
        schemas: trackSchemas,
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
      const lockFields = reactive({});
      const [register, { closeDrawer }] = useDrawerInner((data) => {
        Object.assign(lockFields, data.lockFields);
        id.value = data.id;
      });

      const role = computed(() => {
        return userStore.getUserInfo?.roleSmallVO?.code;
      });

      const handleSubmit = async () => {
        const baseFieldValues = getFieldsValue();
        const profitFieldValues = getProfitFieldsValue();
        const reportFieldValues = getReportFieldsValue();
        const inspectFieldValues = getInspectFieldsValue();
        const trackFieldValues = getTrackFieldsValue();

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

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

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

        if (inspectFieldValues)
          FIELDS_INSPECTION_INFO.map(
            ({ field }) =>
              (inspectFieldValues[field] =
                inspectFieldValues[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 },
          { trackStageFields: trackFieldValues },
          { inspectionStageFields: inspectFieldValues },
        );
        await orderAuth(values);
        closeDrawer();
      };
      return {
        register,
        schemas,
        registerForm,
        registerProfitForm,
        registerReportForm,
        registryInspectForm,
        registerTrackForm,
        handleSubmit,
        ROLE,
        role,
      };
    },
  });
</script>