Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
a8b0fbc3
Commit
a8b0fbc3
authored
Jul 01, 2019
by
Junling Bu
Browse files
chore[litemall-vue]: 商品分类页面基于vant组件重构
parent
39d33234
Changes
1
Hide whitespace changes
Inline
Side-by-side
litemall-vue/src/views/items/list/index.vue
View file @
a8b0fbc3
<
template
>
<
template
>
<div
class=
"item_list over-hide"
>
<div
class=
"item_list"
>
<van-tabs
v-model=
"navActive"
@
click=
"handleTabClick"
>
<van-tabs
v-model=
"navActive"
<van-tab
v-for=
"(nav, index) in navList"
:title=
"nav.name"
:key=
"index"
>
@
click=
"handleTabClick"
>
<!--
<InfinityScroll
<van-tab
v-for=
"(nav, index) in navList"
:ref=
"'tabScrolls' + tabIndex"
:title=
"nav.name"
class=
"full-page scroll-wrap fix-height"
:key=
"index"
>
:beforeRequest=
"beforeRequest"
<van-list
v-model=
"loading"
:apiUrl=
"listApi"
:finished=
"finished"
@
onLoad=
"onLoad(tabIndex, $event)"
:immediate-check=
"false"
>
-->
finished-text=
"没有更多了"
<div
class=
"h"
>
@
load=
"getGoodsList"
>
<div
class=
"name"
>
{{
currentCategory
.
name
}}
</div>
<div
class=
"h"
>
<div
class=
"desc"
>
{{
currentCategory
.
desc
}}
</div>
<div
class=
"name"
>
{{
currentCategory
.
name
}}
</div>
</div>
<div
class=
"desc"
>
{{
currentCategory
.
desc
}}
</div>
<item-group>
</div>
<item-card-hori
<van-card
v-for=
"(item, i) in goodsList"
v-for=
"(item, i) in goodsList"
:key=
"i"
:key=
"i"
:desc=
"item.brief"
:goods=
"item"
:title=
"item.name"
@
click=
"itemClick(item.id)"
:thumb=
"item.picUrl"
/>
:price=
"item.retailPrice"
</item-group>
:origin-price=
"item.counterPrice"
<!--
</InfinityScroll>
-->
@
click=
"itemClick(item.id)"
/>
</van-list>
</van-tab>
</van-tab>
</van-tabs>
</van-tabs>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
goodsCategory
,
goodsList
,
GoodsList
}
from
'
@/api/api
'
;
import
{
goodsCategory
,
goodsList
}
from
'
@/api/api
'
;
import
{
Card
,
List
,
Tab
,
Tabs
}
from
'
vant
'
;
import
ItemGroup
from
'
@/components/item-group
'
;
import
ItemCardHori
from
'
@/components/item-card-hori/
'
;
import
{
Search
,
Tab
,
Tabs
,
Popup
}
from
'
vant
'
;
import
InfinityScroll
from
'
@/components/infinity-scroll
'
;
import
InfinityScroll
from
'
@/components/infinity-scroll
'
;
export
default
{
export
default
{
...
@@ -47,11 +46,14 @@ export default {
...
@@ -47,11 +46,14 @@ export default {
data
()
{
data
()
{
return
{
return
{
categoryId
:
this
.
itemClass
,
categoryId
:
this
.
itemClass
,
listApi
:
GoodsList
,
goodsList
:
[],
goodsList
:
[],
page
:
0
,
limit
:
10
,
currentCategory
:
{},
currentCategory
:
{},
navList
:
[],
navList
:
[],
navActive
:
0
navActive
:
0
,
loading
:
false
,
finished
:
false
};
};
},
},
...
@@ -61,88 +63,66 @@ export default {
...
@@ -61,88 +63,66 @@ export default {
methods
:
{
methods
:
{
handleTabClick
(
index
)
{
handleTabClick
(
index
)
{
this
.
categoryId
=
this
.
navList
[
index
].
id
;
this
.
categoryId
=
this
.
navList
[
index
].
id
;
this
.
$router
.
replace
({
this
.
$router
.
replace
({
name
:
'
list
'
,
name
:
'
list
'
,
query
:
{
itemClass
:
this
.
categoryId
}
query
:
{
itemClass
:
this
.
categoryId
}
});
});
this
.
init
();
this
.
init
();
},
},
init
()
{
init
()
{
goodsCategory
({
id
:
this
.
categoryId
}).
then
(
res
=>
{
goodsCategory
({
id
:
this
.
categoryId
}).
then
(
res
=>
{
this
.
navList
=
res
.
data
.
data
.
brotherCategory
;
this
.
navList
=
res
.
data
.
data
.
brotherCategory
;
this
.
currentCategory
=
res
.
data
.
data
.
currentCategory
;
this
.
currentCategory
=
res
.
data
.
data
.
currentCategory
;
// 当id是L1分类id时,这里需要重新设置成L1分类的一个子分类的id
// 当id是L1分类id时,这里需要重新设置成L1分类的一个子分类的id
if
(
res
.
data
.
data
.
parentCategory
.
id
==
this
.
categoryId
)
{
if
(
res
.
data
.
data
.
parentCategory
.
id
==
this
.
categoryId
)
{
this
.
categoryId
=
res
.
data
.
data
.
currentCategory
.
id
;
this
.
categoryId
=
res
.
data
.
data
.
currentCategory
.
id
;
}
}
for
(
let
i
=
0
;
i
<
this
.
navList
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
this
.
navList
.
length
;
i
++
)
{
if
(
this
.
navList
[
i
].
id
==
this
.
categoryId
)
{
if
(
this
.
navList
[
i
].
id
==
this
.
categoryId
)
{
this
.
navActive
=
i
this
.
navActive
=
i
;
break
;
break
;
}
}
}
}
this
.
page
=
0
;
this
.
getGoodsList
();
this
.
goodsList
=
[];
});
this
.
getGoodsList
();
});
},
getGoodsList
()
{
this
.
page
++
;
goodsList
({
categoryId
:
this
.
categoryId
,
page
:
this
.
page
,
limit
:
this
.
limit
}).
then
(
res
=>
{
this
.
goodsList
.
push
(...
res
.
data
.
data
.
list
);
this
.
loading
=
false
;
this
.
finished
=
res
.
data
.
data
.
page
>=
res
.
data
.
data
.
pages
;
});
}
},
},
getGoodsList
()
{
goodsList
({
categoryId
:
this
.
categoryId
}).
then
(
res
=>
{
this
.
goodsList
=
res
.
data
.
data
.
list
});
},
},
components
:
{
components
:
{
InfinityScroll
,
[
List
.
name
]:
List
,
[
ItemGroup
.
name
]:
ItemGroup
,
[
Card
.
name
]:
Card
,
[
ItemCardHori
.
name
]:
ItemCardHori
,
[
Tab
.
name
]:
Tab
,
[
Tab
.
name
]:
Tab
,
[
Tabs
.
name
]:
Tabs
,
[
Tabs
.
name
]:
Tabs
[
Search
.
name
]:
Search
,
[
Popup
.
name
]:
Popup
}
}
};
};
</
script
>
</
script
>
<
style
lang=
"scss"
scoped
>
<
style
lang=
"scss"
scoped
>
.fade-enter
,
.fade-leave-to
{
opacity
:
0
;
}
.fade-enter-active
,
.fade-leave-active
{
transition
:
all
0
.5s
;
}
.fix-height
{
padding-bottom
:
88px
;
}
.over-hide
{
overflow
:
hidden
;
}
.item_list
{
.item_list
{
background-color
:
#fff
;
background-color
:
#fff
;
padding-bottom
:
0
;
}
.fixedTop
{
position
:
fixed
;
width
:
100%
;
top
:
0
;
z-index
:
999
;
}
.items_loading
{
margin
:
0
auto
;
}
}
.h
{
.h
{
height
:
100px
;
height
:
100px
;
width
:
100%
;
width
:
100%
;
margin-top
:
10px
;
display
:
flex
;
display
:
flex
;
flex-direction
:
column
;
flex-direction
:
column
;
align-items
:
center
;
align-items
:
center
;
...
@@ -162,5 +142,4 @@ export default {
...
@@ -162,5 +142,4 @@ export default {
font-size
:
16px
;
font-size
:
16px
;
color
:
#999
;
color
:
#999
;
}
}
</
style
>
</
style
>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment