预算配置

This commit is contained in:
2023-02-09 22:46:38 +08:00
parent 7a7884abf5
commit 432b4f9815
8 changed files with 79 additions and 43 deletions

View File

@@ -31,12 +31,14 @@ Page({
}, },
changeBudget(e) { changeBudget(e) {
let {type,id} = e.currentTarget.dataset let {type,id} = e.currentTarget.dataset
console.log(id);
console.log(type);
let tCurrentMoney = 0.00; let tCurrentMoney = 0.00;
if (type == 'count'){ if (type == 'count'){
tCurrentMoney = this.data.sumBudget tCurrentMoney = this.data.sumBudget
}else { }else {
this.data.payTypeList.forEach(item => { this.data.payTypeList.forEach(item => {
if (item.id == id){ if (item.expendId == id){
tCurrentMoney = item.budget tCurrentMoney = item.budget
} }
}) })
@@ -68,11 +70,16 @@ Page({
}) })
return; return;
} }
let expendId = this.data.currentId
if (this.data.changeType == 'count'){
expendId = -1
}
app.$api.editBudget({ app.$api.editBudget({
expendId:this.data.currentId, expendId:expendId,
budget:this.data.currentMoney budget:this.data.currentMoney
}).then(res=>{ }).then(res=>{
if(res){ if(res){
this.updateBudget();
this.closeDialog(); this.closeDialog();
} }
}) })

View File

@@ -1,7 +1,7 @@
<view class="main_look"> <view class="main_look">
<view class="look_content"> <view class="look_content">
<view class="pay_look"> <view class="pay_look">
<view bind:tap="changeBudget" data-type="count" class="inline_box font_big">总预算<t-icon name="tools"/></view> <view bind:tap="changeBudget" data-id="-1" data-type="count" class="inline_box font_big">总预算<t-icon name="tools"/></view>
</view> </view>
<view class="pay_look"> <view class="pay_look">
<text class="center_look font_big">{{ sumBudget }}</text> <text class="center_look font_big">{{ sumBudget }}</text>
@@ -19,10 +19,10 @@
note="{{item.budget}}" note="{{item.budget}}"
bind:tap="changeBudget" bind:tap="changeBudget"
data-type="item" data-type="item"
data-id="{{item.id}}" data-id="{{item.expendId}}"
> >
<view wx:if="{{item.money}}" slot="description"> <view wx:if="{{item.id}}" slot="description">
<t-progress percentage="{{25}}" /> <t-progress percentage="{{item.progress}}" />
<text>已使用:{{item.used}}</text> <text>已使用:{{item.used}}</text>
</view> </view>
<text class="error_msg" wx:else slot="description">未设置预算</text> <text class="error_msg" wx:else slot="description">未设置预算</text>

View File

@@ -181,27 +181,19 @@ function initLineChart2(canvas, width, height, dpr) {
chart.setOption(option); chart.setOption(option);
return chart; return chart;
} }
const app = getApp();
Page({ Page({
data: { data: {
// 指定选择区间起始值 // 指定选择区间起始值
start: '2000-01-01 00:00:00', start: '2000-01-01 00:00:00',
end: '2030-09-09 12:12:12', end: '2030-09-09 12:12:12',
showDateVisible:false, showDateVisible:false,
showDate:'2022-01', showDate:app.$utils.formatDateMonth(new Date()),
accountList: [ accountList: [],
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"}, sumExpend: 0,
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, sumIncome: 0,
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"}, sumTransfer: 0,
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, sumRepayment: 0,
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"},
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"},
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"},
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
{"id":1,"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"},
{"id":2,"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"},
],
payTypeList: [ payTypeList: [
{"title":"数码产品","type":"expend","progress":"80","money":"4500.00"}, {"title":"数码产品","type":"expend","progress":"80","money":"4500.00"},
{"title":"房贷","type":"expend","progress":"20","money":"35.00"}, {"title":"房贷","type":"expend","progress":"20","money":"35.00"},
@@ -258,15 +250,25 @@ Page({
ecLine2: { ecLine2: {
onInit: initLineChart2 onInit: initLineChart2
} }
},
onLoad: function (options) {
}, },
onShow: function () { onShow: function () {
this.updateView();
if (wx.canIUse('hideHomeButton')) { if (wx.canIUse('hideHomeButton')) {
wx.hideHomeButton() wx.hideHomeButton()
} }
}, },
updateView(){
app.$api.listBillByAMonth({'rangeDate':this.data.showDate}).then(res => {
if (res.data){
let accountList = res.data.accountList
let sumExpend = res.data.sumExpend
let sumIncome = res.data.sumIncome
let sumTransfer = res.data.sumTransfer
let sumRepayment = res.data.sumRepayment
this.setData({accountList,sumExpend,sumIncome,sumTransfer,sumRepayment})
}
})
},
showPicker(e) { showPicker(e) {
const { mode } = e.currentTarget.dataset; const { mode } = e.currentTarget.dataset;
this.setData({ this.setData({
@@ -283,12 +285,12 @@ Page({
onConfirm(e) { onConfirm(e) {
const { value } = e.detail; const { value } = e.detail;
const { mode } = this.data; const { mode } = this.data;
console.log('confim', value);
this.setData({ this.setData({
[mode]: value [mode]: value
// [`${mode}Text`]: value, // [`${mode}Text`]: value,
}); });
this.hidePicker(); this.updateView()
this.hidePicker()
} }
}); });

View File

@@ -4,10 +4,10 @@
<t-tabs defaultValue="{{0}}" t-class="custom-tabs" theme="card"> <t-tabs defaultValue="{{0}}" t-class="custom-tabs" theme="card">
<t-tab-panel label="总览" value="0" class="tab_content"> <t-tab-panel label="总览" value="0" class="tab_content">
<view class="space_box font_big"> <view class="space_box font_big">
<text class="t-color-expend">支出\n {{1203.00}}</text> <text class="t-color-expend">支出\n {{sumExpend}}</text>
<text class="t-color-income">收入\n {{1203.00}}</text> <text class="t-color-income">收入\n {{sumIncome}}</text>
<text class="t-color-transfer">转账\n {{1203.00}}</text> <text class="t-color-transfer">转账\n {{sumTransfer}}</text>
<text class="t-color-repayment">还款\n {{1203.00}}</text> <text class="t-color-repayment">还款\n {{sumRepayment}}</text>
</view> </view>
<view class="padding_box"> <view class="padding_box">
<t-divider dashed content="账单明细"/> <t-divider dashed content="账单明细"/>
@@ -15,18 +15,18 @@
<view wx:if="{{accountList != null && accountList.length > 0}}"> <view wx:if="{{accountList != null && accountList.length > 0}}">
<t-cell-group theme="card"> <t-cell-group theme="card">
<t-cell wx:for="{{accountList}}" wx:key="index" <t-cell wx:for="{{accountList}}" wx:key="index"
title="{{item.title}}" title="{{item.moneyName}}"
description="{{item.dateTime}} • {{item.from}}" description="{{item.date}} • {{item.accountName}}"
align="top" align="top"
image="/image/bill/4.png" image="{{item.moneyIcon}}"
note="{{item.money}}" note="{{item.money}}"
class="t-cell-{{item.type}}" class="t-cell-{{item.billType}}"
url="{{'/pages/bill/index?id=' + item.id}}" url="{{'/pages/bill/index?id=' + item.id}}"
/> />
</t-cell-group> </t-cell-group>
</view> </view>
<view wx:else class="empty-view" > <view wx:else class="empty-view" >
<t-empty icon="chart-bubble" description="今日还未记账" /> <t-empty icon="chart-bubble" description="本月无账单记录" />
</view> </view>
</t-tab-panel> </t-tab-panel>
<t-tab-panel label="支出分类" value="1"> <t-tab-panel label="支出分类" value="1">

View File

@@ -1,7 +1,11 @@
const app = getApp() const app = getApp()
Page({ Page({
data: { data: {
progress: 89, sumToday:0,
sumBalance:0,
sumBudget:0,
sumUsed:0,
progress:0,
todayList: [] todayList: []
}, },
onLoad: function (options) { onLoad: function (options) {
@@ -13,6 +17,16 @@ Page({
this.setData({todayList}) this.setData({todayList})
} }
}) })
app.$api.getBudgetIndex().then(res => {
if (res.data){
let sumToday = res.data.sumToday
let sumBalance = res.data.sumBalance
let sumBudget = res.data.sumBudget
let sumUsed = res.data.sumUsed
let progress = Math.floor(res.data.sumUsed / res.data.sumBudget * 10000) / 100
this.setData({sumToday,sumBalance,sumBudget,sumUsed,progress})
}
})
if (wx.canIUse('hideHomeButton')) { if (wx.canIUse('hideHomeButton')) {
wx.hideHomeButton() wx.hideHomeButton()
} }

View File

@@ -1,12 +1,12 @@
<view class="main_look"> <view class="main_look">
<view class="look_content"> <view class="look_content font_big">
<view class="pay_look"> <view class="pay_look">
<text>今日支出\n</text> <text>今日支出\n</text>
<text class="font_big">200.00</text> <text class="font_big">{{sumToday}}</text>
</view> </view>
<view class="balance_look"> <view class="balance_look">
<text>账户余额:2235.20</text> <text>账户余额:{{sumBalance}}</text>
<text>预算余额:300.00</text> <text>预算余额:{{sumBudget - sumUsed}}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -15,11 +15,11 @@
<view bind:tap="modifyBudget" class="inline_box"><t-icon name="money-circle" size="28rpx"/>查看</view> <view bind:tap="modifyBudget" class="inline_box"><t-icon name="money-circle" size="28rpx"/>查看</view>
</view> </view>
<view class="padding_box"> <view class="padding_box">
<t-progress theme="plump" percentage="{{progress}}" status="{{progress > 80 ? 'error' : 'success' }}" /> <t-progress theme="plump" percentage="{{progress}}" status="{{ progress > 80 ? 'error' : 'success' }}" />
</view> </view>
<view class="space_box font_small"> <view class="space_box font_small">
<text>当月预算:54602.00</text> <text>当月预算:{{sumBudget}}</text>
<text>已消费:777.80</text> <text>已消费:{{sumUsed}}</text>
</view> </view>
<view class="padding_box"> <view class="padding_box">
<t-button theme="primary" size="medium" block bind:tap="addBill">记一笔</t-button> <t-button theme="primary" size="medium" block bind:tap="addBill">记一笔</t-button>

View File

@@ -286,6 +286,9 @@ export default {
listBillsToday() { listBillsToday() {
return fetchPost('/user/bills/today', null,true,false); return fetchPost('/user/bills/today', null,true,false);
}, },
listBillByAMonth(params){
return fetchPost('/user/bills/month' ,params,true,false);
},
listBillByAccount(params){ listBillByAccount(params){
return fetchPost('/user/bills/account' ,params,true,false); return fetchPost('/user/bills/account' ,params,true,false);
}, },
@@ -301,6 +304,9 @@ export default {
/** /**
* 预算处理 * 预算处理
*/ */
getBudgetIndex(){
return fetchPost('/user/budget/index',null,true,false);
},
getBudget(){ getBudget(){
return fetchPost('/user/budget',null,true,false); return fetchPost('/user/budget',null,true,false);
}, },

View File

@@ -16,6 +16,12 @@ const formatDate = date => {
return `${[year, month, day].map(formatNumber).join('-')}` return `${[year, month, day].map(formatNumber).join('-')}`
} }
const formatDateMonth = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
return `${[year, month].map(formatNumber).join('-')}`
}
const formatNumber = n => { const formatNumber = n => {
n = n.toString() n = n.toString()
return n[1] ? n : `0${n}` return n[1] ? n : `0${n}`
@@ -49,5 +55,6 @@ const getToken = () => {
module.exports = { module.exports = {
formatTime, formatTime,
formatDate, formatDate,
formatDateMonth,
getToken getToken
} }