123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const { museumApi } = require('../../../utils/api.js');
- Page({
- data: {
- formData: {
- title: '',
- content: '',
- name: '',
- email: '',
- feedbackId: 0
- }
- },
- onLoad() {
- // 页面加载时的初始化
- },
- // 标题输入
- onTitleInput(e) {
- this.setData({
- 'formData.title': e.detail.value
- });
- },
- // 内容输入
- onContentInput(e) {
- this.setData({
- 'formData.content': e.detail.value
- });
- },
- // 姓名输入
- onNameInput(e) {
- this.setData({
- 'formData.name': e.detail.value
- });
- },
- // 邮箱输入
- onEmailInput(e) {
- this.setData({
- 'formData.email': e.detail.value
- });
- },
- // 验证表单
- validateForm() {
- const { title, content, name, email } = this.data.formData;
-
- if (!title.trim()) {
- wx.showToast({
- title: '请输入标题',
- icon: 'none'
- });
- return false;
- }
-
- if (!content.trim()) {
- wx.showToast({
- title: '请输入反馈内容',
- icon: 'none'
- });
- return false;
- }
-
- if (!name.trim()) {
- wx.showToast({
- title: '请输入姓名',
- icon: 'none'
- });
- return false;
- }
-
- if (!email.trim()) {
- wx.showToast({
- title: '请输入邮箱',
- icon: 'none'
- });
- return false;
- }
-
- // 简单的邮箱格式验证
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
- if (!emailRegex.test(email)) {
- wx.showToast({
- title: '请输入正确的邮箱格式',
- icon: 'none'
- });
- return false;
- }
-
- return true;
- },
- // 提交反馈
- onSubmit() {
- if (!this.validateForm()) {
- return;
- }
-
- wx.showLoading({
- title: '提交中...'
- });
-
- const submitData = {
- title: this.data.formData.title.trim(),
- content: this.data.formData.content.trim(),
- name: this.data.formData.name.trim(),
- email: this.data.formData.email.trim(),
- feedbackId: this.data.formData.feedbackId
- };
-
- museumApi.submitFeedback(submitData)
- .then((res) => {
- wx.hideLoading();
- wx.showToast({
- title: '提交成功',
- icon: 'success',
- });
-
- // 清空表单
- this.setData({
- formData: {
- title: '',
- content: '',
- name: '',
- email: '',
- feedbackId: 0
- }
- });
-
- // 延迟返回上一页
- setTimeout(() => {
- wx.navigateBack();
- }, 1000);
- })
- .catch((error) => {
- console.error('提交反馈失败:', error);
- wx.showToast({
- title: error.message || '提交失败,请重试',
- icon: 'none'
- });
- wx.hideLoading();
- });
- }
- });
|