流程初步走通

This commit is contained in:
LittleBoy 2019-06-24 20:59:32 +08:00
parent 9a713fdfb9
commit 93198dc163
8 changed files with 373 additions and 105 deletions

View File

@ -13,4 +13,7 @@ npm run dev
### Compiles and minifies for production
```
npm run build
```
```
TODO:
1.部分代码需要重构
2.优化部分流程

66
app.js
View File

@ -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,

View File

@ -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": {

View File

@ -7,7 +7,7 @@ Page({
});
},
bindAgreeTap: function () {
wx.navigateTo({
wx.redirectTo({
url: 'userinfo',
});
},

View File

@ -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);
}
})

View File

@ -1,13 +1,13 @@
<!--pages/user/index.wxml-->
<view class="cu-list menu-avatar user-info">
<view class="cu-item" bindtap="onUserInfoTap">
<view class="cu-item">
<view class="cu-avatar round lg" style="background-image:url({{userInfo.avatarUrl}});"></view>
<view class="content">
<view class="">
<text class="text-cut nickname">{{userDetail.realname}}</text>
</view>
<view class=" text-sm flex">
<text class="text-cut">地区: <text>{{userInfo.address}}</text></text>
<text class="text-cut">地区: <text>{{userDetail.address}}</text></text>
</view>
</view>
<view class="action" bindtap="switchView">
@ -18,7 +18,8 @@
</view>
</view>
<view wx:if="{{showRecord}}">
<!-- 评估数据列表 -->
<view class="evaluation" wx:if="{{showRecord}}">
<view class="collapse">
<view class="item" wx:for="{{dataList}}" wx:key="collapse_item" wx:for-item="item">
<view class="title" bindtap="toggleCollapse" data-index="{{index}}">
@ -77,7 +78,7 @@
<view class="cu-form-group">
<view class="title">姓名</view>
<view class="action" bindtap="showAlert">
<view class="action" bindtap="showAlert" data-key="realname" data-title="姓名">
<view class="">
{{userDetail.realname}}
<text class="cuIcon-right"></text>
@ -98,8 +99,7 @@
<!-- 年龄 -->
<view class="cu-form-group">
<view class="title">年龄</view>
<view class="action" bindtap="showModal" data-target="ChooseModal">
<view class="action" bindtap="showAlert" data-key="age" data-title="年龄">
<view class="">
{{userDetail.age}}
<text class="cuIcon-right"></text>
@ -109,8 +109,7 @@
<!-- 身高 -->
<view class="cu-form-group">
<view class="title">身高</view>
<view class="action" bindtap="showModal" data-target="ChooseModal">
<view class="action" bindtap="showAlert" data-key="height" data-title="身高">
<view class="">
{{userDetail.height}}cm
<text class="cuIcon-right"></text>
@ -120,7 +119,7 @@
<!-- 体重 -->
<view class="cu-form-group">
<view class="title">体重</view>
<view class="action" bindtap="showModal" data-target="ChooseModal">
<view class="action" bindtap="showAlert" data-key="weight" data-title="体重">
<view class="">
{{userDetail.weight}}kg
<text class="cuIcon-right"></text>
@ -133,12 +132,21 @@
<view class="title">世居地</view>
<view class="action" bindtap="showModal" data-target="ChooseCityModal">
<view class="">
北京市 东城区
{{userDetail.address}}
<text class="cuIcon-right"></text>
</view>
</view>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseCityModal'?'show':''}}" bindtap="hideModal">
<view class="cu-dialog" catchtap>
<view class="row actionsheet-btns">
<view class="col text-left">
<text class="" bindtap="hideModal">取消</text>
</view>
<view class="col text-right">
<text class="text-red" bindtap="updateAddress">确定</text>
</view>
</view>
<picker-view indicator-style="height: 36px;" style="width: 100%; height: 200px;" value="{{value}}" bindchange="bindCityChange">
<picker-view-column>
<view wx:for="{{provinces}}" wx:key="item" style="line-height: 36px">{{item.name}}</view>
@ -152,28 +160,104 @@
</view>
<!-- 首次进藏 -->
<view class="cu-form-group">
<view class="title">次进藏</view>
<view class="action" bindtap="showModal" data-target="ChooseModal">
<view class="title">次进藏</view>
<view class="action" bindtap="showModal" data-target="ChooseTibetModal">
<view class="">
{{userDetail.gender==1?'是':'否'}}
{{userDetail.is_first_to_tibet==1?'是':'否'}}
<text class="cuIcon-right"></text>
</view>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseModal'?'show':''}}" bindtap="hideModal">
<view class="cu-dialog" catchtap>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseTibetModal'?'show':''}}" catchtap="hideModal" >
<view class="cu-dialog" catchtap="noTap">
<view class="list-item-se">
<text class="dialog-head-title">首次进藏</text>
<radio-group>
<label class="radio" c>
<radio value="1" checked="true" />是
</label>
<label class="radio">
<radio value="0" />否
</label>
<radio-group bindchange="bindSelectChange" data-key="is_first_to_tibet">
<view class="item">
<label class="radio" c>
<radio value="1" checked="true" checked="{{userDetail.is_first_to_tibet == 1}}" />是
</label>
</view>
<view class="item">
<label class="radio">
<radio value="0" checked="{{userDetail.is_first_to_tibet == 0}}" />否
</label>
</view>
</radio-group>
</view>
<view class="btns">
<view>
<button class="text-red" bindtap="hideModal">确定</button>
<button class="text-red" bindtap="updateSelectData">确定</button>
</view>
<view>
<button bindtap="hideModal">取消</button>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 饮酒情况 -->
<view class="cu-form-group">
<view class="title">饮酒情况</view>
<view class="action" bindtap="showModal" data-target="ChooseDrinkModal">
<view class="">
{{userDetail.drink==1?'长期饮酒':'不饮酒'}}
<text class="cuIcon-right"></text>
</view>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseDrinkModal'?'show':''}}" catchtap="hideModal" >
<view class="cu-dialog" catchtap="noTap">
<view class="list-item-se">
<text class="dialog-head-title">饮酒情况</text>
<radio-group bindchange="bindSelectChange" data-key="drink">
<view class="item">
<label class="radio">
<radio value="1" checked="{{userDetail.drink == 1}}" />长期饮酒
</label>
</view>
<view class="item">
<label class="radio">
<radio value="0" checked="{{userDetail.drink == 0}}" />不饮酒
</label>
</view>
</radio-group>
</view>
<view class="btns">
<view>
<button class="text-red" bindtap="updateSelectData">确定</button>
</view>
<view>
<button bindtap="hideModal">取消</button>
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 抽烟情况 -->
<view class="cu-form-group">
<view class="title">抽烟情况</view>
<view class="action" bindtap="showModal" data-target="ChooseSmokeModal">
<view class="">
{{subjects.smoke[userDetail.smoke].text}}
<text class="cuIcon-right"></text>
</view>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseSmokeModal'?'show':''}}" catchtap="hideModal">
<view class="cu-dialog" catchtap="noTap">
<view class="list-item-se">
<text class="dialog-head-title">抽烟情况</text>
<radio-group bindchange="bindSelectChange" data-key="smoke">
<view class="item" wx:for="{{subjects.smoke}}" wx:key="item">
<label class="radio">
<radio value="{{index}}" checked="{{item.checked}}" />
<text>{{item.text}}</text>
</label>
</view>
</radio-group>
</view>
<view class="btns">
<view>
<button class="text-red" bindtap="updateSelectData">确定</button>
</view>
<view>
<button bindtap="hideModal">取消</button>
@ -184,35 +268,30 @@
</view>
</view>
<!-- 既往病史 -->
<view class="cu-form-group">
<view class="cu-form-group" bindtap="showModal" data-target="ChooseModal">
<view class="title">既往病史</view>
<!-- <picker bindchange="PickerChange" value="{{index}}" range="{{userInfo.subjects.medical_histories}}">
<view class="picker">
{{index?userInfo.subjects.medical_histories[index]:'禁止换行,超出容器部分会以 ... 方式截断'}}
</view>
</picker> -->
<view class="action" bindtap="showModal" data-target="ChooseModal">
<view class="action">
<view class="">
<text class="cuIcon-right"></text>
</view>
</view>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseModal'?'show':''}}" bindtap="hideModal">
<view class="cu-dialog" catchtap>
<view class="cu-modal actionsheet bottom-modal {{modalName=='ChooseModal'?'show':''}}" catchtap="hideModal">
<view class="cu-dialog" catchtap="noTap">
<view class=" medical-info-select">
<text class="dialog-head-title">既往疾病(多选)</text>
<checkbox-group>
<checkbox-group bindchange="bindSelectChange" data-key="medical_history">
<view class="item" wx:for="{{subjects.medical_histories}}" wx:key="item">
<label>
<checkbox value="{{index}}" />
<text>{{item}}</text>
<checkbox value="{{index}}" checked="{{item.checked}}" />
<text>{{item.text}}</text>
</label>
</view>
</checkbox-group>
</view>
<view class="btns">
<view>
<button class="text-red" bindtap="hideModal">确定</button>
<button class="text-red" bindtap="updateSelectData">确定</button>
</view>
<view>
<button bindtap="hideModal">取消</button>
@ -231,7 +310,7 @@
</view>
<view class="toast-main">
<view class="toast-input">
<input placeholder="请输入" bindinput="setValue" data-name="stuEidtName" />
<input placeholder="{{dialog.default}}" value="{{dialog.value}}" bindinput="bindDialogInput" />
</view>
</view>
<view class="toast-button">
@ -239,7 +318,7 @@
<button bindtap="hideInputDialog">取消</button>
</view>
<view class="button2">
<button bindtap="hideInputDialog">确定</button>
<button bindtap="checkInputDialog">确定</button>
</view>
</view>
</view>

View File

@ -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;
}

View File

@ -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;