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.
354 lines
8.7 KiB
354 lines
8.7 KiB
const app = getApp<IAppOption>() |
|
const licia = require('miniprogram-licia') |
|
|
|
Page({ |
|
data: { |
|
active: 0, |
|
list: [] as any, |
|
HistoryId: '', |
|
pagination: { |
|
page: 1, |
|
pages: 1, |
|
count: 1, |
|
}, |
|
picTextStatus: 0, |
|
videoStatus: 0, |
|
config: {} as any, |
|
}, |
|
onLoad() { |
|
app.waitLogin({ type: [0, 1] }).then(() => { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/common/get-config', |
|
}).then((res) => { |
|
this.setData({ |
|
config: res, |
|
}) |
|
this.getConfig() |
|
}) |
|
}) |
|
}, |
|
getConfig() { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/common/get-config', |
|
data: {}, |
|
}).then((res) => { |
|
this.setData({ |
|
picTextStatus: res.picTextStatus, |
|
videoStatus: res.videoStatus, |
|
active: res.picTextStatus == 0 ? 1 : 0, |
|
}) |
|
this.getList() |
|
}) |
|
}, |
|
getList() { |
|
const { active, pagination } = this.data |
|
if (active == 0) { |
|
this.getInfoList() |
|
} else if (active == 1) { |
|
this.getVideoList() |
|
} else if (active == 2) { |
|
this.getQuestionList() |
|
} |
|
|
|
if (active == 0 && pagination.page == 1) { |
|
app.zdMpBehavior({ PageName: 'PG_PATIENTMYFAVORITES_KNOWLEDGEBASE' }) |
|
} |
|
if (active == 1 && pagination.page == 1) { |
|
app.zdMpBehavior({ PageName: 'PG_PATIENTMYFAVORITES_VIDEOCLASS' }) |
|
} |
|
if (active == 2 && pagination.page == 1) { |
|
app.zdMpBehavior({ PageName: 'PG_PATIENTMYFAVORITES_HEALTHQA' }) |
|
} |
|
}, |
|
getInfoList(newPage = 1) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/pic-text/collection-list', |
|
data: { |
|
page: newPage, |
|
}, |
|
loading: true, |
|
}).then((res) => { |
|
res.list = res.list.map((item) => { |
|
return item |
|
}) |
|
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, |
|
}, |
|
}) |
|
}) |
|
}, |
|
getVideoList(newPage = 1) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/video/collection-list', |
|
data: { |
|
page: newPage, |
|
}, |
|
loading: true, |
|
}).then((res) => { |
|
res.list = res.list.map((item) => { |
|
return item |
|
}) |
|
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, |
|
}, |
|
}) |
|
}) |
|
}, |
|
getQuestionList(newPage = 1) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/health-question/collection-list', |
|
data: { |
|
page: newPage, |
|
}, |
|
loading: true, |
|
}).then((res) => { |
|
res.list = res.list.map((item) => { |
|
return item |
|
}) |
|
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, |
|
}, |
|
}) |
|
}) |
|
}, |
|
handleStar(e) { |
|
const { id, index } = e.currentTarget.dataset |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/pic-text/compliment', |
|
data: { |
|
ContentId: id, |
|
}, |
|
loading: true, |
|
}).then(() => { |
|
this.setData({ |
|
[`list[${index}].IsCompliment`]: 1, |
|
[`list[${index}].ComplimentNum`]: Number(this.data.list[index].ComplimentNum) + 1, |
|
}) |
|
}) |
|
}, |
|
handleVideoStar(e: WechatMiniprogram.CustomEvent) { |
|
const { id, index } = e.currentTarget.dataset |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/video/compliment', |
|
data: { |
|
ContentId: id, |
|
}, |
|
loading: true, |
|
}).then(() => { |
|
this.setData({ |
|
[`list[${index}].ComplimentNum`]: Number(this.data.list[index].ComplimentNum) + 1, |
|
[`list[${index}].IsCompliment`]: 1, |
|
}) |
|
}) |
|
}, |
|
handleVideoPlay(e: WechatMiniprogram.CustomEvent) { |
|
const { id, index } = e.currentTarget.dataset |
|
const { list } = this.data |
|
list.map((item: any, i) => { |
|
if (item.play && i != index) { |
|
const ctx = wx.createVideoContext(`video${i}`) |
|
ctx.pause() |
|
this.setData({ |
|
[`list[${index}].play`]: false, |
|
}) |
|
} |
|
}) |
|
this.setData({ |
|
[`list[${index}].play`]: true, |
|
}) |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/video/view', |
|
data: { |
|
ContentId: id, |
|
}, |
|
}).then((res) => { |
|
this.setData({ |
|
HistoryId: res.HistoryId, |
|
}) |
|
}) |
|
}, |
|
handleVideo(e: WechatMiniprogram.CustomEvent) { |
|
const { index } = e.currentTarget.dataset |
|
const context = wx.createVideoContext(`video${index}`) |
|
context.play() |
|
}, |
|
handleVideoTime: licia.throttle(function (e: WechatMiniprogram.CustomEvent) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=zd/video/watch-duration', |
|
data: { |
|
HistoryId: this.data.HistoryId, |
|
WatchDuration: e.detail.currentTime, |
|
}, |
|
}).then((res) => { |
|
console.log('res: ', res) |
|
}) |
|
}, 5000), |
|
handleVideoPause(e: WechatMiniprogram.CustomEvent) { |
|
console.log(e) |
|
}, |
|
handleDetail(e: WechatMiniprogram.CustomEvent) { |
|
const { id } = e.currentTarget.dataset |
|
if (this.data.config.picTextEbookStatus == 1) { |
|
const webviewUrl = encodeURIComponent( |
|
`${app.globalData.url}/zdcare/#/book?loginState=${app.globalData.loginState}&Id=${id}`, |
|
) |
|
wx.navigateTo({ |
|
url: `/patient/pages/webview/index?url=${webviewUrl}`, |
|
}) |
|
} else { |
|
wx.navigateTo({ |
|
url: `/patient/pages/repositoryDetail/index?id=${id}`, |
|
}) |
|
} |
|
}, |
|
handleQuestionDetail(e) { |
|
const { id } = e.currentTarget.dataset |
|
const webviewUrl = encodeURIComponent( |
|
`${app.globalData.url}/zdcare/#/info-detail?loginState=${app.globalData.loginState}&Id=${id}`, |
|
) |
|
wx.navigateTo({ |
|
url: `/patient/pages/webview/index?url=${webviewUrl}`, |
|
}) |
|
}, |
|
handleVideoToggleSave(e: WechatMiniprogram.CustomEvent) { |
|
const { id, collect, index } = e.currentTarget.dataset |
|
if (collect == 1) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/video/cancel-collection', |
|
data: { |
|
ContentId: id, |
|
}, |
|
loading: true, |
|
}).then(() => { |
|
wx.showToast({ |
|
title: '取消收藏', |
|
icon: 'none', |
|
}) |
|
this.setData({ |
|
[`list[${index}].IsCollect`]: 0, |
|
[`list[${index}].CollectionPeopleNum`]: Number(this.data.list[index].CollectionPeopleNum) - 1, |
|
}) |
|
}) |
|
} else { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/video/collection', |
|
data: { |
|
ContentId: id, |
|
}, |
|
loading: true, |
|
}).then(() => { |
|
wx.showToast({ |
|
title: '收藏成功', |
|
icon: 'none', |
|
}) |
|
this.setData({ |
|
[`list[${index}].IsCollect`]: 1, |
|
[`list[${index}].CollectionPeopleNum`]: Number(this.data.list[index].CollectionPeopleNum) + 1, |
|
}) |
|
}) |
|
} |
|
}, |
|
onReachBottom() { |
|
const { page, pages } = this.data.pagination |
|
const { active } = this.data |
|
if (pages > page) { |
|
if (active == 0) { |
|
this.getInfoList(page + 1) |
|
} else { |
|
this.getVideoList(page + 1) |
|
} |
|
} |
|
}, |
|
tabChange(e) { |
|
this.setData({ |
|
active: e.detail.index, |
|
CateId: '', |
|
Search: '', |
|
list: [], |
|
pagination: { |
|
page: 1, |
|
pages: 1, |
|
count: 1, |
|
}, |
|
}) |
|
this.getList() |
|
}, |
|
handleBack() { |
|
wx.navigateBack({ |
|
fail() { |
|
wx.reLaunch({ |
|
url: '/patient/pages/index/index', |
|
}) |
|
}, |
|
}) |
|
}, |
|
onShareAppMessage(e: any) { |
|
if (e.from === 'button') { |
|
const { id, index, type } = e.target.dataset |
|
const { list } = this.data |
|
const { Title, TitlePicLink, ImageUrl } = list[index] |
|
if (type == 'info') { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/pic-text/share', |
|
data: { ContentId: id }, |
|
}).then(() => { |
|
this.setData({ |
|
[`list[${index}].ShareNum`]: Number(this.data.list[index].ShareNum) + 1, |
|
}) |
|
}) |
|
return { |
|
title: Title, |
|
path: `/patient/pages/repositoryDetail/index?id=${id}`, |
|
imageUrl: TitlePicLink, |
|
} |
|
} else { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=zd/video/share', |
|
data: { ContentId: id }, |
|
}).then(() => { |
|
this.setData({ |
|
[`list[${index}].ShareNum`]: Number(this.data.list[index].ShareNum) + 1, |
|
}) |
|
}) |
|
return { |
|
title: Title, |
|
path: `/patient/pages/repository/index?id=${id}&active=1&title=${Title}`, |
|
imageUrl: ImageUrl, |
|
} |
|
} |
|
} else { |
|
return { |
|
title: '知识库', |
|
path: '/patient/pages/repository/index', |
|
} |
|
} |
|
}, |
|
})
|
|
|