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
import { ref, onMounted, reactive, computed, watch } from 'vue'
import { _t } from '@/libs/Language/Language'
import { getProcessRouterList, getWorkStationList } from './api'
 
export const useSelectDialog = (props: any, ctx: any) => {
  const visible = computed({
    get() {
      return props.modelValue
    },
    set(val) {
      ctx.emit('update:modelValue', val)
    },
  })
  const routers = ref([])
  const dataSource = ref<any[]>([])
 
  const innerValue = ref('')
 
  const tableRef = ref()
 
  const checkedList = ref<any[]>([])
 
  const columns = computed(() => [
    {
      title: _t('序号'),
      type: 'seq',
      width: '60',
    },
    {
      field: 'workSection.name',
      title: _t('工序名称'),
    },
    {
      field: 'name',
      title: _t('工位名称'),
    },
    {
      field: 'remark',
      title: _t('备注'),
    },
  ])
 
  const onClose = () => {
    visible.value = false
  }
 
  const onConfirm = async () => {
    ctx.emit('confirm', checkedList.value)
  }
 
  const onSearch = () => {
    initData(innerValue.value)
  }
 
  const onCheck = (list: any) => {
    checkedList.value = list
  }
 
  const selections = computed(() => {
    return props.data?.map((item: any) => item.id) ?? []
  })
 
  const initData = async (filter?: string) => {
    const ids = routers.value.map((item) => item.id) as string[]
    const data = await getWorkStationList(filter)
    const dataSourceItems = data.items.filter((item) =>
      ids.includes(item.workSectionId)
    )
    dataSource.value = dataSourceItems
  }
 
  const onOpen = async () => {
    routers.value = await getProcessRouterList(props.productId)
    initData()
  }
 
  return {
    selections,
    dataSource,
    columns,
    tableRef,
    innerValue,
    visible,
    onSearch,
    onOpen,
    onCheck,
    onClose,
    onConfirm,
  }
}