Commit 8cfe981a3271a7edb2d77c5e899eafd5d3abba65

Authored by BigBoss
1 parent 646a65287b
Exists in master

修改

Showing 1 changed file with 60 additions and 49 deletions   Show diff stats
src/pages/index/index.vue
1 <template> 1 <template>
2 <view class="content"> 2 <view class="content">
3 <view class="header"> 3 <view class="header">
4 <!-- 搜索--> 4 <!-- 搜索-->
5 <view class="searchBar"> 5 <view class="searchBar">
6 <icon class="searchIcon" type="search" size="14"></icon> 6 <icon class="searchIcon" type="search" size="14"></icon>
7 <input class="searchIpt" placeholder="老花镜" confirm-type="search"/> 7 <input class="searchIpt" placeholder="老花镜" confirm-type="search"/>
8 </view> 8 </view>
9 9
10 <!-- 筛选栏--> 10 <!-- 筛选栏-->
11 <view class="screenBar"> 11 <view class="screenBar">
12 <view v-for="item in screenItems" :key="item.current" @click="onClickItem(item.current)" > 12 <view v-for="item in screenItems" :key="item.current" @click="onClickItem(item.current)" >
13 <view class="screenItem" v-bind:class="{ active: current === item.current }" v-if="item.current === 2" @click="dropDown"> 13 <view class="screenItem" v-bind:class="{ active: current === item.current }" v-if="item.current === 2" @click="dropDown">
14 {{ item.text }}<icon type="info" size="14"></icon> 14 {{ item.text }}<icon type="info" size="14"></icon>
15 </view> 15 </view>
16 <view class="screenItem" v-bind:class="{ active: current === item.current }" v-if="item.current === 4" @click="showDrawer('showRight')"> 16 <view class="screenItem" v-bind:class="{ active: current === item.current }" v-if="item.current === 4" @click="showDrawer('showRight')">
17 {{ item.text }}<icon type="info" size="14"></icon> 17 {{ item.text }}<icon type="info" size="14"></icon>
18 </view> 18 </view>
19 <view v-if="item.current !== 2&&item.current!==4"> 19 <view v-if="item.current !== 2&&item.current!==4">
20 <view class="screenItem" v-bind:class="{ active: current === item.current }">{{ item.text }}</view> 20 <view class="screenItem" v-bind:class="{ active: current === item.current }">{{ item.text }}</view>
21 </view> 21 </view>
22 </view> 22 </view>
23 </view> 23 </view>
24 </view> 24 </view>
25 <uni-drawer ref="showRight" mask="true" maskClick=true mode="right" :width="320" @change="change($event,'showRight')"> 25 <Uni-drawer ref="showRight" mask="true" maskClick=true mode="right" :width="320" @change="change($event,'showRight')">
26 <view class="close"> 26 <view class="close">
27 <view @click="closeDrawer('showRight')"><text class="word-btn-white">关闭</text></view> 27 <view @click="closeDrawer('showRight')"><text class="word-btn-white">关闭</text></view>
28 </view> 28 </view>
29 </uni-drawer> 29 </Uni-drawer>
30 30
31 31
32 32
33 <!-- 筛选菜单--> 33 <!-- 筛选菜单-->
34 <view class="content-wrap"> 34 <view class="content-wrap">
35 <view> 35 <view>
36 <HMfilterDropdown :filterData="filterData" :defaultSelected ="filterDropdownValue" :updateMenuName="true" @confirm="confirm" dataFormat="Object"></HMfilterDropdown> 36 <HMfilterDropdown :filterData="filterData" :defaultSelected ="filterDropdownValue" :updateMenuName="true" @confirm="confirm" dataFormat="Object"></HMfilterDropdown>
37 <!-- 占位 -->
38 <view class="place"></view>
39 <!-- 商品列表 --> 37 <!-- 商品列表 -->
40 <view class="goods-list"> 38 <view class="goods-list">
41 <view class="product-list"> 39 <view class="product-list">
42 <view class="product" v-for="(goods) in goodsList" :key="goods.goods_id" @tap="toGoods(goods)"> 40 <view class="product" v-for="(goods) in goodsList" :key="goods.goods_id" @tap="toGoods(goods.goods_id)">
43 <image mode="widthFix" :src="goods.img"></image> 41 <image mode="widthFix" :src="goods.img" ></image>
44 <view class="name">{{goods.name}}</view> 42 <view class="name">{{goods.name}}</view>
45 <view class="info"> 43 <view class="info">
44 <view class="priceBox">
46 <view class="price">{{goods.price}}</view> 45 <view class="price">{{goods.price}}</view>
46 <view class="originCost">{{goods.originCost}}</view>
47 </view>
47 <view class="slogan">{{goods.slogan}}</view> 48 <view class="slogan">{{goods.slogan}}</view>
48 </view> 49 </view>
49 </view> 50 </view>
50 </view> 51 </view>
51 <view class="loading-text">{{loadingText}}</view> 52 <view class="loading-text">{{loadingText}}</view>
52 </view> 53 </view>
53 54
54 </view> 55 </view>
55 </view> 56 </view>
56 </view> 57 </view>
57 </template> 58 </template>
58 59
59 <script> 60 <script>
60 import uniDrawer from "@/components/uni-drawer/uni-drawer.vue"; 61 import UniDrawer from "@/components/Uni-drawer/Uni-drawer.vue";
61 import HMfilterDropdown from "../../components/HM-filterDropdown/HM-filterDropdown.vue"; 62 import HMfilterDropdown from "../../components/HM-filterDropdown/HM-filterDropdown.vue";
62 import data from '@/common/data.js';//筛选菜单数据 63 import data from '@/common/data.js';//筛选菜单数据
63 export default { 64 export default {
64 components: { 65 components: {
65 uniDrawer, 66 'UniDrawer':UniDrawer,
66 'HMfilterDropdown':HMfilterDropdown 67 'HMfilterDropdown':HMfilterDropdown
67 }, 68 },
68 data() { 69 data() {
69 return { 70 return {
70 screenItems: [ 71 screenItems: [
71 {current:0,text:'全部',hasIcon:false}, 72 {current:0,text:'全部',hasIcon:false},
72 {current:1,text:'销量',hasIcon:false}, 73 {current:1,text:'销量',hasIcon:false},
73 {current:2,text:'价格',hasIcon:true}, 74 {current:2,text:'价格',hasIcon:true},
74 {current:3,text:'折扣',hasIcon:false}, 75 {current:3,text:'折扣',hasIcon:false},
75 {current:4,text:'筛选',hasIcon:true}, 76 {current:4,text:'筛选',hasIcon:true},
76 ], 77 ],
77 current: 0, 78 current: 0,
78 showRight: false, 79 showRight: false,
79 indexArr:'', 80 indexArr:'',
80 valueArr:'', 81 valueArr:'',
81 //商品数据 82 //商品数据
82 goodsList:[ 83 goodsList:[
83 { goods_id: 0, img: '/static/img/goods/p1.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 84 { goods_id: 0, img: '/static/img/goods/p1.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
84 { goods_id: 1, img: '/static/img/goods/p2.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 85 { goods_id: 1, img: '/static/img/goods/p2.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
85 { goods_id: 2, img: '/static/img/goods/p3.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 86 { goods_id: 2, img: '/static/img/goods/p3.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
86 { goods_id: 3, img: '/static/img/goods/p4.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 87 { goods_id: 3, img: '/static/img/goods/p4.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
87 { goods_id: 4, img: '/static/img/goods/p5.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 88 { goods_id: 4, img: '/static/img/goods/p5.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
88 { goods_id: 5, img: '/static/img/goods/p6.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 89 { goods_id: 5, img: '/static/img/goods/p6.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
89 { goods_id: 6, img: '/static/img/goods/p7.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 90 { goods_id: 6, img: '/static/img/goods/p7.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
90 { goods_id: 7, img: '/static/img/goods/p8.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 91 { goods_id: 7, img: '/static/img/goods/p8.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
91 { goods_id: 8, img: '/static/img/goods/p9.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }, 92 { goods_id: 8, img: '/static/img/goods/p9.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
92 { goods_id: 9, img: '/static/img/goods/p10.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' } 93 { goods_id: 9, img: '/static/img/goods/p10.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' }
93 ], 94 ],
94 loadingText:"正在加载...", 95 loadingText:"正在加载...",
95 filterDropdownValue:[], 96 filterDropdownValue:[],
96 filterData:[] 97 filterData:[]
97 } 98 }
98 }, 99 },
99 filters: { 100 filters: {
100   outData(value) { 101   outData(value) {
101     return JSON.stringify(value); 102     return JSON.stringify(value);
102   } 103   }
103 }, 104 },
104 onLoad: function () { 105 onLoad: function () {
105 //定时器模拟ajax异步请求数据 106 //定时器模拟ajax异步请求数据
106 setTimeout(()=>{ 107 // setTimeout(()=>{
107 //传入defaultSelected的结构不能错,错了就报错运行异常。 不选中的项目传入null 108 // //传入defaultSelected的结构不能错,错了就报错运行异常。 不选中的项目传入null
108 this.filterDropdownValue = [ 109 // this.filterDropdownValue = [
109 [1,1,0], //第0个菜单选中 一级菜单的第1项,二级菜单的第1项,三级菜单的第3项 110 // [1,1,0], //第0个菜单选中 一级菜单的第1项,二级菜单的第1项,三级菜单的第3项
110 [null,null], //第1个菜单选中 都不选中 111 // [null,null], //第1个菜单选中 都不选中
111 [1], //第2个菜单选中 一级菜单的第1项 112 // [1], //第2个菜单选中 一级菜单的第1项
112 [[0],[1,2,7],[1,0]], //筛选菜单选中 第一个筛选的第0项,第二个筛选的第1,2,7项,第三个筛选的第1,0项 113 // [[0],[1,2,7],[1,0]], //筛选菜单选中 第一个筛选的第0项,第二个筛选的第1,2,7项,第三个筛选的第1,0项
113 [[0],[1],[1]], //单选菜单选中 第一个筛选的第0项,第二个筛选的第1项,第三个筛选的第1项 114 // [[0],[1],[1]], //单选菜单选中 第一个筛选的第0项,第二个筛选的第1项,第三个筛选的第1项
114 ]; 115 // ];
115 this.filterData = data; 116 this.filterData = data;
116 },100); 117 // },100);
117 //模拟ajax请求子菜单数据。 118 // 模拟ajax请求子菜单数据。
118 // setTimeout(()=>{ 119 // setTimeout(()=>{
119 //this.filterData[1].submenu[0].submenu = [{"name": "附近","value": "附近"},{"name": "1km","value": "1km"},{"name": "2km","value": "2km"},{"name": "3km","value": "3km"},{"name": "4km","value": "4km"},{"name": "5km","value": "5km"}]; 120 // this.filterData[1].submenu[0].submenu = [{"name": "附近","value": "附近"},{"name": "1km","value": "1km"},{"name": "2km","value": "2km"},{"name": "3km","value": "3km"},{"name": "4km","value": "4km"},{"name": "5km","value": "5km"}];
120 // },5000) 121 // },5000)
121 }, 122 },
122 methods: { 123 methods: {
123 showDrawer(e) { 124 showDrawer(e) {
124 this.$refs[e].open() 125 this.$refs[e].open()
125 }, 126 },
126 closeDrawer(e) { 127 closeDrawer(e) {
127 this.$refs[e].close() 128 this.$refs[e].close()
128 }, 129 },
129 change(e, type) { 130 change(e, type) {
130 this[type] = e 131 this[type] = e
131 }, 132 },
132 onClickItem(e) { 133 onClickItem(e) {
133 if (this.current !== e) { 134 if (this.current !== e) {
134 this.current = e; 135 this.current = e;
135 } 136 }
136 }, 137 },
137 dropDown(){ 138 dropDown(){
138 console.log('下拉') 139 console.log('下拉')
139 }, 140 },
140 //接收菜单结果 141 //接收菜单结果
141 confirm(e){ 142 confirm(e){
142 this.indexArr = e.index; 143 this.indexArr = e.index;
143 this.valueArr = e.value; 144 this.valueArr = e.value;
144 return; 145 return;
145 console.log('修改菜单'); 146 console.log('修改菜单');
146 this.filterData[4].submenu[1] = { 147 this.filterData[4].submenu[1] = {
147 "name": "项目2", 148 "name": "项目2",
148 "submenu": [ 149 "submenu": [
149 150
150 ] 151 ]
151 } 152 }
153 },
154 toGoods(id){
155 console.log(id)
152 } 156 }
153 }, 157 },
154 onNavigationBarButtonTap(e) { 158 onNavigationBarButtonTap(e) {
155 this.showRight = !this.showRight 159 this.showRight = !this.showRight
156 }, 160 },
157 //上拉加载, 161 //上拉加载,
158 onReachBottom(){ 162 onReachBottom(){
159 console.log('到底加载') 163 console.log('到底加载')
160 let len = this.goodsList.length; 164 let len = this.goodsList.length;
161 if(len>=30){ 165 if(len>=30){
162 this.loadingText="~~到底了~~"; 166 this.loadingText="~~到底了~~";
163 return false; 167 return false;
164 }else{ 168 }else{
165 this.loadingText="正在加载..."; 169 this.loadingText="正在加载...";
166 } 170 }
167 let end_goods_id = this.goodsList[len-1].goods_id; 171 let end_goods_id = this.goodsList[len-1].goods_id;
168 for(let i=1;i<=10;i++){ 172 for(let i=1;i<=10;i++){
169 let goods_id = end_goods_id+i; 173 let goods_id = end_goods_id+i;
170 let p = { goods_id: goods_id, img: '/static/img/goods/p'+(goods_id%10==0?10:goods_id%10)+'.jpg', name: '商品名称', price: '¥168', slogan:'1235人付款' }; 174 let p = { goods_id: goods_id, img: '/static/img/goods/p'+(goods_id%10==0?10:goods_id%10)+'.jpg',name: '商品名称', originCost:'¥198' ,price: '¥168', slogan:'1235人付款' };
171 this.goodsList.push(p); 175 this.goodsList.push(p);
172 } 176 }
173 }, 177 },
174 } 178 }
175 </script> 179 </script>
176 180
177 <style lang="scss"> 181 <style lang="scss">
178 .content { 182 .content {
179 display: flex; 183 display: flex;
180 flex-direction: column; 184 flex-direction: column;
181 align-items: center; 185 align-items: center;
182 justify-content: center; 186 justify-content: center;
183 background-color: #F7F6F6; 187 background-color: #F7F6F6;
184 } 188 }
185 .header{ 189 .header{
186 display: flex; 190 display: flex;
187 flex-direction: column; 191 flex-direction: column;
188 align-items: center; 192 align-items: center;
189 justify-content: center; 193 justify-content: center;
190 background-color: #F7F6F6; 194 background-color: #F7F6F6;
191 height:178rpx ; 195 height:178rpx ;
192 width: 100%; 196 width: 100%;
193 z-index: 999; 197 z-index: 999;
194 position: fixed; 198 position: fixed;
195 top: 0; 199 top: 0;
200 left: 0;
196 } 201 }
197 .searchBar { 202 .searchBar {
198 width: 670rpx; 203 width: 670rpx;
199 display: flex; 204 display: flex;
200 position: fixed;
201 top: 0;
202 justify-content: center; 205 justify-content: center;
203 align-items: center; 206 align-items: center;
204 box-sizing: border-box; 207 box-sizing: border-box;
205 padding: 0rpx 16rpx; 208 padding: 0rpx 16rpx;
206 border: 1px solid #FF6B4A; 209 border: 1px solid #FF6B4A;
207 border-radius: 8rpx; 210 border-radius: 8rpx;
208 background-color: #ffffff; 211 background-color: #ffffff;
209 } 212 }
210 213
211 .searchIpt { 214 .searchIpt {
212 height: 68rpx; 215 height: 68rpx;
213 width: 670rpx; 216 width: 670rpx;
214 padding: 16rpx; 217 padding: 16rpx;
215 font-size: 28rpx; 218 font-size: 28rpx;
216 box-sizing: border-box; 219 box-sizing: border-box;
217 } 220 }
218 .screenBar{ 221 .screenBar{
219 position: fixed;
220 top: 68rpx;
221 width: 670rpx; 222 width: 670rpx;
222 height: 110rpx; 223 height: 110rpx;
223 display: flex; 224 display: flex;
224 flex-direction: row; 225 flex-direction: row;
225 justify-content: space-between; 226 justify-content: space-between;
226 align-items: center; 227 align-items: center;
227 color: #333333; 228 color: #333333;
228 font-size: 32rpx; 229 font-size: 32rpx;
229 } 230 }
230 .active{ 231 .active{
231 color: #FF6B4A; 232 color: #FF6B4A;
232 } 233 }
233 .screenItem{ 234 .screenItem{
234 display: flex; 235 display: flex;
235 justify-content: center; 236 justify-content: center;
236 align-items: center; 237 align-items: center;
237 } 238 }
238 .content-wrap{ 239 .content-wrap{
239 width: 100%; 240 width: 100%;
240 background-color: #FFFFFF; 241 background-color: #FFFFFF;
241 } 242 }
242 243
243 .HMfilterDropdown{ 244 .HMfilterDropdown{
244 position: fixed;
245 top: 178rpx !important; 245 top: 178rpx !important;
246 } 246 }
247 .place{ 247
248 background-color: #ffffff;
249 height: 266rpx;
250 }
251 .goods-list{ 248 .goods-list{
252 padding-top: 10px; 249 padding-top: 286rpx;
253 .loading-text{ 250 .loading-text{
254 width: 100%; 251 width: 100%;
255 display: flex; 252 display: flex;
256 justify-content: center; 253 justify-content: center;
257 align-items: center; 254 align-items: center;
258 height: 30px; 255 height: 30px;
259 color: #979797; 256 color: #979797;
260 font-size: 12px; 257 font-size: 12px;
261 } 258 }
262 .product-list{ 259 .product-list{
263 width: 92%; 260 width: 92%;
264 padding: 0 4% 3vw 4%; 261 padding: 0 4% 3vw 4%;
265 display: flex; 262 display: flex;
266 justify-content: space-between; 263 justify-content: space-between;
267 flex-wrap: wrap; 264 flex-wrap: wrap;
268 .product{ 265 .product{
269 width: 48%; 266 width: 48%;
270 border-radius: 10px; 267 border-radius: 10px;
271 background-color: #fff; 268 background-color: #fff;
272 margin: 0 0 7px 0; 269 margin: 0 0 7px 0;
273 box-shadow: 0 3px 12px rgba(0,0,0,0.1); 270 box-shadow: 0 3px 12px rgba(0,0,0,0.1);
274 image{ 271 image{
275 width: 100%; 272 width: 100%;
276 border-radius: 10px 10px 0 0; 273 border-radius: 10px 10px 0 0;
274 height: 184rpx;
277 } 275 }
278 .name{ 276 .name{
279 width: 92%; 277 width: 92%;
280 padding: 5px 4%; 278 padding: 5px 4%;
281 display: -webkit-box; 279 display: -webkit-box;
282 -webkit-box-orient: vertical; 280 -webkit-box-orient: vertical;
283 -webkit-line-clamp: 2; 281 -webkit-line-clamp: 2;
284 text-align: justify; 282 text-align: justify;
285 overflow: hidden; 283 overflow: hidden;
286 font-size: 15px; 284 font-size: 24rpx;
285 color: #333333;
287 } 286 }
288 .info{ 287 .info{
289 display: flex; 288 display: flex;
290 justify-content: space-between; 289 justify-content: space-between;
291 align-items: flex-end; 290 align-items: center;
292 width: 92%; 291 width: 92%;
293 padding: 5px 4% 5px 4%; 292 padding: 5px 4% 5px 4%;
294 .price{ 293 .priceBox{
295 color: #e65339; 294 display: flex;
296 font-size: 15px; 295 justify-content: space-between;
297 font-weight: 600; 296 align-items: center;
297 .price{
298 color: #EB5D3B;
299 font-size: 28rpx;
300 font-weight: 600;
301 margin-right: 10rpx;
302 }
303 .originCost{
304 text-decoration:line-through;
305 color: #999999;
306 font-size: 20rpx;
307 }
308
298 } 309 }
299 .slogan{ 310 .slogan{