zhou zhou
5 天以前 aaf8a50511d77dbc209ca93bbba308c21179a8bc
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
<template>
  <div class="in-statistic-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>
    <InStatisticDetailDrawer v-model:visible="detailDrawerVisible" :detail="detailData" />
  </div>
</template>
 
<script setup>
  import { computed, ref } from 'vue'
  import { useTable } from '@/hooks/core/useTable'
  import { fetchInStatisticPage } from '@/api/in-statistic'
  import {
    buildInStatisticPageQueryParams,
    buildInStatisticSearchParams,
    createInStatisticSearchState,
    getInStatisticPaginationKey,
    normalizeInStatisticRow
  } from './inStatisticPage.helpers'
  import { createInStatisticTableColumns } from './inStatisticTable.columns'
  import InStatisticDetailDrawer from './modules/in-statistic-detail-drawer.vue'
 
  defineOptions({ name: 'InStatistic' })
 
  const searchForm = ref(createInStatisticSearchState())
  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: 'maktx', type: 'input', props: { clearable: true, placeholder: '请输入物料名称' } },
    { label: '物料编码', key: 'matnrCode', type: 'input', props: { clearable: true, placeholder: '请输入物料编码' } },
    { label: '批次', key: 'batch', type: 'input', props: { clearable: true, placeholder: '请输入批次' } }
  ])
 
  function openDetail(row) {
    detailData.value = normalizeInStatisticRow(row)
    detailDrawerVisible.value = true
  }
 
  const {
    columns,
    columnChecks,
    data,
    loading,
    pagination,
    getData,
    replaceSearchParams,
    resetSearchParams,
    handleSizeChange,
    handleCurrentChange,
    refreshData
  } = useTable({
    core: {
      apiFn: fetchInStatisticPage,
      apiParams: buildInStatisticPageQueryParams(searchForm.value),
      paginationKey: getInStatisticPaginationKey(),
      columnsFactory: () => createInStatisticTableColumns({ handleView: openDetail })
    },
    transform: {
      dataTransformer: (records) => (Array.isArray(records) ? records.map((item) => normalizeInStatisticRow(item)) : [])
    }
  })
 
  function handleSearch(params) {
    replaceSearchParams(buildInStatisticSearchParams(params))
    getData()
  }
 
  function handleReset() {
    Object.assign(searchForm.value, createInStatisticSearchState())
    resetSearchParams()
  }
</script>