Authored by TaoHuang

fetch data ajax

@@ -19,18 +19,9 @@ import Tabs from './components/tabs'; @@ -19,18 +19,9 @@ import Tabs from './components/tabs';
19 import Layout from './components/layout'; 19 import Layout from './components/layout';
20 import YohoPage from './yoho'; 20 import YohoPage from './yoho';
21 import UfoPage from './ufo'; 21 import UfoPage from './ufo';
22 -const TYPE = {notuse: 'notuse', use: 'use', overtime: 'overtime'};  
23 22
24 export default { 23 export default {
25 name: 'ListPage', 24 name: 'ListPage',
26 - asyncData({store}) {  
27 - return Promise.all([  
28 - store.dispatch('coupon/yoho/fetchYohoList', {  
29 - type: TYPE.notuse,  
30 - refresh: true  
31 - })  
32 - ]);  
33 - },  
34 components: { 25 components: {
35 Tabs, 26 Tabs,
36 TabPane: Tabs.Pane, 27 TabPane: Tabs.Pane,
@@ -14,10 +14,13 @@ @@ -14,10 +14,13 @@
14 > 14 >
15 <SlideItem class="slide-item"> 15 <SlideItem class="slide-item">
16 <ExchangeBox class="" v-model="inputCouponCode" @click="onSubmitCode"></ExchangeBox> 16 <ExchangeBox class="" v-model="inputCouponCode" @click="onSubmitCode"></ExchangeBox>
17 - <ScrollView class="scroll-view" ref="notuse" :data="getNotUseList" :options="scrollOptions" v-if="getNotUseList.length" :reach-bottom="reachBottom">  
18 - <CouponItem :item="item" v-for="(item, index) in getNotUseList" :key="index + '' + item.coupon_id"></CouponItem>  
19 - </ScrollView>  
20 - <Empty v-else></Empty> 17 + <Loading class="loading" v-if="showLoading"></Loading>
  18 + <template v-else>
  19 + <ScrollView class="scroll-view" ref="notuse" :data="getNotUseList" :options="scrollOptions" v-if="getNotUseList.length" :reach-bottom="reachBottom">
  20 + <CouponItem :item="item" v-for="(item, index) in getNotUseList" :key="index + '' + item.coupon_id"></CouponItem>
  21 + </ScrollView>
  22 + <Empty v-else></Empty>
  23 + </template>
21 </SlideItem> 24 </SlideItem>
22 25
23 <SlideItem class="slide-item"> 26 <SlideItem class="slide-item">
@@ -49,7 +52,7 @@ import CouponItem from '../components/coupon-item'; @@ -49,7 +52,7 @@ import CouponItem from '../components/coupon-item';
49 import Empty from '../components/empty'; 52 import Empty from '../components/empty';
50 import ScrollView from '../components/scroll-view'; 53 import ScrollView from '../components/scroll-view';
51 54
52 -import {Slide} from 'cube-ui'; 55 +import {Slide, Loading} from 'cube-ui';
53 56
54 const TYPE = {notuse: 'notuse', use: 'use', overtime: 'overtime'}; 57 const TYPE = {notuse: 'notuse', use: 'use', overtime: 'overtime'};
55 58
@@ -62,6 +65,7 @@ export default { @@ -62,6 +65,7 @@ export default {
62 selectType: TYPE.notuse, 65 selectType: TYPE.notuse,
63 selectFilterId: 0, 66 selectFilterId: 0,
64 inputCouponCode: '', 67 inputCouponCode: '',
  68 + showLoading: true,
65 tabLabels: [ 69 tabLabels: [
66 { 70 {
67 label: '未使用', 71 label: '未使用',
@@ -110,16 +114,24 @@ export default { @@ -110,16 +114,24 @@ export default {
110 } 114 }
111 }, 115 },
112 mounted() { 116 mounted() {
113 - this.fetchYohoNum();  
114 -  
115 - this.$store.dispatch('coupon/yoho/fetchYohoList', {  
116 - type: TYPE.use,  
117 - refresh: true  
118 - });  
119 -  
120 - this.$store.dispatch('coupon/yoho/fetchYohoList', {  
121 - type: TYPE.overtime,  
122 - refresh: true 117 + Promise.all([
  118 + this.fetchYohoNum(),
  119 + this.$store.dispatch('coupon/yoho/fetchYohoList', {
  120 + type: TYPE.notuse,
  121 + refresh: true
  122 + }),
  123 + this.$store.dispatch('coupon/yoho/fetchYohoList', {
  124 + type: TYPE.use,
  125 + refresh: true
  126 + }),
  127 + this.$store.dispatch('coupon/yoho/fetchYohoList', {
  128 + type: TYPE.overtime,
  129 + refresh: true
  130 + })
  131 + ]).then(() => {
  132 + this.showLoading = false;
  133 + }).catch(() => {
  134 + this.showLoading = false;
123 }); 135 });
124 }, 136 },
125 methods: { 137 methods: {
@@ -179,7 +191,8 @@ export default { @@ -179,7 +191,8 @@ export default {
179 SlideItem: Slide.Item, 191 SlideItem: Slide.Item,
180 CouponItem, 192 CouponItem,
181 Empty, 193 Empty,
182 - ScrollView 194 + ScrollView,
  195 + Loading
183 } 196 }
184 }; 197 };
185 </script> 198 </script>
@@ -231,4 +244,8 @@ export default { @@ -231,4 +244,8 @@ export default {
231 .tab-slide-container { 244 .tab-slide-container {
232 height: 100%; 245 height: 100%;
233 } 246 }
  247 +
  248 +.loading {
  249 + margin: 40px auto;
  250 +}
234 </style> 251 </style>