verce-vue-test 0.0.75 → 0.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,7 @@
1
1
  <script setup lang="ts">
2
- import { computed, onMounted, reactive, ref } from 'vue'
3
- import {
4
- ElMessage,
5
- ElMessageBox,
6
- type UploadUserFile,
7
- } from 'element-plus'
2
+ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
3
+ import { storeToRefs } from 'pinia'
4
+ import { ElMessage, ElMessageBox } from 'element-plus'
8
5
  import {
9
6
  ArrowDown,
10
7
  ArrowUp,
@@ -19,23 +16,24 @@ import {
19
16
  UploadFilled,
20
17
  } from '@element-plus/icons-vue'
21
18
  import {
22
- addDays,
23
19
  formatDate,
24
20
  mockCurrentUser,
25
- mockFetchForeignPositionForecasts,
26
- type BusinessType,
27
21
  type ForecastStatus,
28
- type ForecastWay,
29
- type ForeignExchangeType,
30
22
  type ForeignPositionForecast,
31
- type PaymentDirection,
32
23
  type VerifyStatus,
33
- } from './foreign-currency-position-forecast/mock'
34
- import ForeignPositionForecastEditor from './foreign-currency-position-forecast/ForeignPositionForecastEditor.vue'
35
- import type {
36
- ForecastEditorMode,
37
- ForecastEditorValue,
38
- } from './foreign-currency-position-forecast/editor'
24
+ } from './mock'
25
+ import {
26
+ approveForeignPositionForecasts,
27
+ createForeignPositionForecast,
28
+ deleteForeignPositionForecast,
29
+ getForeignPositionForecast,
30
+ queryForeignPositionForecasts,
31
+ type ForeignPositionForecastSort,
32
+ updateForeignPositionForecast,
33
+ updateForeignPositionForecastAuthorization,
34
+ } from './api'
35
+ import ForeignPositionForecastEditor from './components/ForeignPositionForecastEditor.vue'
36
+ import type { ForecastEditorValue } from './editor'
39
37
  import {
40
38
  authirizationOptions,
41
39
  businessTypeOptions,
@@ -48,139 +46,70 @@ import {
48
46
  payDirectionOptions,
49
47
  type SelectOption,
50
48
  verifyStatusOptions,
51
- } from './foreign-currency-position-forecast/options'
52
-
53
- type FilterState = {
54
- valueDate: string
55
- payDirection: '' | PaymentDirection
56
- forecastStatuses: ForecastStatus[]
57
- foreignExchangeType: '' | ForeignExchangeType
58
- forecastWay: '' | ForecastWay
59
- verifyStatuses: VerifyStatus[]
60
- organizationName: string
61
- clientName: string
62
- businessType: '' | BusinessType
63
- currencies: string[]
64
- authirization: '' | '1' | '0'
65
- /** 0 仅作为界面“否”的选择值,提交接口时映射为空字符串。 */
66
- ftuFilter: '' | '1' | '0'
67
- minAmount: number | null
68
- maxAmount: number | null
69
- }
70
-
71
-
72
- function createEmptyFilters(): FilterState {
73
- return {
74
- valueDate: '',
75
- payDirection: '',
76
- forecastStatuses: [],
77
- foreignExchangeType: '',
78
- forecastWay: '',
79
- verifyStatuses: [],
80
- organizationName: '',
81
- clientName: '',
82
- businessType: '',
83
- currencies: [],
84
- authirization: '',
85
- ftuFilter: '',
86
- minAmount: null,
87
- maxAmount: null,
88
- }
89
- }
90
-
91
- function cloneFilters(filters: FilterState): FilterState {
92
- return {
93
- ...filters,
94
- forecastStatuses: [...filters.forecastStatuses],
95
- verifyStatuses: [...filters.verifyStatuses],
96
- currencies: [...filters.currencies],
97
- }
98
- }
49
+ } from './options'
50
+ import {
51
+ cloneFilters,
52
+ useForeignPositionForecastStore,
53
+ } from './store'
54
+
55
+ const forecastStore = useForeignPositionForecastStore()
56
+ const {
57
+ filterForm,
58
+ appliedFilters,
59
+ successfulFilters,
60
+ allRows,
61
+ totalCount,
62
+ selectedRows,
63
+ selectionResetKey,
64
+ isLoading,
65
+ isQuerying,
66
+ filterCollapsed,
67
+ currentPage,
68
+ pageSize,
69
+ successfulPage,
70
+ successfulPageSize,
71
+ pageMode,
72
+ editorMode,
73
+ editorRecord,
74
+ isSaving,
75
+ approvalAction,
76
+ hasMixedCurrencySelection,
77
+ amountSummary,
78
+ tableHeight,
79
+ } = storeToRefs(forecastStore)
80
+ const { clearTableSelection, resetFilterForm } = forecastStore
99
81
 
100
- const filterForm = reactive<FilterState>(createEmptyFilters())
101
- const appliedFilters = ref<FilterState>(createEmptyFilters())
102
- const allRows = ref<ForeignPositionForecast[]>([])
103
- const selectedRows = ref<ForeignPositionForecast[]>([])
104
- const selectionResetKey = ref(0)
105
- const isLoading = ref(false)
106
- const isQuerying = ref(false)
107
- const filterCollapsed = ref(true)
108
- const currentPage = ref(1)
109
- const pageSize = ref(25)
110
82
  const amountRangeValid = ref(true)
111
83
  const amountRangeRef = ref<{ validate: () => boolean } | null>(null)
112
-
113
- const pageMode = ref<'list' | 'editor'>('list')
114
- const editorMode = ref<ForecastEditorMode>('add')
115
- const editorRecord = ref<ForeignPositionForecast | null>(null)
116
- const isSaving = ref(false)
117
-
118
- const importVisible = ref(false)
119
- const importFileList = ref<UploadUserFile[]>([])
120
- const isImporting = ref(false)
121
-
122
- const filteredRows = computed(() => {
123
- const filters = appliedFilters.value
124
- const minAmount = filters.minAmount
125
- const maxAmount = filters.maxAmount
126
- const organizationKeyword = filters.organizationName.trim().toLocaleLowerCase('zh-CN')
127
- const clientKeyword = filters.clientName.trim().toLocaleLowerCase('zh-CN')
128
-
129
- return allRows.value.filter((row) => {
130
- if (filters.valueDate && row.valueDate !== filters.valueDate) return false
131
- if (filters.payDirection && row.payDirection !== filters.payDirection) return false
132
- if (filters.forecastStatuses.length && !filters.forecastStatuses.includes(row.predStatus)) return false
133
- if (filters.foreignExchangeType && row.foreignExchangeType !== filters.foreignExchangeType) return false
134
- if (filters.forecastWay && row.predWay !== filters.forecastWay) return false
135
- if (filters.verifyStatuses.length && !filters.verifyStatuses.includes(row.verifyStatus)) return false
136
- if (organizationKeyword && !row.groundBranch.toLocaleLowerCase('zh-CN').includes(organizationKeyword)) return false
137
- if (clientKeyword && !row.clientName.toLocaleLowerCase('zh-CN').includes(clientKeyword)) return false
138
- if (filters.businessType && row.businessType !== filters.businessType) return false
139
- if (filters.currencies.length && !filters.currencies.includes(row.currency)) return false
140
- if (filters.authirization && row.authirization !== filters.authirization) return false
141
- if (filters.ftuFilter === '1' && row.filter !== '1') return false
142
- if (filters.ftuFilter === '0' && row.filter !== '') return false
143
- if (minAmount !== null && row.predAmount < minAmount) return false
144
- if (maxAmount !== null && row.predAmount > maxAmount) return false
145
- return true
146
- })
84
+ const authorizationActionPredRefNo = ref('')
85
+ const forecastSort = ref<ForeignPositionForecastSort>({
86
+ amtOrder: '1',
87
+ predOrder: '',
88
+ timeOrder: '',
147
89
  })
148
-
149
- const paginatedRows = computed(() => {
150
- const start = (currentPage.value - 1) * pageSize.value
151
- return filteredRows.value.slice(start, start + pageSize.value)
152
- })
153
-
154
- const selectedCurrencyCount = computed(() => new Set(selectedRows.value.map((row) => row.currency)).size)
155
- const hasMixedCurrencySelection = computed(
156
- () => selectedRows.value.length > 1 && selectedCurrencyCount.value > 1,
157
- )
158
-
159
- const amountSummary = computed(() => {
160
- if (selectedRows.value.length === 0 || selectedCurrencyCount.value !== 1) return null
161
-
162
- const rows = selectedRows.value
163
- const currency = rows[0]?.currency ?? ''
164
-
165
- const income = rows
166
- .filter((row) => row.payDirection === 'I')
167
- .reduce((sum, row) => sum + row.predAmount, 0) / 10_000
168
- const expense = rows
169
- .filter((row) => row.payDirection === 'O')
170
- .reduce((sum, row) => sum + row.predAmount, 0) / 10_000
171
-
90
+ const tableDefaultSort = computed<{
91
+ prop: 'predAmount' | 'forecastTime' | 'approvalTime'
92
+ order: 'ascending' | 'descending'
93
+ }>(() => {
94
+ if (forecastSort.value.predOrder) {
95
+ return {
96
+ prop: 'forecastTime',
97
+ order: forecastSort.value.predOrder === '1' ? 'descending' : 'ascending',
98
+ }
99
+ }
100
+ if (forecastSort.value.timeOrder) {
101
+ return {
102
+ prop: 'approvalTime',
103
+ order: forecastSort.value.timeOrder === '1' ? 'descending' : 'ascending',
104
+ }
105
+ }
172
106
  return {
173
- currency,
174
- source: `已选 ${rows.length} 笔`,
175
- income,
176
- expense,
177
- net: income - expense,
107
+ prop: 'predAmount',
108
+ order: forecastSort.value.amtOrder === '2' ? 'ascending' : 'descending',
178
109
  }
179
110
  })
180
111
 
181
- const tableHeight = computed(() => (
182
- filterCollapsed.value ? 'calc(100vh - 330px)' : 'calc(100vh - 430px)'
183
- ))
112
+ let listRequestController: AbortController | null = null
184
113
 
185
114
  function getOptionLabel(options: SelectOption[], value: string) {
186
115
  return options.find((option) => option.value === value)?.label ?? value
@@ -208,7 +137,7 @@ function verifyTagType(status: VerifyStatus) {
208
137
  }
209
138
 
210
139
  function validateAmountRange() {
211
- const { minAmount, maxAmount } = filterForm
140
+ const { minAmount, maxAmount } = filterForm.value
212
141
  const componentValid = amountRangeRef.value?.validate() ?? amountRangeValid.value
213
142
 
214
143
  if ((minAmount !== null && minAmount < 0) || (maxAmount !== null && maxAmount < 0)) {
@@ -222,19 +151,66 @@ function validateAmountRange() {
222
151
  return true
223
152
  }
224
153
 
154
+ function isAbortError(error: unknown) {
155
+ return error instanceof Error && error.name === 'AbortError'
156
+ }
157
+
158
+ async function loadForecastRows() {
159
+ listRequestController?.abort()
160
+ const controller = new AbortController()
161
+ listRequestController = controller
162
+ isLoading.value = true
163
+
164
+ try {
165
+ const response = await queryForeignPositionForecasts(
166
+ appliedFilters.value,
167
+ currentPage.value,
168
+ pageSize.value,
169
+ forecastSort.value,
170
+ controller.signal,
171
+ )
172
+
173
+ if (controller.signal.aborted || listRequestController !== controller) return false
174
+
175
+ allRows.value = response.resultList
176
+ totalCount.value = response.totalCount
177
+ successfulFilters.value = cloneFilters(appliedFilters.value)
178
+ successfulPage.value = currentPage.value
179
+ successfulPageSize.value = pageSize.value
180
+ clearTableSelection()
181
+ return true
182
+ } catch (error) {
183
+ if (controller.signal.aborted || isAbortError(error)) return false
184
+ appliedFilters.value = cloneFilters(successfulFilters.value)
185
+ currentPage.value = successfulPage.value
186
+ pageSize.value = successfulPageSize.value
187
+ ElMessage.error(error instanceof Error ? error.message : '外币头寸预报查询失败')
188
+ return false
189
+ } finally {
190
+ if (listRequestController === controller) {
191
+ listRequestController = null
192
+ isLoading.value = false
193
+ }
194
+ }
195
+ }
196
+
225
197
  async function handleQuery() {
226
198
  if (!validateAmountRange() || isQuerying.value) return
227
199
 
228
200
  clearTableSelection()
229
201
  isQuerying.value = true
230
- await Promise.resolve()
231
- appliedFilters.value = cloneFilters(filterForm)
232
- currentPage.value = 1
233
- isQuerying.value = false
202
+
203
+ try {
204
+ appliedFilters.value = cloneFilters(filterForm.value)
205
+ currentPage.value = 1
206
+ await loadForecastRows()
207
+ } finally {
208
+ isQuerying.value = false
209
+ }
234
210
  }
235
211
 
236
212
  function handleReset() {
237
- Object.assign(filterForm, createEmptyFilters())
213
+ resetFilterForm()
238
214
  amountRangeValid.value = true
239
215
  clearTableSelection()
240
216
  }
@@ -243,13 +219,53 @@ function handleSelectionChange(rows: ForeignPositionForecast[]) {
243
219
  selectedRows.value = rows
244
220
  }
245
221
 
246
- function clearTableSelection() {
247
- selectedRows.value = []
248
- selectionResetKey.value += 1
222
+ async function handleSortChange({
223
+ prop,
224
+ order,
225
+ }: {
226
+ prop: string
227
+ order: 'ascending' | 'descending' | null
228
+ }) {
229
+ if (
230
+ prop !== 'predAmount'
231
+ && prop !== 'forecastTime'
232
+ && prop !== 'approvalTime'
233
+ ) return
234
+ if (order !== 'ascending' && order !== 'descending') return
235
+
236
+ const direction = order === 'descending' ? '1' : '2'
237
+ const nextSort: ForeignPositionForecastSort = {
238
+ amtOrder: prop === 'predAmount' ? direction : '',
239
+ predOrder: prop === 'forecastTime' ? direction : '',
240
+ timeOrder: prop === 'approvalTime' ? direction : '',
241
+ }
242
+
243
+ if (
244
+ forecastSort.value.amtOrder === nextSort.amtOrder
245
+ && forecastSort.value.predOrder === nextSort.predOrder
246
+ && forecastSort.value.timeOrder === nextSort.timeOrder
247
+ ) return
248
+
249
+ forecastSort.value = nextSort
250
+ currentPage.value = 1
251
+ clearTableSelection()
252
+ await loadForecastRows()
249
253
  }
250
254
 
251
- function handlePaginationChange() {
255
+ async function handlePaginationChange(pagination: { page: number; pageSize: number }) {
256
+ currentPage.value = pagination.page
257
+ pageSize.value = pagination.pageSize
252
258
  clearTableSelection()
259
+ await loadForecastRows()
260
+ }
261
+
262
+ async function refreshAfterMutation(resetToFirstPage = false) {
263
+ if (resetToFirstPage) currentPage.value = 1
264
+ const loaded = await loadForecastRows()
265
+ if (!loaded || allRows.value.length > 0 || currentPage.value <= 1) return
266
+
267
+ currentPage.value = Math.max(1, Math.ceil(totalCount.value / pageSize.value))
268
+ await loadForecastRows()
253
269
  }
254
270
 
255
271
  function getEditRestriction(row: ForeignPositionForecast) {
@@ -283,12 +299,6 @@ function getDeleteRestriction(row: ForeignPositionForecast) {
283
299
  return ''
284
300
  }
285
301
 
286
- function applyDeleteStatus(row: ForeignPositionForecast) {
287
- if (row.predStatus === 'PS01') row.predStatus = 'PS05'
288
- if (row.predStatus === 'PS02' || row.predStatus === 'PS03') row.predStatus = 'PS06'
289
- row.approvalTime = `${formatDate(new Date())} ${new Date().toTimeString().slice(0, 8)}`
290
- }
291
-
292
302
  function openAddEditor() {
293
303
  clearTableSelection()
294
304
  editorMode.value = 'add'
@@ -296,17 +306,25 @@ function openAddEditor() {
296
306
  pageMode.value = 'editor'
297
307
  }
298
308
 
299
- function openEditEditor(row: ForeignPositionForecast) {
309
+ async function openEditEditor(row: ForeignPositionForecast) {
300
310
  const restriction = getEditRestriction(row)
301
311
  if (restriction) {
302
312
  ElMessage.warning(restriction)
303
313
  return
304
314
  }
305
315
 
306
- clearTableSelection()
307
- editorMode.value = 'edit'
308
- editorRecord.value = { ...row }
309
- pageMode.value = 'editor'
316
+ isLoading.value = true
317
+ try {
318
+ const detail = await getForeignPositionForecast(row.predRefNo)
319
+ clearTableSelection()
320
+ editorMode.value = 'edit'
321
+ editorRecord.value = detail
322
+ pageMode.value = 'editor'
323
+ } catch (error) {
324
+ ElMessage.error(error instanceof Error ? error.message : '预报详情查询失败')
325
+ } finally {
326
+ isLoading.value = false
327
+ }
310
328
  }
311
329
 
312
330
  function returnToList() {
@@ -314,54 +332,30 @@ function returnToList() {
314
332
  editorRecord.value = null
315
333
  }
316
334
 
317
- function createForecastRefNo() {
318
- const prefix = `FPS${formatDate(new Date()).replaceAll('-', '')}`
319
- const sameDayCount = allRows.value.filter((row) => row.predRefNo.startsWith(prefix)).length
320
- return `${prefix}${String(sameDayCount + 1).padStart(4, '0')}`
321
- }
322
-
323
335
  async function submitEditor(value: ForecastEditorValue) {
324
336
  isSaving.value = true
325
337
 
326
338
  try {
327
- await Promise.resolve()
328
- const now = new Date()
329
-
330
339
  if (editorMode.value === 'add') {
331
- const newRow: ForeignPositionForecast = {
332
- predRefNo: createForecastRefNo(),
333
- authirization: '0',
334
- filter: '',
335
- ...value,
336
- predStatus: 'PS01',
337
- verifyStatus: 'VS01',
338
- verifyAmount: 0,
339
- forecasterName: mockCurrentUser.userName,
340
- forecasterCode: mockCurrentUser.userCode,
341
- forecastDepartment: mockCurrentUser.department,
342
- phoneNumber: mockCurrentUser.phoneNumber,
343
- forecastTime: `${formatDate(now)} ${now.toTimeString().slice(0, 8)}`,
344
- approvalTime: '',
345
- }
346
- allRows.value.unshift(newRow)
340
+ await createForeignPositionForecast(value)
347
341
  ElMessage.success('新增预报成功,已进入待分行确认状态')
342
+ await refreshAfterMutation(true)
348
343
  } else {
349
- const row = allRows.value.find((item) => item.predRefNo === editorRecord.value?.predRefNo)
350
- if (!row) {
344
+ const predRefNo = editorRecord.value?.predRefNo
345
+ if (!predRefNo) {
351
346
  ElMessage.error('原预报记录不存在,请返回列表后重试')
352
347
  return
353
348
  }
354
349
 
355
- const wasConfirmed = row.predStatus === 'PS03'
356
- Object.assign(row, value, {
357
- predStatus: wasConfirmed ? 'PS01' : row.predStatus,
358
- approvalTime: wasConfirmed ? '' : row.approvalTime,
359
- })
350
+ await updateForeignPositionForecast(predRefNo, value)
360
351
  ElMessage.success('预报修改成功')
352
+ await refreshAfterMutation()
361
353
  }
362
354
 
363
355
  clearTableSelection()
364
356
  returnToList()
357
+ } catch (error) {
358
+ ElMessage.error(error instanceof Error ? error.message : '预报保存失败')
365
359
  } finally {
366
360
  isSaving.value = false
367
361
  }
@@ -384,25 +378,56 @@ async function handleDelete(row: ForeignPositionForecast) {
384
378
  return
385
379
  }
386
380
 
387
- applyDeleteStatus(row)
388
- clearTableSelection()
389
- ElMessage.success(row.predStatus === 'PS05' ? '删除成功' : '删除申请已提交,等待分行确认')
390
- }
391
-
392
- function nextApprovalStatus(status: ForecastStatus, approved: boolean): ForecastStatus {
393
- if (approved) {
394
- if (status === 'PS01') return 'PS02'
395
- if (status === 'PS02') return 'PS03'
396
- if (status === 'PS06') return 'PS07'
397
- if (status === 'PS07') return 'PS05'
398
- } else {
399
- if (status === 'PS01' || status === 'PS06') return 'PS04'
400
- if (status === 'PS02' || status === 'PS07') return 'PS08'
381
+ try {
382
+ const updatedRow = await deleteForeignPositionForecast(row.predRefNo)
383
+ clearTableSelection()
384
+ ElMessage.success(updatedRow.predStatus === 'PS05' ? '删除成功' : '删除申请已提交,等待分行确认')
385
+ await refreshAfterMutation()
386
+ } catch (error) {
387
+ ElMessage.error(error instanceof Error ? error.message : '预报删除失败')
388
+ }
389
+ }
390
+
391
+ async function handleAuthorization(row: ForeignPositionForecast) {
392
+ if (authorizationActionPredRefNo.value) return
393
+
394
+ const authorization = row.authirization === '1' ? '0' : '1'
395
+ const actionText = authorization === '1' ? '授权' : '取消授权'
396
+ authorizationActionPredRefNo.value = row.predRefNo
397
+
398
+ try {
399
+ try {
400
+ await ElMessageBox.confirm(
401
+ `确认对预报 ${row.predRefNo} 执行${actionText}操作吗?`,
402
+ `${actionText}确认`,
403
+ {
404
+ confirmButtonText: `确认${actionText}`,
405
+ cancelButtonText: '取消',
406
+ type: authorization === '1' ? 'success' : 'warning',
407
+ },
408
+ )
409
+ } catch {
410
+ return
411
+ }
412
+
413
+ const message = await updateForeignPositionForecastAuthorization(
414
+ row.predRefNo,
415
+ authorization,
416
+ currentPage.value,
417
+ pageSize.value,
418
+ )
419
+ ElMessage.success(message)
420
+ await refreshAfterMutation()
421
+ } catch (error) {
422
+ ElMessage.error(error instanceof Error ? error.message : `${actionText}失败`)
423
+ } finally {
424
+ authorizationActionPredRefNo.value = ''
401
425
  }
402
- return status
403
426
  }
404
427
 
405
428
  async function handleApproval(approved: boolean) {
429
+ if (approvalAction.value) return
430
+
406
431
  if (selectedRows.value.length === 0) {
407
432
  ElMessage.warning('请至少选择一条记录')
408
433
  return
@@ -431,123 +456,30 @@ async function handleApproval(approved: boolean) {
431
456
  return
432
457
  }
433
458
 
434
- const approvalTime = `${formatDate(new Date())} ${new Date().toTimeString().slice(0, 8)}`
435
- selectedRows.value.forEach((row) => {
436
- row.predStatus = nextApprovalStatus(row.predStatus, approved)
437
- row.approvalTime = approvalTime
438
- })
439
- clearTableSelection()
440
- ElMessage.success(`审批${actionText}操作成功`)
441
- }
442
-
443
- function escapeCsv(value: unknown) {
444
- return `"${String(value ?? '').replaceAll('"', '""')}"`
445
- }
446
-
447
- function downloadCsv(filename: string, headers: string[], rows: unknown[][]) {
448
- const content = [headers, ...rows].map((row) => row.map(escapeCsv).join(',')).join('\n')
449
- const blob = new Blob(['\ufeff', content], { type: 'text/csv;charset=utf-8' })
450
- const url = URL.createObjectURL(blob)
451
- const link = document.createElement('a')
452
- link.href = url
453
- link.download = filename
454
- link.click()
455
- URL.revokeObjectURL(url)
456
- }
457
-
458
- async function handleExport() {
459
- if (!validateAmountRange()) return
460
- if (filteredRows.value.length === 0) {
461
- ElMessage.warning('当前查询条件下没有可导出的记录')
462
- return
463
- }
459
+ if (approvalAction.value) return
460
+ approvalAction.value = approved ? 'approve' : 'reject'
464
461
 
465
462
  try {
466
- await ElMessageBox.confirm(`确定导出当前查询结果的 ${filteredRows.value.length} 笔记录吗?`, '导出确认', {
467
- confirmButtonText: '确定导出',
468
- cancelButtonText: '取消',
469
- type: 'info',
470
- })
471
- } catch {
472
- return
473
- }
474
-
475
- const headers = [
476
- '预报流水号', '预报方式', '预报状态', '预报类型', '落地机构', '收支方向', '账户行', '币种',
477
- '预报金额(元)', '起息日', '核销状态', '核销金额(元)', '业务类型', '客户名称', '客户账号',
478
- '交易对手名称', '交易对手账号', '交易对手行名称', '交易对手行SWIFTCODE', '结汇/购汇/现汇',
479
- '预报时间', '审批时间',
480
- ]
481
- const rows = filteredRows.value.map((row) => [
482
- row.predRefNo,
483
- getOptionLabel(forecastWayOptions, row.predWay),
484
- getOptionLabel(forecastStatusOptions, row.predStatus),
485
- getOptionLabel(forecastTypeOptions, row.predType),
486
- row.groundBranch,
487
- getOptionLabel(payDirectionOptions, row.payDirection),
488
- row.bankAccount,
489
- row.currency,
490
- row.predAmount,
491
- row.valueDate,
492
- getOptionLabel(verifyStatusOptions, row.verifyStatus),
493
- row.verifyAmount,
494
- getOptionLabel(businessTypeOptions, row.businessType),
495
- row.clientName,
496
- row.clientAccount,
497
- row.counterpartyName,
498
- row.counterpartyAccount,
499
- row.receivingBank,
500
- row.receivingBankSwiftCode,
501
- getOptionLabel(foreignExchangeTypeOptions, row.foreignExchangeType),
502
- row.forecastTime,
503
- row.approvalTime,
504
- ])
505
-
506
- downloadCsv(`外币头寸预报_${formatDate(new Date())}.csv`, headers, rows)
507
- ElMessage.success('导出文件已生成')
508
- }
509
-
510
- function openImportDialog() {
511
- importFileList.value = []
512
- importVisible.value = true
513
- }
514
-
515
- async function handleImport() {
516
- if (importFileList.value.length === 0) {
517
- ElMessage.warning('请选择需要导入的文件')
518
- return
463
+ const response = await approveForeignPositionForecasts(
464
+ selectedRows.value.map((row) => row.predRefNo),
465
+ approved,
466
+ )
467
+ clearTableSelection()
468
+ ElMessage.success(response.message || `审批${actionText}操作成功`)
469
+ await refreshAfterMutation()
470
+ } catch (error) {
471
+ ElMessage.error(error instanceof Error ? error.message : `审批${actionText}操作失败`)
472
+ } finally {
473
+ approvalAction.value = null
519
474
  }
520
-
521
- isImporting.value = true
522
- await Promise.resolve()
523
- const baseRows = allRows.value.slice(0, 2)
524
- const importedRows = baseRows.map((row, index): ForeignPositionForecast => ({
525
- ...row,
526
- predRefNo: createForecastRefNo().slice(0, -4) + String(allRows.value.length + index + 1).padStart(4, '0'),
527
- predWay: 'PW01',
528
- predStatus: 'PS01',
529
- predType: 'PT01',
530
- valueDate: formatDate(addDays(new Date(), index + 2)),
531
- verifyStatus: 'VS01',
532
- verifyAmount: 0,
533
- predAmount: row.predAmount + (index + 1) * 500_000,
534
- forecasterName: mockCurrentUser.userName,
535
- forecasterCode: mockCurrentUser.userCode,
536
- forecastDepartment: mockCurrentUser.department,
537
- forecastTime: `${formatDate(new Date())} ${new Date().toTimeString().slice(0, 8)}`,
538
- approvalTime: '',
539
- }))
540
- allRows.value.unshift(...importedRows)
541
- clearTableSelection()
542
- isImporting.value = false
543
- importVisible.value = false
544
- ElMessage.success(`批量导入成功,共导入 ${importedRows.length} 笔预报`)
545
475
  }
546
476
 
547
- onMounted(async () => {
548
- isLoading.value = true
549
- allRows.value = await mockFetchForeignPositionForecasts()
550
- isLoading.value = false
477
+ onMounted(() => {
478
+ void loadForecastRows()
479
+ })
480
+
481
+ onBeforeUnmount(() => {
482
+ listRequestController?.abort()
551
483
  })
552
484
  </script>
553
485
 
@@ -723,10 +655,11 @@ onMounted(async () => {
723
655
  v-model:page="currentPage"
724
656
  v-model:page-size="pageSize"
725
657
  v-loading="isLoading"
726
- :data="paginatedRows"
727
- :total="filteredRows.length"
658
+ :data="allRows"
659
+ :total="totalCount"
728
660
  :page-sizes="[10, 25, 50, 100]"
729
661
  :selection-reset-key="selectionResetKey"
662
+ :default-sort="tableDefaultSort"
730
663
  table-key="foreign-currency-position-forecast"
731
664
  row-key="predRefNo"
732
665
  border
@@ -737,26 +670,43 @@ onMounted(async () => {
737
670
  layout="total, sizes, prev, pager, next, jumper"
738
671
  pagination-size="small"
739
672
  @selection-change="handleSelectionChange"
673
+ @sort-change="handleSortChange"
740
674
  @pagination-change="handlePaginationChange"
741
675
  >
742
676
  <template #toolbar>
743
677
  <div class="table-toolbar-actions">
744
678
  <el-button size="small" type="primary" :icon="Plus" @click="openAddEditor">新增</el-button>
745
679
  <span class="operation-divider" aria-hidden="true"></span>
746
- <el-button size="small" :icon="UploadFilled" @click="openImportDialog">导入</el-button>
680
+ <el-button size="small" :icon="UploadFilled">导入</el-button>
747
681
  </div>
748
682
  </template>
749
683
 
750
684
  <template #toolbar-right>
751
685
  <div class="table-toolbar-actions">
752
686
  <span class="selection-count">已选 {{ selectedRows.length }} 笔</span>
753
- <el-button size="small" type="success" plain :icon="CircleCheck" @click="handleApproval(true)">
687
+ <el-button
688
+ size="small"
689
+ type="success"
690
+ plain
691
+ :icon="CircleCheck"
692
+ :loading="approvalAction === 'approve'"
693
+ :disabled="approvalAction !== null"
694
+ @click="handleApproval(true)"
695
+ >
754
696
  审批确认
755
697
  </el-button>
756
- <el-button size="small" type="danger" plain :icon="CircleClose" @click="handleApproval(false)">
698
+ <el-button
699
+ size="small"
700
+ type="danger"
701
+ plain
702
+ :icon="CircleClose"
703
+ :loading="approvalAction === 'reject'"
704
+ :disabled="approvalAction !== null"
705
+ @click="handleApproval(false)"
706
+ >
757
707
  审批拒绝
758
708
  </el-button>
759
- <el-button size="small" :icon="Download" @click="handleExport">导出</el-button>
709
+ <el-button size="small" :icon="Download">导出</el-button>
760
710
  </div>
761
711
  </template>
762
712
 
@@ -788,7 +738,14 @@ onMounted(async () => {
788
738
  <el-table-column prop="currency" label="币种" width="82">
789
739
  <template #default="{ row }"><strong class="currency-code">{{ row.currency }}</strong></template>
790
740
  </el-table-column>
791
- <el-table-column prop="predAmount" label="预报金额(元)" width="152" align="right" sortable>
741
+ <el-table-column
742
+ prop="predAmount"
743
+ label="预报金额(元)"
744
+ width="152"
745
+ align="right"
746
+ sortable="custom"
747
+ :sort-orders="['descending', 'ascending']"
748
+ >
792
749
  <template #default="{ row }"><span class="money-cell">{{ formatMoney(row.predAmount) }}</span></template>
793
750
  </el-table-column>
794
751
  <el-table-column prop="valueDate" label="起息日" width="116" />
@@ -814,14 +771,28 @@ onMounted(async () => {
814
771
  <el-table-column label="结汇/购汇/现汇" width="136">
815
772
  <template #default="{ row }">{{ getOptionLabel(foreignExchangeTypeOptions, row.foreignExchangeType) }}</template>
816
773
  </el-table-column>
817
- <el-table-column prop="forecastTime" label="预报时间" width="170" sortable show-overflow-tooltip />
818
- <el-table-column prop="approvalTime" label="审批时间" width="170" show-overflow-tooltip>
774
+ <el-table-column
775
+ prop="forecastTime"
776
+ label="预报时间"
777
+ width="170"
778
+ sortable="custom"
779
+ :sort-orders="['descending', 'ascending']"
780
+ show-overflow-tooltip
781
+ />
782
+ <el-table-column
783
+ prop="approvalTime"
784
+ label="审批时间"
785
+ width="170"
786
+ sortable="custom"
787
+ :sort-orders="['descending', 'ascending']"
788
+ show-overflow-tooltip
789
+ >
819
790
  <template #default="{ row }">{{ row.approvalTime || '—' }}</template>
820
791
  </el-table-column>
821
792
  <el-table-column
822
793
  column-key="operation"
823
794
  label="操作"
824
- width="150"
795
+ width="248"
825
796
  fixed="right"
826
797
  align="center"
827
798
  disabled
@@ -834,31 +805,22 @@ onMounted(async () => {
834
805
  <el-button link type="danger" :icon="Delete" @click.stop="handleDelete(row)">
835
806
  删除
836
807
  </el-button>
808
+ <el-button
809
+ link
810
+ :type="row.authirization === '1' ? 'warning' : 'success'"
811
+ :icon="row.authirization === '1' ? CircleClose : CircleCheck"
812
+ :loading="authorizationActionPredRefNo === row.predRefNo"
813
+ :disabled="Boolean(authorizationActionPredRefNo) && authorizationActionPredRefNo !== row.predRefNo"
814
+ @click.stop="handleAuthorization(row)"
815
+ >
816
+ {{ row.authirization === '1' ? '取消授权' : '授权' }}
817
+ </el-button>
837
818
  </div>
838
819
  </template>
839
820
  </el-table-column>
840
821
  </ElTablePro>
841
822
  </section>
842
823
 
843
- <el-dialog v-model="importVisible" title="批量导入" width="520px" destroy-on-close>
844
- <el-upload
845
- v-model:file-list="importFileList"
846
- class="forecast-upload"
847
- drag
848
- action="#"
849
- accept=".xls,.xlsx,.csv"
850
- :auto-upload="false"
851
- :limit="1"
852
- >
853
- <el-icon class="upload-icon"><UploadFilled /></el-icon>
854
- <div class="upload-title">拖拽文件到此处,或<span>点击选择</span></div>
855
- <p>支持 xls、xlsx、csv,每次仅允许上传 1 个文件</p>
856
- </el-upload>
857
- <template #footer>
858
- <el-button @click="importVisible = false">关闭</el-button>
859
- <el-button type="primary" :loading="isImporting" @click="handleImport">导入</el-button>
860
- </template>
861
- </el-dialog>
862
824
  </template>
863
825
  </main>
864
826
  </template>
@@ -1148,39 +1110,6 @@ onMounted(async () => {
1148
1110
  margin-left: 0;
1149
1111
  }
1150
1112
 
1151
- .forecast-upload :deep(.el-upload),
1152
- .forecast-upload :deep(.el-upload-dragger) {
1153
- width: 100%;
1154
- }
1155
-
1156
- .forecast-upload :deep(.el-upload-dragger) {
1157
- padding: 32px 20px;
1158
- border-color: #b8c8dd;
1159
- background: #f8fafc;
1160
- }
1161
-
1162
- .upload-icon {
1163
- margin-bottom: 10px;
1164
- color: #2a65bf;
1165
- font-size: 42px;
1166
- }
1167
-
1168
- .upload-title {
1169
- color: #344054;
1170
- font-size: 14px;
1171
- }
1172
-
1173
- .upload-title span {
1174
- color: #1f62d6;
1175
- font-weight: 700;
1176
- }
1177
-
1178
- .forecast-upload p {
1179
- margin: 8px 0 0;
1180
- color: #98a2b3;
1181
- font-size: 12px;
1182
- }
1183
-
1184
1113
  @media (max-width: 1380px) {
1185
1114
  .query-grid:not(.is-collapsed) {
1186
1115
  grid-template-columns: repeat(4, minmax(0, 1fr));
@@ -1214,6 +1143,5 @@ onMounted(async () => {
1214
1143
  .summary-caption {
1215
1144
  border-bottom: 1px solid #edf0f5;
1216
1145
  }
1217
-
1218
1146
  }
1219
1147
  </style>