You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

380 lines
8.7 KiB

1 month ago
import dayjs from 'dayjs'
const app = getApp<IAppOption>()
const licia = require('miniprogram-licia')
Page({
data: {
isEdit: false,
area: [] as string[][],
city: [] as string[][],
userInfo: {} as any,
areaValue: '',
bron: '',
age: '',
ageStart: '1930-01-01',
ageEnd: '',
rtValue: '0',
RTList: [
{ id: 1, value: '本人' },
{ id: 2, value: '亲友' },
],
genderValue: '0',
GenderList: [
{
id: 1,
value: '男',
},
{
id: 2,
value: '女',
},
],
ageRangeValue: '0',
ageRangeList: [
{
id: 5,
value: '18岁以下',
},
{
id: 1,
value: '18岁-44岁',
},
{
id: 2,
value: '45岁-59岁',
},
{
id: 3,
value: '60岁-74岁',
},
{
id: 4,
value: '75岁以上',
},
],
taskValue: 0,
TaskList: [
{
id: 1,
value: '接受随访',
},
{
id: 2,
value: '不接受随访',
},
],
antibodyTypeRangeList: [
{
id: '1',
value: 'AchR',
},
{
id: '2',
value: 'MuSK',
},
{
id: '3',
value: 'LRP4',
},
{
id: '4',
value: 'RyR',
},
],
thyroidAbnormalRangeList: [
{
id: '1',
value: '是',
},
{
id: '2',
value: '否',
},
],
previousConvulsionRangeList: [
{
id: '1',
value: '是',
},
{
id: '2',
value: '否',
},
],
traditionalImmunosuppressantRangeList: [
{
id: '1',
value: '他克莫司',
},
{
id: '2',
value: '硫唑嘌呤',
},
{
id: '3',
value: '吗替麦考酚酯',
},
{
id: '4',
value: '其它',
},
],
medicalInsuranceTypeRangeList: [
{
id: '1',
value: '城市职工',
},
{
id: '2',
value: '城市居民',
},
{
id: '3',
value: '新农合',
},
],
DiagnosisTime: '',
selectDiagnoseTypeIndex: '0',
diagnoseTypeShow: false,
diagnoseTypeValue: '0',
DTList: app.globalData.DiagnoseType.map((item) => {
return {
id: item.id,
value: item.name,
}
}),
},
onShow() {
const SystemInfo = app.globalSystemInfo
if (SystemInfo) {
const { bottom } = SystemInfo.capsulePosition
this.setData({
bottom,
})
}
const ageEnd = licia.dateFormat(new Date(), 'yyyy-mm-dd')
this.setData({
ageEnd,
})
app.waitLogin().then(() => {
app.mpBehavior({ PageName: 'PG_PATIENTPERSONALINFO' })
const that = this
app.getUserInfo(that, true, that.formatUserInfo.bind(that))
})
},
formatUserInfo(res) {
this.formatBorn(res.Birth)
this.handleChaneDiagnosisTime({ detail: { value: res.DiagnosisTime } }, false)
const diagnoseTypeValue = this.data.DTList.findIndex((item) => item.id == res.DiagnoseType)
this.handleChangeDiagnoseType({ detail: { value: [diagnoseTypeValue] } })
this.handleDiagnoseTypeSave(false)
// this.handleTapRT();
},
formatBorn(Birth) {
let bron = ''
let age = ''
const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1
if (!Birth) {
bron = `${Birth}`
age = '岁'
} else if (Birth && Birth.split('-').length > 1) {
bron = `${Birth.split('-')[0]}${Birth.split('-')[1]}`
age =
month - Birth.split('-')[1] >= 0
? `${year - Birth.split('-')[0]}${month - Birth.split('-')[1]}个月`
: `${year - Birth.split('-')[0] - 1}${12 - Birth.split('-')[1] + month}个月`
} else {
bron = `${Birth}`
age = `${year - Birth}`
}
age = age.replace('岁0个月', '岁')
this.setData({
bron,
age,
'userInfo.Birth': Birth,
'userInfo.AgeYear': Number(dayjs().format('YYYY')) - Birth.split('-')[0],
})
},
handleChaneAge(e) {
const Birth = e.detail.value
this.formatBorn(Birth)
this.updateUserInfo()
},
handleChaneDiagnosisTime(e, update = true) {
const DiagnosisTime = e.detail.value
this.setData({
DiagnosisTime: dayjs(DiagnosisTime).format('YYYY年MM月'),
'userInfo.DiagnosisTime': DiagnosisTime,
})
this.updateUserInfo(update)
},
handleInput(e) {
const { key } = e.currentTarget.dataset
this.setData({
[`userInfo.${key}`]: e.detail.value,
})
},
handleChangeRT(e, update = true) {
const value = e.detail.value
const id = this.data.RTList.filter((_item, index) => index == value)[0]?.id
this.setData({
rtValue: value,
'userInfo.RelationType': id,
})
this.updateUserInfo(update)
},
handleChangeGender(e, update = true) {
const value = e.detail.value
const id = this.data.GenderList.filter((_item, index) => index == value)[0]?.id
this.setData({
genderValue: value,
'userInfo.Gender': id,
})
this.updateUserInfo(update)
},
handleChangeTask(e, update = true) {
const value = e.detail ? 0 : 1
const id = this.data.TaskList.filter((_item, index) => index == value)[0]?.id
this.setData({
taskValue: value,
'userInfo.PatientCanFollowUp': id,
})
this.updateUserInfo(update)
},
handleChangeAgeRange(e, update = true) {
const value = e.detail.value
const id = this.data.ageRangeList.filter((_item, index) => index == value)[0]?.id
this.setData({
ageRangeValue: value,
'userInfo.AgeRange': id,
})
this.updateUserInfo(update)
},
handleDiagnoseTypeSave(update = true) {
const rangeIndex = this.data.selectDiagnoseTypeIndex
const id = this.data.DTList.filter((_item, index) => index == rangeIndex)[0]?.id
this.setData({
diagnoseTypeValue: rangeIndex,
'userInfo.DiagnoseType': id,
})
if (update) {
this.handleDiagnoseTypeShow()
}
this.updateUserInfo(update)
},
handleRadio(e) {
const { id, key } = e.currentTarget.dataset
this.setData({
[`userInfo.${key}`]: id,
})
this.updateUserInfo(true)
},
handleDiagnoseTypeShow() {
this.setData({
diagnoseTypeShow: !this.data.diagnoseTypeShow,
})
},
handleChangeDiagnoseType(e) {
const value = e.detail.value[0]
this.setData({
selectDiagnoseTypeIndex: value,
})
},
handleRedioSelect(e) {
const { key, id } = e.currentTarget.dataset
this.setData({
[`userInfo.${key}`]: id,
})
this.updateUserInfo()
},
updateUserInfo(update = true) {
if (!update) return
const { PatientName, RelationType, Gender, Birth, DiagnosisTime, DiagnoseType, ...userInfo } = this.data.userInfo
wx.ajax({
method: 'POST',
4 weeks ago
url: '?r=igg4/account/update-info',
1 month ago
data: {
name: PatientName,
relationType: RelationType,
gender: Gender,
birth: Birth,
diagnosisTime: DiagnosisTime,
diagnoseType: DiagnoseType,
ageRange: userInfo.AgeRange,
patientCanFollowUp: userInfo.PatientCanFollowUp,
antibodyType: userInfo.AntibodyType,
thyroidAbnormal: userInfo.ThyroidAbnormal,
previousConvulsion: userInfo.PreviousConvulsion,
traditionalImmunosuppressant: userInfo.TraditionalImmunosuppressant,
medicalInsuranceType: userInfo.MedicalInsuranceType,
...userInfo,
},
})
.then((_res) => {
wx.showToast({
title: '修改成功',
icon: 'none',
})
app.getUserInfo(this, true, this.formatUserInfo.bind(this))
})
.catch((err) => {
wx.showToast({
title: err.data.msg,
icon: 'none',
})
app.getUserInfo(this, true, this.formatUserInfo.bind(this))
})
},
handleChangeTel() {
app.mpBehavior({ PageName: 'PG_PATIENTPERSONALINFO_CHANGEPHONECLICK' })
wx.navigateTo({
url: '/pages/changePhone/index',
})
},
handleChangeUser() {
wx.navigateTo({
url: '/pages/changeUser/index',
})
},
handleLogout() {
app.mpBehavior({ PageName: 'BTN_PATIENTPERSONALINFOLOGOUT' })
wx.navigateTo({
url: '/pages/cancellation/index',
})
},
handleBack() {
wx.navigateBack()
},
routerTo(e) {
const { url } = e.currentTarget.dataset
if (url.includes('/doctor/pages/d_login/index')) {
app.mpBehavior({ PageName: 'BTN_PATIENTPERSONALINFOSWITCHDOCTORPORTAL' })
}
wx.navigateTo({
url,
})
},
redirectTo(e) {
const { url } = e.currentTarget.dataset
wx.redirectTo({
url,
})
},
})