const app = getApp() Page({ data: { tabActive: 0, LNG: '' as number | string, LAT: '' as number | string, HosList: [], DoctortList: [], dtpList: [], infusionCenterList: [], pagination: { page: 1, pages: 1, count: 0, }, ProvinceName: '', ProvinceId: '', CityName: '', CityId: '', Name: '', bottom: 0, asideOut: false, timeToast: false, timeToastType: '17', timeToastParams: { rewardScore: 0, }, areaShow: false, toastShow: false, // toastType: 'dtpDrug',// TODO:已销毁 toastType: 'siteConform', toastParams: {} as any, es: '', locationName: '重新定位', }, onLoad(options) { const SystemInfo = app.globalSystemInfo if (SystemInfo) { const { bottom } = SystemInfo.capsulePosition this.setData({ bottom, }) } app.waitLogin({ type: [0, 1] }).then(() => { if (options.active && ['1', '2'].includes(options.active)) { this.setData({ tabActive: Number(options.active), }) } if (options.pid) { this.setData({ ProvinceName: options.pn || '', ProvinceId: options.pid || '', CityName: options.cn || '', CityId: options.cid || '', }) this.getList() } else { 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.getList() } 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 this.getFuzzyLocation() } else { wx.showToast({ title: '授权失败', icon: 'none', duration: 1000, }) this.getList() } }, }) } }, }) } }, }) } else { this.setData({ LNG: '', LAT: '', }) this.getLocationInfo() } }, getFuzzyLocation() { wx.getFuzzyLocation({ success: (res) => { this.setData({ LNG: res.longitude, LAT: res.latitude, }) this.getLocationInfo() }, fail: (err) => { console.log('DEBUGPRINT[99]: index.ts:147: err=', err) this.getList() }, }) }, handleChangeSite(e: WechatMiniprogram.CustomEvent) { const detail = e.detail this.setData({ ProvinceId: detail.ProvinceId, ProvinceName: detail.ProvinceName, CityId: detail.CityId, CityName: detail.CityName, }) this.getList() }, onChange(e: WechatMiniprogram.CustomEvent) { const index = e.detail.index this.setData({ tabActive: index, }) wx.pageScrollTo({ scrollTop: 0, }) this.getList() }, handleBlur() { this.getList() }, getLocationInfo() { wx.ajax({ method: 'GET', url: '?r=zd/hospital/location-info', data: { lng: this.data.LNG, lat: this.data.LAT, }, }).then((res) => { this.setData({ ProvinceId: res.ProvinceId, ProvinceName: res.ProvinceName, CityId: res.CityId, CityName: res.CityName, }) this.getList() }) }, getList() { const { tabActive, toastShow, toastType } = this.data if (tabActive != 1 && toastShow && toastType == 'dtpDrug') { this.hideDtpAlert() } if (tabActive == 0) { this.getHosList() } else if (tabActive == 1) { this.getDtpList() } else if (tabActive == 2) { this.getInfusionCenter() } }, getHosList() { const { Name, LNG, LAT, ProvinceId, CityId } = this.data wx.ajax({ method: 'GET', url: '?r=zd/hospital/list', data: { lng: LNG, lat: LAT, ProvinceId: Name ? '' : ProvinceId, CityId: Name ? '' : CityId, Name, }, }).then((res) => { if (res.CanGetScore) { this.handleTimeOut() } this.setData({ HosList: Array.isArray(res) ? res : res.list, locationName: '重新定位', }) }) }, getDtpList() { const { Name, LNG, LAT, ProvinceId, CityId } = this.data wx.ajax({ method: 'GET', url: '?r=zd/dtp-pharmacy/list', data: { lng: LNG, lat: LAT, ProvinceId: Name ? '' : ProvinceId, CityId: Name ? '' : CityId, Name, }, }).then((res) => { this.setData({ dtpList: res.list, locationName: '重新定位', }) }) }, getInfusionCenter() { const { Name, LNG, LAT, ProvinceId, CityId } = this.data wx.ajax({ method: 'GET', url: '?r=xd/infusion-center/list', data: { lng: LNG, lat: LAT, ProvinceId: Name ? '' : ProvinceId, CityId: Name ? '' : CityId, Name, }, }).then((res) => { this.setData({ infusionCenterList: Array.isArray(res) ? res : res.list, locationName: '重新定位', }) }) }, // getDtpAlert() { // wx.ajax({ // method: 'GET', // url: '?r=zd/popup/info', // data: { Type: 3 }, // }).then((res) => { // if (res.showAlert) { // this.setData({ // toastShow: true, // toastType: 'dtpDrug', // }) // } // }) // }, hideDtpAlert() { wx.ajax({ method: 'POST', url: '?r=zd/popup/close-popup', data: { Type: 3 }, }).then((_res) => {}) }, handleDetail(e: WechatMiniprogram.CustomEvent) { const { url } = e.currentTarget.dataset wx.navigateTo({ url, }) }, handleOpenMap(e: WechatMiniprogram.CustomEvent) { const { lat, lng, name, address } = e.currentTarget.dataset wx.openLocation({ latitude: lat * 1, longitude: lng * 1, name, address, }) }, handleBack() { wx.navigateBack() }, onPageScroll() {}, handleToastOk() { this.handleToastCancel() }, handleToastCancel() { this.hideDtpAlert() this.setData({ toastShow: false, }) }, handleDtpPhone(e: any) { const { tel } = e.currentTarget.dataset if (!tel) { wx.showToast({ icon: 'none', title: '电话暂未开通', }) return } wx.makePhoneCall({ phoneNumber: tel, }) }, handleTimeOut() { this.setData({ asideOut: false, }) wx.ajax({ method: 'POST', url: '?r=zd/score/send-score', data: { Type: this.data.timeToastType, Id: 0, }, }).then((res) => { if (!Array.isArray(res)) { this.setData({ timeToast: true, timeToastParams: { rewardScore: res.rewardScore, }, }) setTimeout(() => { this.setData({ timeToast: false, }) }, 3000) } }) }, handleSiteShare(e) { this.setData({ toastShow: true, toastType: 'siteConform', toastParams: e.detail, }) }, handleDefultLocation() { if (this.data.locationName === '定位中') return this.setData({ locationName: '定位中', }) this.handleToggleSite() }, handleSiteShareShow(e) { this.setData({ areaShow: e.detail, }) }, onShareAppMessage(e: any) { let path = `/patient/pages/doctor/index?active=${this.data.tabActive}&es=${this.data.es}` const { toastType, toastParams } = this.data if (toastType === 'siteConform' && e.from === 'button') { path = `${path}&pid=${toastParams.ProvinceId}&cid=${toastParams.CityId}&pn=${toastParams.ProvinceName}&cn=${toastParams.CityName}` this.setData({ ProvinceId: toastParams.ProvinceId, ProvinceName: toastParams.ProvinceName, CityId: toastParams.CityId, CityName: toastParams.CityName, }) this.getList() } return { title: '【就诊地图】帮您快速找到医生和医院', path, } }, }) export {}