Authored by shuaiguo

feat(我的收入): 数据获取

... ... @@ -5,11 +5,11 @@
<span class="total-wait-apply">收款清单</span>
<span><span class="wait-label">待收金额:</span><span class="wait-price-num">¥{{props.data.waitApplyCashAmount}}</span></span>
</p>
<slot><div class="no-data">暂无收款清单</div></slot>
<slot name="waitApply"><div class="no-data">暂无收款清单</div></slot>
</div>
<div class="income-detail-header">
<p class="total-income">收入明细</p>
<slot><div class="no-data">暂无收入明细</div></slot>
<slot name="income"><div class="no-data">暂无收入明细</div></slot>
</div>
</div>
</template>
... ...
... ... @@ -8,10 +8,17 @@
<incomeHeader :data="getAssetSummary" class="header-inner-padding"></incomeHeader>
<payAccount class="inner-padding"></payAccount>
<incomeDetail :data="incomeData">
<template v-for="(item,index) in incomeData.list">
<incomeDetail :data="assetData">
<template #waitApply>
<div v-for="(item,index) in assetData.waitApplyInfo.list" :key="index">
<incomeItem :item="item" :key="index"></incomeItem>
</template>
</div>
</template>
<template #income>
<div v-for="(item,index) in assetData.incomeInfo.list" :key="index">
<incomeItem :item="item" :key="index"></incomeItem>
</div>
</template>
</incomeDetail>
<!-- 自定义下拉刷新内容 -->
<!-- <template v-if="customPullDown" slot="pulldown" slot-scope="props">
... ... @@ -29,73 +36,77 @@ import incomeItem from './components/incomeItem';
import pullDown from './components/pullDown';
import payAccount from './components/payAccount';
import { createNamespacedHelpers } from 'vuex';
import {Style, Scroll} from 'cube-ui';
import {Style} from 'cube-ui';
import scrollMixin from '../../../mixins/scroll';
const {mapState, mapGetters, mapActions} = createNamespacedHelpers('home/mine');
export default {
mixins: [scrollMixin],
data() {
return {
page: 0,
totalPage: 0
mixins: [scrollMixin],
data() {
return {
page: 0,
totalPage: 0
};
},
computed: {
...mapGetters(['getAssetSummary']),
...mapState({
assetData: (state) => state.assetData,
isEnd: state => {
const {incomeInfo} = state.assetData;
return incomeInfo.isEnd;
}
},
computed:{
...mapGetters(['getAssetSummary']),
...mapState({
incomeData: (state) => state.assetData
}),
loadingOptions() {
return {
hide: !this.totalPage,
noMore: this.page >= this.totalPage
};
}),
loadingOptions() {
return {
hide: !this.totalPage,
noMore: this.page >= this.totalPage
};
}
},
created() {
},
activated() {
this.fetchAssetsAsync(true);
},
watch: {
'assetData.incomeInfo.list': function(val) {
if (val.length === 0) {
this.options.pullUpLoad.txt.noMore = '';
} else {
this.options.pullUpLoad.txt.noMore = '到底啦~';
}
},
created() {
},
activated() {
this.fetchAssetsAsync(true)
},
watch: {
"incomeData.list": function(val) {
if(val.length === 0) {
this.options.pullUpLoad.txt.noMore = ''
// this.$refs.scroll.disable()
} else {
this.options.pullUpLoad.txt.noMore = '到底啦~'
// this.$refs.scroll.enable()
}
}
},
methods: {
...mapActions(['fetchAssets']),
onPullingUp() {
if (!this.isEnd) {
this.fetchAssetsAsync(false);
} else {
this.$refs.scroll.forceUpdate();
}
},
methods: {
...mapActions(['fetchAssets']),
onPullingUp() {
if(!this.incomeData.endReached) {
this.fetchAssetsAsync(false)
} else {
this.$refs.scroll.forceUpdate()
}
},
fetchAssetsAsync(reFetch) {
return this.fetchAssets(reFetch).then(res => {
if (res.code === 200) {
let { page, pagetotal } = res.data || {};
fetchAssetsAsync(reFetch) {
return this.fetchAssets(reFetch).then(res => {
if (res) {
let { currentPage, totalPage } = res || {};
this.page = page || 0;
this.totalPage = pagetotal || 0;
}
});
}
},
components: {
incomeHeader,
incomeDetail,
incomeItem,
pullDown,
payAccount,
Style
this.page = currentPage || 0;
this.totalPage = totalPage || 0;
}
});
}
},
components: {
incomeHeader,
incomeDetail,
incomeItem,
pullDown,
payAccount,
Style
}
};
</script>
... ...
... ... @@ -24,14 +24,24 @@ export default function() {
askBuyNum: 0,
couponNum: 0,
assetData: {
isFetching: false,
list: [],
currentPage: 1,
pageSize: 20,
endReached: false,
compensateIncome: '¥0.00',
goodsIncome: '¥0.00',
totalIncome: '¥0.00',
waitApplyCashAmount: '0.00',
waitApplyInfo: {
isEnd: false,
currentPage: 1,
pageSize: 20,
totalPage: 0,
list: []
},
incomeInfo: {
isEnd: false,
currentPage: 1,
pageSize: 20,
totalPage: 0,
list: []
}
},
walletData: {
isFetching: false,
... ... @@ -293,6 +303,18 @@ export default function() {
state.resource1 = Object.assign({}, state.resource1, resource1);
state.resource2 = Object.assign({}, state.resource1, resource2);
},
setAssetStatisticalInfo(state, summary = {}) {
const {compensateIncome, goodsIncome, totalIncome, waitApplyCashAmount} = summary;
state.assetData.compensateIncome = formatNumber(compensateIncome || 0);
state.assetData.goodsIncome = formatNumber(goodsIncome || 0);
state.assetData.totalIncome = formatNumber(totalIncome || 0);
state.assetData.waitApplyCashAmount = waitApplyCashAmount;
},
setAssets(state, assetsInfo = {}) {
state.assetData = {...state.assetData, ...assetsInfo};
}
},
actions: {
async fetchRollBoardList({ commit }) {
... ... @@ -379,38 +401,82 @@ export default function() {
commit('addCouponSummary', { count: result.data });
}
},
async fetchAssets({ commit, state }, isRefresh) {
let {
isFetching,
endReached,
currentPage,
list,
pageSize,
} = state.assetData;
async fetchAssets({state, dispatch}, isRefresh) {
const {incomeInfo, waitApplyInfo} = state.assetData;
if (isFetching || (!isRefresh && endReached)) {
if (!isRefresh && waitApplyInfo.isEnd && incomeInfo.isEnd) {
return;
}
let oldList = isRefresh ? [] : list;
// commit('assetFetching', {isFetching: true});
let page = isRefresh ? 1 : currentPage + 1;
if (waitApplyInfo.isEnd) {
const res = await dispatch('fetchInComeAssets');
return res;
} else {
const res = await dispatch('fetchWaitApplyAssets', isRefresh);
return res;
}
},
async fetchInComeAssets({commit, state}, isRefresh) {
let {currentPage, list, pageSize} = state.assetData.incomeInfo;
const page = isRefresh ? 1 : currentPage + 1;
if (isRefresh) {
list = [];
}
const result = await this.$api.get('/api/ufo/mine/assets', {
type: 1,
type: 2,
page,
limit: pageSize,
});
// commit('assetFetching', {isFetching: false});
if (result.code === 200) {
let assetData = parseAssetList(result.data);
let newList = [...oldList, ...assetData.list];
assetData.list = newList;
commit('addAssets', assetData);
assetData.list = [...list, ...assetData.list];
commit('setAssetStatisticalInfo', result.data.summary);
commit('setAssets', {incomeInfo: assetData});
return assetData;
}
},
async fetchWaitApplyAssets({commit, state, dispatch}, isRefresh) {
let {currentPage, list, pageSize} = state.assetData.waitApplyInfo;
return result;
const page = isRefresh ? 1 : currentPage + 1;
if (isRefresh) {
list = [];
}
const result = await this.$api.get('/api/ufo/mine/assets', {
type: 1,
page,
limit: pageSize,
});
if (result.code === 200) {
let assetData = parseAssetList(result.data);
assetData.list = [...list, ...assetData.list];
commit('setAssetStatisticalInfo', result.data.summary);
commit('setAssets', {waitApplyInfo: assetData});
if (assetData.isEnd) {
const res = await dispatch('fetchInComeAssets', isRefresh);
return res;
}
return assetData;
}
},
async applyCash(_, id) {
... ...
... ... @@ -5,7 +5,6 @@ export function parseAssetList(json) {
data,
page,
pagetotal,
summary
} = json;
let parsedList = data ? data.map((item) => {
let price = '';
... ... @@ -40,19 +39,14 @@ export function parseAssetList(json) {
isWaitApply: item.links.includes('applyCash')
};
}) : [];
let endReached = parsedList.length === 0 || page === pagetotal;
let isEnd = parsedList.length === 0 || page === pagetotal;
let dealedList = {
currentPage: page,
totalPage: pagetotal,
list: parsedList,
endReached,
isEnd,
};
if (summary) {
dealedList.compensateIncome = summary.compensateIncome;
dealedList.goodsIncome = summary.goodsIncome;
dealedList.totalIncome = summary.totalIncome;
dealedList.waitApplyCashAmount = summary.waitApplyCashAmount;
}
return dealedList;
}
export function formatNumber(number) {
... ...