基本流程走通了
This commit is contained in:
parent
3ef98415b0
commit
9a713fdfb9
82
app.js
82
app.js
@ -1,45 +1,77 @@
|
|||||||
//app.js
|
//app.js
|
||||||
// global.regeneratorRuntime = require('./utils/regenerator/runtime-module')
|
// global.regeneratorRuntime = require('./utils/regenerator/runtime-module')
|
||||||
|
|
||||||
|
import api from './utils/api.js';
|
||||||
|
|
||||||
|
|
||||||
App({
|
App({
|
||||||
onLaunch: function() {
|
|
||||||
|
async onLaunch() {
|
||||||
// 展示本地存储能力
|
// 展示本地存储能力
|
||||||
// var logs = wx.getStorageSync('logs') || []
|
// var logs = wx.getStorageSync('logs') || []
|
||||||
// logs.unshift(Date.now())
|
// logs.unshift(Date.now())
|
||||||
// wx.setStorageSync('logs', logs)
|
// wx.setStorageSync('logs', logs)
|
||||||
var openId = this.globalData.openId = wx.getStorageSync('openId') || '';
|
var openId = wx.getStorageSync('openId') || '';
|
||||||
|
|
||||||
// 登录
|
this.globalData.openId = openId
|
||||||
// wx.login({
|
|
||||||
// success: res => {
|
if (openId) { // 已经有openid了 可以直接获取用户信息
|
||||||
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
|
console.log('init get user info');
|
||||||
// console.log('login==>', res);
|
await this.getUserInfo(openId);
|
||||||
// }
|
return;
|
||||||
// })
|
} else {
|
||||||
if (openId){
|
// 登录并获取openid
|
||||||
|
wx.login({
|
||||||
|
success: res => {
|
||||||
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
||||||
|
console.log('login==>', res);
|
||||||
|
if (res.errMsg == 'login:ok') {
|
||||||
|
this.processLogin(res.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
wx.getSetting({
|
|
||||||
success: res => {
|
|
||||||
console.log('getSetting==>', res);
|
|
||||||
if (res.authSetting['scope.userInfo']) {
|
|
||||||
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
|
||||||
wx.getUserInfo({
|
|
||||||
success: res => {
|
|
||||||
// 可以将 res 发送给后台解码出 unionId
|
|
||||||
this.globalData.wxuserInfo = res.userInfo
|
|
||||||
|
|
||||||
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
},
|
||||||
// 所以此处加入 callback 以防止这种情况
|
async processLogin(code) {
|
||||||
if (this.userInfoReadyCallback) {
|
try {
|
||||||
this.userInfoReadyCallback(res)
|
let data = await api.userLogin(code);
|
||||||
|
// 获取openid
|
||||||
|
this.globalData.openId = data.openid;
|
||||||
|
// 保存用户openid
|
||||||
|
wx.setStorageSync('openId', this.globalData.openId);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log('login error->', e);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
getOpenId() {
|
||||||
|
return new Promise(async(resolve, reject) => {
|
||||||
|
if(this.globalData.openId){
|
||||||
|
resolve(this.globalData.openId)
|
||||||
|
}else{
|
||||||
|
wx.login({
|
||||||
|
success:async res => {
|
||||||
|
if (res.errMsg == 'login:ok') {
|
||||||
|
await this.processLogin(res.code);
|
||||||
|
resolve(this.globalData.openId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
async getUserInfo() {
|
||||||
|
try {
|
||||||
|
let openid = this.globalData.openId;
|
||||||
|
let userInfo = await api.userInfo(openid, false);
|
||||||
|
console.log('init user info data', userInfo);
|
||||||
|
this.globalData.userInfo = userInfo;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('init user info error', e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
|
||||||
globalData: {
|
globalData: {
|
||||||
|
2
app.json
2
app.json
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
"pages/index/index",
|
"pages/index/index",
|
||||||
|
"pages/init/userinfo",
|
||||||
"pages/user/result",
|
"pages/user/result",
|
||||||
"pages/user/evaluation",
|
"pages/user/evaluation",
|
||||||
"pages/user/index",
|
"pages/user/index",
|
||||||
"pages/init/userinfo",
|
|
||||||
"pages/init/agreement"
|
"pages/init/agreement"
|
||||||
],
|
],
|
||||||
"window": {
|
"window": {
|
||||||
|
1
assets/icon-error.svg
Normal file
1
assets/icon-error.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1561285411508" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1985" width="48" height="48" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M149.961 240.472c-24.993-24.993-24.993-65.517 0-90.51s65.517-24.993 90.51 0L512 421.491l271.529-271.529c24.992-24.993 65.516-24.993 90.508 0 24.994 24.993 24.994 65.517 0 90.51L602.51 512l271.529 271.528c24.992 24.993 24.992 65.516 0 90.51-24.994 24.993-65.518 24.993-90.51-0.001L512 602.508 240.471 874.037c-24.993 24.994-65.517 24.994-90.51 0-24.993-24.993-24.993-65.516 0-90.509L421.49 512 149.961 240.472z" p-id="1986" fill="#ffffff"></path></svg>
|
After Width: | Height: | Size: 826 B |
@ -2,10 +2,11 @@
|
|||||||
//index.js
|
//index.js
|
||||||
//获取应用实例
|
//获取应用实例
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
|
import api from './../../utils/api.js';
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
motto: 'Hello World',
|
motto: 'Hello',
|
||||||
userInfo: {
|
userInfo: {
|
||||||
avatarUrl: '/assets/head.svg',
|
avatarUrl: '/assets/head.svg',
|
||||||
realname: '张二娃',
|
realname: '张二娃',
|
||||||
@ -21,51 +22,132 @@ Page({
|
|||||||
content: '',
|
content: '',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onUserInfoTap(){
|
|
||||||
wx.navigateTo({
|
|
||||||
url: '../user/index'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
onLoad: function() {
|
onLoad: function() {
|
||||||
|
console.log('index load data',app.globalData)
|
||||||
// 加载
|
// 加载
|
||||||
if (app.globalData.userInfo) {
|
if (app.globalData.openId) { // 已经获取了用户数据
|
||||||
this.setData({
|
this.processGetUserInfo();
|
||||||
userInfo: app.globalData.userInfo,
|
|
||||||
hasUserInfo: true
|
|
||||||
})
|
|
||||||
} else if (this.data.canIUse) { // 可以获取用户信息
|
} else if (this.data.canIUse) { // 可以获取用户信息
|
||||||
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
||||||
// 所以此处加入 callback 以防止这种情况
|
// 所以此处加入 callback 以防止这种情况
|
||||||
app.userInfoReadyCallback = res => {
|
// app.userInfoReadyCallback = res => {
|
||||||
this.setData({
|
// this.processGetUserInfo(res.userInfo)
|
||||||
userInfo: res.userInfo,
|
// }
|
||||||
hasUserInfo: true
|
// 获取用户信息
|
||||||
|
wx.getSetting({
|
||||||
|
success: res => {
|
||||||
|
console.log('getSetting==>', res);
|
||||||
|
if (res.authSetting['scope.userInfo']) {
|
||||||
|
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
||||||
|
wx.getUserInfo({
|
||||||
|
success: res => {
|
||||||
|
this.processGetUserInfo(res.userInfo)
|
||||||
|
// // 可以将 res 发送给后台解码出 unionId
|
||||||
|
// this.globalData.wxuserInfo = res.userInfo
|
||||||
|
|
||||||
|
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
||||||
|
// // 所以此处加入 callback 以防止这种情况
|
||||||
|
// if (this.userInfoReadyCallback) {
|
||||||
|
// this.userInfoReadyCallback(res)
|
||||||
|
// }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// 在没有 open-type=getUserInfo 版本的兼容处理
|
// 在没有 open-type=getUserInfo 版本的兼容处理
|
||||||
wx.getUserInfo({
|
wx.getUserInfo({
|
||||||
success: res => {
|
success: res => {
|
||||||
app.globalData.userInfo = res.userInfo
|
this.processGetUserInfo(res.userInfo)
|
||||||
this.setData({
|
|
||||||
userInfo: res.userInfo,
|
|
||||||
hasUserInfo: true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getUserInfo: function(e) {
|
getUserInfo: function(e) { // 获取草用户数据
|
||||||
console.log(e)
|
this.processGetUserInfo(e.detail.userInfo)
|
||||||
app.globalData.wxuserInfo = e.detail.userInfo
|
},
|
||||||
|
|
||||||
|
// 初始化用户数据
|
||||||
|
async initUserInfo() {
|
||||||
|
try {
|
||||||
|
let openid = await app.getOpenId();
|
||||||
|
let userInfo = await api.userInfo(openid, false);
|
||||||
|
console.log('init user info data', userInfo);
|
||||||
|
this.globalData.userInfo = userInfo;
|
||||||
|
this.processGetUserInfo(userInfo);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('init user info error', e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 处理获取到用户数据的逻辑
|
||||||
|
async processGetUserInfo(userInfo) {
|
||||||
|
//
|
||||||
|
if (app.globalData.userInfo) { // 已经存在数据则直接跳过
|
||||||
this.setData({
|
this.setData({
|
||||||
userInfo: e.detail.userInfo,
|
userInfo: app.globalData.userInfo,
|
||||||
hasUserInfo: true
|
hasUserInfo: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}else{ // 尝试创建该用户
|
||||||
|
|
||||||
|
let openid = app.globalData.openId;
|
||||||
|
let userInfo = null;
|
||||||
|
try{
|
||||||
|
userInfo = await api.userInfo(openid, false);
|
||||||
|
if (userInfo.detail){
|
||||||
|
userInfo['realname'] = userInfo.detail.realname;
|
||||||
|
}
|
||||||
|
app.globalData.userInfo = userInfo;
|
||||||
|
this.setData({
|
||||||
|
userInfo: userInfo,
|
||||||
|
hasUserInfo: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}catch(e){}
|
||||||
|
try {
|
||||||
|
let data = await api.createUserInfo({
|
||||||
|
open_id: app.globalData.openId,
|
||||||
|
nickname: userInfo.nickName,
|
||||||
|
username: app.globalData.openId,
|
||||||
|
avatarUrl: userInfo.avatarUrl,
|
||||||
|
});
|
||||||
|
// 保存数据
|
||||||
|
app.globalData.userInfo = data;
|
||||||
|
this.setData({
|
||||||
|
userInfo: data,
|
||||||
|
hasUserInfo: true
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log('create user error', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 判断是否需要跳转
|
||||||
|
if (this.data.userInfo.detail) { return; }
|
||||||
|
this.gotoAgreementPage()
|
||||||
|
|
||||||
|
},
|
||||||
|
gotoAgreementPage() {
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '../init/agreement'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
gotoUserIndex() {
|
||||||
|
if (this.data.userInfo.detail) { // 判断是否已经存在用户数据
|
||||||
|
wx.navigateTo({
|
||||||
|
url: '../user/index'
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
this.gotoAgreementPage()
|
||||||
|
}
|
||||||
|
},
|
||||||
gotoEvaluation() {
|
gotoEvaluation() {
|
||||||
|
if (this.data.userInfo.detail) { // 判断是否已经存在用户数据
|
||||||
wx.navigateTo({
|
wx.navigateTo({
|
||||||
url: './../user/evaluation',
|
url: './../user/evaluation',
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
this.gotoAgreementPage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -1,7 +1,7 @@
|
|||||||
<!--index.wxml-->
|
<!--index.wxml-->
|
||||||
<view class="container page-user">
|
<view class="container page-user">
|
||||||
<view hidden="{{!hasUserInfo}}" class="cu-list menu-avatar user-info">
|
<view hidden="{{!hasUserInfo}}" class="cu-list menu-avatar user-info">
|
||||||
<view class="cu-item" bindtap="onUserInfoTap">
|
<view class="cu-item" bindtap="gotoUserIndex">
|
||||||
<view class="cu-avatar round lg" style="background-image:url({{userInfo.avatarUrl}});"></view>
|
<view class="cu-avatar round lg" style="background-image:url({{userInfo.avatarUrl}});"></view>
|
||||||
<view class="content">
|
<view class="content">
|
||||||
<view class="text-grey">
|
<view class="text-grey">
|
||||||
@ -9,7 +9,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="text-gray text-sm flex">
|
<view class="text-gray text-sm flex">
|
||||||
<view class="text-cut">
|
<view class="text-cut">
|
||||||
评估时间:<text>{{userInfo.lastEvaluation}}</text>
|
评估时间:<text>{{userInfo.lastEvaluation?userInfo.lastEvaluation:'还没有评估过'}}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,44 +1,9 @@
|
|||||||
// pages/init/userinfo.js
|
// pages/init/userinfo.js
|
||||||
const allCities = [{
|
|
||||||
'code': '123',
|
import {
|
||||||
'name': '北京',
|
updateUserDetail
|
||||||
children: [{
|
} from './../../utils/api.js';
|
||||||
"code": "110101",
|
import allCities from './../../utils/allCities.js';
|
||||||
"name": "东城区"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": "110102",
|
|
||||||
"name": "西城区"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'code': '123',
|
|
||||||
'name': '天津',
|
|
||||||
children: [{
|
|
||||||
"code": "110105",
|
|
||||||
"name": "朝阳区"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": "110106",
|
|
||||||
"name": "丰台区"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'code': '123',
|
|
||||||
'name': '上海',
|
|
||||||
children: [{
|
|
||||||
"code": "110107",
|
|
||||||
"name": "石景山区"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"code": "110108",
|
|
||||||
"name": "海淀区"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
|
|
||||||
@ -62,23 +27,114 @@ Page({
|
|||||||
'其他疾病'
|
'其他疾病'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
hiddenSelect: true,
|
||||||
provinces: allCities,
|
provinces: allCities,
|
||||||
cities: allCities[0].children,
|
cities: allCities[0].children,
|
||||||
provinceId: 0,
|
provinceId: -1,
|
||||||
cityId: 0
|
cityId: -1,
|
||||||
|
userDetailModel: {
|
||||||
|
realname: "",
|
||||||
|
gender: 1,
|
||||||
|
age: '',
|
||||||
|
province: 0,
|
||||||
|
city: 0,
|
||||||
|
is_first_to_tibet: 1,
|
||||||
|
height: '',
|
||||||
|
weight: '',
|
||||||
|
smoke: 0,
|
||||||
|
drink: 1,
|
||||||
|
medical_history: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onBoxInput(e) {
|
||||||
|
this.setUpdateData(
|
||||||
|
e.currentTarget.dataset.key, e.detail.value
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onSelectChange(e) {
|
||||||
|
this.setUpdateData(
|
||||||
|
e.currentTarget.dataset.key, e.detail.value
|
||||||
|
)
|
||||||
|
console.log(e.currentTarget.dataset.key, e.detail.value);
|
||||||
|
},
|
||||||
|
onMedicalChange(e) {
|
||||||
|
var v = e.detail.value;
|
||||||
|
this.setData({
|
||||||
|
hiddenSelect: v == 0
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onMedicalValueChange(e) {
|
||||||
|
this.setUpdateData('medical_history', e.detail.value.join(','))
|
||||||
|
},
|
||||||
|
setUpdateData(key, value) {
|
||||||
|
var userDetailModel = this.data.userDetailModel;
|
||||||
|
userDetailModel[key] = value;
|
||||||
|
this.setData({
|
||||||
|
userDetailModel
|
||||||
|
})
|
||||||
},
|
},
|
||||||
bindProvinceChange(e) {
|
bindProvinceChange(e) {
|
||||||
|
let _id = parseInt(e.detail.value);
|
||||||
|
this.setUpdateData('province', this.data.provinces[_id].code);
|
||||||
this.setData({
|
this.setData({
|
||||||
provinceId: e.detail.value,
|
provinceId: _id,
|
||||||
cities: allCities[e.detail.value].children
|
cities: this.data.provinces[_id].children
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
bindCityChange(e) {
|
bindCityChange(e) {
|
||||||
|
let _id = parseInt(e.detail.value);
|
||||||
|
this.setUpdateData('city', this.data.cities[_id].code);
|
||||||
this.setData({
|
this.setData({
|
||||||
cityId: e.detail.value
|
cityId: _id
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
validateUpdate() {
|
||||||
|
var model = this.data.userDetailModel;
|
||||||
|
var title = false;
|
||||||
|
if (!model.realname) {
|
||||||
|
title = '请填写您的姓名';
|
||||||
|
} else if (!model.age) {
|
||||||
|
title = '请填写您的年龄';
|
||||||
|
} else if (model.province == 0 || model.city == 0) {
|
||||||
|
title = '请选择您的世居地';
|
||||||
|
} else if (!model.height) {
|
||||||
|
title = '请填写您的身高';
|
||||||
|
} else if (!model.weight) {
|
||||||
|
title = '请填写您的体重';
|
||||||
|
} else if (this.data.hiddenSelect == false && !model.medical_history) {
|
||||||
|
title = '请选择既往疾病记录';
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
},
|
||||||
|
async updateAndEvaluation() { // 更新数据
|
||||||
|
var err = this.validateUpdate();
|
||||||
|
if (err) {
|
||||||
|
var title = {
|
||||||
|
title: err,
|
||||||
|
icon: 'none'
|
||||||
|
};
|
||||||
|
wx.showToast({
|
||||||
|
title: err,
|
||||||
|
icon: 'none' //:err,image:'/assets/icon-error.svg'
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.showModal({
|
||||||
|
title: '确认填写正确并进行评估?',
|
||||||
|
success:async res => {
|
||||||
|
if (res.confirm) {
|
||||||
|
console.log(this.data.userDetailModel)
|
||||||
|
let data = await updateUserDetail(this.data.userDetailModel);
|
||||||
|
// // 跳转到 评估页
|
||||||
|
wx.redirectTo({
|
||||||
|
url: './../user/evaluation',
|
||||||
|
})
|
||||||
|
} else if (res.cancel) {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户点击右上角分享
|
* 用户点击右上角分享
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
<view class="card">
|
<view class="card">
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>1、您的姓名:</label>
|
<label>1、您的姓名:</label>
|
||||||
<input />
|
<input bindinput="onBoxInput" data-key="realname" />
|
||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>2、您的性别:</label>
|
<label>2、您的性别:</label>
|
||||||
<radio-group>
|
<radio-group bindchange="onSelectChange" data-key="gender">
|
||||||
<label class="radio" c>
|
<label class="radio" c>
|
||||||
<radio value="1" checked="true" />男
|
<radio value="1" checked="true" />男
|
||||||
</label>
|
</label>
|
||||||
@ -20,11 +20,11 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>3、您的年龄:</label>
|
<label>3、您的年龄:</label>
|
||||||
<input />
|
<input bindinput="onBoxInput" data-key="age" />
|
||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>4、您是否第一次进藏?</label>
|
<label>4、您是否第一次进藏?</label>
|
||||||
<radio-group>
|
<radio-group bindchange="onSelectChange" data-key="is_first_to_tibet">
|
||||||
<label class="radio">
|
<label class="radio">
|
||||||
<radio value="1" checked="true" />是
|
<radio value="1" checked="true" />是
|
||||||
</label>
|
</label>
|
||||||
@ -37,27 +37,27 @@
|
|||||||
<label>5、您的世居地(居住十年以上):</label>
|
<label>5、您的世居地(居住十年以上):</label>
|
||||||
|
|
||||||
<picker bindchange="bindProvinceChange" value="{{provinceId}}" range="{{provinces}}" range-key="name">
|
<picker bindchange="bindProvinceChange" value="{{provinceId}}" range="{{provinces}}" range-key="name">
|
||||||
<view class="select-input">{{provinces[provinceId].name}}</view>
|
<view class="select-input">{{provinceId==-1?"请选择省份":provinces[provinceId].name}}</view>
|
||||||
</picker>
|
</picker>
|
||||||
|
|
||||||
<picker bindchange="bindCityChange" value="{{cityId}}" range="{{cities}}" range-key="name">
|
<picker bindchange="bindCityChange" value="{{cityId}}" range="{{cities}}" range-key="name">
|
||||||
<view class="select-input">{{cities[cityId].name}}</view>
|
<view class="select-input">{{cityId == -1?"请选择城市":cities[cityId].name}}</view>
|
||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>6、您的身高(cm):</label>
|
<label>6、您的身高(cm):</label>
|
||||||
<input />
|
<input bindinput="onBoxInput" data-key="height" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>7、您的体重(kg):</label>
|
<label>7、您的体重(kg):</label>
|
||||||
<input />
|
<input bindinput="onBoxInput" data-key="weight" />
|
||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>8、您是否长期吸烟,吸烟量(支/天):</label>
|
<label>8、您是否长期吸烟,吸烟量(支/天):</label>
|
||||||
<radio-group>
|
<radio-group bindchange="onSelectChange" data-key="smoke">
|
||||||
<view class="item" wx:for="{{subjects.smoke}}">
|
<view class="item" wx:key="smoke" wx:for="{{subjects.smoke}}">
|
||||||
<label>
|
<label>
|
||||||
<radio value="{{index}}" checked="{{index == 0}}" />{{item}}</label>
|
<radio value="{{index}}" checked="{{index == 0}}" />{{item}}</label>
|
||||||
</view>
|
</view>
|
||||||
@ -65,7 +65,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>9、您是否长期饮酒?</label>
|
<label>9、您是否长期饮酒?</label>
|
||||||
<radio-group>
|
<radio-group bindchange="onSelectChange" data-key="drink">
|
||||||
<label class="radio">
|
<label class="radio">
|
||||||
<radio value="1" checked="true" />是
|
<radio value="1" checked="true" />是
|
||||||
</label>
|
</label>
|
||||||
@ -76,19 +76,19 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group">
|
||||||
<label>10、您是否有既往基础疾病?</label>
|
<label>10、您是否有既往基础疾病?</label>
|
||||||
<radio-group>
|
<radio-group bindchange="onMedicalChange">
|
||||||
<label class="radio">
|
<label class="radio">
|
||||||
<radio value="1" checked="true" />是
|
<radio value="1" />是
|
||||||
</label>
|
</label>
|
||||||
<label class="radio">
|
<label class="radio">
|
||||||
<radio value="0" />否
|
<radio value="0" checked="true" />否
|
||||||
</label>
|
</label>
|
||||||
</radio-group>
|
</radio-group>
|
||||||
</view>
|
</view>
|
||||||
<view class="form-group">
|
<view class="form-group" hidden="{{hiddenSelect}}">
|
||||||
<label>11、既往疾病包括(多选):</label>
|
<label>11、既往疾病包括(多选):</label>
|
||||||
<checkbox-group>
|
<checkbox-group bindchange="onMedicalValueChange">
|
||||||
<view class="item" wx:for="{{subjects.medical_histories}}">
|
<view class="item" wx:key="medical" wx:for="{{subjects.medical_histories}}">
|
||||||
<label>
|
<label>
|
||||||
<checkbox value="{{index}}" />
|
<checkbox value="{{index}}" />
|
||||||
<text>{{item}}</text>
|
<text>{{item}}</text>
|
||||||
@ -98,6 +98,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="text-center container-card">
|
<view class="text-center container-card">
|
||||||
<button class="btn-green go-to-next btn-round">下一步</button>
|
<button bindtap="updateAndEvaluation" class="btn-green go-to-next btn-round">下一步</button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
@ -11,6 +11,10 @@ radio-group > label > radio {
|
|||||||
.form-group picker, radio-group .item, checkbox-group .item {
|
.form-group picker, radio-group .item, checkbox-group .item {
|
||||||
margin-bottom: 30rpx;
|
margin-bottom: 30rpx;
|
||||||
}
|
}
|
||||||
|
.form-group checkbox{
|
||||||
|
top:-8rpx;
|
||||||
|
margin-right:10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
checkbox-group .item>label {
|
checkbox-group .item>label {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -3,6 +3,7 @@ import allCities from './../../utils/allCities.js';
|
|||||||
import api from './../../utils/api.js';
|
import api from './../../utils/api.js';
|
||||||
|
|
||||||
// const { regeneratorRuntime } = global
|
// const { regeneratorRuntime } = global
|
||||||
|
const app =getApp();
|
||||||
Page({
|
Page({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,7 +12,7 @@ Page({
|
|||||||
data: {
|
data: {
|
||||||
allCities,
|
allCities,
|
||||||
userInfo: {
|
userInfo: {
|
||||||
avatarUrl: 'http://thirdwx.qlogo.cn/mmopen/vi_32/9xkaQhBrbjIsJNJkxKicKayJiajy2ZsKFHM7vhibPjic0sLhn0cxCicxgQUl9VDF9o02NsQlcxZicJPWb4K9RibQJ8ibDQ/132',
|
avatarUrl: '',
|
||||||
address: '北京 东城区',
|
address: '北京 东城区',
|
||||||
realname: '',
|
realname: '',
|
||||||
},
|
},
|
||||||
@ -57,30 +58,13 @@ Page({
|
|||||||
console.log(evaluationData);
|
console.log(evaluationData);
|
||||||
evaluationData.forEach((o,i) => {
|
evaluationData.forEach((o,i) => {
|
||||||
tags.push(true);
|
tags.push(true);
|
||||||
// let level = 0;
|
|
||||||
// // 判断结果
|
|
||||||
// if(o.options[0].score == 0 || o.score < 3){
|
|
||||||
// // 没有高反
|
|
||||||
// level = 0;
|
|
||||||
// } else if (o.score <= 5) {
|
|
||||||
// level = 1;
|
|
||||||
// } else if (o.score <= 9) {
|
|
||||||
// level = 2;
|
|
||||||
// } else if (o.score <= 12) {
|
|
||||||
// level = 3;
|
|
||||||
// } else {
|
|
||||||
// level = 4;
|
|
||||||
// }
|
|
||||||
// evaluationData.data[i]['level'] = level;
|
|
||||||
})
|
})
|
||||||
this.setData({
|
this.setData({
|
||||||
|
userDetail:app.globalData.userInfo.detail,
|
||||||
|
userInfo: app.globalData.userInfo,
|
||||||
dataList: evaluationData,
|
dataList: evaluationData,
|
||||||
collapseTags: tags
|
collapseTags: tags
|
||||||
});
|
});
|
||||||
let userDetail = await api.queryUserDetail();
|
|
||||||
this.setData({
|
|
||||||
userDetail: userDetail
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
switchView() {
|
switchView() {
|
||||||
this.setData({
|
this.setData({
|
||||||
|
File diff suppressed because one or more lines are too long
63
utils/api.js
63
utils/api.js
@ -1,9 +1,16 @@
|
|||||||
const API_URL = 'http://127.0.0.1:8000';
|
const API_URL = 'http://127.0.0.1:8000';
|
||||||
const app = getApp();
|
|
||||||
const openId = app.globalData.openId;
|
const getOpenId = () => {
|
||||||
const requestApi = (api, data = {}, method = "GET") => {
|
return getApp().globalData.openId;
|
||||||
|
}
|
||||||
|
const requestApi = (api, data = {}, method = "GET", showError) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
data['open_id'] = openId;
|
if (typeof(showError) == "undefined") {
|
||||||
|
showError = true;
|
||||||
|
}
|
||||||
|
if (!data['open_id']) {
|
||||||
|
data['open_id'] = getOpenId();
|
||||||
|
}
|
||||||
wx.showLoading({
|
wx.showLoading({
|
||||||
title: '请求数据中...',
|
title: '请求数据中...',
|
||||||
});
|
});
|
||||||
@ -26,8 +33,14 @@ const requestApi = (api, data = {}, method = "GET") => {
|
|||||||
reject(res);
|
reject(res);
|
||||||
} else {
|
} else {
|
||||||
if (res.data.code && res.data.code != 0) {
|
if (res.data.code && res.data.code != 0) {
|
||||||
wx.showModal({ title: res.data.message, showCancel: false })
|
if (showError) {
|
||||||
//reject(res);
|
wx.showModal({
|
||||||
|
title: res.data.message,
|
||||||
|
showCancel: false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
reject(res);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
}
|
}
|
||||||
@ -40,18 +53,37 @@ const requestApi = (api, data = {}, method = "GET") => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 使用用户登录code获取用户session及open_id
|
||||||
|
*/
|
||||||
|
export function userLogin(code) {
|
||||||
|
return requestApi('/user/login', {
|
||||||
|
code
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询用户基本信息
|
* 查询用户基本信息
|
||||||
*/
|
*/
|
||||||
export function queryUserInfo() {
|
export function userInfo(openid, showError) {
|
||||||
return requestApi('/user/info');
|
return requestApi('/user/info', {
|
||||||
|
open_id: openid
|
||||||
|
}, 'GET', showError);
|
||||||
|
}
|
||||||
|
export function createUserInfo(data) {
|
||||||
|
return requestApi('/user/create', data, 'POST', false);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 查询用户详细信息
|
* 查询用户详细信息
|
||||||
*/
|
*/
|
||||||
export function queryUserDetail() {
|
export function userDetail() {
|
||||||
return requestApi('/user/detail');
|
return requestApi('/user/detail');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 更新用户详细信息
|
||||||
|
*/
|
||||||
|
export function updateUserDetail(data) {
|
||||||
|
return requestApi('/user/update', data, 'POST');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 查询用户所有的评估数据
|
* 查询用户所有的评估数据
|
||||||
*/
|
*/
|
||||||
@ -59,7 +91,9 @@ export function queryAllEvaluation() {
|
|||||||
return requestApi('/evaluation/all');
|
return requestApi('/evaluation/all');
|
||||||
}
|
}
|
||||||
export function queryEvaluationById(id) {
|
export function queryEvaluationById(id) {
|
||||||
return requestApi('/evaluation/detail',{id});
|
return requestApi('/evaluation/detail', {
|
||||||
|
id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 创建用户评估数据
|
* 创建用户评估数据
|
||||||
@ -69,8 +103,11 @@ export function createEvaluation(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
queryUserInfo,
|
userInfo,
|
||||||
queryUserDetail,
|
updateUserDetail,
|
||||||
|
createUserInfo,
|
||||||
|
userDetail,
|
||||||
queryAllEvaluation,
|
queryAllEvaluation,
|
||||||
createEvaluation
|
createEvaluation,
|
||||||
|
userLogin
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user