zhou zhou
11 分钟以前 28c6a76ead9b65a0b5861d70f0838ef2a46f5c45
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
<template>
  <div class="revise-log-page art-full-height">
    <ArtSearchBar
      v-model="searchForm"
      :items="searchItems"
      :showExpand="true"
      @search="handleSearch"
      @reset="handleReset"
    />
 
    <ElCard class="art-table-card">
      <ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData" />
 
      <ArtTable
        :loading="loading"
        :data="data"
        :columns="columns"
        :pagination="pagination"
        @pagination:size-change="handleSizeChange"
        @pagination:current-change="handleCurrentChange"
      />
    </ElCard>
 
    <ReviseLogDetailDrawer
      v-model:visible="detailDrawerVisible"
      :loading="detailLoading"
      :summary="detailData"
      :item-loading="itemLoading"
      :item-data="itemTableData"
      :item-columns="itemColumns"
      :item-pagination="itemPagination"
      @item-size-change="handleItemSizeChange"
      @item-current-change="handleItemCurrentChange"
    />
  </div>
</template>
 
<script setup>
  import { computed, reactive, ref } from 'vue'
  import { ElMessage } from 'element-plus'
  import { useTable } from '@/hooks/core/useTable'
  import { useTableColumns } from '@/hooks/core/useTableColumns'
  import { defaultResponseAdapter } from '@/utils/table/tableUtils'
  import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
  import { fetchGetReviseLogDetail, fetchReviseLogPage } from '@/api/revise-log'
  import { fetchReviseLogItemPage } from '@/api/revise-log-item'
  import ReviseLogDetailDrawer from './modules/revise-log-detail-drawer.vue'
  import { createReviseLogTableColumns } from './reviseLogTable.columns'
  import {
    buildReviseLogPageQueryParams,
    buildReviseLogSearchParams,
    createReviseLogSearchState,
    getReviseLogPaginationKey,
    getReviseLogStatusOptions,
    getReviseLogTypeOptions,
    normalizeReviseLogRow
  } from './reviseLogPage.helpers'
  import { createReviseLogItemDetailColumns } from '../revise-log-item/reviseLogItemTable.columns'
  import { normalizeReviseLogItemRow } from '../revise-log-item/reviseLogItemPage.helpers'
 
  defineOptions({ name: 'ReviseLog' })
 
  const searchForm = ref(createReviseLogSearchState())
  const detailDrawerVisible = ref(false)
  const detailLoading = ref(false)
  const detailData = ref({})
  const itemLoading = ref(false)
  const itemTableData = ref([])
  const activeDetail = ref({})
  const itemPagination = reactive({ current: 1, size: 20, total: 0 })
 
  const searchItems = computed(() => [
    {
      label: '关键字',
      key: 'condition',
      type: 'input',
      props: { clearable: true, placeholder: '请输入调整单号/库位/容器码' }
    },
    {
      label: '调整单号',
      key: 'reviseId',
      type: 'input',
      props: { clearable: true, placeholder: '请输入调整单ID' }
    },
    {
      label: '调整编码',
      key: 'reviseCode',
      type: 'input',
      props: { clearable: true, placeholder: '请输入调整单编码' }
    },
    {
      label: '仓库ID',
      key: 'warehouseId',
      type: 'input',
      props: { clearable: true, placeholder: '请输入仓库ID' }
    },
    {
      label: '库区ID',
      key: 'areaId',
      type: 'input',
      props: { clearable: true, placeholder: '请输入库区ID' }
    },
    {
      label: '调整类型',
      key: 'type',
      type: 'select',
      props: {
        clearable: true,
        options: getReviseLogTypeOptions().map((item) => ({ label: item.label, value: item.value }))
      }
    },
    {
      label: '容器码',
      key: 'barcode',
      type: 'input',
      props: { clearable: true, placeholder: '请输入容器码' }
    },
    {
      label: '库位状态',
      key: 'useStatus',
      type: 'input',
      props: { clearable: true, placeholder: '请输入库位状态' }
    },
    {
      label: '巷道',
      key: 'channel',
      type: 'input',
      props: { clearable: true, placeholder: '请输入巷道' }
    },
    {
      label: '排',
      key: 'row',
      type: 'input',
      props: { clearable: true, placeholder: '请输入排' }
    },
    {
      label: '列',
      key: 'col',
      type: 'input',
      props: { clearable: true, placeholder: '请输入列' }
    },
    {
      label: '层',
      key: 'lev',
      type: 'input',
      props: { clearable: true, placeholder: '请输入层' }
    },
    {
      label: '状态',
      key: 'status',
      type: 'select',
      props: {
        clearable: true,
        options: getReviseLogStatusOptions().map((item) => ({ label: item.label, value: item.value }))
      }
    },
    {
      label: '备注',
      key: 'memo',
      type: 'input',
      props: { clearable: true, placeholder: '请输入备注' }
    },
    {
      label: '开始时间',
      key: 'timeStart',
      type: 'date',
      props: { clearable: true, valueFormat: 'YYYY-MM-DD', type: 'date' }
    },
    {
      label: '结束时间',
      key: 'timeEnd',
      type: 'date',
      props: { clearable: true, valueFormat: 'YYYY-MM-DD', type: 'date' }
    }
  ])
 
  function updatePaginationState(target, response, fallbackCurrent, fallbackSize) {
    target.total = Number(response?.total || 0)
    target.current = Number(response?.current || fallbackCurrent || 1)
    target.size = Number(response?.size || fallbackSize || target.size || 20)
  }
 
  async function openDetail(row) {
    detailDrawerVisible.value = true
    detailLoading.value = true
    activeDetail.value = row || {}
    itemTableData.value = []
    itemPagination.current = 1
    try {
      detailData.value = normalizeReviseLogRow(
        await guardRequestWithMessage(fetchGetReviseLogDetail(row.id), {}, {
          timeoutMessage: '库位调整日志详情加载超时,已停止等待'
        })
      )
      await loadItemData(row.id)
    } catch (error) {
      detailDrawerVisible.value = false
      detailData.value = {}
      ElMessage.error(error?.message || '获取库位调整日志详情失败')
    } finally {
      detailLoading.value = false
    }
  }
 
  async function loadItemData(reviseLogId = activeDetail.value?.id) {
    if (!reviseLogId) {
      itemTableData.value = []
      return
    }
    itemLoading.value = true
    try {
      const response = await guardRequestWithMessage(
        fetchReviseLogItemPage({
          reviseLogId,
          current: itemPagination.current,
          pageSize: itemPagination.size
        }),
        { records: [], total: 0, current: itemPagination.current, size: itemPagination.size },
        { timeoutMessage: '库位调整日志明细加载超时,已停止等待' }
      )
      const normalized = defaultResponseAdapter(response)
      itemTableData.value = Array.isArray(normalized?.records)
        ? normalized.records.map((record) => normalizeReviseLogItemRow(record))
        : []
      updatePaginationState(itemPagination, normalized, itemPagination.current, itemPagination.size)
    } finally {
      itemLoading.value = false
    }
  }
 
  const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData } =
    useTable({
      core: {
        apiFn: fetchReviseLogPage,
        apiParams: buildReviseLogPageQueryParams(searchForm.value),
        paginationKey: getReviseLogPaginationKey(),
        columnsFactory: () => createReviseLogTableColumns({ handleView: openDetail })
      },
      transform: {
        dataTransformer: (records) => (Array.isArray(records) ? records.map((item) => normalizeReviseLogRow(item)) : [])
      }
    })
 
  const itemColumns = computed(() => createReviseLogItemDetailColumns())
 
  function handleItemSizeChange(size) {
    itemPagination.size = size
    itemPagination.current = 1
    loadItemData()
  }
 
  function handleItemCurrentChange(current) {
    itemPagination.current = current
    loadItemData()
  }
 
  function handleSearch(params) {
    replaceSearchParams(buildReviseLogSearchParams(params))
    getData()
  }
 
  function handleReset() {
    Object.assign(searchForm.value, createReviseLogSearchState())
    resetSearchParams()
  }
</script>