feedback.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="feedback-page">
  3. <!-- 顶部banner -->
  4. <view class="banner">
  5. <image src="../static/feedback.png" mode="aspectFill" class="banner-img"></image>
  6. <text class="history-btn" @click="goToHistory">我的历史反馈</text>
  7. </view>
  8. <!-- 反馈类型区域 -->
  9. <view class="form-item type-section flex-a flex-j-b">
  10. <view class="label" style="margin-bottom: 0;">
  11. 反馈类型
  12. <text class="required">*</text>
  13. </view>
  14. <view class="picker-box" @click="showTypePicker">
  15. <text :class="['picker-text', !model.type && 'placeholder']">
  16. {{ model.type || '请选择反馈类型' }}
  17. </text>
  18. <u-icon name="arrow-right" color="#999" size="32" top="2rpx"></u-icon>
  19. </view>
  20. </view>
  21. <!-- 反馈描述区域 -->
  22. <view class="form-item content-section">
  23. <view class="label">
  24. 反馈描述
  25. <text class="required">*</text>
  26. </view>
  27. <view class="textarea-box">
  28. <u-input type="textarea" v-model="model.content" placeholder="请输入不少于10个字的描述" :height="200"></u-input>
  29. </view>
  30. </view>
  31. <!-- 图片上传区域 -->
  32. <view class="form-item upload-section">
  33. <view class="label">上传图片(最多五张):</view>
  34. <view class="upload-box">
  35. <u-upload :file-list="fileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  36. :max-count="5" :previewFullImage="true"></u-upload>
  37. </view>
  38. </view>
  39. <!-- 提交按钮 -->
  40. <view class="bottom-fixed-con">
  41. <button class="common-btn" @click="submit">提交</button>
  42. </view>
  43. <!-- 反馈类型选择器 -->
  44. <u-picker v-model="showPicker" :range="feedbackTypes" @confirm="onTypeConfirm" @cancel="showPicker = false"
  45. mode="selector"></u-picker>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. showPicker: false,
  53. feedbackTypes: ['功能建议', '内容建议', '产品建议', '其他'],
  54. model: {
  55. type: '',
  56. content: '',
  57. images: []
  58. },
  59. fileList: [],
  60. rules: {
  61. type: [{
  62. required: true,
  63. message: '请选择反馈类型'
  64. }],
  65. content: [{
  66. required: true,
  67. message: '请输入反馈描述'
  68. }, {
  69. min: 10,
  70. message: '描述不能少于10个字'
  71. }]
  72. }
  73. }
  74. },
  75. methods: {
  76. // 显示类型选择器
  77. showTypePicker() {
  78. this.showPicker = true
  79. },
  80. // 类型选择确认
  81. onTypeConfirm(e) {
  82. this.model.type = e.value[0]
  83. this.showPicker = false
  84. },
  85. // 上传图片
  86. afterRead(event) {
  87. const {
  88. file
  89. } = event
  90. // 上传图片到服务器
  91. uni.uploadFile({
  92. url: 'your-upload-url',
  93. filePath: file.url,
  94. name: 'file',
  95. success: (res) => {
  96. const response = JSON.parse(res.data)
  97. if (response.code === 1) {
  98. this.model.images.push(response.data.url)
  99. }
  100. }
  101. })
  102. },
  103. // 删除图片
  104. deletePic(event) {
  105. this.model.images.splice(event.index, 1)
  106. },
  107. // 去历史记录
  108. goToHistory() {
  109. uni.navigateTo({
  110. url: '/pages/feedback-history/index'
  111. })
  112. },
  113. // 提交表单
  114. submit() {
  115. if (!this.model.type) {
  116. return uni.$u.toast('请选择反馈类型')
  117. }
  118. if (this.model.content.length < 10) {
  119. return uni.$u.toast('描述不能少于10个字')
  120. }
  121. // 提交表单
  122. uni.showLoading({
  123. title: '提交中'
  124. })
  125. // 这里调用提交接口
  126. setTimeout(() => {
  127. uni.hideLoading()
  128. uni.$u.toast('提交成功')
  129. setTimeout(() => {
  130. uni.navigateBack()
  131. }, 1500)
  132. }, 1000)
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .feedback-page {
  139. min-height: 100vh;
  140. background: #F5F5F5;
  141. // banner样式保持不变
  142. .banner {
  143. position: relative;
  144. height: 230rpx;
  145. overflow: hidden;
  146. .banner-img {
  147. width: 100%;
  148. height: 100%;
  149. }
  150. .history-btn {
  151. position: absolute;
  152. right: 30rpx;
  153. top: 30rpx;
  154. background: rgba(56, 193, 72, 0.9);
  155. color: #FFFFFF;
  156. padding: 10rpx 20rpx;
  157. border-radius: 10rpx;
  158. font-size: 24rpx;
  159. }
  160. }
  161. // 表单项通用样式
  162. .form-item {
  163. background: #FFFFFF;
  164. margin: 20rpx;
  165. padding: 30rpx;
  166. border-radius: 12rpx;
  167. .label {
  168. font-size: 28rpx;
  169. color: #333;
  170. margin-bottom: 20rpx;
  171. .required {
  172. color: #FF5B5B;
  173. margin-left: 4rpx;
  174. }
  175. }
  176. }
  177. // 反馈类型区域
  178. .type-section {
  179. position: relative;
  180. z-index: 1;
  181. .picker-box {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. .picker-text {
  186. font-size: 28rpx;
  187. color: #333;
  188. &.placeholder {
  189. color: #999;
  190. }
  191. }
  192. }
  193. }
  194. // 反馈描述区域
  195. .content-section {
  196. .textarea-box {
  197. background: #F8F8F8;
  198. border-radius: 8rpx;
  199. padding: 20rpx;
  200. }
  201. }
  202. }
  203. </style>