Commit 734125c5 authored by 郭志伟's avatar 郭志伟

fix: 数据模拟

parent 262baa76
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</template> </template>
<script> <script>
import BScroll from '@better-scroll/core'; import BScroll from '@better-scroll/core';
const ITEM_WIDTH = 108; const SCROLL_ITEM_WIDTH = 108;
export default { export default {
name: 'SpuList', name: 'SpuList',
props: { props: {
...@@ -54,18 +54,18 @@ export default { ...@@ -54,18 +54,18 @@ export default {
this.listWrapper.scrollTo(0, 0); this.listWrapper.scrollTo(0, 0);
this.listWrapper.refresh(); this.listWrapper.refresh();
}); });
return ITEM_WIDTH * (this.list.length + 2.28); return SCROLL_ITEM_WIDTH * (this.list.length + 2.28);
} }
}, },
watch: { watch: {
info: { info: {
deep: true, deep: true,
handler(val) { handler(val) {
if (Object.hasOwnProperty.call(val, 'index')) { if (Object.hasOwnProperty.call(val, 'parentIndex')) {
const itemIndex = this.list.findIndex(item => item.index === val.index); const itemIndex = this.list.findIndex(item => item.parentIndex === val.parentIndex);
if (itemIndex === -1) return; if (itemIndex === -1) return;
this.$nextTick(() => { this.$nextTick(() => {
this.handleSpuClick(this.$refs.spuItem[itemIndex], val, itemIndex); this.handleSpuClick(this.$refs.spuItem[itemIndex], val);
}); });
} }
} }
...@@ -76,28 +76,34 @@ export default { ...@@ -76,28 +76,34 @@ export default {
this.createScroller(); this.createScroller();
}, },
beforeDestroy() { beforeDestroy() {
this.listWrapper.off('scroll', this.handleScroll);
this.listWrapper.destroy(); this.listWrapper.destroy();
}, },
methods: { methods: {
createScroller() { createScroller() {
this.$nextTick(() => { if (this.listWrapper) {
if (this.listWrapper) { this.listWrapper.destroy();
this.listWrapper.destroy(); }
} this.listWrapper = new BScroll(this.$refs.spuList, {
this.listWrapper = new BScroll(this.$refs.spuList, { click: true,
click: true, scrollX: true,
scrollX: true, scrollY: false,
scrollY: false probeType: 1
});
}); });
this.listWrapper.on('scroll', this.handleScroll);
},
handleScroll(e) {
console.log(e);
}, },
numAddUnit(num) { numAddUnit(num) {
return num / 37.5 + 'rem'; return num / 37.5 + 'rem';
}, },
handleSpuClick(e, item, index) { handleSpuClick(e, item) {
this.$parent.handleSpuSelected(item, index); this.$parent.handleSpuSelected(item);
const target = e.path ? e.path.find(item => item.className.indexOf('Vl__spu-item') > -1) : e; const target = e.path ? e.path.find(item => item.className.indexOf('Vl__spu-item') > -1) : e;
this.listWrapper.scrollToElement(target, 500, -10, 0); this.$nextTick(() => {
this.listWrapper.scrollToElement(target, 500, -10, 0);
});
} }
} }
}; };
......
...@@ -67,8 +67,10 @@ export default { ...@@ -67,8 +67,10 @@ export default {
spuList() { spuList() {
let spuList = []; let spuList = [];
this.spuData.forEach((item, index) => { this.spuData.forEach((item, index) => {
item.itemList[0].index = index; item.itemList.forEach(it => {
spuList = [...spuList, ...item.itemList]; it.parentIndex = index;
spuList.push(it);
});
}); });
return spuList; return spuList;
}, },
...@@ -130,8 +132,10 @@ export default { ...@@ -130,8 +132,10 @@ export default {
const [res] = await rechargeApi.getSkuList(spuNos, type); const [res] = await rechargeApi.getSkuList(spuNos, type);
if (res) { if (res) {
this.skuList = res.rechargeList; this.skuList = res.rechargeList;
const defaultItem = res.rechargeList.find(item => item.hasStock); // const defaultItem = res.rechargeList.find(item => item.hasStock);
const defaultIndex = res.rechargeList.findIndex(item => item.hasStock); // const defaultIndex = res.rechargeList.findIndex(item => item.hasStock);
const defaultItem = res.rechargeList[0];
const defaultIndex = 0;
defaultItem && this.handleSkuSelected(defaultItem, defaultIndex); defaultItem && this.handleSkuSelected(defaultItem, defaultIndex);
} }
this.showLoading = false; this.showLoading = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment