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.

156 lines
3.4 KiB

const app = getApp<IAppOption>()
Page({
1 month ago
data: {
// 搜索关键词
keyword: '',
// 时间筛选
startDate: '',
endDate: '',
// 药师列表
pharmacistList: [] as any[],
totalCount: 0,
// 分页
page: 1,
pageSize: 20,
loading: false,
hasMore: true,
pagination: {
count: 0,
page: 0,
pages: 0,
},
1 month ago
},
onLoad() {
// 地推端药师页面,仅允许地推人员访问
app.waitLogin({ types: [3] }).then(() => {
this.getPharmacistList()
})
},
// 获取药师列表
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 {}