|
|
<template>
|
|
|
<div class="goods-box">
|
|
|
<ul class="cardlist card-large">
|
|
|
<div class="goods-box" v-infinite-scroll="fetch()" infinite-scroll-disable="disableFetch">
|
|
|
<ul class="cardlist card-large clearfix">
|
|
|
<li class="card" v-for="item in products">
|
|
|
<div class="card-pic">
|
|
|
<a href="">
|
|
|
<img :src="item.goodsList[0].imagesUrl | resize 372 499" alt="{{item.productName}}">
|
|
|
<img v-lazy="item.goodsList[0].imagesUrl | resize 372 499" alt="{{item.productName}}">
|
|
|
</a>
|
|
|
</div>
|
|
|
<div class="card-bd">
|
...
|
...
|
@@ -16,43 +16,76 @@ |
|
|
</div>
|
|
|
</li>
|
|
|
</ul>
|
|
|
<p class="cardlist--loading text-center" v-show="inLoading">正在加载...</p>
|
|
|
<p class="cardlist--end text-center" v-show="atEnd ">--End--</p>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
let $ = require('yoho-jquery');
|
|
|
|
|
|
/**
|
|
|
* @example
|
|
|
* <List url='' :query='{}' disable-fetch></List>
|
|
|
* <List :init-data='{}'></List>
|
|
|
*/
|
|
|
|
|
|
module.exports = {
|
|
|
props: {
|
|
|
|
|
|
/* 请求地址 */
|
|
|
url: {
|
|
|
type: String,
|
|
|
required: true
|
|
|
},
|
|
|
initData: Array, /* 初始数据, 应该只单次绑定, 然后fetch数据全靠url */
|
|
|
query: Object /* 请求参数 */
|
|
|
|
|
|
/* 初始数据, 应该只单次绑定, 然后fetch数据全靠url */
|
|
|
initData: Array,
|
|
|
|
|
|
/* 请求参数 */
|
|
|
query: Object,
|
|
|
|
|
|
/* 开启滚动加载 */
|
|
|
disableFetch: Boolean
|
|
|
},
|
|
|
data: function() {
|
|
|
return {
|
|
|
products: []
|
|
|
state: {
|
|
|
curPage: 0,
|
|
|
totalPage: 10
|
|
|
},
|
|
|
products: [],
|
|
|
inLoading: false,
|
|
|
atEnd: false
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
fetch: function() {
|
|
|
if (this.atEnd) {
|
|
|
return;
|
|
|
}
|
|
|
let self = this;
|
|
|
|
|
|
this.state.curPage++;
|
|
|
this.inLoading = true;
|
|
|
$.ajax({
|
|
|
url: this.url,
|
|
|
type: 'POST',
|
|
|
})
|
|
|
.then(result => {
|
|
|
.done(result => {
|
|
|
self.$set('products', self.products.concat(result.data.productList));
|
|
|
})
|
|
|
.always(() => {
|
|
|
self.inLoading = false;
|
|
|
self.atEnd = self.state.curPage === self.state.totalPage;
|
|
|
});
|
|
|
|
|
|
}
|
|
|
},
|
|
|
created: function() {
|
|
|
// 有初始数据,用初始数据
|
|
|
if (this.initData) {
|
|
|
self.$set('products', self.products.concat(this.initData));
|
|
|
this.$set('products', this.products.concat(this.initData));
|
|
|
this.atEnd = true;
|
|
|
} else if (this.url) {
|
|
|
this.fetch();
|
|
|
}
|
...
|
...
|
@@ -115,23 +148,4 @@ module.exports = { |
|
|
color: $red;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
.drawer-slide {
|
|
|
position: fixed;
|
|
|
top: 0;
|
|
|
right: 0;
|
|
|
bottom: 0;
|
|
|
left: 0;
|
|
|
background-color: rgba(0, 0, 0, 0.6);
|
|
|
}
|
|
|
|
|
|
.drawer-main {
|
|
|
position: absolute;
|
|
|
top: 0;
|
|
|
right: 0;
|
|
|
bottom: 0;
|
|
|
min-width: 80%;
|
|
|
max-width: 100%;
|
|
|
background-color: #fff;
|
|
|
}
|
|
|
</style> |
...
|
...
|
|