#
whycq
2022-02-26 5df158f54eb0c7e0e0ba79eb172aaba42735a221
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
<template>
    <view class="t-table" :style="{ 'border-width': border + 'px', 'border-color': borderColor }">
        <slot />
    </view>
</template>
 
<script>
    export default {
        props: {
            border: {
                type: String,
                default: '1'
            },
            borderColor: {
                type: String,
                default: '#d0dee5'
            },
            isCheck: {
                type: Boolean,
                default: false
            }
        },
        provide() {
            return {
                table: this
            };
        },
        data() {
            return {};
        },
        created() {
            this.childrens = [];
            this.index = 0;
        },
        methods: {
            fire(e, index, len) {
                let childrens = this.childrens;
                console.log(childrens);
                // 全选
                if (index === 0) {
                    childrens.map((vm, index) => {
                        vm.checkboxData.checked = e;
                        return vm;
                    });
                } else {
                    let isAll = childrens.find((n, ids) => ids !== 0 && !n.checkboxData.checked);
                    childrens[0].checkboxData.checked = isAll ? false : true;
                }
 
                let fireArr = [];
                for (let i = 0; i < childrens.length; i++) {
                    if (childrens[i].checkboxData.checked && i !== 0) {
                        fireArr.push(childrens[i].checkboxData.value - 1);
                    }
                }
                this.$emit('change', {
                    detail: fireArr
                });
            }
        }
    };
</script>
 
<style scoped>
    .t-table {
        width: 100%;
        border: 1px #d0dee5 solid;
        border-left: none;
        border-top: none;
        box-sizing: border-box;
    }
 
    .t-table>>>t-tr {
        display: flex;
    }
 
    .t-table>>>t-tr:nth-child(2n) {
        background: #f5f5f5;
    }
 
    /* #ifdef H5 */
    .t-table>>>.t-tr:nth-child(2n) {
        background: #f5f5f5;
    }
    /* #endif */
</style>