multiMallList.vue
5.12 KB
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
<template>
<view class="">
<headerComp
:leftImgSrc="leftSrc"
@leftClick="backClick"
:title="titleStr"
rightText="完成"
@rightClick="confirmFun"></headerComp>
<searchBox @handleEvent="searchFun"></searchBox>
<view class="list">
<view :class="{ 'list-item': !isQuerying, 'hide-item': isQuerying }" @tap="allClickHandle" v-if="cacheList.length">
<image :src="selectSrc" mode="" v-show="isAll"></image>
<image :src="unSelectSrc" mode="" v-show="!isAll"></image>
<text>全部</text>
</view>
<view class="list-item" @tap="itemFun(index)" v-for="(item, index) in cacheList" :key="item.id">
<image :src="selectSrc" mode="" v-show="item._selected"></image>
<image :src="unSelectSrc" mode="" v-show="!item._selected"></image>
<text>{{ item.name }}</text>
</view>
<view class="empty-list-item" v-if="!cacheList.length">
<text>暂无数据</text>
</view>
</view>
</view>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import headerComp from '../../components/header'
import searchBox from '../../components/search'
export default {
components: {
headerComp, searchBox
},
data() {
return {
backUrl: '',
analysisLevel: '',
titleStr: this.$t('index').storeSelect,
leftSrc:'../../static/header/backArrow.png',
selectSrc:'../../static/list/select.png',
unSelectSrc:'../../static/list/unselect.png',
isAll: false,
isQuerying: false,
checkedCount: 0,
checkedMallIds: [],
cacheList: []
}
},
onLoad(options) {
// console.log('multimalllist load options', options)
this.backUrl = options.backUrl;
this.analysisLevel = options.analysisLevel;
let lists = JSON.parse(JSON.stringify(this.mallList));
if(lists.length) {
let count = 0;
this.cacheList = lists.map(item => {
let isChecked = this.multiCheckedMallId.some(checkedItem => {
return item.id === checkedItem.id;
})
if(isChecked) count++;
item._selected = isChecked;
this.isAll = count == lists.length;
return item;
})
}
this.checkedMallIds = JSON.parse(JSON.stringify(this.multiCheckedMallId));
// console.log('onload:', this.multiCheckedMallId, this.checkedMallIds, this.mallList, this.cacheList)
},
computed: {
...mapState({
mallList: state => state.malls.list,
checkedMallId: state => state.malls.checkedMallId,
multiCheckedMallId: state => state.malls.multiCheckedMallId
}),
},
watch: {
},
created() {
},
mounted() {
},
methods: {
backClick() {
uni.navigateBack({
delta:1
})
// uni.navigateTo({
// url: '../passenger/groupTimeReport/groupTime'
// })
},
confirmFun() {
if(this.checkedMallIds.length == 0){
uni.showToast({
icon:'none',
title:'请至少选择一项'
});
return;
}
this.$store.dispatch('malls/updateMultiCheckedMall', this.checkedMallIds)
uni.reLaunch({
url: `${this.backUrl}?type=${this.analysisLevel}`
})
},
searchFun(queryStr) {
let that = this;
if(queryStr === '全部') return;
this.isQuerying = queryStr.length > 0 ? true : false;
this.query(queryStr, function(res) {
console.log('query res', res)
that.cacheList = res.length
? res.map(item => {
let isChecked = that.multiCheckedMallId.some(checkedItem => {
return item.id === checkedItem.id;
})
item._selected = isChecked;
return item;
})
: res;
})
},
query(queryString, cb) {
queryString = queryString.toLocaleLowerCase();
let result = queryString
? this.mallList.length > 0
? this.mallList.filter(item => {
if(!!~item['name'].toLocaleLowerCase().indexOf(queryString)) {
return true;
}
})
: []
: this.mallList;
cb(result);
},
allClickHandle() {
this.isAll = !this.isAll;
this.cacheList.forEach(item => item._selected = this.isAll)
},
itemFun(index) {
this.cacheList[index]._selected = !this.cacheList[index]._selected;
let hasUnselected = this.cacheList.some(item => !item._selected);
this.isAll = !hasUnselected;
let idx = null;
this.checkedMallIds.forEach((item, checkedIdx) => {
if(item.id == this.cacheList[index].id) {
idx = checkedIdx
}
});
if(this.cacheList[index]._selected) {
if(typeof idx !== 'number') {
this.checkedMallIds.push({
id: this.cacheList[index].id,
name: this.cacheList[index].name
})
}
} else {
if(typeof idx === 'number' && idx >= 0) {
this.checkedMallIds.splice(idx, 1);
}
}
this.$forceUpdate();
},
}
}
</script>
<style>
.hide-item {
display: none;
}
.list-item {
border-bottom: 1px solid #979797;
height: 72.46upx;
line-height: 72.46upx;
font-size: 25.37upx;
background: #FFFFFF;
position: relative;
}
.list-item > image{
width: 28.99upx;
height: 28.99upx;
position: absolute;
top:23.55upx;
left: 25.36upx;
}
.list-item text{
margin-left: 77.89upx;
}
.empty-list-item {
font-size: 25.37upx;
text-align: center;
padding-top: 54.34upx;
}
.empty-list-item text {
margin-left: 0;
color: #c9c9c9;
}
</style>