@ -27,7 +27,7 @@ Page({
// 对比角度
// 对比角度
photoAngle : '' ,
photoAngle : '' ,
photoAngleName : '' ,
photoAngleName : '' ,
angleList : [ ] as { key : string , name : string } [ ] ,
angleList : [ ] as { key : string ; name : string } [ ] ,
angleMap : { } as Record < string , string > ,
angleMap : { } as Record < string , string > ,
// 日期选择
// 日期选择
@ -48,8 +48,7 @@ Page({
} )
} )
} ,
} ,
onShow() {
onShow() { } ,
} ,
// 获取对比角度列表
// 获取对比角度列表
getCompareAngle() {
getCompareAngle() {
@ -58,33 +57,34 @@ Page({
url : '?r=xd/doctor/proptosis/get-compare-angle' ,
url : '?r=xd/doctor/proptosis/get-compare-angle' ,
// 兼容后端实际需要 patientId(文档可能漏写)
// 兼容后端实际需要 patientId(文档可能漏写)
data : this.data.patientId ? { patientId : this.data.patientId } : { } ,
data : this.data.patientId ? { patientId : this.data.patientId } : { } ,
} ) . then ( ( res : any ) = > {
const angleMap = res . photoAngle || { }
const angleList = Object . keys ( angleMap ) . map ( key = > ( {
key ,
name : angleMap [ key ] ,
} ) )
this . setData ( {
angleMap ,
angleList ,
// 默认选择第一个角度
photoAngle : angleList [ 0 ] ? . key || '' ,
photoAngleName : angleList [ 0 ] ? . name || '' ,
} )
// 获取对比日期
if ( this . data . photoAngle ) {
this . getCompareDates ( )
}
} ) . catch ( ( err ) = > {
console . error ( '获取对比角度失败:' , err )
wx . showToast ( { title : '获取对比角度失败' , icon : 'none' } )
} )
} )
. then ( ( res : any ) = > {
const angleMap = res . photoAngle || { }
const angleList = Object . keys ( angleMap ) . map ( ( key ) = > ( {
key ,
name : angleMap [ key ] ,
} ) )
this . setData ( {
angleMap ,
angleList ,
// 默认选择第一个角度
photoAngle : angleList [ 0 ] ? . key || '' ,
photoAngleName : angleList [ 0 ] ? . name || '' ,
} )
// 获取对比日期
if ( this . data . photoAngle ) {
this . getCompareDates ( )
}
} )
. catch ( ( err ) = > {
console . error ( '获取对比角度失败:' , err )
wx . showToast ( { title : '获取对比角度失败' , icon : 'none' } )
} )
} ,
} ,
// 获取对比可用日期
// 获取对比可用日期
getCompareDates() {
getCompareDates() {
if ( ! this . data . photoAngle )
if ( ! this . data . photoAngle ) return
return
wx . ajax ( {
wx . ajax ( {
method : 'GET' ,
method : 'GET' ,
url : '?r=xd/doctor/proptosis/compare-dates' ,
url : '?r=xd/doctor/proptosis/compare-dates' ,
@ -92,15 +92,34 @@ Page({
patientId : this.data.patientId ,
patientId : this.data.patientId ,
photoAngle : this.data.photoAngle ,
photoAngle : this.data.photoAngle ,
} ,
} ,
} ) . then ( ( res : any ) = > {
this . setData ( {
baseline : res.baseline || null ,
nonBaselineList : res.nonBaselineList || [ ] ,
} )
} ) . catch ( ( err ) = > {
console . error ( '获取对比日期失败:' , err )
wx . showToast ( { title : '获取对比日期失败' , icon : 'none' } )
} )
} )
. then ( ( res : any ) = > {
const newBaseline = res . baseline || null
const newList = res . nonBaselineList || [ ]
const newRecordIds = newList . map ( ( item : CompareDate ) = > item . recordId )
if ( newBaseline ) {
newRecordIds . push ( newBaseline . recordId )
}
const selectedDates = this . data . selectedDates . filter ( ( id : string ) = > newRecordIds . includes ( id ) )
const nonBaselineList = newList . map ( ( item : CompareDate & { isSelected? : boolean } ) = > ( {
. . . item ,
isSelected : selectedDates.includes ( item . recordId ) ,
} ) )
this . setData ( {
baseline : newBaseline ,
nonBaselineList ,
selectedDates ,
} )
if ( selectedDates . length > 0 || newBaseline ) {
this . getComparePhotos ( )
} else {
this . setData ( { comparePhotos : [ ] } )
}
} )
. catch ( ( err ) = > {
console . error ( '获取对比日期失败:' , err )
wx . showToast ( { title : '获取对比日期失败' , icon : 'none' } )
} )
} ,
} ,
// 选择对比角度
// 选择对比角度
@ -110,7 +129,6 @@ Page({
this . setData ( {
this . setData ( {
photoAngle : angle.key ,
photoAngle : angle.key ,
photoAngleName : angle.name ,
photoAngleName : angle.name ,
selectedDates : [ ] ,
comparePhotos : [ ] ,
comparePhotos : [ ] ,
} )
} )
this . getCompareDates ( )
this . getCompareDates ( )
@ -123,8 +141,12 @@ Page({
const index = selectedDates . indexOf ( recordId )
const index = selectedDates . indexOf ( recordId )
if ( index > - 1 ) {
if ( index > - 1 ) {
selectedDates . splice ( index , 1 )
selectedDates . splice ( index , 1 )
}
} else {
else {
const maxSelect = this . data . baseline ? 5 : 6
if ( selectedDates . length >= maxSelect ) {
wx . showToast ( { title : '最多选择6张对比图' , icon : 'none' } )
return
}
selectedDates . push ( recordId )
selectedDates . push ( recordId )
}
}
// 更新列表中的选中状态
// 更新列表中的选中状态
@ -140,12 +162,15 @@ Page({
// 获取对比照片
// 获取对比照片
getComparePhotos() {
getComparePhotos() {
const { photoAngle , selectedDates , baseline } = this . data
const { photoAngle , selectedDates , baseline } = this . data
if ( ! photoAngle || selectedDates . length === 0 ) {
if ( ! photoAngle ) {
this . setData ( { comparePhotos : [ ] } )
this . setData ( { comparePhotos : [ ] } )
return
return
}
}
// 包含基准照ID
const recordIds = baseline ? [ baseline . recordId , . . . selectedDates ] : selectedDates
const recordIds = baseline ? [ baseline . recordId , . . . selectedDates ] : selectedDates
if ( recordIds . length === 0 ) {
this . setData ( { comparePhotos : [ ] } )
return
}
wx . ajax ( {
wx . ajax ( {
method : 'GET' ,
method : 'GET' ,
url : '?r=xd/doctor/proptosis/compare' ,
url : '?r=xd/doctor/proptosis/compare' ,
@ -154,41 +179,43 @@ Page({
photoAngle ,
photoAngle ,
recordIds : recordIds.join ( ',' ) ,
recordIds : recordIds.join ( ',' ) ,
} ,
} ,
} ) . then ( ( res : any ) = > {
} )
const baselineRes = res . baseline
. then ( ( res : any ) = > {
const compareList = res . compareList || [ ]
const baselineRes = res . baseline
const merged : ComparePhoto [ ] = [ ]
const compareList = res . compareList || [ ]
if ( baselineRes ) {
const merged : ComparePhoto [ ] = [ ]
merged . push ( {
if ( baselineRes ) {
recordId : baselineRes.recordId ,
merged . push ( {
recordDate : baselineRes.recordDate ,
recordId : baselineRes.recordId ,
isBaseline : 1 ,
recordDate : baselineRes.recordDate ,
photoUrl : baselineRes.photoUrl ,
isBaseline : 1 ,
leftEye : baselineRes.leftEye ,
photoUrl : baselineRes.photoUrl ,
rightEye : baselineRes.rightEye ,
leftEye : baselineRes.leftEye ,
interorbitalDistance : baselineRes.interorbitalDistance ,
rightEye : baselineRes.rightEye ,
treatmentCount : baselineRes.treatmentCount ,
interorbitalDistance : baselineRes.interorbitalDistance ,
treatmentCount : baselineRes.treatmentCount ,
} )
}
compareList . forEach ( ( item : any ) = > {
merged . push ( {
recordId : item.recordId ,
recordDate : item.recordDate ,
isBaseline : 0 ,
photoUrl : item.photoUrl ,
leftEye : item.leftEye ,
rightEye : item.rightEye ,
interorbitalDistance : item.interorbitalDistance ,
treatmentCount : item.treatmentCount ,
} )
} )
} )
}
this . setData ( {
compareList . forEach ( ( item : any ) = > {
comparePhotos : merged.filter ( ( item ) = > item . photoUrl ) . sort ( ( a , b ) = > b . isBaseline - a . isBaseline ) ,
merged . push ( {
recordId : item.recordId ,
recordDate : item.recordDate ,
isBaseline : 0 ,
photoUrl : item.photoUrl ,
leftEye : item.leftEye ,
rightEye : item.rightEye ,
interorbitalDistance : item.interorbitalDistance ,
treatmentCount : item.treatmentCount ,
} )
} )
} )
} )
this . setData ( {
. catch ( ( err ) = > {
comparePhotos : merged.filter ( item = > item . photoUrl ) ,
console . error ( '获取对比照片失败:' , err )
wx . showToast ( { title : '获取对比照片失败' , icon : 'none' } )
} )
} )
} ) . catch ( ( err ) = > {
console . error ( '获取对比照片失败:' , err )
wx . showToast ( { title : '获取对比照片失败' , icon : 'none' } )
} )
} ,
} ,
// 生成对比图
// 生成对比图