账单增删改调整

This commit is contained in:
2023-02-07 20:19:02 +08:00
parent 1fadf4c339
commit 1f5580c0f3
12 changed files with 109 additions and 83 deletions

View File

@@ -128,6 +128,9 @@ t-cell {
color: whitesmoke !important; color: whitesmoke !important;
} }
/*文本域*/ /*文本域*/
.t-textarea {
--td-textarea-disabled-text-color: orange;
}
.t-textarea__label { .t-textarea__label {
--td-font-size-base: 32rpx; --td-font-size-base: 32rpx;
--td-textarea-label-color:none --td-textarea-label-color:none

View File

@@ -1,14 +1,14 @@
<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"> <t-tab-panel label="支出" value="0">
<expenses changeType="expend"/> <expenses changeType="EXPEND"/>
</t-tab-panel> </t-tab-panel>
<t-tab-panel label="收入" value="1"> <t-tab-panel label="收入" value="1">
<expenses changeType="income"/> <expenses/>
</t-tab-panel> </t-tab-panel>
<t-tab-panel label="转账" value="2"> <t-tab-panel label="转账" value="2">
<transfer/> <transfer/>
</t-tab-panel> </t-tab-panel>
<t-tab-panel label="还款" value="3"> <t-tab-panel label="还款" value="3">
<transfer changeType="repayment"/> <transfer changeType="REPAYMENT"/>
</t-tab-panel> </t-tab-panel>
</t-tabs> </t-tabs>

View File

@@ -1,9 +1,11 @@
Page({ Page({
data: { data: {
sid: null sid: null,
billType: null
}, },
onLoad: function (options) { onLoad: function (options) {
let sid = options.id let sid = options.id
this.setData({sid}) let billType = options.billType
this.setData({sid,billType})
} }
}); });

View File

@@ -1,4 +1,4 @@
<view class="padding_box"> <view class="padding_box">
<expenses/> <expenses wx:if="{{billType == 'INCOME' || billType == 'EXPEND'}}" billId="{{sid}}" changeType="{{billType}}"/>
<!-- <transfer/>--> <transfer wx:if="{{billType == 'REPAYMENT' || billType == 'TRANSFER'}}" billId="{{sid}}" changeType="{{billType}}"/>
</view> </view>

View File

@@ -12,6 +12,7 @@ Page({
moneyName: null, moneyName: null,
fromAccountName: null, fromAccountName: null,
accountName: null, accountName: null,
remark: null,
}, },
onLoad: function (options) { onLoad: function (options) {
let sid = options.id let sid = options.id
@@ -29,13 +30,14 @@ Page({
let moneyName = res.data.moneyName let moneyName = res.data.moneyName
let fromAccountName = res.data.fromAccountName let fromAccountName = res.data.fromAccountName
let accountName = res.data.accountName let accountName = res.data.accountName
this.setData({sid,name,money,balance,date,billType,moneyName,fromAccountName,accountName}) let remark = res.data.remark
this.setData({sid,name,money,balance,date,billType,moneyName,fromAccountName,accountName,remark})
} }
}) })
}, },
editBill() { editBill() {
wx.navigateTo({ wx.navigateTo({
url: './edit/index?id=' + this.data.sid url: './edit/index?id=' + this.data.sid + '&billType=' + this.data.billType
}) })
}, },
deleteBill() { deleteBill() {

View File

@@ -13,15 +13,15 @@
</t-cell> </t-cell>
<view wx:if="{{billType == 'TRANSFER' || billType == 'REPAYMENT'}}"> <view wx:if="{{billType == 'TRANSFER' || billType == 'REPAYMENT'}}">
<t-cell title="账户" note="{{fromAccountName}}"> <t-cell title="账户" note="{{fromAccountName}}">
<t-icon name="fromAccount" slot="left-icon" /> <t-icon name="creditcard" slot="left-icon" />
</t-cell> </t-cell>
<t-cell title="目标" note="{{accountName}}"> <t-cell title="目标" note="{{accountName}}">
<t-icon name="account" slot="left-icon" /> <t-icon name="creditcard" slot="left-icon" />
</t-cell> </t-cell>
</view> </view>
<view wx:if="{{billType == 'INCOME' || billType == 'EXPEND'}}"> <view wx:if="{{billType == 'INCOME' || billType == 'EXPEND'}}">
<t-cell title="账户" note="{{accountName}}"> <t-cell title="账户" note="{{accountName}}">
<t-icon name="account" slot="left-icon" /> <t-icon name="creditcard" slot="left-icon" />
</t-cell> </t-cell>
<t-cell title="余额" note="{{balance}}"> <t-cell title="余额" note="{{balance}}">
<t-icon name="root-list" slot="left-icon" /> <t-icon name="root-list" slot="left-icon" />
@@ -30,6 +30,7 @@
<t-cell title="时间" note="{{date}}"> <t-cell title="时间" note="{{date}}">
<t-icon name="calendar" slot="left-icon" /> <t-icon name="calendar" slot="left-icon" />
</t-cell> </t-cell>
<t-textarea value="{{remark}}" maxlength="200" bindchange="onRemarkInput" disabled />
<view class="bottom_box"> <view class="bottom_box">
<view class="space_box"> <view class="space_box">
<t-button theme="danger" variant="outline" block bind:tap="deleteBill">删除</t-button> <t-button theme="danger" variant="outline" block bind:tap="deleteBill">删除</t-button>

View File

@@ -15,3 +15,6 @@ image {
t-button { t-button {
width: 50%; width: 50%;
} }
.t-color-input {
color: orange;
}

View File

@@ -1,21 +1,24 @@
const app = getApp(); const app = getApp();
import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index'; import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index';
let handler = null; let handler = null;
const firstGrid = [];
const secondGrid = [];
Component({ Component({
properties: { properties: {
billId: { billId: {
type: String, type: String,
value: null value: -1
}, },
/* income & expend */ /* income & expend */
changeType: { changeType: {
type: String, type: String,
value: 'income' value: 'INCOME'
}, },
}, },
data: { data: {
incomeGrid1: [],
incomeGrid2: [],
expendGrid1: [],
expendGrid2: [],
priceError: false, priceError: false,
grid: '', grid: '',
outText: '', outText: '',
@@ -36,48 +39,60 @@ Component({
remark: null, remark: null,
}, },
attached(){ attached(){
let incomeGrid1 = [];
let incomeGrid2 = [];
let expendGrid1 = [];
let expendGrid2 = [];
app.$api.getSettings().then(setting => { app.$api.getSettings().then(setting => {
if (setting){ if (setting){
let expend = setting.data.EXPEND_SETTING; let expend = setting.data.EXPEND_SETTING;
let income = setting.data.INCOME_SETTING; let income = setting.data.INCOME_SETTING;
let cash = setting.data.CASH_SETTING; let cash = setting.data.CASH_SETTING;
let owe = setting.data.OWE_SETTING; let owe = setting.data.OWE_SETTING;
if ('expend' == this.properties.changeType){
expend.forEach(x=>{ expend.forEach(x=>{
firstGrid.fill({ expendGrid1 = expendGrid1.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) })
}else {
income.forEach(x=>{ income.forEach(x=>{
firstGrid.fill({ incomeGrid1 = incomeGrid1.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) })
}
cash.forEach(x=>{ cash.forEach(x=>{
secondGrid.fill({ incomeGrid2 = incomeGrid2.concat({
id: x.id,
label: x.name,
icon: x.icon,
});
expendGrid2 = expendGrid2.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) })
owe.forEach(x=>{ owe.forEach(x=>{
secondGrid.fill({ incomeGrid2 = incomeGrid2.concat({
id: x.id,
label: x.name,
icon: x.icon,
});
expendGrid2 = expendGrid2.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) })
this.setData({expendGrid1,expendGrid2,incomeGrid1,incomeGrid2})
} }
}); });
if (this.properties.billId){ if (this.properties.billId != -1){
app.$api.getBill(this.properties.billId).then(res => { app.$api.getBill(this.properties.billId).then(res => {
if (res){ if (res.data){
let name = res.data.name; let name = res.data.name;
let money = res.data.money; let money = res.data.money;
let billType = res.data.billType; let billType = res.data.billType;
@@ -86,18 +101,14 @@ Component({
let typeText = res.data.moneyName; let typeText = res.data.moneyName;
let accountText = res.data.accountName; let accountText = res.data.accountName;
let remark = res.data.remark; let remark = res.data.remark;
let date = res.data.date; let dateText = res.data.date;
let dateText = app.$utils.formatDate(date)
this.setData({ this.setData({
name,money,billType,account,moneyType,typeText,accountText,remark,date,dateText name,money,billType,account,moneyType,typeText,accountText,remark,dateText
}) })
} }
}) })
}else { }else {
let billType = 'INCOME' let billType = this.properties.changeType
if ('expend' == this.properties.changeType){
billType = 'EXPEND'
}
this.setData({billType}) this.setData({billType})
} }
}, },
@@ -124,14 +135,14 @@ Component({
theme: ActionSheetTheme.Grid, theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet', selector: '#t-action-sheet',
context: this, context: this,
items: firstGrid items: this.properties.changeType == 'EXPEND' ? this.data.expendGrid1 : this.data.incomeGrid1
}); });
}else { }else {
handler = ActionSheet.show({ handler = ActionSheet.show({
theme: ActionSheetTheme.Grid, theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet', selector: '#t-action-sheet',
context: this, context: this,
items: secondGrid items: this.properties.changeType == 'EXPEND' ? this.data.expendGrid2 : this.data.incomeGrid2
}); });
} }
}, },
@@ -181,20 +192,17 @@ Component({
bYesterday () { bYesterday () {
let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 2); let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 2);
this.setData({ this.setData({
date : preDate,
dateText: app.$utils.formatDate(preDate) dateText: app.$utils.formatDate(preDate)
}) })
}, },
yesterday() { yesterday() {
let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000); let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
this.setData({ this.setData({
date : preDate,
dateText: app.$utils.formatDate(preDate) dateText: app.$utils.formatDate(preDate)
}) })
}, },
today () { today () {
this.setData({ this.setData({
date : new Date(),
dateText: app.$utils.formatDate(new Date()) dateText: app.$utils.formatDate(new Date())
}) })
}, },
@@ -207,7 +215,7 @@ Component({
account:this.data.account, account:this.data.account,
moneyType:this.data.moneyType, moneyType:this.data.moneyType,
remark:this.data.remark, remark:this.data.remark,
date:this.data.date date:this.data.dateText
} }
app.$api.editBill(param).then(res => { app.$api.editBill(param).then(res => {
if (res) { if (res) {

View File

@@ -32,7 +32,7 @@
<view class="placeholder_line"></view> <view class="placeholder_line"></view>
<t-tag size="large" bind:tap="today" variant="light">今天</t-tag> <t-tag size="large" bind:tap="today" variant="light">今天</t-tag>
</view> </view>
<t-textarea label="备注" placeholder="请输入该账单说明..." bindchange="onRemarkInput" maxlength="200" indicator /> <t-textarea label="备注" placeholder="请输入该账单说明..." value="{{remark}}" bindchange="onRemarkInput" maxlength="200" indicator />
<view class="view_button"> <view class="view_button">
<t-button theme="primary" block bind:tap="saveBill">保存</t-button> <t-button theme="primary" block bind:tap="saveBill">保存</t-button>
</view> </view>

View File

@@ -1,8 +1,6 @@
const app = getApp(); const app = getApp();
import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index'; import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index';
let handler = null; let handler = null;
const firstGrid = [];
const secondGrid = [];
Component({ Component({
properties: { properties: {
billId: { billId: {
@@ -12,10 +10,14 @@ Component({
/* transfer & repayment */ /* transfer & repayment */
changeType: { changeType: {
type: String, type: String,
value: 'transfer' value: 'TRANSFER'
}, },
}, },
data: { data: {
transferGrid1: [],
transferGrid2: [],
repaymentGrid1: [],
repaymentGrid2: [],
priceError: false, priceError: false,
grid: '', grid: '',
typeText: '', typeText: '',
@@ -41,35 +43,41 @@ Component({
if (setting){ if (setting){
let cash = setting.data.CASH_SETTING; let cash = setting.data.CASH_SETTING;
let owe = setting.data.OWE_SETTING; let owe = setting.data.OWE_SETTING;
let transferGrid1 = []
let transferGrid2 = []
let repaymentGrid1 = []
let repaymentGrid2 = []
cash.forEach(x=>{ cash.forEach(x=>{
firstGrid.fill({ transferGrid1 = transferGrid1.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) transferGrid2 = transferGrid2.concat({
if ('transfer' == this.properties.changeType){
cash.forEach(x=>{
secondGrid.fill({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
repaymentGrid1 = repaymentGrid1.concat({
id: x.id,
label: x.name,
icon: x.icon,
});
}) })
}else {
owe.forEach(x=>{ owe.forEach(x=>{
secondGrid.fill({ repaymentGrid2 = repaymentGrid2.concat({
id: x.id, id: x.id,
label: x.name, label: x.name,
icon: x.icon, icon: x.icon,
}); });
}) })
} this.setData({transferGrid1,transferGrid2,repaymentGrid1,repaymentGrid2})
} }
}) })
if (this.properties.billId){ if (this.properties.billId != -1){
app.$api.getBill(this.properties.billId).then(res => { app.$api.getBill(this.properties.billId).then(res => {
if (res){ if (res.data){
let name = res.data.name; let name = res.data.name;
let money = res.data.money; let money = res.data.money;
let billType = res.data.billType; let billType = res.data.billType;
@@ -79,17 +87,16 @@ Component({
let inText = res.data.accountName; let inText = res.data.accountName;
let moneyType = res.data.moneyType; let moneyType = res.data.moneyType;
let remark = res.data.remark; let remark = res.data.remark;
let date = res.data.date; let dateText = res.data.date;
let dateText = app.$utils.formatDate(date)
this.setData({ this.setData({
name,money,billType,fromAccount,account,outText,inText,moneyType,remark,date,dateText name,money,billType,fromAccount,account,outText,inText,moneyType,remark,dateText
}) })
} }
}) })
}else { }else {
let billType = 'TRANSFER' let billType = 'TRANSFER'
let moneyType = -1 let moneyType = -1
if ('repayment' == this.properties.changeType){ if ('REPAYMENT' == this.properties.changeType){
billType = 'REPAYMENT' billType = 'REPAYMENT'
moneyType = -2 moneyType = -2
} }
@@ -118,14 +125,14 @@ Component({
theme: ActionSheetTheme.Grid, theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet', selector: '#t-action-sheet',
context: this, context: this,
items: firstGrid items: this.properties.changeType == 'REPAYMENT' ? this.data.repaymentGrid1 : this.data.transferGrid1
}); });
}else { }else {
handler = ActionSheet.show({ handler = ActionSheet.show({
theme: ActionSheetTheme.Grid, theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet', selector: '#t-action-sheet',
context: this, context: this,
items: secondGrid items: this.properties.changeType == 'REPAYMENT' ? this.data.repaymentGrid2 : this.data.transferGrid2
}); });
} }
}, },
@@ -199,7 +206,7 @@ Component({
account:this.data.account, account:this.data.account,
moneyType:this.data.moneyType, moneyType:this.data.moneyType,
remark:this.data.remark, remark:this.data.remark,
date:this.data.date date:this.data.dateText
} }
app.$api.editBill(param).then(res => { app.$api.editBill(param).then(res => {
if (res) { if (res) {

View File

@@ -32,7 +32,7 @@
<view class="placeholder_line"></view> <view class="placeholder_line"></view>
<t-tag size="large" bind:tap="today" variant="light">今天</t-tag> <t-tag size="large" bind:tap="today" variant="light">今天</t-tag>
</view> </view>
<t-textarea label="备注" placeholder="请输入该账单说明..." maxlength="200" bindchange="onRemarkInput" indicator /> <t-textarea label="备注" placeholder="请输入该账单说明..." value="{{remark}}" maxlength="200" bindchange="onRemarkInput" indicator />
<view class="view_button"> <view class="view_button">
<t-button theme="primary" block bind:tap="saveBill">保存</t-button> <t-button theme="primary" block bind:tap="saveBill">保存</t-button>
</view> </view>

View File

@@ -31,7 +31,7 @@
title="{{item.name}}" title="{{item.name}}"
description="{{item.date}} • {{item.accountName}}" description="{{item.date}} • {{item.accountName}}"
align="top" align="top"
image="{{item.icon}}" image="{{item.moneyIcon}}"
note="{{item.money}}" note="{{item.money}}"
class="t-cell-{{item.type}}" class="t-cell-{{item.type}}"
url="{{'/pages/bill/index?id=' + item.id}}" url="{{'/pages/bill/index?id=' + item.id}}"