diff --git a/pages/index/index.js b/pages/index/index.js
index 8f349ac..a9af712 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -18,7 +18,7 @@ Page({
onLoad: function (options) {
},
onShow: function () {
- app.$api.taskList().then(x => {
+ app.$api.getSetting(1).then(x => {
console.log(x);
})
if (wx.canIUse('hideHomeButton')) {
diff --git a/pages/myself/index.js b/pages/myself/index.js
index a4344dd..c969b9c 100644
--- a/pages/myself/index.js
+++ b/pages/myself/index.js
@@ -17,24 +17,33 @@ Page({
}
},
loginAcc () {
+ let that = this;
wx.login({
success (res) {
if (res.code) {
- app.$api.getOpenId(res.code).then(res => {
- wx.setStorageSync("openid",res.data.openid)
- this.setData({
- noLogin : false
- })
- }, err => {
- console.log(err);
+ let param = {
+ appid:'wxb1f499f0a173865b',
+ secret:'833eefaf9206337d6c2d643f94baef7b',
+ js_code: res.code,
+ grant_type: 'authorization_code'
+ };
+ //发起网络请求
+ wx.request({
+ url: 'https://api.weixin.qq.com/sns/jscode2session',
+ data: param,
+ success: function(x) {
+ app.$api.loginAccount({"openId":x.data.openid}).then(t=>{
+ wx.setStorageSync("userId",t.data)
+ that.setData({
+ noLogin : false
+ })
+ })
+ }
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
- app.$api.loginAccount(wx.getStorageSync('openid')).then(res => {
- wx.setStorageSync('userId',res.data)
- });
}
});
diff --git a/pages/myself/index.wxml b/pages/myself/index.wxml
index 32ce56c..b971cef 100644
--- a/pages/myself/index.wxml
+++ b/pages/myself/index.wxml
@@ -1,22 +1,24 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/settings/edit/index.js b/pages/settings/edit/index.js
index 6179f72..11c1c1a 100644
--- a/pages/settings/edit/index.js
+++ b/pages/settings/edit/index.js
@@ -7,7 +7,8 @@ Page({
isIncome: 0,
isAdd: 0,
showDeleteConfirm: false,
- icon : null
+ icon : null,
+ accType: null
},
onLoad: function (options) {
this.setData({
diff --git a/pages/settings/edit/index.wxml b/pages/settings/edit/index.wxml
index 7969425..fb6e0cc 100644
--- a/pages/settings/edit/index.wxml
+++ b/pages/settings/edit/index.wxml
@@ -6,7 +6,7 @@
value="{{ '假的名称' }}"
/>
-
+
diff --git a/pages/settings/expend/index.js b/pages/settings/expend/index.js
index fc1352f..1a85aa4 100644
--- a/pages/settings/expend/index.js
+++ b/pages/settings/expend/index.js
@@ -4,9 +4,24 @@ Page({
payList: null
},
onLoad: function (options) {
- let payList = app.$api.getSettings('EXPEND_SETTING');
- app.$api.
- this.setData({payList})
+ app.$api.getSettings().then(setting => {
+ let payList = setting.data.EXPEND_SETTING;
+ app.$api.getSettingsExpend().then(res => {
+ let result = res.data;
+ payList.forEach(item => {
+ let money = 0
+ if (result[item.id]){
+ money = result[item.id];
+ }
+ if (!money){
+ money = 0
+ }
+ item.money = money;
+ })
+ console.log(payList);
+ this.setData({payList})
+ });
+ });
},
handleClick() {
wx.navigateTo({
diff --git a/pages/settings/income/index.js b/pages/settings/income/index.js
index f60dd8c..36b1cf1 100644
--- a/pages/settings/income/index.js
+++ b/pages/settings/income/index.js
@@ -1,3 +1,4 @@
+const app = getApp();
Page({
data: {
incomeList: [
@@ -6,7 +7,24 @@ Page({
]
},
onLoad: function (options) {
-
+ app.$api.getSettings().then(setting => {
+ let incomeList = setting.data.INCOME_SETTING;
+ app.$api.getSettingsIncome().then(res => {
+ let result = res.data;
+ incomeList.forEach(item => {
+ let money = 0
+ if (result[item.id]){
+ money = result[item.id];
+ }
+ if (!money){
+ money = 0
+ }
+ item.money = money;
+ })
+ console.log(incomeList);
+ this.setData({incomeList})
+ });
+ });
},
handleClick() {
wx.navigateTo({
diff --git a/utils/api.js b/utils/api.js
index 0eba398..a143a2d 100644
--- a/utils/api.js
+++ b/utils/api.js
@@ -6,7 +6,6 @@ const LOGIN_URL = 'https://api.weixin.qq.com/sns/jscode2session';
// const BASE_URL = 'https://www.qnforever.top/wx';
function buildURL(url, needToken) {
let userId = wx.getStorageSync('userId');
- console.log(url)
if (!userId && url != '/user/login') {
wx.redirectTo({
url: '../myself/index'
@@ -17,7 +16,7 @@ function buildURL(url, needToken) {
})
setTimeout(function () {
wx.hideLoading()
- }, 4000)
+ }, 2000)
return;
}
if (url != '/user/login'){
@@ -239,72 +238,33 @@ export function fetchGet(url, params, needToken) {
// 暴露接口
export default {
- /**
- * 获取用户唯一标识openId
- */
- getOpenId(code) {
- let param = {
- appid:'wxb1f499f0a173865b',
- secret:'833eefaf9206337d6c2d643f94baef7b',
- js_code: code,
- grant_type: 'authorization_code'
- };
- //发起网络请求
- return wx.request({
- url: LOGIN_URL,
- data: {
- appid:'wxb1f499f0a173865b',
- secret:'833eefaf9206337d6c2d643f94baef7b',
- js_code: res.code,
- grant_type: 'authorization_code'
- }
- })
- },
-
loginAccount(params) {
return fetchPost('/user/login',params,true,false);
},
-
+ getSetting(params) {
+ return fetchPost('user/setting/' + params,true,false);
+ },
addSetting(params) {
return fetchPost('user/settings/add',params,true,false);
},
deleteSetting(params) {
- return fetchPost('user/settings/delete',params,true,false);
+ return fetchPost('user/settings/delete' + params,true,false);
},
- getSettings(type) {
- let result;
- if (type == 'INCOME_SETTING'){
- result = wx.getStorageSync('INCOME_SETTING');
- }
- if (type == 'EXPEND_SETTING'){
- result = wx.getStorageSync('INCOME_SETTING');
- }
- if (type == 'ACCOUNT_SETTING'){
- result = wx.getStorageSync('INCOME_SETTING');
- }
- if (result){
- return result;
- }
- let income;
- let expend;
- let account;
- fetchPost('/user/settings', null, true,false).then(res => {
- income = res.INCOME_SETTING;
- expend = res.INCOME_SETTING;
- account = res.INCOME_SETTING;
- wx.setStorageSync('INCOME_SETTING',income)
- wx.setStorageSync('EXPEND_SETTING',expend)
- wx.setStorageSync('ACCOUNT_SETTING',account)
- if (type == 'INCOME_SETTING'){
- return income;
- }
- if (type == 'EXPEND_SETTING'){
- return expend;
- }
- if (type == 'ACCOUNT_SETTING'){
- return account;
- }
- })
+ getSettings() {
+ // let result;
+ // if (type == 'INCOME_SETTING'){
+ // result = wx.getStorageSync('INCOME_SETTING');
+ // }
+ // if (type == 'EXPEND_SETTING'){
+ // result = wx.getStorageSync('INCOME_SETTING');
+ // }
+ // if (type == 'ACCOUNT_SETTING'){
+ // result = wx.getStorageSync('INCOME_SETTING');
+ // }
+ // if (result){
+ // return result;
+ // }
+ return fetchPost('/user/settings', null, true, false);
},
getSettingsExpend(){