diff --git a/app.js b/app.js index 634c5cd..73eb13e 100644 --- a/app.js +++ b/app.js @@ -5,10 +5,20 @@ App({ onLaunch() { }, globalData: { + /** + * 图标设置 + */ INCOME_SETTING: 'INCOME_SETTING', EXPEND_SETTING: 'EXPEND_SETTING', CASH_SETTING: 'CASH_SETTING', OWE_SETTING: 'OWE_SETTING', + /** + * 账单类型 + */ + INCOME: 'INCOME', + EXPEND: 'EXPEND', + TRANSFER: 'TRANSFER', + REPAYMENT: 'REPAYMENT', billIcon : [ {label: '度假', icon: '/image/bill/0.png'}, {label: '电影', icon: '/image/bill/1.png'}, diff --git a/app.wxss b/app.wxss index 4ab5a61..43f155f 100644 --- a/app.wxss +++ b/app.wxss @@ -36,16 +36,16 @@ page { t-cell { --td-cell-note-color: orange; } -.t-cell-income { +.t-cell-INCOME { --td-cell-note-color: red; } -.t-cell-expend { +.t-cell-EXPEND { --td-cell-note-color: green; } -.t-cell-transfer { +.t-cell-TRANSFER { --td-cell-note-color: blue; } -.t-cell-repayment { +.t-cell-REPAYMENT { --td-cell-note-color: yellow; } /* 字体大小 */ diff --git a/pages/bill/add/index.wxml b/pages/bill/add/index.wxml index 0fbcbf4..7b5698c 100644 --- a/pages/bill/add/index.wxml +++ b/pages/bill/add/index.wxml @@ -1,9 +1,9 @@ - + - + diff --git a/pages/bill/edit/index.js b/pages/bill/edit/index.js index c498f70..5c3a72f 100644 --- a/pages/bill/edit/index.js +++ b/pages/bill/edit/index.js @@ -1,6 +1,9 @@ Page({ - data: {}, + data: { + sid: null + }, onLoad: function (options) { - + let sid = options.id + this.setData({sid}) } }); diff --git a/pages/bill/index.js b/pages/bill/index.js index 48be91f..c446ac6 100644 --- a/pages/bill/index.js +++ b/pages/bill/index.js @@ -1,15 +1,41 @@ +const app = getApp() Page({ data: { + sid: null, showDeleteConfirm: false, - title : "账单名称", - money : "2000" + + name : null, + money : null, + balance : null, + date : null, + billType: null, + moneyName: null, + fromAccountName: null, + accountName: null, }, onLoad: function (options) { - + let sid = options.id + this.setData({sid}) + }, + onShow() { + app.$api.getBill(this.data.sid).then(res => { + if (res.data) { + let sid = res.data.id + let name = res.data.name + let money = res.data.money + let balance = res.data.balance + let date = res.data.date + let billType = res.data.billType + let moneyName = res.data.moneyName + let fromAccountName = res.data.fromAccountName + let accountName = res.data.accountName + this.setData({sid,name,money,balance,date,billType,moneyName,fromAccountName,accountName}) + } + }) }, editBill() { wx.navigateTo({ - url: './edit/index' + url: './edit/index?id=' + this.data.sid }) }, deleteBill() { @@ -18,8 +44,12 @@ Page({ }) }, onConfirm (e) { - wx.navigateBack(); - this.closeDialog() + app.$api.deleteBill(this.data.sid).then(res => { + if (res){ + wx.navigateBack(); + this.closeDialog() + } + }) }, closeDialog() { this.setData({ diff --git a/pages/bill/index.wxml b/pages/bill/index.wxml index 5162195..774a364 100644 --- a/pages/bill/index.wxml +++ b/pages/bill/index.wxml @@ -1,23 +1,33 @@ - {{title}} + {{name}} {{money > 0 ? "+" + money : money}} - + - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/pages/bill/types/expenses.js b/pages/bill/types/expenses.js index 1099aea..f4af1a1 100644 --- a/pages/bill/types/expenses.js +++ b/pages/bill/types/expenses.js @@ -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(); + } + }) } } }); diff --git a/pages/bill/types/expenses.wxml b/pages/bill/types/expenses.wxml index 230ca69..e2a4bd7 100644 --- a/pages/bill/types/expenses.wxml +++ b/pages/bill/types/expenses.wxml @@ -1,3 +1,10 @@ + @@ -25,7 +32,7 @@ 今天 - + 保存 diff --git a/pages/bill/types/transfer.js b/pages/bill/types/transfer.js index 0af4ddc..28f6cc1 100644 --- a/pages/bill/types/transfer.js +++ b/pages/bill/types/transfer.js @@ -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(); + } + }) } } }); diff --git a/pages/bill/types/transfer.wxml b/pages/bill/types/transfer.wxml index 206b963..4c3823d 100644 --- a/pages/bill/types/transfer.wxml +++ b/pages/bill/types/transfer.wxml @@ -1,3 +1,10 @@ + @@ -25,7 +32,7 @@ 今天 - + 保存 diff --git a/pages/index/index.js b/pages/index/index.js index a9af712..837b38a 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -3,23 +3,26 @@ Page({ data: { progress: 89, todayList: [ - {"title":"电脑","type":"income","dateTime":"01-06","from":"银行卡","money":"4500.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, - {"title":"狗粮","type":"expend","dateTime":"01-06","from":"支付宝","money":"35.00"}, + {"name":"电脑","type":"INCOME","date":"01-06","accountName":"银行卡","money":"4500.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, + {"name":"狗粮","type":"EXPEND","date":"01-06","accountName":"支付宝","money":"35.00"}, ] }, onLoad: function (options) { }, onShow: function () { - app.$api.getSetting(1).then(x => { - console.log(x); + app.$api.listBillsToday().then(x => { + if (x){ + let todayList = x.data + this.setData({todayList}) + } }) if (wx.canIUse('hideHomeButton')) { wx.hideHomeButton() diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 593e72f..5e846c2 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -28,10 +28,10 @@ } + */ loginAccount(params) { return fetchPost('/user/login',params,true,false); }, getSetting(params) { - return fetchPost('/user/setting/' + params,true,false); + return fetchPost('/user/setting/' + params,null,true,false); }, editSetting(params) { return fetchPost('/user/settings/edit',params,true,false); }, deleteSetting(params) { - return fetchPost('/user/settings/del/' + params,true,false); + return fetchPost('/user/settings/del/' + params,null,true,false); }, getSettings() { // let result; @@ -273,4 +278,19 @@ export default { getSettingsIncome(){ return fetchPost('/user/settings/income',null,true,false); }, + /** + * 账单处理 + */ + listBillsToday() { + return fetchPost('/user/bills/today', null,true,false); + }, + editBill(params) { + return fetchPost('/user/bill/edit',params,true,false); + }, + getBill(params) { + return fetchPost('/user/bill/' + params,null,true,false); + }, + deleteBill(params) { + return fetchPost('/user/bill/del/' + params,null,true,false); + }, }