schangxiang@126.com
2025-05-21 fa365d77dfa1d6619774a790e424e98dac849457
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import { ref, onMounted, reactive, Ref, nextTick, computed } from 'vue' 
import { injectModel } from '@/libs/Provider/Provider' 
import { PipeAccessoryAssembly } from '../Models/PipeAccessoryAssembly' 
import { ElMessage } from 'element-plus' 
import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox' 
import { useFile } from './File' 
 
interface CurrentType { 
  row: any 
  index: number 
export const usePipeAccessoryAssembly = (props: any, ctx?: any) => { 
  const PipeAccessoryAssembly = injectModel<PipeAccessoryAssembly>('PipeAccessoryAssembly') 
  const { exportFile } = useFile() 
  /** 
   * 头部配置 
   */ 
  const headers = ref({}) 
  /** 
   * 动态列配置 
   */ 
  const PipeAccessoryAssemblyColumns = ref<Record<string, any>>([]) 
  /** 
   * 搜索值 
   */ 
  const search = ref('') 
 
  /** 
   * 排序 
   */ 
  const sort = ref(0) 
  /** 
   * 选择项 
   */ 
  const selection = ref([]) 
  /** 
   * 当前选中的行 
   */ 
  const current = ref<any>(null) 
  /** 
   * 数据源 
   */ 
  const dataSource: Ref<any[]> = ref([]) 
 
  /** 
   * 表格 
   */ 
  const tableRef = ref() 
  const dialogConfig = reactive({ 
    visible: false, 
    title: '', 
    isAdd: false, 
  }) 
  const dialogConfigForQuery = reactive({ 
    visible: false, 
    title: '', 
    isAdd: false, 
  }) 
 
 
  const dialogSettingConfig = reactive({ 
    visible: false, 
    title: '', 
  }) 
 
  /** 
   * 分页数据 
   */ 
  const paginationParams = ref({}) 
 
  /** 
   * 打开详情 
   * @param row 
   */ 
  const openDetail = (row: any) => { 
    current.value = row 
    dialogConfig.visible = true 
    dialogConfig.title = row.name 
    dialogConfig.isAdd = false 
    sort.value = row.sort 
  } 
 
  const contextMenu = [ 
    { 
      label: '展开详情', 
      fn: (c: CurrentType) => { 
        current.value = null 
        sort.value = c.row.sort 
        nextTick(() => openDetail(c.row)) 
      }, 
      divided: true, 
      icon: 'o', 
    }, 
    // { 
    //   label: '向上添加', 
    //   fn: (c: CurrentType, pageNum: number) => { 
    //     current.value = null 
    //     sort.value = c.index + 1 + (pageNum - 1) * 50 
    //     dialogConfig.visible = true 
    //     dialogConfig.title = '添加' 
    //     dialogConfig.isAdd = false 
    //   }, 
    //   divided: true, 
    //   icon: 'up', 
    // }, 
    // { 
    //   label: '向下添加', 
    //   fn: (c: CurrentType, pageNum: number) => { 
    //     current.value = null 
    //     sort.value = c.index + 2 + (pageNum - 1) * 50 
    //     dialogConfig.visible = true 
    //     dialogConfig.title = '添加' 
    //     dialogConfig.isAdd = false 
    //   }, 
    //   divided: true, 
    //   icon: 'down', 
    // }, 
    // { 
    //   label: '创建副本', 
    //   fn: async ({ row }: CurrentType) => { 
    //     await PipeAccessoryAssembly.cloneData([row.id]) 
    //     ElMessage.success('创建副本成功') 
    //     tableRef.value?.getList() 
    //   }, 
    //   divided: true, 
    //   icon: 'copy', 
    // }, 
    { 
      label: '删除', 
      fn: async (c: CurrentType) => { 
        const names = selection.value.map((item: { materialId: string }) => item.materialId) 
        ConfirmBox( 
          `是否删除${names.length ? names.join(',') : c.row.materialId}` 
        ).then(async () => { 
          const ids = selection.value.map((item: { id: string }) => item.id) 
          await PipeAccessoryAssembly.deletePipeAccessoryAssemblys(ids.length ? ids : [c.row.id]) 
          ElMessage.success('删除成功') 
          tableRef.value.getList() 
        }) 
      }, 
      icon: 'close', 
    }, 
  ] 
 
 
  //下发法兰冲码
  const onSendFlangeCode = () => { 
    const names = selection.value.map((item: { dataIdentifier: string }) => item.dataIdentifier) 
    if(names.length==0){
      ElMessage.warning('请选择一条记录');
      return;
    }
    if(names.length>1){
      ElMessage.warning('请只能选择一条记录');
      return;
    }
    ConfirmBox( 
      `是否要下发法兰冲码${names.length ? names.join(',') : ''}` 
    ).then(async () => { 
      // 获取选中的第一条记录
  const selectedItem = selection.value[0];
  
  // 构建参数对象
  const param = {
    Son_TaskCode: selectedItem.son_TaskCode || '',  // 子任务编号
    TaskCode: selectedItem.taskCode || '',        // 任务编号
    PipeSpecCode: selectedItem.pipeSpecCode || '',// 管段编码
  };
 
     var ret= await PipeAccessoryAssembly.sendFlangeCode(param) 
      if(ret.code=="200"){
        ElMessage.success('下发成功') 
        tableRef.value.getList() 
      }else{
        ElMessage.error('下发失败:'+ret.message) 
      }
    }) 
  } 
  //法兰冲码完工
  const onFinishSendFlangeCode = () => { 
    const names = selection.value.map((item: { dataIdentifier: string }) => item.dataIdentifier) 
    if(names.length==0){
      ElMessage.warning('请选择一条记录');
      return;
    }
    if(names.length>1){
      ElMessage.warning('请只能选择一条记录');
      return;
    }
    ConfirmBox( 
      `是否要完工法兰冲码${names.length ? names.join(',') : ''}` 
    ).then(async () => { 
      // 获取选中的第一条记录
  const selectedItem = selection.value[0];
  
  // 构建参数对象
  const param = {
    processName: selectedItem.processName || '',        // 任务编号
    PipeSpecCode: selectedItem.pipeSpecCode || '',// 管段编码
  };
 
     var ret= await PipeAccessoryAssembly.finishSendFlangeCode(param) 
      if(ret.code=="200"){
        ElMessage.success('完工法兰冲码成功') 
        tableRef.value.getList() 
      }else{
        ElMessage.error('完工法兰冲码失败:'+ret.message) 
      }
    }) 
  } 
  const onCheck = (records: any) => { 
    selection.value = records 
  } 
 
  const onAddPipeAccessoryAssembly = () => { 
    const params = tableRef.value?.getPaginationParams() 
    current.value = null 
    dialogConfig.visible = true 
    dialogConfig.isAdd = true 
    dialogConfig.title = '添加' 
    sort.value = params.totalCount + 1 
  } 
 
  //点击按钮【高级查询】 
  const onAdvancedQuery = () => { 
    const params = tableRef.value?.getPaginationParams() 
    current.value = null 
    dialogConfigForQuery.visible = true 
    dialogConfigForQuery.isAdd = true 
    dialogConfigForQuery.title = '高级查询' 
  } 
  
  const onConfirmPipeAccessoryAssembly = async () => { 
    dialogConfig.visible = false 
    if (dialogConfig.isAdd) { 
      tableRef.value?.scrollToRow({ 
        skip: true, 
      }) 
    } else { 
      await tableRef.value?.getList() 
    } 
  } 
  /** 
   * 行点击时更新current 
   */ 
  const onRowClick = ({ row }: any) => { 
    if (dialogConfig.visible && current.value) { 
      current.value = row 
    } 
  } 
  /** 
   * 导出 
   */ 
  const onExport = (data={}) => { 
    //const params = tableRef.value?.getParams() 
    exportFile('/api/v1/HIAWms/PipeAccessoryAssembly/export', data, 'PipeAccessoryAssembly') 
  } 
 
  /** 
   * 关键字搜索 
   */ 
  const onSearch = () => { 
    tableRef.value?.getList({ 
      Filter: search.value, 
    }) 
  } 
 
  /** 
   * 重置表格数据 
   */ 
  const reloadList = () => { 
    tableRef.value?.getList() 
  } 
  /** 
   * 上传成功 
   */ 
  const onSuccess = () => { 
    tableRef.value?.getList() 
    ElMessage.success('导入成功') 
  } 
  /** 
   * 失败 
   * @param err 
   */ 
  const onError = (err: any) => { 
    try { 
      const message = JSON.parse(err.message) 
      ElMessage.error(message.msg) 
    } catch (error) { 
      ElMessage.error('导入失败') 
    } 
  } 
  /** 
   * 上传钩子 
   */ 
  const onBeforeUpload = (file: File) => { 
    const format = ['xlsx', 'xls', 'csv'] 
    if (!format.includes(file.name.split('.')[1])) { 
      ElMessage.error('导入文件格式不正确,请导入.xlsx/.xls与.csv格式的文件') 
      return false 
    } 
    return true 
  } 
 
  onMounted(() => { 
    headers.value = { 
      Authorization: `Bearer ${sessionStorage.getItem('Token')}`, 
      'X-Project': sessionStorage.getItem('X-Project'), 
    } 
  }) 
 
  ctx.expose({ 
    reloadList, 
  }) 
 
  return { 
    dataSource, 
    contextMenu, 
    dialogConfig, 
    dialogConfigForQuery, 
    dialogSettingConfig, 
    tableRef, 
    current, 
    search, 
    sort, 
    PipeAccessoryAssemblyColumns, 
    paginationParams, 
    headers, 
    onBeforeUpload, 
    onError, 
    onSuccess, 
    openDetail, 
    onSearch, 
    onExport, 
    onRowClick, 
    onConfirmPipeAccessoryAssembly, 
    onCheck, 
    onAddPipeAccessoryAssembly, 
    onAdvancedQuery,
    onSendFlangeCode,
    onFinishSendFlangeCode 
  }