forked from nsjcy/frontEnd/nsjcy

LAPTOP-RI7D261L\Mr Ke
2020-02-13 a2789abb73725738127b03d95c95081b66954916
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
<view class="wux-class {{ classes.wrap }}">
    <wux-backdrop id="wux-backdrop" data-index="{{ index }}" bind:click="onClose" />
    <view class="{{ classes.bd }}">
        <block wx:for="{{ options }}" wx:key="">
            <view class="{{ classes.item }} {{ common.getItemCls(prefixCls, item) }}" bindtap="onClick" data-index="{{ index }}">
                <view class="{{ classes.text }}">
                    {{ item.type !== 'filter' ? displayValues[index] : item.label }}
                    <view class="{{ classes.icon }} {{ common.getIconCls(prefixCls, item) }}" wx:if="{{ item.type !== 'text' }}"></view>
                </view>
            </view>
        </block>
    </view>
    <block wx:for="{{ options }}" wx:key="">
        <wux-animation-group wux-class="{{ classes.pop }}" in="{{ item.visible }}" class-names="wux-animate--slideInRight" bind:enter="onEnter" bind:exit="onExit" wx:if="{{ item.type === 'filter' }}">
            <scroll-view class="{{ classes.scrollView }}" scroll-y bindscroll="onScroll">
                <block wx:for="{{ item.children }}" wx:for-item="p" wx:for-index="pIndex" wx:key="">
                    <view class="{{ classes.panel }}">
                        <view class="{{ classes.panelHd }}">
                            <div class="{{ classes.panelTitle }}">{{ p.label }}</div>
                            <div class="{{ classes.panelSelected }}">{{ displayValues[index] && displayValues[index][pIndex] }}</div>
                        </view>
                        <view class="{{ classes.panelBd }}">
                            <radio-group bindchange="onPopupSelectChange" data-parent-index="{{ index }}" data-index="{{ pIndex }}" wx:if="{{ p.type === 'radio' }}">
                                <view class="{{ classes.groups }}">
                                    <block wx:for="{{ p.children }}" wx:for-item="g" wx:for-index="cIndex" wx:key="">
                                        <view class="{{ classes.group }}">
                                            <radio
                                                class="{{ classes.radio }}"
                                                value="{{ g.value }}"
                                                checked="{{ common.getChecked(values[index] && values[index][pIndex], g.value) }}"
                                            />
                                            <view class="{{ classes.btn }} {{ common.getChecked(values[index] && values[index][pIndex], g.value) ? prefixCls + '__btn--checked' : '' }}">{{ g.label }}</view>
                                        </view>
                                    </block>
                                </view>
                            </radio-group>
                            <checkbox-group bindchange="onPopupSelectChange" data-parent-index="{{ index }}" data-index="{{ pIndex }}" wx:else="{{ p.type === 'checkbox' }}">
                                <view class="{{ classes.groups }}">
                                    <block wx:for="{{ p.children }}" wx:for-item="g" wx:for-index="cIndex" wx:key="">
                                        <view class="{{ classes.group }}">
                                            <checkbox
                                                class="{{ classes.check }}"
                                                value="{{ g.value }}"
                                                checked="{{ common.getChecked(values[index] && values[index][pIndex], g.value) }}"
                                            />
                                            <view class="{{ classes.btn }} {{ common.getChecked(values[index] && values[index][pIndex], g.value) ? prefixCls + '__btn--checked' : '' }}">{{ g.label }}</view>
                                        </view>
                                    </block>
                                </view>
                            </checkbox-group>
                        </view>
                    </view>
                </block>
            </scroll-view>
            <div class="{{ classes.btns }}">
                <view class="{{ classes.btn }}" data-index="{{ index }}" bindtap="onSelectReset">{{ cancelText }}</view>
                <view class="{{ classes.btn }} {{ prefixCls + '__btn--danger' }}" data-index="{{ index }}" bindtap="onSelectConfirm">{{ confirmText }}</view>
            </div>
        </wux-animation-group>
        <wux-animation-group wux-class="{{ classes.select }}" in="{{ item.visible }}" class-names="wux-animate--fadeIn" bind:enter="onEnter" bind:exit="onExit" wx:if="{{ item.type === 'radio' }}">
            <scroll-view class="{{ classes.scrollView }}" scroll-y>
                <wux-radio-group
                    value="{{ values[index] }}"
                    options="{{ common.getOptions(item.children) }}"
                    bind:change="onSelectChange"
                    data-index="{{ index }}"
                    data-type="{{ item.type }}"
                />
            </scroll-view>
        </wux-animation-group>
        <wux-animation-group wux-class="{{ classes.select }}" in="{{ item.visible }}" class-names="wux-animate--fadeIn" bind:enter="onEnter" bind:exit="onExit" wx:if="{{ item.type === 'checkbox' }}">
            <scroll-view class="{{ classes.scrollView }}" scroll-y>
                <wux-checkbox-group
                    value="{{ values[index] }}"
                    options="{{ common.getOptions(item.children) }}"
                    bind:change="onSelectChange"
                    data-index="{{ index }}"
                    data-type="{{ item.type }}"
                />
                <div class="{{ classes.btns }}">
                    <view class="{{ classes.btn }}" data-index="{{ index }}" bindtap="onSelectReset">{{ cancelText }}</view>
                    <view class="{{ classes.btn }} {{ prefixCls + '__btn--danger' }}" data-index="{{ index }}" bindtap="onSelectConfirm">{{ confirmText }}</view>
                </div>
            </scroll-view>
        </wux-animation-group>
    </block>
</view>
 
<wxs module="common">
    module.exports = {
        getOptions: function(options) {
            return options.map(function(option) {
                if (option.constructor === 'String') {
                    return {
                        title: option,
                        value: option
                    }
                }
                return {
                    title: option.label,
                    value: option.value
                }
            })
        },
        getChecked: function(values, value) {
            if (!values || !values.length) return false
            if (values.constructor === 'Array') {
                return values.indexOf(value) !== -1
            }
            return values === value
        },
        getItemCls: function(prefixCls, item) {
            var itemCls = []
            if (item.type !== 'text') {
                itemCls.push(prefixCls + '__item--has-icon')
            }
            if (item.checked) {
                itemCls.push(prefixCls + '__item--checked')
            }
            return itemCls.join(' ')
        },
        getIconCls: function(prefixCls, icon) {
            var iconCls = [prefixCls + '__icon--' + icon.type]
            if (icon.type === 'sort') {
                if (icon.sort === 1) {
                    iconCls.push(prefixCls + '__icon--sort-asc')
                } else if (icon.sort === -1) {
                    iconCls.push(prefixCls + '__icon--sort-desc')
                }
            }
            return iconCls.join(' ')
        },
    }
</wxs>