zhou zhou
6 小时以前 450c9d39c6eb3765642f977512202e3240ac9b03
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
<template>
  <div class="in-statistic-item-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>
    <InStatisticItemDetailDrawer v-model:visible="detailDrawerVisible" :detail="detailData" />
  </div>
</template>
 
<script setup>
  import { computed, ref } from 'vue'
  import { useTable } from '@/hooks/core/useTable'
  import { fetchInStatisticItemPage } from '@/api/in-statistic-item'
  import {
    buildInStatisticItemPageQueryParams,
    buildInStatisticItemSearchParams,
    createInStatisticItemSearchState,
    getInStatisticItemPaginationKey,
    normalizeInStatisticItemRow
  } from './inStatisticItemPage.helpers'
  import { createInStatisticItemTableColumns } from './inStatisticItemTable.columns'
  import InStatisticItemDetailDrawer from './modules/in-statistic-item-detail-drawer.vue'
 
  defineOptions({ name: 'InStatisticItem' })
 
  const searchForm = ref(createInStatisticItemSearchState())
  const detailDrawerVisible = ref(false)
  const detailData = ref({})
 
  const searchItems = computed(() => [
    { label: '关键字', key: 'condition', type: 'input', props: { clearable: true, placeholder: '请输入物料名称/编码/批次/库位' } },
    { label: '统计日期', key: 'dayTime', type: 'date', props: { clearable: true, type: 'date', valueFormat: 'YYYY-MM-DD' } },
    { label: '库位', key: 'locCode', type: 'input', props: { clearable: true, placeholder: '请输入库位' } },
    { label: '物料编码', key: 'matnrCode', type: 'input', props: { clearable: true, placeholder: '请输入物料编码' } },
    { label: '物料名称', key: 'maktx', type: 'input', props: { clearable: true, placeholder: '请输入物料名称' } },
    { label: '批次', key: 'batch', type: 'input', props: { clearable: true, placeholder: '请输入批次' } }
  ])
 
  function openDetail(row) {
    detailData.value = normalizeInStatisticItemRow(row)
    detailDrawerVisible.value = true
  }
 
  const {
    columns,
    columnChecks,
    data,
    loading,
    pagination,
    getData,
    replaceSearchParams,
    resetSearchParams,
    handleSizeChange,
    handleCurrentChange,
    refreshData
  } = useTable({
    core: {
      apiFn: fetchInStatisticItemPage,
      apiParams: buildInStatisticItemPageQueryParams(searchForm.value),
      paginationKey: getInStatisticItemPaginationKey(),
      columnsFactory: () => createInStatisticItemTableColumns({ handleView: openDetail })
    },
    transform: {
      dataTransformer: (records) => (Array.isArray(records) ? records.map((item) => normalizeInStatisticItemRow(item)) : [])
    }
  })
 
  function handleSearch(params) {
    replaceSearchParams(buildInStatisticItemSearchParams(params))
    getData()
  }
 
  function handleReset() {
    Object.assign(searchForm.value, createInStatisticItemSearchState())
    resetSearchParams()
  }
</script>