Ben Lin
2024-07-27 a82003f4cf9ae6b69f70212374b3a71090f1770f
src/views/tigerprojects/mes/eng/route/components/ActionItemProps.vue
@@ -1,4 +1,12 @@
<!--
 * @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>
@@ -22,6 +30,14 @@
          :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"
@@ -33,46 +49,42 @@
          placeholder="请选择行为类型"
        />
      </FormItem>
      <FormItem label="自定义方法类型" name="自定义方法类型">
        <ApiSelect
          :api="GetEnum"
          :params="{ name: 'MES_ROUTE_NODE_ACT+DO_TYPEs' }"
          v-model:value="routeConfig.currentAct.DO_TYPE"
          resultField="Data"
          :label-field="actTypeLable"
          valueField="Value"
          placeholder="请选择行为类型"
        />
      </FormItem>
      <FormItem label="自定义方法(调用方法的全名)" name="自定义方法">
      <FormItem label="行为定义" name="行为定义">
        <Input
          :style="{ width: '100%' }"
          v-model:value="routeConfig.currentAct.DO_METHOD"
          :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="通过时执行(调用方法的全名)" name="通过时执行">
        <Input
          :style="{ width: '100%' }"
          v-model:value="routeConfig.currentAct.DO_IF_PASS"
          :min="0"
          :step="1"
      <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="失败时执行(调用方法的全名)" name="失败时执行">
        <Input
          :style="{ width: '100%' }"
          v-model:value="routeConfig.currentAct.DO_IF_FAIL"
          :min="0"
          :step="1"
      <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: 120px"
          style="width: 150px"
          :options="options1"
        />
      </FormItem>
@@ -80,15 +92,21 @@
  </div>
</template>
<script lang="ts" setup>
  import { Select, Input, Form, FormItem } from 'ant-design-vue';
  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 { ref, unref, watch } from 'vue';
  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']>([
    {
@@ -100,21 +118,126 @@
      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.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;
          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>