const app = getApp() Page({ data: { // 表单数据 name: '', pharmacyId: '', pharmacyName: '', // 药店选择弹窗 show: false, // 省市区选择 provinceId: '', provinceName: '', cityId: '', cityName: '', districtId: '', districtName: '', // 药店列表 pharmacyList: [] as any[], // 搜索关键词 keyword: '', // 分页 page: 1, pageSize: 20, loading: false, hasMore: true, pagination: { count: 0, page: 0, pages: 0, }, }, onLoad() { // 页面加载 }, // 输入姓名 handleNameInput(e: WechatMiniprogram.CustomEvent) { this.setData({ name: e.detail.value, }) }, // 打开药店选择弹窗 handleDrug() { this.setData({ show: true, page: 1, pharmacyList: [], hasMore: true, pagination: { count: 0, page: 0, pages: 0, }, }) this.getPharmacyList() }, // 关闭弹窗 onClose() { this.setData({ show: false, }) }, // 获取药店列表 getPharmacyList() { if (this.data.loading || !this.data.hasMore) return this.setData({ loading: true }) wx.ajax({ method: 'GET', url: '/app/common/common/pharmacy-list', data: { keyword: this.data.keyword, provinceId: this.data.provinceId, cityId: this.data.cityId, districtId: this.data.districtId, page: this.data.page, pageSize: this.data.pageSize, }, }) .then((res: any) => { const list = res.list || [] const currentPage = this.data.page const total = res.total || 0 const pages = Math.ceil(total / this.data.pageSize) const otherPharmacy = { id: '-1', name: '其他药店', address: '没有找到所在药店', } this.setData({ pharmacyList: [...this.data.pharmacyList, ...list, otherPharmacy], total, page: currentPage + 1, hasMore: currentPage < pages, loading: false, pagination: { count: total, page: currentPage, pages, }, }) }) .catch(() => { this.setData({ loading: false }) }) }, // 省市区选择变化 handleChange(e: WechatMiniprogram.CustomEvent) { const [province, city, district] = e.detail this.setData({ provinceId: province?.value || '', provinceName: province?.label || '', cityId: city?.value || '', cityName: city?.label || '', districtId: district?.value || '', districtName: district?.label || '', page: 1, pharmacyList: [], hasMore: true, pagination: { count: 0, page: 0, pages: 0, }, }) this.getPharmacyList() }, // 搜索药店 handleSearch(e: WechatMiniprogram.CustomEvent) { this.setData({ keyword: e.detail.value, page: 1, pharmacyList: [], hasMore: true, pagination: { count: 0, page: 0, pages: 0, }, }) this.getPharmacyList() }, // 加载更多 loadMore() { this.getPharmacyList() }, // 选择药店 selectPharmacy(e: WechatMiniprogram.CustomEvent) { const { id, name } = e.currentTarget.dataset this.setData({ pharmacyId: id, pharmacyName: name, show: false, }) }, // 提交注册 handleSubmit() { const { name, pharmacyId } = this.data if (!name.trim()) { wx.showToast({ title: '请输入姓名', icon: 'none', }) return } if (!pharmacyId) { wx.showToast({ title: '请选择所属药店', icon: 'none', }) return } wx.showLoading({ title: '提交中...' }) wx.ajax({ method: 'POST', url: '/app/pharmacist/pharmacist/register', data: { name: name.trim(), pharmacyId, }, }) .then((res: any) => { wx.hideLoading() // 保存登录信息 app.globalData.initLoginInfo = { ...app.globalData.initLoginInfo, isLogin: 1, loginIdentity: 4, loginIdentityId: res.pharmacistId, } wx.showToast({ title: '注册成功', icon: 'success', }) // 跳转到药店端首页 setTimeout(() => { wx.reLaunch({ url: '/doctor/pages/home/index', }) }, 1500) }) .catch(() => { wx.hideLoading() wx.showToast({ title: '注册失败', icon: 'none', }) }) }, }) export {}