CheckDetail.vue 3.61 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" />
    </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, FormSchema, useForm } from '/@/components/Form/index';
  import { orderAuth } from '/@/api/project/order';

  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { FIELDS_BASE_INFO, FIELDS_PROFIT_INFO } from './tableData';
  import { cloneDeep, isEmpty, mapValues, mergeWith } from 'lodash-es';

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

  export default defineComponent({
    components: { BasicDrawer, BasicForm },
    props: {
      onGoFormDetail: {
        type: Function,
      },
    },
    setup() {
      const id = ref('');
      const schemas = getSchema(FIELDS_BASE_INFO, 'baseFields');
      const profitSchemas = getSchema(FIELDS_PROFIT_INFO, 'profitAnalysisFields');
      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 lockFields = reactive({});
      const [register, { closeDrawer }] = useDrawerInner((data) => {
        Object.assign(lockFields, data.lockFields);
        id.value = data.id;
      });

      function customizer(objValue, srcValue, key) {
        // 检查是否在 baseFields 内以及值是否为 true
        if (srcValue === true) {
          return 'UN_LOCKED';
        }
        return objValue; // 如果不需要改变,返回原值
      }
      const handleSubmit = async () => {
        const baseFieldValues = getFieldsValue();
        const profitFieldValues = getProfitFieldsValue();

        !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';
          });

        const values = Object.assign({ orderId: id.value }, baseFieldValues, profitFieldValues);
        console.log('%c [ values ]-103', 'font-size:13px; background:pink; color:#bf2c9f;', values);
        await orderAuth(values);
        closeDrawer();
      };
      return { register, schemas, registerForm, registerProfitForm, handleSubmit };
    },
  });
</script>