Blame view

src/components/report/commonReportTable.vue 8.23 KB
71def04c   wuxw   优化优惠
1
2
3
4
  <template>
    <div class="common-report-table">
      <div v-for="(item, index) in commonReportTableInfo.components" :key="index">
        <el-card v-if="item.conditions && item.conditions.length > 0" class="query-card">
f804bf62   wuxw   报表功能测试完成
5
          <div slot="header" class="flex justify-between">
71def04c   wuxw   优化优惠
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
            <span>{{ $t('commonReportTable.queryConditions') }}</span>
          </div>
          <el-row :gutter="20">
            <el-col v-for="(conditionItem, conditionIndex) in item.conditions" :key="conditionIndex" :span="6">
                <el-input v-model.trim="conditionItem.value" :type="conditionItem.type"
                  :placeholder="conditionItem.holdpace" clearable />
            </el-col>
            <el-col :span="6">
              <el-button type="primary" @click="_queryReportTableMethod(item)">
                <i class="el-icon-search"></i>
                {{ $t('commonReportTable.query') }}
              </el-button>
              <el-button @click="_resetReportTableMethod(item)">
                <i class="el-icon-refresh"></i>
                {{ $t('commonReportTable.reset') }}
              </el-button>
            </el-col>
          </el-row>
        </el-card>
  
        <el-card class="table-card">
f804bf62   wuxw   报表功能测试完成
27
          <div slot="header" class="flex justify-between">
71def04c   wuxw   优化优惠
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
            <span>{{ item.componentName }}</span>
            <div style="float: right;">
              <el-button type="primary" size="small" @click="_exportReportTableMethod(item)">
                <i class="el-icon-download"></i>
                {{ $t('commonReportTable.export') }}
              </el-button>
              <el-button type="primary" size="small" @click="_printReportTableMethod(item)">
                <i class="el-icon-printer"></i>
                {{ $t('commonReportTable.print') }}
              </el-button>
            </div>
          </div>
  
          <el-table :data="item.data" border style="width: 100%" v-loading="loading">
            <el-table-column v-for="(itemTh, indexTh) in item.th" :key="indexTh" :label="itemTh" align="center">
              <template slot-scope="scope">
                <div class="text-auto">
                  {{ scope.row[itemTh] }}
                </div>
              </template>
            </el-table-column>
          </el-table>
  
          <div v-if="item.footer" class="footer-wrapper">
            <el-row :gutter="20">
              <el-col v-for="(tmpItemTh, key) in item.footer" :key="key" :span="4">
                <div class="footer-item">
                  {{ key }}: {{ tmpItemTh }}
                </div>
              </el-col>
            </el-row>
          </div>
  
          <el-pagination :current-page.sync="pagination.current" :page-sizes="[10, 20, 30, 50]" :page-size="pagination.size"
            :total="pagination.total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
            @current-change="handleCurrentChange" />
        </el-card>
      </div>
    </div>
  </template>
  
  <script>
  import {
    listReportCustomComponentRel,
    listReportCustomComponentCondition,
    listReportCustomComponentData,
    listReportCustomComponentDataFooter,
    exportData
  } from '@/api/report/commonReportApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'CommonReportTable',
    data() {
      return {
        commonReportTableInfo: {
          components: [],
          customId: ''
        },
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        loading: false,
        communityId: ''
      }
    },
    created() {
      this.communityId = getCommunityId()
    },
    methods: {
      handleSwitch(value) {
        this.commonReportTableInfo.customId = value.customId
        this._listReportCustomTableComponent()
      },
      handleSizeChange(val) {
        this.pagination.size = val
        this._queryReportTableMethod(this.commonReportTableInfo.components[0])
      },
      handleCurrentChange(val) {
        this.pagination.current = val
        this._queryReportTableMethod(this.commonReportTableInfo.components[0])
      },
      async _queryReportTableMethod(item) {
        const condition = {}
        item.conditions.forEach(_item => {
          condition[_item.param] = _item.value
        })
        await this._listReportCustomTableDatas(this.pagination.current, this.pagination.size, item, condition)
        await this._listReportCustomTableFooter(this.pagination.current, this.pagination.size, item, condition)
      },
      _resetReportTableMethod(item) {
        const condition = {}
        item.conditions.forEach(_item => {
          _item.value = ''
          condition[_item.param] = _item.value
        })
        this._listReportCustomTableDatas(1, this.pagination.size, item, condition)
        this._listReportCustomTableFooter(1, this.pagination.size, item, condition)
      },
      async _listReportCustomTableComponent() {
        try {
          this.loading = true
          const params = {
            page: 1,
            row: this.pagination.size,
            customId: this.commonReportTableInfo.customId,
            componentType: '1001'
          }
          const { data } = await listReportCustomComponentRel(params)
          this.commonReportTableInfo.components = data
          for (const item of this.commonReportTableInfo.components) {
            await this._listReportCustomTableConditions(item)
            await this._listReportCustomTableDatas(1, this.pagination.size, item)
            await this._listReportCustomTableFooter(1, this.pagination.size, item)
          }
        } catch (error) {
          console.error('Failed to load report components:', error)
        } finally {
          this.loading = false
        }
      },
      async _listReportCustomTableConditions(component) {
        try {
          const params = {
            page: 1,
            row: this.pagination.size,
            componentId: component.componentId
          }
          const { data } = await listReportCustomComponentCondition(params)
          component.conditions = data
        } catch (error) {
          console.error('Failed to load conditions:', error)
        }
      },
      async _listReportCustomTableDatas(page, row, component, conditions) {
        try {
          this.loading = true
          const params = {
            page,
            row,
            componentId: component.componentId,
            communityId: this.communityId,
            ...conditions
          }
          const { data, total } = await listReportCustomComponentData(params)
          component.th = data.th
          component.data = data.td
          this.pagination.total = total
        } catch (error) {
          console.error('Failed to load table data:', error)
        } finally {
          this.loading = false
        }
      },
      async _listReportCustomTableFooter(page, row, component, conditions) {
        try {
          const params = {
            page,
            row,
            componentId: component.componentId,
            communityId: this.communityId,
            ...conditions
          }
          const { data } = await listReportCustomComponentDataFooter(params)
          component.footer = data
        } catch (error) {
          console.error('Failed to load footer data:', error)
        }
      },
      async _exportReportTableMethod(item) {
        try {
          const condition = {}
          item.conditions.forEach(_item => {
            condition[_item.param] = _item.value
          })
          const params = {
            page: 1,
            row: 10000,
            componentId: item.componentId,
            communityId: this.communityId,
            pagePath: 'exportCustomReportTableData',
            ...condition
          }
          const { code, msg } = await exportData(params)
          this.$message.success(msg)
          if (code === 0) {
            this.$router.push('/pages/property/downloadTempFile?tab=downloadCenter')
          }
        } catch (error) {
          console.error('Export failed:', error)
        }
      },
      _printReportTableMethod(data) {
f804bf62   wuxw   报表功能测试完成
223
224
        localStorage.setItem('printCommonReportTableData', JSON.stringify(data))
        window.open('/#/pages/property/printCommonReportTable')
71def04c   wuxw   优化优惠
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
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .common-report-table {
    .query-card {
      margin-bottom: 20px;
    }
  
    .table-card {
      margin-bottom: 20px;
    }
  
    .text-auto {
      max-width: 200px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  
    .footer-wrapper {
      margin-top: 20px;
      padding: 10px;
      background-color: #f5f7fa;
      border-radius: 4px;
  
      .footer-item {
        padding: 5px 0;
      }
    }
  
    .el-pagination {
      margin-top: 20px;
      text-align: right;
    }
  }
  </style>