1
This commit is contained in:
@@ -1,21 +1,100 @@
|
||||
import request from "@/utils/request"
|
||||
import { getToken, setToken } from "@/utils/auth/manageToken"
|
||||
import { formatDate } from "@/utils/common"
|
||||
const app = getApp()
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
parmas: {},
|
||||
mood: "manual",
|
||||
showPicker: false,
|
||||
date: new Date().getTime(),
|
||||
|
||||
//手术
|
||||
showSurgery: false,
|
||||
surgeryList: [],
|
||||
selectSurgery: [],
|
||||
//医院信息
|
||||
hospital: "",
|
||||
department: "",
|
||||
//其他信息
|
||||
age: "",
|
||||
allergy: "",
|
||||
comorbidity: "",
|
||||
},
|
||||
onLoad(e) {
|
||||
if (Object.keys(e).length > 0) {
|
||||
this.setData({
|
||||
parmas: e,
|
||||
mood: "scan"
|
||||
})
|
||||
}
|
||||
this.init()
|
||||
},
|
||||
//初始化
|
||||
async init() {
|
||||
let token = getToken()
|
||||
//如果存在
|
||||
if (token) {
|
||||
let info = await request.get("/my-info")
|
||||
this.handUser(info)
|
||||
} else {
|
||||
wx.login({
|
||||
success: async (res) => {
|
||||
let response = await request.post("/login", {
|
||||
"wx_code": res.code
|
||||
})
|
||||
setToken(response.accessToken)
|
||||
this.handUser(response)
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
//处理信息
|
||||
async handUser(data) {
|
||||
app.globalData.userInfo = data.userInfo
|
||||
if (data.needProfile == 0) {
|
||||
wx.switchTab({
|
||||
url: "/pages/home/index",
|
||||
})
|
||||
} else {
|
||||
let res = await request.get("/profile/surgicals")
|
||||
this.setData({
|
||||
surgeryList: res.list,
|
||||
})
|
||||
}
|
||||
this.setData({
|
||||
loading: false,
|
||||
})
|
||||
},
|
||||
|
||||
onInputChange(e) {
|
||||
const { field } = e.currentTarget.dataset;
|
||||
this.setData({
|
||||
[`${field}`]: e.detail.value,
|
||||
});
|
||||
},
|
||||
//选择手术
|
||||
changeSurgeryShow() {
|
||||
this.setData({
|
||||
showSurgery: !this.data.showSurgery
|
||||
})
|
||||
},
|
||||
handSelectSurgery(e) {
|
||||
let { data } = e.currentTarget.dataset
|
||||
let { selectSurgery } = this.data
|
||||
let isHave = selectSurgery.find(item => item.id == data.id)
|
||||
if (isHave) {
|
||||
this.setData({
|
||||
selectSurgery: selectSurgery.filter((item) => item.id != data.id)
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
selectSurgery: [...selectSurgery, data]
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
//选择时间
|
||||
chaneTimeShow() {
|
||||
this.setData({
|
||||
@@ -29,22 +108,26 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
//选择手术
|
||||
changeSurgeryShow() {
|
||||
this.setData({
|
||||
showSurgery: !this.data.showSurgery
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
//提交
|
||||
onSubmit() {
|
||||
let { date, age, allergy, comorbidity } = this.data
|
||||
async onSubmit() {
|
||||
let { mood, hospital, department, date, age, allergy, comorbidity, parmas, selectSurgery } = this.data
|
||||
let errorText = ""
|
||||
if (!date) {
|
||||
if (mood == 'manual' && !hospital.trim()) {
|
||||
errorText = "请输入医院"
|
||||
}
|
||||
else if (mood == 'manual' && !department.trim()) {
|
||||
errorText = "请输入科室"
|
||||
}
|
||||
|
||||
else if (selectSurgery.length == 0) {
|
||||
errorText = "请选择手术"
|
||||
}
|
||||
else if (!date) {
|
||||
errorText = "请选择时间"
|
||||
}
|
||||
if (!age.trim()) {
|
||||
else if (!age.trim()) {
|
||||
errorText = "请填写年龄"
|
||||
}
|
||||
if (errorText) {
|
||||
@@ -54,8 +137,29 @@ Page({
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.switchTab({
|
||||
url: '/pages/home/index',
|
||||
})
|
||||
try {
|
||||
wx.showLoading({
|
||||
title: '提交中',
|
||||
mask: true
|
||||
})
|
||||
await request.post("/profile", {
|
||||
entry_mode: mood,
|
||||
...parmas,
|
||||
hospital_name: hospital,
|
||||
department_name: department,
|
||||
surgical_ids: selectSurgery.map(item => item.id),
|
||||
surgical_date: formatDate(date, 'YYYY-MM-DD'),
|
||||
age: age,
|
||||
allergy_history: allergy,
|
||||
complication: comorbidity
|
||||
})
|
||||
wx.hideLoading()
|
||||
wx.switchTab({
|
||||
url: '/pages/home/index',
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
wx.hideLoading()
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user