2
schangxiang@126.com
2025-05-12 6177ed5cb88df34f2a67d9d0610e3e0dc7030e70
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
<template>
  <BaseDialog
    :title="_t(dialogConfig.title)"
    v-model="visible"
    width="50%"
    destroy-on-close
    @open="onOpen"
    @close="onClose"
    @confirm="onConfirm"
  >
    <div class="table-body">
      <div class="table-header">
        <el-select
          :placeholder="_t('请选择')"
          clearable
          style="width: 180px"
          v-if="type === TYPE_MAP.BOM"
          v-model="importSelected"
        >
          <el-option :label="_t('重要')" value="Y"></el-option>
          <el-option :label="_t('非重要')" value="N"></el-option>
        </el-select>
        <el-input
          :placeholder="_t('搜索')"
          clearable
          style="width: 180px; margin: 0 10px"
          v-model="searchValue"
        ></el-input>
        <el-button @click="onSearch" type="info">{{ _t('查询') }}</el-button>
      </div>
      <div class="table-content">
        <Table
          ref="productRef"
          :dataSource="dataSource"
          :columns="dialogConfig.columns"
          :total="dialogConfig.total"
          :pageSize="MaxResultCount"
          @page="onPageChange"
        />
      </div>
    </div>
    <template #custom-btn>
      <el-button class="update" size="small" type="info" @click="onUpdate">{{
        _t('更新')
      }}</el-button>
    </template>
  </BaseDialog>
</template>
<script lang="ts" setup>
import { ref, computed, reactive } from 'vue'
import Table from '@/components/Table/index.vue'
import {
  getBomList,
  getLotList,
  getProcessList,
  updateProcess,
  updateBom,
  updateLot,
} from '../../api/process'
import { ElMessage } from 'element-plus'
import { _t } from '../../app'
import { getEnum } from '../../enum'
const { TYPE_MAP } = getEnum()
interface ParamsItem {
  Filter?: string
  Sorting?: string
  SkipCount?: string | number
  MaxResultCount?: string | number
  IsDesc?: boolean
  SerialInputFlag?: string
}
 
const MaxResultCount = 20
const SkipCount = 0
const searchValue = ref('')
const importSelected = ref('')
 
const params: ParamsItem = reactive({
  MaxResultCount,
  SkipCount,
})
 
const props = defineProps<{
  modelValue: boolean
  title: string
  columns: any[]
  type: string
  other: string
}>()
 
const emit = defineEmits(['update:modelValue', 'update:dataSource'])
 
const visible = computed({
  get() {
    return props.modelValue
  },
  set(v) {
    emit('update:modelValue', v)
  },
})
 
const dataSource = ref([])
 
const dialogConfig = computed(() => {
  return {
    title: props.title,
    columns: props.columns,
    total: 0,
  }
})
 
const getList = async () => {
  dataSource.value = []
  const typeMap = {
    [TYPE_MAP.PROCESS]: getProcessList,
    [TYPE_MAP.LOT]: getLotList,
    [TYPE_MAP.BOM]: getBomList,
  }
  const otherParamsMap = {
    [TYPE_MAP.PROCESS]: {
      OrderNumber: props.other,
    },
    [TYPE_MAP.LOT]: {
      Code: props.other,
    },
    [TYPE_MAP.BOM]: {
      OrderNumber: props.other,
    },
  }
  const otherParams = otherParamsMap[props.type]
  if (searchValue.value) {
    params.Filter = searchValue.value
  } else {
    delete params.Filter
  }
  if (props.type === TYPE_MAP.BOM) {
    params.SerialInputFlag = importSelected.value
  }
  Object.assign(params, otherParams)
  const fn = typeMap[props.type]
  const res = await fn(params)
 
  dataSource.value = res.items
  dialogConfig.value.total = res.totalCount
}
 
const onSearch = () => getList()
 
const onOpen = () => {
  searchValue.value = ''
  getList()
}
 
const onClose = () => {
  visible.value = false
}
 
const onConfirm = () => {
  onClose()
}
 
const onUpdate = async () => {
  const updateFnMap = {
    [TYPE_MAP.PROCESS]: updateProcess,
    [TYPE_MAP.LOT]: updateLot,
    [TYPE_MAP.BOM]: updateBom,
  }
  const fn = updateFnMap[props.type]
  await fn(props.other)
  ElMessage.success(_t('更新成功'))
  visible.value = false
}
 
const onPageChange = (v: number) => {
  params.SkipCount = (v - 1) * MaxResultCount
  getList()
}
</script>
 
<style lang="scss" scoped>
.table-content {
  width: 100%;
  height: 400px;
}
 
.table-header {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.update {
  width: 96px;
  height: 26px;
}
.table-body {
  width: 100%;
  height: 500px;
}
</style>