Ben Lin
2024-06-25 3505aa60ad15de91bc9b437ca8d69124c8074974
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!--
 * @Description: file content
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-24 23:44:31
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-25 00:33:57
-->
<template>
  <Card title="行为配置">
    <BasicForm @register="registerForm">
      <template #addItem="{ 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>
  </Card>
</template>
<script lang="ts" setup>
  import { unref } from 'vue';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  import { Card } from 'ant-design-vue';
  import { useModal } from '/@/components/Modal';
  import { useUserStore } from '/@/store/modules/user';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { GetEnum } from '/@/api/tigerapi/system';
  import { useLocale } from '/@/locales/useLocale';
 
  const { t } = useI18n();
  const { getLocale } = useLocale();
  const emit = defineEmits(['success', 'register']);
  const [registerItemAdd, { openModal: openItemModal }] = useModal();
 
  const formSchema: FormSchema[] = [
    {
      field: 'ACT_NAME',
      label: '行为名称',
      required: true,
      component: 'Input',
      colProps: { span: 12 },
    },
    {
      field: 'ID',
      label: 'ID',
      component: 'Input',
      show: false,
    },
    {
      field: 'ORDER_DESC',
      label: '工单描述',
      component: 'Input',
      show: false,
      colProps: { span: 12 },
    },
    {
      field: 'ACT_TYPE',
      label: '行为类型',
      component: 'ApiSelect',
      colProps: { span: 12 },
      defaultValue: '',
      componentProps: {
        api: GetEnum,
        params: { name: 'MES_CUSTOM_ACT+ACT_TYPEs' },
        resultField: 'Data',
        labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
        valueField: 'Value',
        // onChange: (e, v) => {
        //   alert(e)
        //   console.log('ApiSelect====>:', e, v);
        // },
      },
    },
    {
      field: 'IS_ACTIVE',
      label: '是否启用',
      required: true,
      component: 'Select',
      colProps: { span: 12 },
      componentProps: {
        options: [
          {
            label: '是',
            value: 'Y',
            key: 'Y',
          },
          {
            label: '否',
            value: 'N',
            key: 'N',
          },
        ],
      },
    },
    {
      field: 'STATUS',
      label: '状态',
      component: 'Input',
      show: false,
    },
    {
      field: 'DO_TYPE',
      label: '自定义方法类型',
      required: true,
      component: 'ApiSelect',
      colProps: { span: 12 },
      componentProps: {
        api: GetEnum,
        params: { name: 'MES_CUSTOM_ACT+DO_TYPEs' },
        resultField: 'Data',
        labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
        valueField: 'Value',
        // onChange: (e, v) => {
        //   alert(e)
        //   console.log('ApiSelect====>:', e, v);
        // },
      },
    },
    {
      field: 'DO_METHOD',
      label: '自定义方法',
      required: true,
      component: 'Input',
      colProps: { span: 12 },
    },
    // {
    //   field: '0',
    //   component: 'Input',
    //   label: '1',
    //   colSlot: 'addItem',
    //   colProps: {
    //     span: 4,
    //   },
    // },
    {
      field: 'DO_IF_PASS',
      label: '通过时执行',
      //required: true,
      component: 'Input',
      colProps: { span: 12 },
    },
    {
      field: 'DO_IF_FAIL',
      label: '失败时执行',
      //required: true,
      component: 'Input',
      colProps: { span: 12 },
    },
    {
      field: 'REMARK',
      label: '备注',
      component: 'Input',
      colProps: { span: 12 },
    },
  ];
  const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
    labelWidth: 120,
    schemas: formSchema,
    actionColOptions: {
      offset: 8,
      span: 24,
    },
    wrapperCol: {
      span: 15,
    },
    showActionButtonGroup: true,
    submitButtonOptions: {
      text: '提交',
    },
  });
 
  async function handleSubmit() {
    // try {
    //   const values = await validate();
    //   setDrawerProps({ confirmLoading: true });
    //   // TODO custom api
    //   //保存工单
    //   if (!unref(isUpdate)) {
    //     values.STATUS = 0;
    //   }
    //   values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
    //   values.FACTORY = useUserStore().getUserInfo.prodCode;
    //   const apiAction = SaveEntity(values, unref(isUpdate), 'BIZ_MES_WO');
    //   apiAction.then((action) => {
    //     if (action.IsSuccessed) {
    //       closeDrawer();
    //       emit('success');
    //     }
    //   });
    // } finally {
    //   setDrawerProps({ confirmLoading: false });
    // }
  }
 
  //点击打开物料列表框
  function handleSelectItem() {
    openItemModal(true, {
      title: '物料列表',
      schemas: [
        {
          field: 'ITEM_CODE',
          component: 'Input',
          label: '物料编码',
          colProps: {
            span: 12,
          },
        },
      ],
      ItemColumns: [
        {
          title: t('物料编码'),
          dataIndex: 'ITEM_CODE',
          resizable: true,
          sorter: true,
          width: 200,
        },
        {
          title: t('物料名称'),
          dataIndex: 'ITEM_NAME',
          resizable: true,
          sorter: true,
          width: 180,
        },
      ],
      tableName: 'BAS_ITEM',
      rowKey: 'ITEM_CODE',
      searchInfo: { TABLE_NAME: 'BAS_ITEM' },
    });
  }
 
  function handleItemSuccess(d, u) {
    setFieldsValue({
      ITEM_CODE: d.values['val'],
    });
  }
</script>