信达小程序
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.

355 lines
8.7 KiB

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