zhou zhou
2 天以前 0a1d91e42e6c5af96e1108e9ebcc37e99eb3b22c
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
<template>
  <div class="subsystem-flow-template-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">
        <template #left>
          <ListExportPrint
            class="inline-flex"
            :preview-visible="previewVisible"
            @update:previewVisible="handlePreviewVisibleChange"
            :report-title="reportTitle"
            :selected-rows="selectedRows"
            :query-params="reportQueryParams"
            :columns="reportColumns"
            :preview-rows="previewRows"
            :preview-meta="previewMeta"
            :total="pagination.total"
            :disabled="loading"
            @export="handleExport"
            @print="handlePrint"
          />
        </template>
      </ArtTableHeader>
 
      <ArtTable
        :loading="loading"
        :data="data"
        :columns="columns"
        :pagination="pagination"
        @selection-change="handleSelectionChange"
        @pagination:size-change="handleSizeChange"
        @pagination:current-change="handleCurrentChange"
      />
    </ElCard>
 
    <SubsystemFlowTemplateDetailDrawer v-model:visible="detailDrawerVisible" :detail="detailData" />
  </div>
</template>
 
<script setup>
  import { computed, ref } from 'vue'
  import { useUserStore } from '@/store/modules/user'
  import { useTable } from '@/hooks/core/useTable'
  import { defaultResponseAdapter } from '@/utils/table/tableUtils'
  import ListExportPrint from '@/components/biz/list-export-print/index.vue'
  import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
  import {
    fetchExportSubsystemFlowTemplateReport,
    fetchGetSubsystemFlowTemplateDetail,
    fetchGetSubsystemFlowTemplateMany,
    fetchSubsystemFlowTemplatePage
  } from '@/api/subsystem-flow-template'
  import {
    buildSubsystemFlowTemplatePageQueryParams,
    buildSubsystemFlowTemplatePrintRows,
    buildSubsystemFlowTemplateSearchParams,
    createSubsystemFlowTemplateSearchState,
    getSubsystemFlowTemplatePaginationKey,
    getSubsystemFlowTemplateReportColumns,
    normalizeSubsystemFlowTemplateRow,
    SUBSYSTEM_FLOW_TEMPLATE_REPORT_TITLE
  } from './subsystemFlowTemplatePage.helpers'
  import { createSubsystemFlowTemplateTableColumns } from './subsystemFlowTemplateTable.columns'
  import SubsystemFlowTemplateDetailDrawer from './modules/subsystem-flow-template-detail-drawer.vue'
 
  defineOptions({ name: 'SubsystemFlowTemplate' })
 
  const userStore = useUserStore()
  const searchForm = ref(createSubsystemFlowTemplateSearchState())
  const detailDrawerVisible = ref(false)
  const detailData = ref({})
  const selectedRows = ref([])
  const reportTitle = SUBSYSTEM_FLOW_TEMPLATE_REPORT_TITLE
  const reportQueryParams = computed(() => buildSubsystemFlowTemplateSearchParams(searchForm.value))
  const reportColumns = getSubsystemFlowTemplateReportColumns()
 
  const searchItems = computed(() => [
    { label: '关键字', key: 'condition', type: 'input', props: { clearable: true, placeholder: '请输入流程编码/流程名称' } },
    { label: '流程编码', key: 'flowCode', type: 'input', props: { clearable: true, placeholder: '请输入流程编码' } },
    { label: '流程名称', key: 'flowName', type: 'input', props: { clearable: true, placeholder: '请输入流程名称' } },
    { label: '系统编码', key: 'systemCode', type: 'input', props: { clearable: true, placeholder: '请输入系统编码' } },
    { label: '系统名称', key: 'systemName', type: 'input', props: { clearable: true, placeholder: '请输入系统名称' } },
    { label: '节点类型', key: 'nodeType', 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 openDetail(row) {
    detailDrawerVisible.value = true
    loadDetail(row.id, row)
  }
 
  const {
    columns,
    columnChecks,
    data,
    loading,
    pagination,
    getData,
    replaceSearchParams,
    resetSearchParams,
    handleSizeChange,
    handleCurrentChange,
    refreshData
  } = useTable({
    core: {
      apiFn: fetchSubsystemFlowTemplatePage,
      apiParams: buildSubsystemFlowTemplatePageQueryParams(searchForm.value),
      paginationKey: getSubsystemFlowTemplatePaginationKey(),
      columnsFactory: () => createSubsystemFlowTemplateTableColumns({ handleView: openDetail })
    },
    transform: {
      dataTransformer: (records) =>
        Array.isArray(records) ? records.map((item) => normalizeSubsystemFlowTemplateRow(item)) : []
    }
  })
 
  const resolvePrintRecords = async (payload) => {
    if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
      return defaultResponseAdapter(await fetchGetSubsystemFlowTemplateMany(payload.ids)).records
    }
    return defaultResponseAdapter(
      await fetchSubsystemFlowTemplatePage({
        ...reportQueryParams.value,
        current: 1,
        pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : 20
      })
    ).records
  }
 
  const {
    previewVisible,
    previewRows,
    previewMeta,
    handlePreviewVisibleChange,
    handleExport,
    handlePrint
  } = usePrintExportPage({
    downloadFileName: 'subsystem-flow-template.xlsx',
    requestExport: (payload) =>
      fetchExportSubsystemFlowTemplateReport(payload, {
        headers: {
          Authorization: userStore.accessToken || ''
        }
      }),
    resolvePrintRecords,
    buildPreviewRows: (records) => buildSubsystemFlowTemplatePrintRows(records),
    buildPreviewMeta: (rows) => ({
      reportTitle,
      reportDate: new Date().toLocaleDateString('zh-CN'),
      printedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
      operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
      count: rows.length
    })
  })
 
  async function loadDetail(id, fallback) {
    const detail = await fetchGetSubsystemFlowTemplateDetail(id)
    detailData.value = normalizeSubsystemFlowTemplateRow({
      ...fallback,
      ...detail
    })
  }
 
  function handleSelectionChange(rows) {
    selectedRows.value = Array.isArray(rows) ? rows : []
  }
 
  function handleSearch(params) {
    replaceSearchParams(buildSubsystemFlowTemplateSearchParams(params))
    getData()
  }
 
  function handleReset() {
    Object.assign(searchForm.value, createSubsystemFlowTemplateSearchState())
    resetSearchParams()
  }
</script>