微信API 账单处理

This commit is contained in:
limqhz
2023-02-07 16:37:00 +08:00
parent f2261a3066
commit 1fadf4c339
13 changed files with 358 additions and 163 deletions

View File

@@ -1,68 +1,21 @@
const app = getApp();
import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index';
let handler = null;
const firstGrid = [
{
label: '红包',
icon: 'star',
},
{
label: '数码',
icon: 'star',
},
{
label: '虚拟',
icon: 'star',
},
{
label: '游戏',
icon: 'star',
},
{
label: '包包',
icon: 'star',
},
{
label: '手机',
icon: 'refresh',
},
{
label: '话费',
icon: 'download',
},
{
label: '技术',
icon: 'queue',
},
];
const secondGrid = [
{
label: '银行卡',
icon: 'star',
},
{
label: '支付宝',
icon: 'star',
},
{
label: '微信',
icon: 'star',
},
{
label: '信用卡',
icon: 'star',
}
];
const firstGrid = [];
const secondGrid = [];
Component({
properties: {
/* income & out */
billId: {
type: String,
value: null
},
/* income & expend */
changeType: {
type: String,
value: 'income'
},
},
data: {
price: '10.2',
priceError: false,
grid: '',
outText: '',
@@ -74,6 +27,79 @@ Component({
// 指定选择区间起始值
start: '2000-01-01 00:00:00',
end: '2030-09-09 12:12:12',
name: null,
money: null,
billType: null,
account: null,
moneyType: null,
remark: null,
},
attached(){
app.$api.getSettings().then(setting => {
if (setting){
let expend = setting.data.EXPEND_SETTING;
let income = setting.data.INCOME_SETTING;
let cash = setting.data.CASH_SETTING;
let owe = setting.data.OWE_SETTING;
if ('expend' == this.properties.changeType){
expend.forEach(x=>{
firstGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
}else {
income.forEach(x=>{
firstGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
}
cash.forEach(x=>{
secondGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
owe.forEach(x=>{
secondGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
}
});
if (this.properties.billId){
app.$api.getBill(this.properties.billId).then(res => {
if (res){
let name = res.data.name;
let money = res.data.money;
let billType = res.data.billType;
let account = res.data.account;
let moneyType = res.data.moneyType;
let typeText = res.data.moneyName;
let accountText = res.data.accountName;
let remark = res.data.remark;
let date = res.data.date;
let dateText = app.$utils.formatDate(date)
this.setData({
name,money,billType,account,moneyType,typeText,accountText,remark,date,dateText
})
}
})
}else {
let billType = 'INCOME'
if ('expend' == this.properties.changeType){
billType = 'EXPEND'
}
this.setData({billType})
}
},
methods: {
onPriceInput(e) {
@@ -84,6 +110,9 @@ Component({
priceError: !isNumber,
});
}
let money = e.detail.value;
this.setData({money})
},
handleMultiAction(e) {
const { grid } = e.currentTarget.dataset;
@@ -95,35 +124,37 @@ Component({
theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet',
context: this,
items: firstGrid.concat(
new Array(8).fill({
label: '标题文字',
icon: 'star',
}),
),
items: firstGrid
});
}else {
handler = ActionSheet.show({
theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet',
context: this,
items: secondGrid.concat(
new Array(8).fill({
label: '标题文字',
icon: 'star',
}),
),
items: secondGrid
});
}
},
onCancel(){
handler.close();
},
onNameInput(e) {
this.setData({ name : e.detail.value})
},
onRemarkInput(e) {
this.setData({ remark : e.detail.value})
},
handleSelected(e) {
const {grid} = this.data
this.setData({
[`${grid}Text`]: e.detail.selected.label,
});
if (grid == 'type'){
this.setData({moneyType:e.detail.selected.id})
}
if (grid == 'account'){
this.setData({account:e.detail.selected.id})
}
},
showPicker(e) {
const { mode } = e.currentTarget.dataset;
@@ -150,22 +181,39 @@ Component({
bYesterday () {
let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000 * 2);
this.setData({
date : preDate,
dateText: app.$utils.formatDate(preDate)
})
},
yesterday() {
let preDate = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
this.setData({
date : preDate,
dateText: app.$utils.formatDate(preDate)
})
},
today () {
this.setData({
date : new Date(),
dateText: app.$utils.formatDate(new Date())
})
},
saveBill () {
wx.navigateBack();
let param = {
id : this.properties.billId,
name:this.data.name,
money:this.data.money,
billType:this.data.billType,
account:this.data.account,
moneyType:this.data.moneyType,
remark:this.data.remark,
date:this.data.date
}
app.$api.editBill(param).then(res => {
if (res) {
wx.navigateBack();
}
})
}
}
});

View File

@@ -1,3 +1,10 @@
<t-input
label="名称"
placeholder="请输入名称"
align="right"
bindchange="onNameInput"
value="{{name}}"
/>
<t-input
label="金额"
placeholder="0.00"
@@ -5,7 +12,7 @@
align="right"
type="number"
bindchange="onPriceInput"
value="{{price}}"
value="{{money}}"
tips="{{priceError ? '请输入正确的价格' : ''}}"
t-class-tips="tips"
/>
@@ -25,7 +32,7 @@
<view class="placeholder_line"></view>
<t-tag size="large" bind:tap="today" variant="light">今天</t-tag>
</view>
<t-textarea label="备注" placeholder="请输入该账单说明..." maxlength="200" indicator />
<t-textarea label="备注" placeholder="请输入该账单说明..." bindchange="onRemarkInput" maxlength="200" indicator />
<view class="view_button">
<t-button theme="primary" block bind:tap="saveBill">保存</t-button>
</view>

View File

@@ -1,48 +1,18 @@
const app = getApp();
import ActionSheet, { ActionSheetTheme } from '../../../miniprogram_npm/tdesign-miniprogram/action-sheet/index';
let handler = null;
const firstGrid = [
{
label: '银行卡',
icon: 'star',
},
{
label: '支付宝',
icon: 'star',
},
{
label: '微信',
icon: 'star',
},
{
label: '信用卡',
icon: 'star',
}
];
const secondGrid = [
{
label: '银行卡',
icon: 'star',
},
{
label: '支付宝',
icon: 'star',
},
{
label: '微信',
icon: 'star',
},
{
label: '信用卡',
icon: 'star',
}
];
const firstGrid = [];
const secondGrid = [];
Component({
properties: {
/* normal & repayment */
billId: {
type: String,
value: -1
},
/* transfer & repayment */
changeType: {
type: String,
value: 'normal'
value: 'transfer'
},
},
data: {
@@ -56,7 +26,75 @@ Component({
dateText: '',
// 指定选择区间起始值
start: '2000-01-01 00:00:00',
end: '2030-09-09 12:12:12'
end: '2030-09-09 12:12:12',
name: null,
money: null,
billType: null,
fromAccount: null,
account: null,
moneyType: null,
remark: null,
},
attached(){
app.$api.getSettings().then(setting => {
if (setting){
let cash = setting.data.CASH_SETTING;
let owe = setting.data.OWE_SETTING;
cash.forEach(x=>{
firstGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
if ('transfer' == this.properties.changeType){
cash.forEach(x=>{
secondGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
}else {
owe.forEach(x=>{
secondGrid.fill({
id: x.id,
label: x.name,
icon: x.icon,
});
})
}
}
})
if (this.properties.billId){
app.$api.getBill(this.properties.billId).then(res => {
if (res){
let name = res.data.name;
let money = res.data.money;
let billType = res.data.billType;
let fromAccount = res.data.fromAccount;
let account = res.data.account;
let outText = res.data.fromAccountName;
let inText = res.data.accountName;
let moneyType = res.data.moneyType;
let remark = res.data.remark;
let date = res.data.date;
let dateText = app.$utils.formatDate(date)
this.setData({
name,money,billType,fromAccount,account,outText,inText,moneyType,remark,date,dateText
})
}
})
}else {
let billType = 'TRANSFER'
let moneyType = -1
if ('repayment' == this.properties.changeType){
billType = 'REPAYMENT'
moneyType = -2
}
this.setData({billType,moneyType})
}
},
methods: {
onPriceInput(e) {
@@ -67,6 +105,8 @@ Component({
priceError: !isNumber,
});
}
let money = e.detail.value;
this.setData({money})
},
handleMultiAction(e) {
const { grid } = e.currentTarget.dataset;
@@ -78,35 +118,37 @@ Component({
theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet',
context: this,
items: firstGrid.concat(
new Array(8).fill({
label: '标题文字',
icon: 'star',
}),
),
items: firstGrid
});
}else {
handler = ActionSheet.show({
theme: ActionSheetTheme.Grid,
selector: '#t-action-sheet',
context: this,
items: secondGrid.concat(
new Array(8).fill({
label: '标题文字',
icon: 'star',
}),
),
items: secondGrid
});
}
},
onCancel(){
handler.close();
},
onNameInput(e) {
this.setData({ name : e.detail.value})
},
onRemarkInput(e) {
this.setData({ remark : e.detail.value})
},
handleSelected(e) {
const {grid} = this.data
this.setData({
[`${grid}Text`]: e.detail.selected.label,
});
if (grid == 'out'){
this.setData({fromAccount:e.detail.selected.id})
}
if (grid == 'in'){
this.setData({account:e.detail.selected.id})
}
},
showPicker(e) {
const { mode } = e.currentTarget.dataset;
@@ -148,7 +190,22 @@ Component({
})
},
saveBill () {
wx.navigateBack();
let param = {
id : this.properties.billId,
name:this.data.name,
money:this.data.money,
billType:this.data.billType,
fromAccount:this.data.fromAccount,
account:this.data.account,
moneyType:this.data.moneyType,
remark:this.data.remark,
date:this.data.date
}
app.$api.editBill(param).then(res => {
if (res) {
wx.navigateBack();
}
})
}
}
});

View File

@@ -1,3 +1,10 @@
<t-input
label="名称"
placeholder="请输入名称"
align="right"
bindchange="onNameInput"
value="{{name}}"
/>
<t-input
label="金额"
placeholder="0.00"
@@ -5,7 +12,7 @@
align="right"
type="number"
bindchange="onPriceInput"
value="{{price}}"
value="{{money}}"
tips="{{priceError ? '请输入正确的价格' : ''}}"
t-class-tips="tips"
/>
@@ -25,7 +32,7 @@
<view class="placeholder_line"></view>
<t-tag size="large" bind:tap="today" variant="light">今天</t-tag>
</view>
<t-textarea label="备注" placeholder="请输入该账单说明..." maxlength="200" indicator />
<t-textarea label="备注" placeholder="请输入该账单说明..." maxlength="200" bindchange="onRemarkInput" indicator />
<view class="view_button">
<t-button theme="primary" block bind:tap="saveBill">保存</t-button>
</view>