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.
227 lines
5.5 KiB
227 lines
5.5 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
// 搜索关键词 |
|
keyword: '', |
|
// 时间筛选 |
|
startDate: '', |
|
endDate: '', |
|
|
|
// 项目列表 |
|
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, |
|
currentProjectId: 0, |
|
currentProjectName: '', |
|
projectIndex: 0, |
|
|
|
// 药师列表 |
|
pharmacistList: [] as any[], |
|
totalCount: 0, |
|
|
|
// 分页 |
|
page: 1, |
|
pageSize: 20, |
|
loading: false, |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
}, |
|
onLoad() { |
|
// 地推端药师页面,仅允许地推人员访问 |
|
app.waitLogin({ types: [3] }).then(() => { |
|
this.getProjectList() |
|
}) |
|
}, |
|
|
|
// 获取项目列表 |
|
getProjectList() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '/app/promoter/promoter/project-list', |
|
}).then((res: any) => { |
|
const projectList = res.list || [] |
|
const currentProjectId = res.currentProjectId || (projectList[0]?.projectId || 0) |
|
const currentProject = projectList.find((item: any) => item.projectId === currentProjectId) || projectList[0] |
|
const projectIndex = projectList.findIndex((item: any) => item.projectId === currentProjectId) |
|
|
|
this.setData({ |
|
projectList, |
|
currentProjectId, |
|
currentProjectName: currentProject?.projectName || '特诺雅', |
|
projectIndex: projectIndex >= 0 ? projectIndex : 0, |
|
}) |
|
|
|
// 获取药师列表 |
|
this.getPharmacistList() |
|
}) |
|
}, |
|
|
|
// 切换项目 |
|
onProjectChange(e: WechatMiniprogram.CustomEvent) { |
|
const index = e.detail.value |
|
const project = this.data.projectList[index] |
|
if (project && project.projectId !== this.data.currentProjectId) { |
|
// 先调用切换项目接口 |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '/app/promoter/promoter/switch-project', |
|
data: { |
|
projectId: project.projectId, |
|
}, |
|
}).then(() => { |
|
// 切换成功后更新页面数据 |
|
this.setData({ |
|
currentProjectId: project.projectId, |
|
currentProjectName: project.projectName, |
|
projectIndex: index, |
|
// 重置列表数据 |
|
page: 1, |
|
pharmacistList: [], |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
}) |
|
// 重新加载数据 |
|
this.getPharmacistList() |
|
wx.showToast({ |
|
title: '切换成功', |
|
icon: 'success', |
|
}) |
|
}).catch(() => { |
|
wx.showToast({ |
|
title: '切换失败', |
|
icon: 'none', |
|
}) |
|
}) |
|
} |
|
}, |
|
// 获取药师列表 |
|
getPharmacistList() { |
|
if (this.data.loading || !this.data.hasMore) return |
|
|
|
this.setData({ loading: true }) |
|
|
|
wx.ajax({ |
|
method: 'GET', |
|
url: '/app/promoter/promoter/pharmacist-list', |
|
data: { |
|
keyword: this.data.keyword, |
|
startDate: this.data.startDate, |
|
endDate: this.data.endDate, |
|
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) |
|
|
|
this.setData({ |
|
pharmacistList: [...this.data.pharmacistList, ...list], |
|
totalCount: total, |
|
page: currentPage + 1, |
|
hasMore: currentPage < pages, |
|
loading: false, |
|
pagination: { |
|
count: total, |
|
page: currentPage, |
|
pages, |
|
}, |
|
}) |
|
}).catch(() => { |
|
this.setData({ loading: false }) |
|
}) |
|
}, |
|
// 搜索药师 |
|
handleSearch(e: WechatMiniprogram.CustomEvent) { |
|
this.setData({ |
|
keyword: e.detail.value, |
|
page: 1, |
|
pharmacistList: [], |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
}) |
|
this.getPharmacistList() |
|
}, |
|
// 开始时间选择 |
|
handleStartDateChange(e: WechatMiniprogram.CustomEvent) { |
|
const startDate = e.detail.value |
|
const { endDate } = this.data |
|
|
|
// 如果已选择结束时间,验证开始时间不能大于结束时间 |
|
if (endDate && startDate > endDate) { |
|
wx.showToast({ |
|
title: '开始时间不能大于结束时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
|
|
this.setData({ |
|
startDate, |
|
page: 1, |
|
pharmacistList: [], |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
}) |
|
this.getPharmacistList() |
|
}, |
|
// 结束时间选择 |
|
handleEndDateChange(e: WechatMiniprogram.CustomEvent) { |
|
const endDate = e.detail.value |
|
const { startDate } = this.data |
|
|
|
// 如果已选择开始时间,验证结束时间不能小于开始时间 |
|
if (startDate && endDate < startDate) { |
|
wx.showToast({ |
|
title: '结束时间不能小于开始时间', |
|
icon: 'none', |
|
}) |
|
return |
|
} |
|
|
|
this.setData({ |
|
endDate, |
|
page: 1, |
|
pharmacistList: [], |
|
hasMore: true, |
|
pagination: { |
|
count: 0, |
|
page: 0, |
|
pages: 0, |
|
}, |
|
}) |
|
this.getPharmacistList() |
|
}, |
|
// 页面上拉触底事件 |
|
onReachBottom() { |
|
if (this.data.loading || !this.data.hasMore) { |
|
return |
|
} |
|
this.getPharmacistList() |
|
}, |
|
// 查看详情 |
|
handleInfo(e: WechatMiniprogram.CustomEvent) { |
|
const { id } = e.currentTarget.dataset |
|
wx.navigateTo({ |
|
url: `/ground/pages/stat/index?id=${id}`, |
|
}) |
|
}, |
|
}) |
|
|
|
export {}
|
|
|