zs
2025-06-04 5a149d626ae8bc3fa4bddbb53f8caf40f51f6da6
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
244
245
246
247
248
249
import { computed, defineComponent, onMounted, ref } from 'vue'
import styles from './WorkSectionParams.module.scss'
import Tab from '@/components/Tab/Tab'
import TabPane from '@/components/Tab/TabPane'
import CommonTable from '@/components/CommonTable/CommonTable'
import { _t } from '@/libs/Language/Language'
import DyForm from '../DyForm/DyForm'
import BaseDialog from '../BaseDialog/BaseDialog'
import { getWorkSection } from './api'
import { useGlobalState } from '@/libs/Store/Store'
import IconButton from '../IconButton/IconButton'
import { ElMessage } from 'element-plus'
 
export default defineComponent({
  name: 'WorkSectionParams',
  props: {
    onConfirm: {
      type: Function,
    },
    selections: {
      type: Array,
      default: () => [],
    },
  },
  emits: ['update:visible', 'confirm', 'cancel'],
  setup(props, ctx) {
    const { workSectionList } = useGlobalState()
    const tabData = ref<any[]>()
    const formRef = ref<any>(null)
    const formData = ref<any>({})
    const visible = ref(false)
    const paramsData = ref<any[]>([])
    const formulaData = ref<any[]>([])
    const materielData = ref<any[]>([])
    const paramRef = ref<any>(null)
    const formulaRef = ref<any>(null)
    const materielRef = ref<any>(null)
    const selectedMap = ref<any>({})
    const isEdit = ref(false)
 
    const typeMap = computed(() => {
      return {
        process: {
          type: 0,
          name: _t('采集参数'),
        },
        formula: {
          type: 1,
          name: _t('配方参数'),
        },
        material: {
          type: 2,
          name: _t('物料参数'),
        },
      }
    })
    const currentTab = computed(() => {
      const base = [
        {
          label: _t('采集参数'),
          name: 'process',
          hidden: false,
          edition: 'G',
          data: paramsData,
          ref: paramRef,
        },
        {
          label: _t('配方参数'),
          name: 'formula',
          hidden: false,
          data: formulaData,
          ref: formulaRef,
          edition: 'H',
        },
        {
          label: _t('物料参数'),
          name: 'material',
          hidden: false,
          data: materielData,
          ref: materielRef,
        },
      ]
 
      return base
    })
 
    const workSectionMap = computed(() => {
      const map = {}
      workSectionList.state.value.forEach((item: any) => {
        map[item.value] = item
      })
      return map
    })
 
    const refMap = computed(() => ({
      0: paramRef,
      1: formulaRef,
      2: materielRef,
    }))
 
    const onConfirm = () => {
      const getItem = (item: any, key: string) => {
        return {
          ...item,
          workSectionId: formData.value.id,
          sourceDisplayTxt: item.name,
          source: item.key,
          sourceType: typeMap.value[key].type,
          sourceTypeDisplayTxt: typeMap.value[key].name,
          workSectionName: workSectionMap.value[formData.value.id].label,
          productionLineSegmentId:
            workSectionMap.value[formData.value.id].source?.segment?.id,
          productionLineSegmentName:
            workSectionMap.value[formData.value.id].source?.segment?.name,
        }
      }
      const { process = [], formula = [], material = [] } = selectedMap.value
      const data = process
        .map((item: any) => getItem(item, 'process'))
        .concat(formula.map((item: any) => getItem(item, 'formula')))
        .concat(material.map((item: any) => getItem(item, 'material')))
      if (isEdit.value) {
        if (data.length !== 1) {
          ElMessage.warning(_t('请选择一个参数!'))
          return
        }
      }
      ctx.emit('confirm', isEdit.value ? data[0] : data)
      visible.value = false
    }
    const onCancel = () => {
      visible.value = false
    }
 
    const onEdit = async () => {
      if (!props.selections.length) {
        ElMessage.warning(_t('请选择一个配置!'))
        return
      }
      if (props.selections.length > 1) {
        ElMessage.warning(_t('请勿选择多个配置操作!'))
        return
      }
      isEdit.value = true
      visible.value = true
      const data = props.selections[0] as any
      formData.value.id = data.workSectionId
      await getWorkSectionParams(data.workSectionId)
 
      const ref = refMap.value[data.sourceType]
      ref?.value?.setSelectRow([data.id])
    }
 
    const getWorkSectionParams = async (id: string) => {
      if (!id) return
      const res = await getWorkSection(id)
      const { processParameters, formulaParameters, materialDetections } = res
      paramsData.value = processParameters
      formulaData.value = formulaParameters
      materielData.value = materialDetections
    }
 
    onMounted(async () => {
      if (workSectionList.state.value) {
        const id = workSectionList.state.value[0]?.value
        formData.value.id = id
        await getWorkSectionParams(id)
      }
    })
    return () => {
      return (
        <div class={styles.workSectionParams}>
          <div class={styles.btnList}>
            <IconButton
              icon="add-p"
              type="primary"
              onClick={() => {
                isEdit.value = false
                visible.value = true
              }}
            >
              {_t('新增')}
            </IconButton>
            {/* <IconButton icon="edit" onClick={onEdit}>
              {_t('编辑')}
            </IconButton> */}
          </div>
          <BaseDialog
            title={_t('新增产品下发参数值配置')}
            onConfirm={onConfirm}
            onClose={onCancel}
            v-model={visible.value}
            width="954px"
            height="536px"
          >
            <DyForm
              ref={formRef}
              formData={formData.value}
              labelWidth="106px"
              formItemProps={[
                {
                  label: _t('工序'),
                  prop: 'id',
                  el: 'select',
                  options: workSectionList.state.value,
                  placeholder: _t('请选择工序'),
                  onChange: getWorkSectionParams,
                },
              ]}
            ></DyForm>
            <Tab active={currentTab.value[0].name} size="small" type="params">
              {currentTab.value.map((item: any) => {
                return (
                  <TabPane key={item.name} label={item.label} name={item.name}>
                    <div style={{ height: '300px' }}>
                      <CommonTable
                        ref={item.ref}
                        isContextMenu={false}
                        v-model:dataSource={item.data.value}
                        isFooter={false}
                        height="290px"
                        onCheck={(records: any[]) => {
                          selectedMap.value[item.name] = records
                        }}
                        columns={[
                          {
                            title: _t('参数名'),
                            field: 'name',
                            key: 'name',
                          },
                          {
                            title: _t('参数描述'),
                            field: 'description',
                            key: 'description',
                          },
                        ]}
                        isStop={item.isStop}
                      />
                    </div>
                  </TabPane>
                )
              })}
            </Tab>
          </BaseDialog>
        </div>
      )
    }
  },
})