Blame view

src/views/project/order/FormDetail/InspectionFormPanel.vue 3.32 KB
sanmu authored
1
2
3
4
<template>
  <BasicForm @register="registerForm" />
</template>
<script lang="ts">
sanmu authored
5
  import { computed, defineComponent, ref } from 'vue';
sanmu authored
6
  import { BasicForm, useForm } from '/@/components/Form/index';
sanmu authored
7
  import { FIELDS_INSPECTION_INFO } from '../tableData';
sanmu authored
8
  import { getDisable, getQualityDisable } from '/@/utils/project';
sanmu authored
9
  import { useOrderStoreWithOut } from '/@/store/modules/order';
sanmu authored
10
  import { get } from 'lodash-es';
sanmu authored
11
12
13
14
15
16
  import { useOrderInfo } from '/@/hooks/component/order';

  export default defineComponent({
    components: { BasicForm },

    props: {
sanmu authored
17
18
      id: {
        type: String,
sanmu authored
19
      },
sanmu authored
20
21
22
      inspectFormData: {
        type: Object,
      },
23
      // HOD时间:超过HOD时间后,质检信息表所有字段禁用
24
25
26
27
      hodTime: {
        type: String,
        default: '',
      },
sanmu authored
28
29
    },
    emits: ['success'],
sanmu authored
30
31
    setup(props, { emit }) {
      let fields = ref({});
sanmu authored
32
33
34
35
      const orderStore = useOrderStoreWithOut();

      const { midCheckResult, endCheckResult } = useOrderInfo(orderStore);
36
      /**
37
38
39
40
       * 检查当前时间是否已经超过HOD时间
       * 当前时间超过HOD时间后,质检信息表所有字段禁用
       * 当前时间小于等于HOD时间时可编辑
       * @returns {boolean} true表示当前时间已超过HOD时间,需要禁用字段
41
       */
42
      const isAfterHodTime = computed(() => {
43
44
45
        if (!props.hodTime) return false;
        const hodDate = new Date(props.hodTime);
        const currentDate = new Date();
46
        // 只比较日期部分,忽略时间部分
47
48
        const hodDateOnly = new Date(hodDate.getFullYear(), hodDate.getMonth(), hodDate.getDate());
        const currentDateOnly = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
49
50
        // 当前日期大于HOD日期时禁用
        return currentDateOnly > hodDateOnly;
51
52
      });
sanmu authored
53
54
55
56
57
      const schemas = computed(() => {
        const options = {
          midCheckResult,
          endCheckResult,
        };
sanmu authored
58
        return FIELDS_INSPECTION_INFO.map((item) => {
59
60
          // 如果当前时间已超过HOD时间,则禁用所有字段
          const isDisabledByHodTime = isAfterHodTime.value;
sanmu authored
61
62
63
          return {
            ...item,
            componentProps: {
64
              ...(item.component === 'Select' && { showSearch: true }),
sanmu authored
65
              ...(item.component === 'Select' && { options: options[item.field] }),
66
              // 当前时间超过HOD时间后禁用,否则按原有权限逻辑
67
              disabled: isDisabledByHodTime || getQualityDisable(
sanmu authored
68
                item.field,
sanmu authored
69
70
71
                get(fields.value, item.field),
                props.id,
                get(props.inspectFormData, `${item.field}`),
sanmu authored
72
                get(props.inspectFormData, 'endCheckResult'),
sanmu authored
73
              ),
sanmu authored
74
75
76
77
78
79
            },
            colProps: {
              span: 24,
            },
          };
        });
sanmu authored
80
81
      });
sanmu authored
82
      const [registerForm, { setFieldsValue, getFieldsValue, resetFields }] = useForm({
sanmu authored
83
84
        labelWidth: 120,
        schemas,
sanmu authored
85
        layout: 'vertical',
sanmu authored
86
87
88
89
90
91
        showActionButtonGroup: false,
        actionColOptions: {
          span: 24,
        },
      });
sanmu authored
92
93
94
95
96
97
98
      return {
        fields,
        schemas,
        registerForm,
        setFieldsValue,
        resetFields,
        getFieldsValue,
99
        isAfterHodTime,
sanmu authored
100
      };
sanmu authored
101
102
103
    },
  });
</script>
sanmu authored
104
../constant