刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
<script lang="ts" setup>
import { computed, reactive, toRefs, unref } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { buildBitUUID } from '@jnpf/utils';
 
import { cloneDeep } from 'lodash-es';
 
import { invoiceDetailIds, ocrMap } from '../../helper/ocrMap';
 
interface State {
  dataForm: any;
  selectedRowKeys: string[];
  drawingList: any[];
  activeData: any;
  isEdit: boolean;
}
 
const emit = defineEmits(['register', 'confirm']);
const state = reactive<State>({
  dataForm: {
    storageType: 1,
  },
  selectedRowKeys: [],
  drawingList: [],
  activeData: {},
  isEdit: false,
});
const { dataForm, selectedRowKeys, isEdit } = toRefs(state);
const [registerModal, { closeModal }] = useModalInner(init);
const storageTypeOptions = [
  { fullName: '存为新字段', id: 1 },
  { fullName: '存到已有字段', id: 2 },
];
 
const getColumns = computed(() => {
  const fullName = { title: '识别字段', dataIndex: 'fullName', key: 'fullName', width: 250 };
  const defJnpfKey = { title: '控件类型', dataIndex: 'defJnpfKey', key: 'defJnpfKey', width: 250 };
  const jnpfKey = { title: '选择控件', dataIndex: 'jnpfKey', key: 'jnpfKey', width: 250 };
  return [fullName, state.dataForm.storageType == 1 && !state.isEdit ? defJnpfKey : jnpfKey];
});
const getTableBindValues = computed(() => ({
  size: 'small',
  rowKey: 'id',
  dataSource: state.dataForm.transferList,
  columns: unref(getColumns),
  pagination: false,
  scroll: { y: state.isEdit ? 490 : 360 },
  rowSelection: state.isEdit ? undefined : { columnWidth: 50, selectedRowKeys, onChange: onSelectChange },
}));
 
function init(data) {
  state.selectedRowKeys = [];
  state.activeData = cloneDeep(data.activeData) || [];
  state.isEdit = !!state.activeData.__config__?.transferList?.length;
  state.drawingList = data.drawingList || [];
  state.dataForm.transferList = state.isEdit ? state.activeData.__config__?.transferList : cloneDeep(ocrMap[`${state.activeData.ocrType}List`]);
  state.dataForm.storageType = state.activeData.__config__.storageType || 1;
}
function getFieldOptions(record) {
  const list: any[] = [];
  const loop = (data, parent?) => {
    if (!data) return;
    if (data.__config__ && data.__config__.children && Array.isArray(data.__config__.children)) {
      loop(data.__config__.children, data);
    }
    if (Array.isArray(data)) data.forEach((d) => loop(d, parent));
    if (data.__config__ && data.__config__.jnpfKey && record.supportJnpfKey.includes(data.__config__.jnpfKey)) {
      const isTableChild = parent && parent.__config__ && parent.__config__.jnpfKey === 'table';
      if (
        (isTableChild && !invoiceDetailIds.includes(record.id)) ||
        (!isTableChild && invoiceDetailIds.includes(record.id) && data.__config__.jnpfKey == 'inputNumber')
      )
        return;
      list.push({
        id: data.__config__.formId,
        fullName: isTableChild ? `${parent.__config__.label}-${data.__config__.label}` : data.__config__.label,
      });
    }
  };
  loop(state.drawingList);
  return list;
}
function getCompName(jnpfKey) {
  if (jnpfKey == 'textarea') return '多行输入';
  if (jnpfKey == 'datePicker') return '日期选择';
  if (jnpfKey == 'inputNumber') return '数字输入';
  return '单行输入';
}
function onSelectChange(selectedRowKeys) {
  state.selectedRowKeys = selectedRowKeys;
}
function handleSubmit() {
  if (!state.isEdit) {
    state.dataForm.transferList = state.dataForm.transferList.map((o) => ({
      ...o,
      formId: state.selectedRowKeys.includes(o.id) ? (state.dataForm.storageType == 2 ? o.formId : `formItemOcr${buildBitUUID()}`) : '',
    }));
  }
  emit('confirm', state.dataForm, state.isEdit);
  closeModal();
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="识别规则配置" :width="800" @ok="handleSubmit" destroy-on-close>
    <a-form :model="dataForm" layout="vertical" :colon="false">
      <a-form-item label="识别的内容如何存储" v-if="!isEdit">
        <jnpf-radio v-model:value="dataForm.storageType" :options="storageTypeOptions" />
      </a-form-item>
      <a-form-item label="识别内容输出">
        <a-table v-bind="getTableBindValues">
          <template #bodyCell="{ column, record }">
            <template v-if="column.key === 'defJnpfKey'"> {{ getCompName(record.defJnpfKey) }} </template>
            <template v-if="column.key === 'jnpfKey'">
              <jnpf-select v-model:value="record.formId" :options="getFieldOptions(record)" show-search />
            </template>
          </template>
        </a-table>
      </a-form-item>
    </a-form>
  </BasicModal>
</template>