Ben Lin
2024-07-27 a82003f4cf9ae6b69f70212374b3a71090f1770f
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
242
243
<!--
 * @Description: file content
 * @Author: your name
 * @version: 
 * @Date: 2024-05-01 17:18:49
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-19 15:58:20
-->
<!--
 * @Description: 表单项属性,控件属性面板
-->
<template>
  <div class="properties-content">
    <Form class="properties-body" label-align="left" layout="vertical">
      <FormItem label="工艺路线编码" name="工艺路线编码">
        <Input
          :style="{ width: '100%' }"
          v-model:value="mesRoute.ROT_CODE"
          :min="0"
          :step="1"
          :readonly="true"
        />
      </FormItem>
      <FormItem label="节点ID" name="节点ID">
        <Input
          :style="{ width: '100%' }"
          v-model:value="routeConfig.currentAct.NODE_ID"
          :min="0"
          :step="1"
          :readonly="true"
        />
      </FormItem>
      <FormItem label="行为名称" name="行为名称">
        <Input
          :style="{ width: '100%' }"
          v-model:value="routeConfig.currentAct.ACT_NAME"
          :min="0"
          :step="1"
        />
      </FormItem>
      <FormItem label="行为类型" name="行为类型">
        <ApiSelect
          :api="GetEnum"
          :params="{ name: 'MES_ROUTE_NODE_ACT+ACT_TYPEs' }"
          v-model:value="routeConfig.currentAct.ACT_TYPE"
          resultField="Data"
          :label-field="actTypeLable"
          valueField="Value"
          placeholder="请选择行为类型"
        />
      </FormItem>
      <FormItem label="行为定义" name="行为定义">
        <Input
          :style="{ width: '85%' }"
          v-model:value="routeConfig.currentAct.ACT_CODE"
          :min="0"
          :step="1"
        />
        <a-button
          class="mt-1 ml-1"
          size="small"
          @click="handleSelectItem(item)"
          preIcon="search|svg"
        />
        <GeneralModal @register="registerItemAdd" @success="handleItemSuccess" />
      </FormItem>
      <FormItem label="是否设置才能下发生产(Y/N)" name="是否设置才能下发生产(Y/N)">
        <Select
          ref="select"
          v-model:value="routeConfig.currentAct.NEED_SETUP"
          style="width: 150px"
          :options="needSetupOptions"
        />
      </FormItem>
      <FormItem label="执行出错时,是否重置整个工序的操作(Y/N)" name="执行出错时,是否重置整个工序的操作(Y/N)">
        <Select
          ref="select"
          v-model:value="routeConfig.currentAct.NEED_RESET"
          style="width: 150px"
          :options="needResetOptions"
        />
      </FormItem>
      <FormItem label="是否启用" name="是否启用">
        <Select
          ref="select"
          v-model:value="routeConfig.currentAct.IS_ACTIVE"
          style="width: 150px"
          :options="options1"
        />
      </FormItem>
    </Form>
  </div>
</template>
<script lang="ts" setup>
  import { Select, Input, Form, FormItem, Tag } from 'ant-design-vue';
  import { useRouteDesignState } from '../hooks/useRouteDesignState';
  import GeneralModal from '/@/views/components/GeneralModal.vue';
  import { SelectTypes } from 'ant-design-vue/es/select';
  import { ApiSelect } from '/@/components/Form/index';
  import { h, ref, unref, watch } from 'vue';
  import { useLocale } from '/@/locales/useLocale';
  import { GetEnum } from '/@/api/tigerapi/system';
  import { useModal } from '/@/components/Modal';
  import { useI18n } from '/@/hooks/web/useI18n';
 
  const { getLocale } = useLocale();
  const { t } = useI18n();
  const emit = defineEmits(['changeName']);
  const [registerItemAdd, { openModal: openItemModal }] = useModal();
  const { routeConfig, mesRoute } = useRouteDesignState();
  const options1 = ref<SelectTypes['options']>([
    {
      value: 'Y',
      label: '启用',
    },
    {
      value: 'N',
      label: '不启用',
    },
  ]);
  const needSetupOptions = ref<SelectTypes['options']>([
    {
      value: 'Y',
      label: '必需设置',
    },
    {
      value: 'N',
      label: '无需设置',
    },
  ]);
  const needResetOptions = ref<SelectTypes['options']>([
    {
      value: 'Y',
      label: '是',
    },
    {
      value: 'N',
      label: '否',
    },
  ]);
  const actTypeLable = unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name';
  watch(
    () => routeConfig.currentAct,
    (newVal, oldVal) => {
      routeConfig.routeData.acts.forEach((r) => {
        if (r.ID == routeConfig.currentAct.ID) {
          if (r.ACT_NAME != newVal.ACT_NAME) {
            r.ACT_NAME = newVal.ACT_NAME;
            console.log(r.ACT_NAME, newVal.ACT_NAME);
            emit('changeName', { id: r.ID, val: r.ACT_NAME });
          }
          r.IS_ACTIVE = newVal.IS_ACTIVE;
          r.ACT_TYPE = newVal.ACT_TYPE;
          r.ACT_CODE = newVal.ACT_CODE;
          r.NEED_SETUP = newVal.NEED_SETUP;
          r.NEED_RESET = newVal.NEED_RESET;
          // r.DO_TYPE = newVal.DO_TYPE;
          // r.DO_METHOD = newVal.DO_METHOD;
          // r.DO_IF_PASS = newVal.DO_IF_PASS;
          // r.DO_IF_FAIL = newVal.DO_IF_FAIL;
        }
      });
    },
    { deep: true, immediate: true },
  );
 
  function handleSelectItem(item) {
    openItemModal(true, {
      title: '工序行为定义',
      schemas: [
        {
          field: 'ACT_CODE',
          component: 'Input',
          label: '行为编码',
          colProps: {
            span: 12,
          },
        },
      ],
      ItemColumns: [
        {
          title: t('行为编码'),
          dataIndex: 'ACT_CODE',
          resizable: true,
          sorter: true,
          width: 100,
        },
        {
          title: t('行为名称'),
          dataIndex: 'ACT_NAME',
          resizable: true,
          sorter: true,
          width: 100,
        },
        {
          title: t('行为类型'),
          dataIndex: 'ACT_TYPE',
          resizable: true,
          sorter: true,
          width: 100,
          customRender: ({ record }) => {
            const type = record.ACT_TYPE;
            var text = '';
            var color = 'green';
            switch (type) {
              case 0:
                text = '默认行为';
                break;
              case 1:
                color = 'orange';
                text = '扫码验证';
                break;
              case 2:
                color = 'blue';
                text = '组装上料';
                break;
              case 3:
                color = '#24c7cf';
                text = '产品测试';
                break;
              case 4:
                color = '#550689';
                text = '产品抽检';
                break;
              case 5:
                color = '#bfbfbf';
                text = '标签打印';
                break;
            }
            return h(Tag, { color: color }, () => text);
          },
        },
      ],
      tableName: 'MES_CUSTOM_ACT',
      rowKey: 'ACT_CODE',
      searchInfo: { TABLE_NAME: 'MES_CUSTOM_ACT', ACT_TYPE: routeConfig.currentAct.ACT_TYPE },
    });
  }
 
  function handleItemSuccess(d, u) {
    routeConfig.currentAct.ACT_CODE = d.values['val'];
  }
</script>