index.vue 3.7 KB
<template>
  <view class="min-h-screen flex flex-col bg-white">
    <AppHeader title="意见反馈" />
    <view class="flex-1 px-4 py-6 pb-20">
      <form @submit.prevent="handleSubmit" class="space-y-6">
        <view>
          <label for="feedback" class="block text-sm font-medium text-gray-700 mb-1">
            您的反馈
          </label>
          <textarea
            id="feedback"
            rows="5"
            class="w-full p-3 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
            placeholder="请描述您遇到的问题或建议..."
            v-model="feedback"
            required
          />
        </view>
        <view>
          <label class="block text-sm font-medium text-gray-700 mb-1">
            上传截图 (可选)
          </label>
          <view class="flex flex-wrap gap-2 mb-2">
            <view v-for="(image, index) in images" :key="index" class="relative w-20 h-20">
              <image :src="image" :alt="`上传图片 ${index + 1}`" class="w-full h-full object-cover rounded-lg" />
              <button type="button" class="absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-1" @click="removeImage(index)">
                <Failure size="16" />
              </button>
            </view>
            <view
              class="w-20 h-20 flex flex-col items-center justify-center border-2 border-dashed border-gray-300 rounded-lg cursor-pointer hover:bg-gray-50"
              @click="chooseImage"
            >
              <Upload size="24" class="text-gray-400" />
              <span class="text-xs text-gray-500 mt-1">添加图片</span>
            </view>
          </view>
        </view>
        <view>
          <label for="name" class="block text-sm font-medium text-gray-700 mb-1">
            您的姓名
          </label>
          <input
            type="text"
            id="name"
            class="w-full p-3 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
            placeholder="请输入您的姓名"
            v-model="name"
          />
        </view>
        <view>
          <label for="contact" class="block text-sm font-medium text-gray-700 mb-1">
            联系方式
          </label>
          <input
            type="text"
            id="contact"
            class="w-full p-3 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500"
            placeholder="请输入您的手机号或微信号"
            v-model="contact"
          />
        </view>
        <button type="submit" class="w-full py-3 bg-blue-500 text-white font-medium rounded-lg hover:bg-blue-600 transition-colors">
          提交反馈
        </button>
      </form>
    </view>
    <BottomNav />
  </view>
</template>

<script setup>
import { ref } from 'vue';
import Taro from '@tarojs/taro';
import AppHeader from '../../components/AppHeader.vue';
import BottomNav from '../../components/BottomNav.vue';
import { Upload, Failure } from '@nutui/icons-vue-taro';

const feedback = ref('');
const name = ref('');
const contact = ref('');
const images = ref([]);

const chooseImage = () => {
  Taro.chooseImage({
    count: 9 - images.value.length,
    sizeType: ['original', 'compressed'],
    sourceType: ['album', 'camera'],
    success: (res) => {
      images.value = [...images.value, ...res.tempFilePaths];
    }
  });
};

const removeImage = (index) => {
  images.value = images.value.filter((_, i) => i !== index);
};

const handleSubmit = () => {
  // In a real app, we would send this data to a server
  Taro.showToast({
    title: '感谢您的反馈!我们会尽快处理。',
    icon: 'success',
    duration: 2000
  });

  setTimeout(() => {
    Taro.navigateBack();
  }, 2000);
};
</script>