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.
203 lines
5.1 KiB
203 lines
5.1 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
id: '', |
|
detail: {} as any, |
|
LNG: '' as number | string, |
|
LAT: '' as number | string, |
|
pagination: { |
|
page: 1, |
|
pages: 1, |
|
count: 0, |
|
}, |
|
|
|
asideOut: false, |
|
timeToast: false, |
|
timeToastType: '18', |
|
timeToastParams: { |
|
rewardScore: 0, |
|
}, |
|
}, |
|
onLoad(options) { |
|
app.zdWaitLogin().then((_res) => { |
|
this.setData({ |
|
id: options.id, |
|
}) |
|
this.handleToggleSite() |
|
}) |
|
}, |
|
handleToggleSite() { |
|
const that = this |
|
if (!this.data.LNG) { |
|
wx.getSetting({ |
|
success(res) { |
|
if ( |
|
res.authSetting['scope.userFuzzyLocation'] != undefined |
|
&& res.authSetting['scope.userFuzzyLocation'] == true |
|
) { |
|
// 获取当前位置 |
|
that.getFuzzyLocation() |
|
} |
|
else if (res.authSetting['scope.userFuzzyLocation'] == undefined) { |
|
// 获取当前位置 |
|
that.getFuzzyLocation() |
|
} |
|
else { |
|
wx.showModal({ |
|
title: '请求授权当前位置', |
|
content: '需要获取您的地理位置,请确认授权', |
|
confirmColor: '#8c75d0', |
|
success(res) { |
|
if (res.cancel) { |
|
// 取消授权 |
|
wx.showToast({ |
|
title: '拒绝授权', |
|
icon: 'none', |
|
duration: 1000, |
|
}) |
|
that.getDetail() |
|
} |
|
else if (res.confirm) { |
|
// 确定授权,通过wx.openSetting发起授权请求 |
|
wx.openSetting({ |
|
success(res) { |
|
if (res.authSetting['scope.userFuzzyLocation'] == true) { |
|
wx.showToast({ |
|
title: '授权成功', |
|
icon: 'success', |
|
duration: 1000, |
|
}) |
|
// 再次授权,调用wx.getLocation的API |
|
that.getFuzzyLocation() |
|
} |
|
else { |
|
wx.showToast({ |
|
title: '授权失败', |
|
icon: 'none', |
|
duration: 1000, |
|
}) |
|
that.getDetail() |
|
} |
|
}, |
|
}) |
|
} |
|
}, |
|
}) |
|
} |
|
}, |
|
}) |
|
} |
|
else { |
|
that.setData({ |
|
LNG: '', |
|
LAT: '', |
|
}) |
|
this.getDetail() |
|
} |
|
}, |
|
getFuzzyLocation() { |
|
const that = this |
|
wx.getFuzzyLocation({ |
|
success(res) { |
|
console.log(res) |
|
that.setData({ |
|
LNG: res.longitude, |
|
LAT: res.latitude, |
|
}) |
|
that.getDetail() |
|
}, |
|
fail() { |
|
that.getDetail() |
|
}, |
|
}) |
|
}, |
|
getDetail() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/hospital/detail', |
|
data: { |
|
Id: this.data.id, |
|
lng: this.data.LNG, |
|
lat: this.data.LAT, |
|
}, |
|
}).then((res) => { |
|
if (res.CanGetScore) { |
|
this.handleTimeOut(res.Id) |
|
} |
|
this.setData({ |
|
detail: { |
|
...res, |
|
doctors: res.doctors?.map((item: any) => { |
|
let weekName = '' |
|
if (item.ClinicType == 2) { |
|
weekName = item.Clinic |
|
} |
|
else { |
|
weekName = (JSON.parse(item.Clinic) ? JSON.parse(item.Clinic) : []).map( |
|
(subItem: { weekday: string | number, timeType: string | number }) => { |
|
const week = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] |
|
const timeDay = { 1: '上午', 2: '下午' } |
|
return { week: week[Number(subItem.weekday) - 1], timeDay: timeDay[subItem.timeType] } |
|
}, |
|
) |
|
} |
|
return { |
|
weekName, |
|
...item, |
|
} |
|
}), |
|
}, |
|
}) |
|
}) |
|
}, |
|
handlePhone() { |
|
const { detail } = this.data |
|
wx.makePhoneCall({ |
|
phoneNumber: detail.Telephone, |
|
}) |
|
}, |
|
handleOpenMap() { |
|
const { detail } = this.data |
|
wx.openLocation({ |
|
latitude: detail.LAT, |
|
longitude: detail.LNG, |
|
name: detail.Name, |
|
address: `${detail.ProvinceName}${detail.CityName}${detail.CountyName}${detail.Address}`, |
|
}) |
|
}, |
|
handleTimeOut(Id) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/score/send-score', |
|
data: { |
|
Type: this.data.timeToastType, |
|
Id, |
|
}, |
|
}).then((res) => { |
|
if (!Array.isArray(res)) { |
|
this.setData({ |
|
timeToast: true, |
|
timeToastParams: { |
|
rewardScore: res.rewardScore, |
|
}, |
|
}) |
|
setTimeout(() => { |
|
this.setData({ |
|
timeToast: false, |
|
}) |
|
}, 3000) |
|
} |
|
}) |
|
}, |
|
routerTo(e) { |
|
const { url } = e.currentTarget.dataset |
|
wx.navigateTo({ |
|
url, |
|
}) |
|
}, |
|
handleBack() { |
|
wx.navigateBack() |
|
}, |
|
onPageScroll() {}, |
|
})
|
|
|