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.
94 lines
2.1 KiB
94 lines
2.1 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
content: '', |
|
imageList: [] as any[], |
|
submitting: false, |
|
// 弹窗 |
|
popupShow: false, |
|
popupType: 'popup2', |
|
popupParams: {} as any, |
|
}, |
|
|
|
onLoad() { |
|
app.waitLogin({ type: 1 }) |
|
}, |
|
|
|
onContentInput(e: any) { |
|
this.setData({ content: e.detail.value }) |
|
}, |
|
|
|
onUploadSuccess(e: any) { |
|
const file = e.detail.file |
|
const imageList = this.data.imageList.concat([file]) |
|
this.setData({ imageList }) |
|
}, |
|
|
|
onUploadError(e: any) { |
|
wx.showToast({ title: '图片上传失败', icon: 'none' }) |
|
}, |
|
|
|
deleteImage(e: any) { |
|
const uid = e.currentTarget.dataset.uid |
|
const imageList = this.data.imageList.filter((item: any) => item.uid !== uid) |
|
this.setData({ imageList }) |
|
}, |
|
|
|
previewImage(e: any) { |
|
const url = e.currentTarget.dataset.url |
|
const urls = this.data.imageList.map((item: any) => item.url) |
|
wx.previewImage({ current: url, urls }) |
|
}, |
|
|
|
handleSubmit() { |
|
if (this.data.submitting) return |
|
|
|
const content = this.data.content.trim() |
|
if (!content) { |
|
wx.showToast({ title: '请输入反馈内容', icon: 'none' }) |
|
return |
|
} |
|
if (content.length > 500) { |
|
wx.showToast({ title: '反馈内容不能超过500字', icon: 'none' }) |
|
return |
|
} |
|
|
|
this.setData({ submitting: true }) |
|
|
|
const images = this.data.imageList.map((item: any) => item.url) |
|
const imagesStr = images.length > 0 ? JSON.stringify(images) : '' |
|
|
|
wx.ajax({ |
|
url: '/feedback/submit', |
|
method: 'POST', |
|
data: { |
|
content, |
|
images: imagesStr, |
|
}, |
|
loading: true, |
|
loadingText: '提交中...', |
|
}) |
|
.then(() => { |
|
this.setData({ popupShow: true }) |
|
}) |
|
.catch(() => { |
|
wx.showToast({ title: '提交失败,请重试', icon: 'none' }) |
|
}) |
|
.finally(() => { |
|
this.setData({ submitting: false }) |
|
}) |
|
}, |
|
|
|
handlePopupOk() { |
|
this.setData({ popupShow: false }) |
|
wx.navigateBack() |
|
}, |
|
|
|
handlePopupCancel() { |
|
this.setData({ popupShow: false }) |
|
wx.navigateBack() |
|
}, |
|
}) |
|
|
|
export {}
|
|
|