张卓
2022-09-20 5aead44ba1be31db948dfd8362c2bfcbedbbce29
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
<template>
  <div>
    <!-- <div class="standardTable">
      <a-table
        :loading="loading"
        :dataSource="dataSource"
 
        @change="handleTableChange"
        :columns="columns"
        :pagination="paginationProps"
      ></a-table>
    </div> -->
    <div class="standardTable">
      <a-table
        :loading="loading"
        :dataSource="dataSource"
        @change="handleTableChange"
        :columns="columns"
        :pagination="paginationProps"
      ></a-table>
    </div>
  </div>
</template>
 
<style lang="less">
.standardTable {
  :global {
    .ant-table-pagination {
      margin-top: 24px;
    }
  }
 
  .tableAlert {
    margin-bottom: 16px;
  }
}
</style>
 
<script lang="tsx">
import {
    Component,
    Prop,
    Vue,
    Emit,
 
} from 'vue-property-decorator';
import * as _ from 'lodash';
import axios from "axios";
@Component({})
export default class StandardTable extends Vue {
 
    private needTotalList: any[] = [];
 
    private selectedRowKeys: any[] = [];
 
    private total:any=null;
 
 
 
    @Prop({
        type: Boolean,
        default: false,
    })
    private loading!: boolean;
 
 
 
    @Prop({
        type: Array,
        default: () => [],
    })
    private columns!: any[];
 
    @Prop({
        type: Array,
        default: () => [],
    })
    private dataSource!: any[];
 
    @Prop({
        type: Array,
        default: () => [],
    })
    private selectedRows!: any[];
 
    @Prop({
      type:Object,
      default:()=>{
      }
    })
    private paginationProps!:any;
 
      get rowSelection() {
        return {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.handleRowSelectChange,
            getCheckboxProps: (record: any) => ({
                props: {
                    disabled: record.disabled,
 
                },
            }),
        };
    }
 
    private cleanSelectedKeys(): void {
        this.handleRowSelectChange([], []);
    }
 
    private handleTableChange(pagination: any, filters: any, sorter: any): void {
 
        this.onTableChange(pagination, filters, sorter);
    }
 
    private handleRowSelectChange(selectedRowKeys: any, selectedRows: any): void {
        this.selectedRowKeys = selectedRowKeys;
 
        this.needTotalList = this.needTotalList.map((item: any) => ({
            ...item,
            total: _.sumBy(selectedRows, item.dataIndex),
        }));
        this.onSelectChange(selectedRowKeys, selectedRows);
 
    }
 
    private mounted() {
      this.needTotalList = this.initTotalList(this.columns);
    }
    private initTotalList(columns: any[]) {
        const totalList: any[] = [];
        columns.forEach((column: any) => {
            if (column.needTotal) {
                totalList.push({ ...column,
                    total: 0,
                });
            }
        });
        return totalList;
    }
    @Emit('selectChange')
    private onSelectChange(selectedRowKeys: any, selectedRows: any) {
 
    }
 
    @Emit('tableChange')
    private onTableChange(pagination: any, filters: any, sorter: any) {
 
    }
 
}
</script>