|
|
|
|
const app = getApp<IAppOption>()
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
popupShow: false,
|
|
|
|
|
popupType: '',
|
|
|
|
|
popupParams: {
|
|
|
|
|
position: 'bottom',
|
|
|
|
|
} as any,
|
|
|
|
|
|
|
|
|
|
topicShow: false,
|
|
|
|
|
replayShow: false,
|
|
|
|
|
|
|
|
|
|
fileList: [] as any[],
|
|
|
|
|
|
|
|
|
|
topicList: [] as any[],
|
|
|
|
|
categoryList: [] as any[],
|
|
|
|
|
selectedTopicIds: [] as number[],
|
|
|
|
|
selectedTopics: [] as any[],
|
|
|
|
|
selectedCategoryIds: [] as number[],
|
|
|
|
|
title: '',
|
|
|
|
|
content: '',
|
|
|
|
|
visibility: 1,
|
|
|
|
|
isEdit: false,
|
|
|
|
|
editPostId: '',
|
|
|
|
|
},
|
|
|
|
|
onLoad(options: any) {
|
|
|
|
|
if (options && options.id) {
|
|
|
|
|
this.setData({ isEdit: true, editPostId: options.id })
|
|
|
|
|
}
|
|
|
|
|
app.waitLogin({ type: 1 }).then(() => {
|
|
|
|
|
const listReady = Promise.all([this.getTopicList(), this.getCategoryList()])
|
|
|
|
|
if (this.data.isEdit) {
|
|
|
|
|
listReady.then(() => {
|
|
|
|
|
this.getPostDetail()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getTopicList() {
|
|
|
|
|
return wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '?r=psvt/topic/top-list',
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
this.setData({
|
|
|
|
|
topicList: res.list || [],
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getCategoryList() {
|
|
|
|
|
return wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '?r=psvt/wall/index-category',
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
this.setData({
|
|
|
|
|
categoryList: res.list || [],
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
getPostDetail() {
|
|
|
|
|
const { editPostId } = this.data
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: '?r=psvt/post/detail',
|
|
|
|
|
data: { id: editPostId },
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
if (!res) return
|
|
|
|
|
const fileList = (res.attachments || []).map((item: any) => {
|
|
|
|
|
if (item.attachmentType == 2) {
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
fileType: 'video',
|
|
|
|
|
url: item.videoCoverUrl || '',
|
|
|
|
|
videoUrl: item.attachmentUrl || '',
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
fileType: 'image',
|
|
|
|
|
url: item.attachmentUrl || '',
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// Build selectedTopics directly from the post detail, which already carries
|
|
|
|
|
// topicName. We must NOT rely on topicList.find() here because topic/top-list
|
|
|
|
|
// only returns the top-10 by weight, so a post's topics may not be in it.
|
|
|
|
|
const selectedTopics = (res.topics || []).map((t: any) => ({
|
|
|
|
|
id: Number(t.topicId),
|
|
|
|
|
topicName: t.topicName || '',
|
|
|
|
|
}))
|
|
|
|
|
this.setData({
|
|
|
|
|
title: res.title || '',
|
|
|
|
|
content: res.content || '',
|
|
|
|
|
visibility: res.visibility || 1,
|
|
|
|
|
selectedTopicIds: selectedTopics.map((t: any) => t.id),
|
|
|
|
|
selectedTopics,
|
|
|
|
|
selectedCategoryIds: (res.categories || []).map((c: any) => Number(c.categoryId)),
|
|
|
|
|
fileList,
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
onTitleInput(e: any) {
|
|
|
|
|
this.setData({ title: e.detail.value })
|
|
|
|
|
},
|
|
|
|
|
onContentInput(e: any) {
|
|
|
|
|
this.setData({ content: e.detail.value })
|
|
|
|
|
},
|
|
|
|
|
handleTopicTap(e: any) {
|
|
|
|
|
const id = Number(e.currentTarget.dataset.id)
|
|
|
|
|
const selectedTopicIds = [...this.data.selectedTopicIds]
|
|
|
|
|
const selectedTopics = [...this.data.selectedTopics]
|
|
|
|
|
const index = selectedTopicIds.indexOf(id)
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
selectedTopicIds.splice(index, 1)
|
|
|
|
|
selectedTopics.splice(index, 1)
|
|
|
|
|
} else {
|
|
|
|
|
const topic = this.data.topicList.find((t: any) => Number(t.id) === id)
|
|
|
|
|
if (topic) {
|
|
|
|
|
selectedTopicIds.push(id)
|
|
|
|
|
selectedTopics.push({ id: Number(topic.id), topicName: topic.topicName })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.setData({ selectedTopicIds, selectedTopics })
|
|
|
|
|
},
|
|
|
|
|
handleRemoveTopic(e: any) {
|
|
|
|
|
const id = Number(e.currentTarget.dataset.id)
|
|
|
|
|
const index = this.data.selectedTopicIds.indexOf(id)
|
|
|
|
|
if (index === -1) return
|
|
|
|
|
const selectedTopicIds = [...this.data.selectedTopicIds]
|
|
|
|
|
const selectedTopics = [...this.data.selectedTopics]
|
|
|
|
|
selectedTopicIds.splice(index, 1)
|
|
|
|
|
selectedTopics.splice(index, 1)
|
|
|
|
|
this.setData({ selectedTopicIds, selectedTopics })
|
|
|
|
|
},
|
|
|
|
|
showTopicPopup() {
|
|
|
|
|
this.setData({ topicShow: true })
|
|
|
|
|
},
|
|
|
|
|
topicPopupClose() {
|
|
|
|
|
this.setData({ topicShow: false })
|
|
|
|
|
},
|
|
|
|
|
handleCategoryTap(e: any) {
|
|
|
|
|
const id = Number(e.currentTarget.dataset.id)
|
|
|
|
|
const selectedCategoryIds = [...this.data.selectedCategoryIds]
|
|
|
|
|
const index = selectedCategoryIds.indexOf(id)
|
|
|
|
|
if (index > -1) {
|
|
|
|
|
selectedCategoryIds.splice(index, 1)
|
|
|
|
|
} else {
|
|
|
|
|
selectedCategoryIds.push(id)
|
|
|
|
|
}
|
|
|
|
|
this.setData({ selectedCategoryIds })
|
|
|
|
|
},
|
|
|
|
|
handleVisibilityChange(e: any) {
|
|
|
|
|
this.setData({ visibility: Number(e.currentTarget.dataset.value) })
|
|
|
|
|
},
|
|
|
|
|
buildAttachments() {
|
|
|
|
|
const { fileList } = this.data
|
|
|
|
|
return fileList.map((item: any, index: number) => {
|
|
|
|
|
const isVideo = item.fileType === 'video'
|
|
|
|
|
const attachment: any = {
|
|
|
|
|
attachmentType: isVideo ? 2 : 1,
|
|
|
|
|
attachmentUrl: isVideo ? item.videoUrl : item.url,
|
|
|
|
|
sortOrder: index,
|
|
|
|
|
}
|
|
|
|
|
if (isVideo) {
|
|
|
|
|
attachment.videoCoverUrl = item.url
|
|
|
|
|
}
|
|
|
|
|
if (item.id) {
|
|
|
|
|
attachment.id = item.id
|
|
|
|
|
}
|
|
|
|
|
return attachment
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSaveDraft() {
|
|
|
|
|
this.submitPost(0)
|
|
|
|
|
},
|
|
|
|
|
handleSubmit() {
|
|
|
|
|
this.submitPost(1)
|
|
|
|
|
},
|
|
|
|
|
submitPost(postStatus: number) {
|
|
|
|
|
const { title, content, visibility, selectedTopicIds, selectedCategoryIds, isEdit, editPostId } = this.data
|
|
|
|
|
if (!title.trim()) {
|
|
|
|
|
wx.showToast({ title: '请添加标题', icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const data: any = {
|
|
|
|
|
title,
|
|
|
|
|
content,
|
|
|
|
|
postStatus,
|
|
|
|
|
visibility,
|
|
|
|
|
topicIds: selectedTopicIds,
|
|
|
|
|
categoryIds: selectedCategoryIds,
|
|
|
|
|
attachments: this.buildAttachments(),
|
|
|
|
|
}
|
|
|
|
|
if (isEdit) {
|
|
|
|
|
data.postId = Number(editPostId)
|
|
|
|
|
}
|
|
|
|
|
wx.ajax({
|
|
|
|
|
method: 'POST',
|
|
|
|
|
url: isEdit ? '?r=psvt/my-post/update' : '?r=psvt/post/create',
|
|
|
|
|
data,
|
|
|
|
|
}).then(() => {
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: postStatus === 0 ? '草稿已保存' : '发布成功',
|
|
|
|
|
icon: 'success',
|
|
|
|
|
})
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
wx.navigateBack()
|
|
|
|
|
}, 1000)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
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',
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleSetData(e) {
|
|
|
|
|
const { fileList } = this.data
|
|
|
|
|
this.setData({
|
|
|
|
|
fileList: [...fileList, ...e.detail],
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleDeleteFile(e) {
|
|
|
|
|
const { index } = e.detail
|
|
|
|
|
const { fileList } = this.data
|
|
|
|
|
this.setData({
|
|
|
|
|
fileList: fileList.filter((_, i) => i !== index),
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
handleBack() {
|
|
|
|
|
wx.navigateBack()
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export {}
|