Rodney Chen
2024-07-06 e34d8f9133f196f17667d8051a6a9d080b0385fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<template>
  <div class="w-120 m-auto">
    <Alert message="确认选择了正确的客户,如果有误可以点上一步重新选择。" show-icon />
    <BasicForm @register="register">
      <template #add="{ field }">
        <a-button
          v-if="field"
          class="mt-1 ml-1"
          size="small"
          @click="handleSelectItem"
          preIcon="search|svg"
        />
        <GeneralModal @register="registerItemAdd" @success="handleItemSuccess" />
      </template>
    </BasicForm>
    <Divider />
    <h3>说明</h3>
    <h4>添加工艺路线</h4>
    <p> 添加该产品的客户的工艺路线,针对客户的不同工艺有所不同。 </p>
  </div>
</template>
<script lang="ts" setup>
  import { BasicForm, useForm } from '@/components/Form';
  import { step2Schemas } from './data';
  import { Alert, Divider, Descriptions } from 'ant-design-vue';
  import GeneralModal from '/@/views/components/GeneralModal.vue';
  import { useModal } from '/@/components/Modal';
  import { useI18n } from '/@/hooks/web/useI18n';
 
  const emit = defineEmits(['next', 'prev']);
  const { t } = useI18n();
  const [registerItemAdd, { openModal: openItemModal }] = useModal();
  const [register, { validate, setProps, setFieldsValue }] = useForm({
    labelWidth: 80,
    schemas: step2Schemas,
    actionColOptions: {
      span: 14,
    },
    resetButtonOptions: {
      text: '上一步',
    },
    submitButtonOptions: {
      text: '提交',
    },
    resetFunc: customResetFunc,
    submitFunc: customSubmitFunc,
  });
 
  async function customResetFunc() {
    emit('prev');
  }
 
  async function customSubmitFunc() {
    try {
      const values = await validate();
      setProps({
        submitButtonOptions: {
          loading: true,
        },
      });
      setTimeout(() => {
        setProps({
          submitButtonOptions: {
            loading: false,
          },
        });
        emit('next', values);
      }, 1500);
    } catch (error) {
      console.error(error);
    }
  }
 
  /**
   * @description: 弹出选择框
   * @param {*} item
   * @return {*}
   */
  function handleSelectItem(item) {
    openItemModal(true, {
      title: '工艺路线列表',
      schemas: [
        {
          field: 'ROT_CODE',
          component: 'Input',
          label: '工艺路线编码',
          colProps: {
            span: 12,
          },
        },
      ],
      ItemColumns: [
        {
          title: t('工艺路线编码'),
          dataIndex: 'ROT_CODE',
          resizable: true,
          sorter: true,
          width: 200,
        },
        {
          title: t('工艺路线名称'),
          dataIndex: 'ROT_NAME',
          resizable: true,
          sorter: true,
          width: 180,
        },
      ],
      tableName: 'MES_ROUTE',
      rowKey: 'ROT_CODE',
      returnFieldName: 'ROUTE_CODE', //返回值要赋值的字段名称
      searchInfo: { TABLE_NAME: 'MES_ROUTE' },
      which: '',
    });
  }
 
  /**
   * @description: 弹出选择框选择成功后事件
   * @param {*} d
   * @param {*} u
   * @return {*}
   */
  function handleItemSuccess(d, u) {
    setFieldsValue({
      ROT_CODE: d.values['val'],
      ROT_ID: d.values['id'],
    });
  }
</script>