mallList.vue
4.03 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
<template>
<view class="">
<headerComp
:leftImgSrc="leftSrc"
@leftClick="backClick"
:title="titleStr"></headerComp>
<searchBox @handleEvent="searchFun"></searchBox>
<view class="list">
<view class="list-item" @tap="itemFun(index)" v-for="(item, index) in cacheList" :key="item.id">
<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',
isQuerying: false,
cacheCheckedMallId: [],
cacheList: []
}
},
onLoad(options) {
// console.log('multimalllist load options', options)
this.backUrl = options.backUrl;
this.analysisLevel = options.analysisLevel;
this.changeScope();
},
computed: {
...mapState({
mallList: state => state.malls.list,
checkedMallId: state => state.malls.checkedMallId
}),
},
watch: {
checkedMallId(val) {
this.changeScope();
}
},
created() {
if(!this.checkedMallId) { // 处理刷新获取参数失败
this.$store.dispatch('malls/getMallList', {
data: {
accountId: this.getStorage('accountId'),
_t:Date.parse(new Date()) / 1000
},
header: {
'app-code':'mobile',
'Authorization': this.getStorage('atoken') //自定义请求头信息
},
isMultiple: true
})
}
},
mounted() {
},
methods: {
changeScope() { // 不能直接修改 vuex 的 state
let lists = JSON.parse(JSON.stringify(this.mallList));
if(lists.length) {
this.cacheList = lists.map(item => {
// item._selected = item.id = this.checkedMallId['id'];
return item;
})
}
this.cacheCheckedMallId = JSON.parse(JSON.stringify(this.checkedMallId));
},
backClick() {
uni.navigateBack({
delta:1
})
},
searchFun(queryStr) {
let that = this;
this.isQuerying = queryStr.length > 0 ? true : false;
this.query(queryStr, function(res) {
that.cacheList = 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);
},
itemFun(index) {
this.cacheCheckedMallId = {
id: this.cacheList[index].id,
name: this.cacheList[index].name
}
console.log(this.cacheCheckedMallId)
this.$store.dispatch('malls/updateCheckedMall', this.cacheCheckedMallId)
this.$store.dispatch('malls/getGateList', {
data: {
mallId: this.cacheCheckedMallId.id,
status: 1,
isHasFace: 1,
_t:Date.parse(new Date()) / 1000
},
header: {
'app-code':'mobile',
'Authorization': this.getStorage('atoken') //自定义请求头信息
},
isMultiple: true
})
uni.reLaunch({
url: `${this.backUrl}?type=${this.analysisLevel}`
})
},
getStorage(key) {
let storageVal = '';
uni.getStorage({
key: key,
success: (res) => {
storageVal = res.data;
}
})
return storageVal
},
}
}
</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>