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.

276 lines
7.1 KiB

1 week ago
const app = getApp<IAppOption>()
Page({
data: {
popupShow: false,
popupType: '',
popupParams: {
position: 'bottom',
} as any,
userInfo: {} as any,
days: 0,
cateList: [] as Array<{ CateId: string; CateName: string }>,
activeCateId: '',
picTextList: [] as Array<any>,
pagination: {
page: 1,
pages: 1,
count: 0,
},
videoList: [] as Array<any>,
configList: [] as Array<any>,
sectionList: [] as Array<{ code: string; visible: boolean; subList: any[] }>,
moduleVisible: {
health: true,
'spread1': true,
'video-big': true,
'spread2': true,
'qiye-wx': true,
'education': true,
} as Record<string, boolean>,
1 week ago
},
onLoad() {
app.waitLogin({ type: 'any' }).then(() => {
this.getMyInfo()
this.getCateList()
this.getList()
this.getVideoList()
this.getConfig()
})
},
onShow() {
if (app.globalData.loginState) {
this.getMyInfo()
}
},
getConfig() {
wx.ajax({
method: 'GET',
url: `?r=psvt/mini-conf/get-config`,
data: {},
}).then((res: any) => {
const list = res || []
list.forEach((item: any) => {
if (
(item.code === 'spread1' || item.code === 'spread2' || item.code === 'serviceConf') &&
item.subList
) {
item.subList = item.subList.filter((subItem: any) => subItem.showStatus == 1)
}
})
const moduleVisible: Record<string, boolean> = {} as any
list.forEach((item: any) => {
moduleVisible[item.code] = item.showStatus == 1
})
const sectionCodes = ['health', 'spread1', 'video-big', 'spread2']
const sectionList = sectionCodes
.map((code) => {
const conf = list.find((item: any) => item.code === code)
return {
code,
visible: conf ? conf.showStatus == 1 : false,
subList: conf?.subList || [],
}
})
.sort((a, b) => {
const aSeq = list.find((item: any) => item.code === a.code)?.sequence || 0
const bSeq = list.find((item: any) => item.code === b.code)?.sequence || 0
return Number(aSeq) - Number(bSeq)
})
this.setData({ configList: list, moduleVisible, sectionList })
})
},
getMyInfo() {
wx.ajax({
method: 'GET',
url: '?r=psvt/patient/my-info',
}).then((res: any) => {
let days = 0
if (res.firstOpenTime) {
const first = new Date(res.firstOpenTime.replace(/-/g, '/'))
const now = new Date()
days = Math.max(1, Math.ceil((now.getTime() - first.getTime()) / (1000 * 60 * 60 * 24)))
}
this.setData({
userInfo: res,
days,
})
})
},
getCateList() {
wx.ajax({
method: 'GET',
url: '?r=psvt/pic-text/cate-list',
}).then((res: any) => {
this.setData({
cateList: res || [],
})
})
},
getList(page = 1, cateId = '', append = false) {
const params: any = {
page,
count: 10,
}
if (cateId) {
params.CateId = cateId
}
wx.ajax({
method: 'GET',
url: '?r=psvt/pic-text/list',
data: params,
}).then((res: any) => {
const list = res.list || []
this.setData({
picTextList: append ? this.data.picTextList.concat(list) : list,
pagination: {
page: res.page || 1,
pages: res.pages || 1,
count: Number(res.count) || 0,
},
})
})
},
getVideoList() {
wx.ajax({
method: 'GET',
url: '?r=psvt/video/list',
data: { page: 1, count: 10 },
}).then((res: any) => {
this.setData({
videoList: res.list || [],
})
})
},
handleCateTap(e: any) {
const { cateid } = e.currentTarget.dataset
this.setData({
activeCateId: cateid || '',
})
this.getList(1, cateid || '')
},
handleLoadMore() {
const { pagination, activeCateId } = this.data
if (pagination.page < pagination.pages) {
this.getList(pagination.page + 1, activeCateId, true)
}
1 week ago
},
handlePopupOk() {
const { popupType } = this.data
if (popupType === 'argument') {
wx.ajax({
method: 'POST',
url: '?r=wtx/user/agree-guest-privacy',
data: {
WorkerId: app.globalData.scene?.workerId || '',
},
}).then(() => {
this.setData({
popupShow: false,
popupType: '',
popupParams: {},
})
const waitBindDoctorId = app.globalData.waitBindDoctorId
if (waitBindDoctorId) {
this.handleBindDoctor(waitBindDoctorId)
}
})
}
if (popupType === 'conformBindDoctorConform') {
this.setData({
popupShow: false,
})
wx.ajax({
method: 'POST',
url: '?r=wtx/account/wait-bind-doctor',
data: {
doctorId: app.globalData.waitBindDoctorId,
},
}).then(() => {
wx.navigateTo({
url: `/patient/pages/login/index`,
})
})
}
},
handlePopupCancel() {
const { popupType } = this.data
if (popupType === 'argument') {
wx.exitMiniProgram()
}
if (popupType === 'conformBindDoctorConform') {
this.setData({
popupShow: false,
})
wx.ajax({
method: 'POST',
url: '?r=wtx/account/wait-bind-doctor',
data: {
doctorId: app.globalData.waitBindDoctorId,
},
}).then(() => {
app.globalData.waitBindDoctorId = ''
})
}
},
handleWechatWork() {
wx.navigateTo({
url: '/pages/wechatWork/index',
})
},
onReachBottom() {
this.handleLoadMore()
},
handleBackTop() {
wx.pageScrollTo({ scrollTop: 0 })
},
handleVideoMore() {
wx.navigateTo({
url: '/pages/videoList/index',
})
},
handleVideoDetail(e) {
const { index } = e.currentTarget.dataset
const { videoList } = this.data
const { Id } = videoList[index]
wx.navigateTo({
url: `/pages/videoDetail/index?id=${Id}&index=${index}`,
})
},
3 days ago
handleBannerTap(e) {
const { linkurl } = e.currentTarget.dataset
if (!linkurl) return
const tabBarPages = ['pages/index/index', 'pages/wall/index', 'pages/health/index', 'pages/my/index']
const [path, query] = linkurl.split('?')
if (tabBarPages.some((p) => path === p || path === `/${p}`)) {
// tabBar 页面:通过 globalData 传参,switchTab 不支持 query
if (query) {
app.globalData.tabBarParams = app.globalData.tabBarParams || {}
app.globalData.tabBarParams[path.replace(/^\//, '')] = query
}
wx.switchTab({ url: path.startsWith('/') ? path : `/${path}` })
} else {
wx.navigateTo({ url: linkurl })
}
},
handlePicTextDetail(e) {
const { index } = e.currentTarget.dataset
const { picTextList } = this.data
const { Id, Type } = picTextList[index]
if (Type == 1) {
wx.navigateTo({
url: `/pages/articleDetail/index?id=${Id}`,
})
} else if (Type == 2) {
wx.navigateTo({
url: `/pages/articleVideoDetail/index?id=${Id}`,
})
}
},
1 week ago
})
export {}