const app = getApp(); Page({ data: { showArea: false, fieldNames: { text: "label", value: "value", children: "children" }, hospitalClassification: {}, hospitalLevel: {}, search: "", ProvinceId: "", CityId: "", CountyId: "", ProvinceName: "", CityName: "", CountyName: "", pagination: { page: 1, pages: 1, count: 1, }, list: [], area: [], reg: true, }, onLoad(options) { this.setData({ reg: options.reg === "1", }); app.waitLogin(true).then(() => { this.getHostipalDict(); this.getList(); this.getArea(); }); }, getHostipalDict() { wx.ajax({ method: "GET", url: "?r=takeda/reg/hospital-dict", data: {}, }).then((res) => { this.setData({ hospitalClassification: res.hospitalClassification, hospitalLevel: res.hospitalLevel, }); }); }, handleSearch() { this.setData({ list: [], }); this.getList(); }, getList(newPage = 1) { wx.ajax({ method: "GET", url: "?r=takeda/reg/hospitals", data: { page: newPage, ProvinceId: this.data.ProvinceId, CityId: this.data.CityId, CountyId: this.data.CountyId, Search: this.data.search, }, }).then((res) => { const list = res.page === 1 ? res.list : [...this.data.list, ...res.list]; this.setData({ list, pagination: { page: res.page, pages: res.pages, count: res.count, }, }); }); }, onReachBottom() { const { page, pages } = this.data.pagination; if (pages > page) { this.getList(page + 1); } }, getArea() { wx.ajax({ method: "GET", url: "/js/area.json", isJSON: true, }).then((res) => { this.setData({ area: res, }); }); }, handleArea() { this.setData({ showArea: true, }); }, onClose() { this.setData({ showArea: false, }); }, onFinish(e: any) { this.setData({ ProvinceId: e.detail.selectedOptions[0].value, ProvinceName: e.detail.selectedOptions[0].label, CityId: e.detail.selectedOptions[1].value, CityName: e.detail.selectedOptions[1].label, CountyId: e.detail.selectedOptions[2].value, CountyName: e.detail.selectedOptions[2].label, showArea: false, }); this.handleSearch(); }, handleSelect(e: any) { const { index } = e.currentTarget.dataset; const { list } = this.data; const item: any = list[index]; const eventChannel = this.getOpenerEventChannel(); eventChannel.emit("acceptDataFromOpenedPage", { hid: item.HospitalId, hname: item.ShortName || item.Name, }); wx.navigateBack(); }, handlePushDoctor() { wx.navigateTo({ url: "/module1/pages/cHostipal/index", }); }, }); export {};