huangxiaoqiang
2025-02-19 5bc6d819399409a429093a6001c553d6fa2d2e15
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
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
223
224
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<template>
    <div class="layout-container">
        <div class="view-container">
            <div class="grid-search">
                <div class="fiexd-search-box" v-show="true">
                    <vol-form ref="searchForm" style="padding: 0 15px" :label-width="100" :formRules="searchFormOptions"
                        :formFields="searchFormFields">
                    </vol-form>
                    <div v-if="fiexdSearchForm" class="fs-line"></div>
                </div>
                <div class="view-header">
                    <div class="desc-text">
                        <i class="el-icon-s-grid" />
                        <span>{{ title }}</span>
                    </div>
                    <div class="notice">
                        <a class="text" title="{{title}}"></a>
                    </div>
 
                    <div class="btn-group">
                        <template :key="bIndex" v-for="(btn, bIndex) in Mybuttons.slice(0, 6)">
                            <el-button :type="btn.type" size="small" :dark="btn.dark" :plain="btn.plain"
                                @click="changeDropdown(btn.name)">
                                <i :class="btn.icon"></i>
                                {{ btn.name }}
                            </el-button>
                        </template>
                        <el-dropdown size="small" @click="changeDropdown"
                            v-if="Mybuttons.length > 5">
                            <el-button type="primary" plain size="small">
                                更多<i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item @click="changeDropdown(item.name)" :name="item.name"
                                        v-show="!item.hidden" v-for="(item, dIndex) in Mybuttons.slice(6)" :key="dIndex">
                                        <i :class="item.icon"></i>
                                        {{ item.name }}
                                    </el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                </div>
            </div>
 
            <div class="grid-container">
                <el-table ref="table" stripe :data="tableData" :height="heigth" style="width: 100%" border
                    @selection-change="selectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column prop="order_id" label="主键" v-if="false"></el-table-column>
                    <el-table-column type="expand">
                        <template #default="props">
                            <h4>明细数据</h4>
                            <div m="4">
                                <el-table stripe :data="props.row.boxingInfoDetails" max-height="400"
                                    style="width: 100%" border>
                                    <el-table-column label="序号" type="index" fixed="left" width="55"></el-table-column>
                                    <el-table-column :key="index" v-for="(item, index) in detailColumns"
                                        :label="item.title" :prop="item.field" :width="item.width"
                                        show-overflow-tooltip></el-table-column>
                                </el-table>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column v-for="(item, index) in columns" :key="index" :label="item.title"
                        :prop="item.field" sortable="true" show-overflow-tooltip>
                        <template #default="scope" v-if="item.type == 'tag'">
                            <el-tag size="small">
                                {{ getDictionary(scope.row, item) }}
                            </el-tag>
                        </template>
                    </el-table-column>
                </el-table>
                <template v-if="true">
                    <div class="block pagination" key="pagination-01" style="display: flex">
                        <div style="flex: 1"></div>
                        <el-pagination key="pagination-02" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange" :current-page="currentPage1.page"
                            :page-sizes="currentPage1.sizes" :page-size="currentPage1.size"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="currentPage1.total"></el-pagination>
                    </div>
                </template>
            </div>
        </div>
    </div>
</template>
 
<script>
import VolForm from "../VolForm.vue";
import VolBox from "../VolBox.vue";
import VolTable from "../VolTable.vue";
import buttons from "@/api/buttons";
import methodss from './methodsDetail.jsx';
export default {
    components: {
        'vol-form': VolForm,
        'vol-table': VolTable,
        'vol-box': VolBox
    },
 
    name: 'CustomTableComponent',
    data() {
        return {
            tableData: [],
            Mybuttons: [],
            currentPage1: {
                sort: "",
                order: "desc",
                Foots: "",
                total: 0,
                // 2020.08.29增加自定义分页条大小
                sizes: [30, 60, 100, 120],
                size: 30, // 默认分页大小
                Wheres: [],
                page: 1,
                rows: 30,
            },
            selectRows: [],
        };
    },
    props: {
        url: String,
        title: String,
        columns: {
            type: Array,
            default: []
        },
        detailColumns: Array,
        searchFormOptions: Object,
        searchFormFields: Array,
        dropdownItems: Array,
        heigth: String,
        table: String,
    },
    methods: {
        ...methodss.methods,
        ...methodss.data,
        changeDropdown(btnName, v1) {
            let button = this.dropdownItems.filter((x) => {
                return x.name == btnName
            })
            if (button && button.length > 0) {
                button[0].onClick.apply(this)
            }
        },
        handleSizeChange(val) {
            this.currentPage1.pageSize = val;
        },
        handleCurrentChange(val) {
            this.currentPage1.currentPage = val;
        },
 
        getPageData() {
            // 获取分页数据
            var query = this.getSearchParameters();
            let param = {
                page: this.currentPage1.page,
                rows: this.currentPage1.rows,
                sort: this.currentPage1.sort,
                order: this.currentPage1.order,
                wheres: "", // 查询条件,格式为[{ name: "字段", value: "xx" }]
            };
            param = Object.assign(param, query);
            param.wheres = JSON.stringify(param.wheres);
            this.http.post(this.url, param, "查询中").then((x) => {
                this.tableData = x.rows;
                this.currentPage1.total = x.total;
            });
        },
        search() {
            this.getPageData();
        },
 
        getSearchParameters() {
            //获取查询参数
            let query = { wheres: [] };
            for (const key in this.searchFormFields) {
                let value = this.searchFormFields[key];
                if (this.emptyValue(value)) continue;
 
                if (typeof value == "number") {
                    value = value + "";
                }
                let displayType = this.getSearchItem(key);
 
                //联级只保留选中节点的最后一个值
                if (displayType == "cascader") {
                    //查询下面所有的子节点,如:选中的是父节点,应该查询下面所有的节点数据--待完
                    value = value.length ? value[value.length - 1] + "" : "";
                }
                //2021.05.02增加区间查询
                if (
                    typeof value == "string" ||
                    ["date", "datetime", "range"].indexOf(displayType) == -1
                ) {
                    query.wheres.push({
                        name: key,
                        value:
                            typeof value == "string" ? (value + "").trim() : value.join(","),
                        displayType: displayType,
                    });
                    continue;
                }
                for (let index = 0; index < value.length; index++) {
                    if (!this.emptyValue(value[index])) {
                        query.wheres.push({
                            name: key,
                            value: (value[index] + "").trim(),
                            displayType: (() => {
                                if (["date", "datetime", "range"].indexOf(displayType) != -1) {
                                    return index ? "lessorequal" : "thanorequal";
                                }
                                return displayType;
                            })(),
                        });
                    }
                }
            }
            return query;
        },
 
        getSearchItem(field) {
            //获取查询的参数
            let data;
            for (let index = 0; index < this.searchFormOptions.length; index++) {
                if (data) return data.type;
                const item = this.searchFormOptions[index];
                data = item.find((x) => {
                    return x.field == field;
                });
            }
 
            return (data || {}).type;
        },
 
        emptyValue(value) {
            if (typeof value == "string" && value.trim() === "") {
                return true;
            }
            if (value instanceof Array && !value.length) {
                return true;
            }
            return value === null || value === undefined || value === "";
        },
 
 
        filterPermission(tableName, permission) {
            //2021.03.19判断是否有某个表的按钮权限
            //:["Search","Add","Delete","Update","Import","Export","Upload","Audit"]
            const _result = (this.$store.state.permission || []).find((x) => {
                return x.url == '/' + tableName
            })
            return _result
        },
        getButtons() {
            console.log(buttons);
            buttons.forEach(element => {
                this.dropdownItems.push(element);
            });
        }
    },
    created() {
        this.getPageData();
        let permission = this.filterPermission(this.table);
        console.log(permission);
        this.getButtons();
        this.Mybuttons = this.dropdownItems.filter(item => permission.permission.includes(item.value));
    }
};
</script>
 
<style>
@import "./ViewGrid.less";
 
.pagination {
    text-align: right;
    padding: 2px 28px;
    border: 1px solid #eee;
    border-top: 0px;
}
</style>