diff --git a/README.md b/README.md index c3c4014..f03f43c 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,7 @@ npm run dev ### Compiles and minifies for production ``` npm run build -``` \ No newline at end of file +``` +TODO: +1.部分代码需要重构 +2.优化部分流程 \ No newline at end of file diff --git a/app.js b/app.js index b885f7b..06ccf9d 100644 --- a/app.js +++ b/app.js @@ -11,30 +11,54 @@ App({ // var logs = wx.getStorageSync('logs') || [] // logs.unshift(Date.now()) // wx.setStorageSync('logs', logs) - var openId = wx.getStorageSync('openId') || ''; - + let userInfo = wx.getStorageSync('userinfo'); + let openId = wx.getStorageSync('openId') || ''; this.globalData.openId = openId + if (userInfo) { + this.globalData.userInfo = userInfo; + return; + } if (openId) { // 已经有openid了 可以直接获取用户信息 console.log('init get user info'); await this.getUserInfo(openId); - return; } else { - // 登录并获取openid - wx.login({ - success: res => { - // 发送 res.code 到后台换取 openId, sessionKey, unionId - console.log('login==>', res); - if (res.errMsg == 'login:ok') { - this.processLogin(res.code); - } - } - }); - return; + console.log('await user login'); + let code = await this.getLoginCode(); + if (code) { + await this.processLogin(code); + } } // 获取用户信息 }, + async getLoginCode() { + let loginCode = null; + // 登录并获取openid + try { + loginCode = await (() => { + return new Promise((resolve, reject) => { + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + console.log('login==>', res); + if (res.errMsg == 'login:ok') { + resolve(res.code) + } else { + reject(res); + } + }, + fail: (res) => { + reject(res); + } + }) + }) + })(); + } catch (e) { + console.log('get login code error,', e); + } + return loginCode; + }, async processLogin(code) { try { let data = await api.userLogin(code); @@ -49,11 +73,11 @@ App({ }, getOpenId() { return new Promise(async(resolve, reject) => { - if(this.globalData.openId){ + if (this.globalData.openId) { resolve(this.globalData.openId) - }else{ + } else { wx.login({ - success:async res => { + success: async res => { if (res.errMsg == 'login:ok') { await this.processLogin(res.code); resolve(this.globalData.openId) @@ -62,7 +86,7 @@ App({ }); } }) - }, + }, async getUserInfo() { try { let openid = this.globalData.openId; @@ -73,7 +97,11 @@ App({ console.log('init user info error', e); } }, - + async refreshUserInfo() { + let userInfo = await api.userInfo(null, false); + console.log('refresh user info data', userInfo); + this.globalData.userInfo = userInfo; + }, globalData: { wxuserInfo: null, userInfo: null, diff --git a/app.json b/app.json index 352747c..80faeb3 100644 --- a/app.json +++ b/app.json @@ -1,10 +1,10 @@ { "pages": [ "pages/index/index", - "pages/init/userinfo", + "pages/user/index", "pages/user/result", "pages/user/evaluation", - "pages/user/index", + "pages/init/userinfo", "pages/init/agreement" ], "window": { diff --git a/pages/init/agreement.js b/pages/init/agreement.js index a97d10e..9d8e95b 100644 --- a/pages/init/agreement.js +++ b/pages/init/agreement.js @@ -7,7 +7,7 @@ Page({ }); }, bindAgreeTap: function () { - wx.navigateTo({ + wx.redirectTo({ url: 'userinfo', }); }, diff --git a/pages/user/index.js b/pages/user/index.js index 44c001b..802ac3c 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -2,7 +2,24 @@ import allCities from './../../utils/allCities.js'; import api from './../../utils/api.js'; -// const { regeneratorRuntime } = global +const medicalList = [ + { checked: false, text: '慢性支气管炎、支气管哮喘、支气管扩张病、肺心病' }, + { checked: false, text: '高血压、冠心病、心肌病、先天性心脏病、风湿性心脏病' }, + { checked: false, text: '反流性食道炎、慢性胃炎、胃溃疡、慢性胰腺炎、肠易激惹综合征、结肠炎' }, + { checked: false, text: '3个月内脑梗塞和/或脑出血、癫痫、脑炎、脑膜炎' }, + { checked: false, text: '特发性或继发性肺动脉高压症' }, + { checked: false, text: '其他疾病' } +]; +const smokeList = [ + { checked: false, text: '不吸烟' }, + { checked: false, text: '10支/天以下' }, + { checked: false, text: '10~20支/天' }, + { checked: false, text: '20支/天以上' } +]; +const cacheData = { + key:'', + value:'' +}; const app =getApp(); Page({ @@ -17,29 +34,20 @@ Page({ realname: '', }, subjects: { - smoke: [ - '不吸烟', - '10支/天以下', - '10~20支/天', - '20支/天以上', - ], - medical_histories: [ - '慢性支气管炎、支气管哮喘、支气管扩张病、肺心病', - '高血压、冠心病、心肌病、先天性心脏病、风湿性心脏病', - '反流性食道炎、慢性胃炎、胃溃疡、慢性胰腺炎、肠易激惹综合征、结肠炎', - '3个月内脑梗塞和/或脑出血、癫痫、脑炎、脑膜炎', - '特发性或继发性肺动脉高压症', - '其他疾病' - ] + smoke: [], + medical_histories: [] }, provinces: allCities, cities: allCities[0].children, + province:0, + city:0, showRecord: true, dialog: { title: '姓名', - default: '', + default: '请输入', show: false, - value: '' + value: '', + key:null }, userDetail: {}, dataList: [], @@ -59,13 +67,43 @@ Page({ evaluationData.forEach((o,i) => { tags.push(true); }) + let d = app.globalData.userInfo.detail; + medicalList.forEach((o, i) => { + medicalList[i].checked = d.medical_history.indexOf(i) != -1 + }) + smokeList[d.smoke].checked = true; + // d['address'] = this.parseUserAddress( + // d.province,d.city + // ) this.setData({ - userDetail:app.globalData.userInfo.detail, + userDetail:d, userInfo: app.globalData.userInfo, dataList: evaluationData, - collapseTags: tags + collapseTags: tags, + subjects: { + smoke:smokeList, + medical_histories: medicalList + } }); }, + + parseUserAddress(province,city){ + if (province && province > 0){ + for(var i = 0;i < allCities.length;i++){ + if(allCities[i].code == province){ + if (!city || city < 1){ + return allCities[i].name; + } + for (var j = 0; j < allCities[i].children.length;j ++){ + if(allCities[i].children[j].code == city){ + return allCities[i].name + ' ' + allCities[i].children[j].name; + } + } + } + } + } + return '未知'; + }, switchView() { this.setData({ showRecord: !this.data.showRecord @@ -79,19 +117,51 @@ Page({ collapseTags: this.data.collapseTags }); }, + /* 输入框相关样式 */ bindDialogInput: function(e) { - this.setData({ - dialog: { - value: e.detail.value - } - }) + this.setDialog('value',e.detail.value) + }, + + async updateUserDetail(key,value){ + try{ + let data = {}; + data[key] = value + await api.updateUserDetail(data) + this.setUserDetail(key,value); + }catch(e){ + console.log('update error',e); + } + }, + setUserDetail(key, value) { + let d = this.data.userDetail; + d[key] = value; + this.setData({ userDetail: d }); + }, + setDialog(key,value){ + /* + title: '姓名', + default: '请输入', + show: false, + value: '', + key:null + */ + let d = this.data.dialog; + d[key] = value; + this.setData({dialog:d}); }, hideInputDialog() { - this.setData({ - dialog: { - show: false - } - }) + this.setDialog('show',false); + }, + checkInputDialog(){ + let data = this.data.dialog.value + if(!data){ + wx.showToast({ + title: '请填写内容后确定',icon:'none' + }) + return; + } + this.hideInputDialog(); + this.updateUserDetail(this.data.dialog.key,data); }, showModal(e) { this.setData({ @@ -103,13 +173,72 @@ Page({ modalName: null }) }, + async updateAddress() { + + let { province,city,userDetail} = this.data; + let privinceCode = allCities[province].code, + cityCode = allCities[province].children[city].code, + address = allCities[province].name + ' ' + allCities[province].children[city].name; + this.hideModal(); + if (privinceCode == userDetail.province && cityCode == userDetail.city){ + console.log('not modify'); + }else{ + // 更新地址 + await api.updateUserDetail({ + province:privinceCode, + city:cityCode, + address + }) + this.setUserDetail('province', privinceCode); + this.setUserDetail('city', cityCode); + this.setUserDetail('address', address); + } + }, + // 城市选择 bindCityChange(e) { let data = e.detail.value; + let province = data[0],city = data[1] this.setData({ - cities: allCities[data[0]].children + cities: allCities[province].children, + province,city }) }, - showAlert() { - + // 显示可输入的值 + showAlert(e) { + let key = e.currentTarget.dataset.key; + let title = e.currentTarget.dataset.title; + let value = this.data.userDetail[key]; + this.setData({ + dialog:{ + default: '请输入' + title, + show: true, + title,value,key + } + }) + }, + noTap() { }, + bindSelectChange(e){ + cacheData.key = e.currentTarget.dataset.key; + cacheData.value = e.detail.value; + if (Array.isArray(cacheData.value)){ + cacheData.value.forEach((v,i)=>{ + cacheData.value[i] = parseInt(v); + }) + }else{ + cacheData.value = parseInt(cacheData.value); + } + console.log(cacheData); + }, + // 更新数据 + async updateSelectData(e){ + this.hideModal(); + if(!cacheData.key){ + return; + } + cacheData.value = Array.isArray(cacheData.value) ? cacheData.value.join(',') : cacheData.value; + var data = {}; + data[cacheData.key] = cacheData.value; + await api.updateUserDetail(data) + this.setUserDetail(cacheData.key, cacheData.value); } }) \ No newline at end of file diff --git a/pages/user/index.wxml b/pages/user/index.wxml index 5bcaf3d..0d25dbc 100644 --- a/pages/user/index.wxml +++ b/pages/user/index.wxml @@ -1,13 +1,13 @@ - + {{userDetail.realname}} - 地区: {{userInfo.address}} + 地区: {{userDetail.address}} @@ -18,7 +18,8 @@ - + + @@ -77,7 +78,7 @@ 姓名 - + {{userDetail.realname}} @@ -98,8 +99,7 @@ 年龄 - - + {{userDetail.age}} @@ -109,8 +109,7 @@ 身高 - - + {{userDetail.height}}cm @@ -120,7 +119,7 @@ 体重 - + {{userDetail.weight}}kg @@ -133,12 +132,21 @@ 世居地 - 北京市 东城区 + {{userDetail.address}} + + + 取消 + + + 确定 + + + {{item.name}} @@ -152,28 +160,104 @@ - 抽次进藏 - + 首次进藏 + - {{userDetail.gender==1?'是':'否'}} + {{userDetail.is_first_to_tibet==1?'是':'否'}} - - + + 首次进藏 - - - + + + + + + + - + + + + + + + + + + + + + + 饮酒情况 + + + {{userDetail.drink==1?'长期饮酒':'不饮酒'}} + + + + + + 饮酒情况 + + + + + + + + + + + + + + + + + + + + + + + + + 抽烟情况 + + + {{subjects.smoke[userDetail.smoke].text}} + + + + + + 抽烟情况 + + + + + + + + + @@ -184,35 +268,30 @@ - + 既往病史 - - + - - + + 既往疾病(多选) - + - + @@ -231,7 +310,7 @@ - + @@ -239,7 +318,7 @@ - + diff --git a/pages/user/index.wxss b/pages/user/index.wxss index 22fd696..2f3c5c8 100644 --- a/pages/user/index.wxss +++ b/pages/user/index.wxss @@ -25,34 +25,40 @@ text.nickname { margin-right: 15rpx; } -checkbox-group { +checkbox-group,radio-group { padding: 20rpx; } -checkbox-group .item { - margin-bottom: 30rpx; +.cu-dialog .item { + margin-bottom: 20rpx; } -checkbox-group .item:last-child { +.cu-dialog.item:last-child { margin-bottom: 0; } -checkbox-group .item>label { +.cu-dialog .item>label { display: flex; text-align: left; } -checkbox-group .item>label>checkbox { +.cu-dialog .item>label>checkbox, +.cu-dialog .item>label>radio { margin-right: 20rpx; } -.medical-info-select { +.medical-info-select,.cu-dialog .list-item-se { padding: 20rpx; text-align: left; background: #fff; margin-bottom: 20rpx; } - +.medical-info-select .item,.cu-dialog .item{ + border-bottom: none; +} +.cu-dialog .list-item-se radio-group{ + display: block; +} /* dialog */ .toast-box { @@ -131,8 +137,9 @@ checkbox-group .item>label>checkbox { color: red; } -.toast-button button:active { - background-color: solid 1px rgba(220, 223, 230, 0.7) !important; +.toast-button button:hover { + background-color: rgba(220, 223, 230, 0.4) !important; + color:#000000; } .picker { @@ -194,7 +201,7 @@ checkbox-group .item>label>checkbox { /* */ -.text-right>text { +.evaluation .text-right>text { background-color: #259b24; border-radius: 8rpx; color: #fff; @@ -231,3 +238,25 @@ checkbox-group .item>label>checkbox { .result .level-3 { color: #e51c23; } + +.cu-modal{ + /* background: rgba(220, 223, 230, 0.4); */ +} +.actionsheet-btns{ + background: #fff; + padding:20rpx; +} +.actionsheet-btns .col{ + margin:0; +} +.actionsheet-btns::after{ + content: ' '; + display: block; + clear: both; +} +.actionsheet-btns .left{ + float:left; +} +.actionsheet-btns .right{ + float:right; +} \ No newline at end of file diff --git a/utils/api.js b/utils/api.js index 9ebf16f..c329687 100644 --- a/utils/api.js +++ b/utils/api.js @@ -1,4 +1,4 @@ -const API_URL = 'http://127.0.0.1:8000'; +const API_URL = 'http://192.168.10.121:8000'; const getOpenId = () => { return getApp().globalData.openId;