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.
139 lines
3.4 KiB
139 lines
3.4 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
id: '', |
|
detail: {} as any, |
|
|
|
LNG: '' as number | string, |
|
LAT: '' as number | string, |
|
}, |
|
onLoad(options) { |
|
this.setData({ |
|
id: options.id, |
|
}) |
|
app.waitLogin({ type: [0, 1] }).then(() => { |
|
this.handleToggleSite() |
|
}) |
|
}, |
|
handleToggleSite() { |
|
if (!this.data.LNG) { |
|
wx.getSetting({ |
|
success: (res) => { |
|
if ( |
|
res.authSetting['scope.userFuzzyLocation'] != undefined |
|
&& res.authSetting['scope.userFuzzyLocation'] == true |
|
) { |
|
// 获取当前位置 |
|
this.getFuzzyLocation() |
|
} |
|
else if (res.authSetting['scope.userFuzzyLocation'] == undefined) { |
|
// 获取当前位置 |
|
this.getFuzzyLocation() |
|
} |
|
else { |
|
wx.showModal({ |
|
title: '请求授权当前位置', |
|
content: '需要获取您的地理位置,请确认授权', |
|
confirmColor: '#8c75d0', |
|
success: (res) => { |
|
if (res.cancel) { |
|
// 取消授权 |
|
wx.showToast({ |
|
title: '拒绝授权', |
|
icon: 'none', |
|
duration: 1000, |
|
}) |
|
this.getDetail() |
|
} |
|
else if (res.confirm) { |
|
// 确定授权,通过wx.openSetting发起授权请求 |
|
wx.openSetting({ |
|
success: (res) => { |
|
if (res.authSetting['scope.userFuzzyLocation'] == true) { |
|
wx.showToast({ |
|
title: '授权成功', |
|
icon: 'success', |
|
duration: 1000, |
|
}) |
|
this.getFuzzyLocation() |
|
} |
|
else { |
|
wx.showToast({ |
|
title: '授权失败', |
|
icon: 'none', |
|
duration: 1000, |
|
}) |
|
this.getDetail() |
|
} |
|
}, |
|
}) |
|
} |
|
}, |
|
}) |
|
} |
|
}, |
|
}) |
|
} |
|
else { |
|
this.setData({ |
|
LNG: '', |
|
LAT: '', |
|
}) |
|
this.getDetail() |
|
} |
|
}, |
|
getFuzzyLocation() { |
|
wx.getFuzzyLocation({ |
|
success: (res) => { |
|
this.setData({ |
|
LNG: res.longitude, |
|
LAT: res.latitude, |
|
}) |
|
this.getDetail() |
|
}, |
|
fail: () => { |
|
this.getDetail() |
|
}, |
|
}) |
|
}, |
|
getDetail() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/dtp-pharmacy/detail', |
|
data: { |
|
Id: this.data.id, |
|
lng: this.data.LNG, |
|
lat: this.data.LAT, |
|
}, |
|
}).then((res) => { |
|
this.setData({ |
|
detail: res, |
|
}) |
|
}) |
|
}, |
|
handleSite() { |
|
const { LNG, LAT, ProvinceName, CityName, CountyName, Address, Name } = this.data.detail |
|
wx.openLocation({ |
|
latitude: LAT, |
|
longitude: LNG, |
|
name: Name, |
|
address: `${ProvinceName}${CityName}${CountyName}${Address}`, |
|
}) |
|
}, |
|
handlePhone() { |
|
const tel = this.data.detail.Telephone |
|
if (!tel) { |
|
wx.showToast({ |
|
icon: 'none', |
|
title: '电话暂未开通', |
|
}) |
|
return |
|
} |
|
wx.makePhoneCall({ |
|
phoneNumber: tel, |
|
}) |
|
}, |
|
}) |
|
|
|
export {}
|
|
|