feedback.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="page">
  3. <!-- <PageHeader title="意见与反馈" class="PageHeader">
  4. <template slot="center"> </template>
  5. </PageHeader> -->
  6. <view class="feedback-container">
  7. <!-- 问题描述区域 -->
  8. <view class="description-area">
  9. <view class="title">问题描述</view>
  10. <textarea class="input-area" v-model="content" placeholder="请尽可能详细地描述您的反馈或问题" :maxlength="200"
  11. show-count></textarea>
  12. <view class="word-count">{{ content.length }}/200</view>
  13. </view>
  14. <!-- 图片上传区域 -->
  15. <view class="upload-area">
  16. <view class="title">上传图片 <text class="subtitle">(最多5张,可选)</text></view>
  17. <view class="tips">* 上传问题截图更好的帮助我们快速定位您反馈的问题</view>
  18. <view class="tips" style="margin-bottom: 20rpx;">* 需要您授权相册权限</view>
  19. <view class="image-list">
  20. <view class="image-item" v-for="(item, index) in imgList" :key="index">
  21. <image class="preview" :src="item" mode="aspectFill"></image>
  22. <view class="delete-btn" @tap="deleteImage(index)">
  23. <text class="fa fa-times"></text>
  24. </view>
  25. </view>
  26. <view class="upload-btn" @tap="upload" v-if="imgList.length < 5">
  27. <text class="fa fa-plus"></text>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 提交按钮 -->
  32. <view class="submit-btn" @tap="submitFeedback">
  33. 确认提交
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. content: '',
  43. imgList: [],
  44. skey: getApp().globalData.skey || ''
  45. }
  46. },
  47. methods: {
  48. // 上传图片
  49. upload() {
  50. if (this.imgList.length >= 5) {
  51. uni.showToast({
  52. title: '最多只能上传5张图片',
  53. icon: 'none'
  54. });
  55. return;
  56. }
  57. let that = this;
  58. uni.chooseImage({
  59. count: 5 - this.imgList.length,
  60. sizeType: ['compressed'],
  61. sourceType: ['album', 'camera'],
  62. success: function (res) {
  63. let tempFilePaths = [];
  64. // #ifdef H5
  65. res.tempFiles.forEach(file => {
  66. tempFilePaths.push(file.path);
  67. });
  68. // #endif
  69. // #ifdef APP-PLUS || MP
  70. tempFilePaths = res.tempFilePaths;
  71. // #endif
  72. for (let i = 0; i < tempFilePaths.length; i++) {
  73. const uploadTask = uni.uploadFile({
  74. url: that.$apiHost + '/Xweb/upload_img?skey=' + that.skey,
  75. filePath: tempFilePaths[i],
  76. name: 'file',
  77. success: function (uploadFileRes) {
  78. let resdata = JSON.parse(uploadFileRes.data);
  79. if (resdata.success == 'yes') {
  80. that.imgList.push(resdata.url);
  81. } else {
  82. uni.showToast({
  83. title: resdata.str || '上传失败',
  84. icon: 'none'
  85. });
  86. }
  87. },
  88. fail: function (err) {
  89. console.error('上传失败:', err);
  90. uni.showToast({
  91. title: '图片上传失败',
  92. icon: 'none'
  93. });
  94. }
  95. });
  96. }
  97. }
  98. });
  99. },
  100. // 删除图片
  101. deleteImage(index) {
  102. this.imgList.splice(index, 1);
  103. },
  104. // 提交反馈
  105. submitFeedback() {
  106. if (!this.content.trim()) {
  107. uni.showToast({
  108. title: '请输入问题描述',
  109. icon: 'none'
  110. });
  111. return;
  112. }
  113. let imgStr = this.imgList.join('|');
  114. uni.request({
  115. url: this.$apiHost + '/Member/feedback',
  116. method: 'POST',
  117. data: {
  118. uuid: getApp().globalData.uuid,
  119. content: this.content,
  120. image: imgStr
  121. },
  122. header: {
  123. 'Content-Type': 'application/x-www-form-urlencoded',
  124. 'sign': getApp().globalData.headerSign,
  125. uuid: getApp().globalData.uuid,
  126. },
  127. success: (res) => {
  128. if (res.data.success === 'yes') {
  129. uni.showToast({
  130. title: '反馈成功!我们将尽快处理',
  131. icon: 'no'
  132. });
  133. setTimeout(() => {
  134. uni.navigateBack();
  135. }, 1500);
  136. } else {
  137. uni.showToast({
  138. title: res.data.str || '提交失败',
  139. icon: 'none'
  140. });
  141. }
  142. },
  143. fail: (err) => {
  144. console.error('提交失败:', err);
  145. uni.showToast({
  146. title: '网络错误,请稍后重试',
  147. icon: 'none'
  148. });
  149. }
  150. });
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss">
  156. // 导入FontAwesome
  157. @import url("https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css");
  158. .page {
  159. min-height: 100vh;
  160. background-color: #f8f8f8;
  161. padding-bottom: env(safe-area-inset-bottom);
  162. }
  163. .feedback-container {
  164. padding: 30rpx;
  165. .description-area {
  166. background: #fff;
  167. border-radius: 16rpx;
  168. padding: 24rpx;
  169. margin-bottom: 30rpx;
  170. position: relative;
  171. .title {
  172. font-size: 32rpx;
  173. color: #333;
  174. margin-bottom: 20rpx;
  175. }
  176. .input-area {
  177. width: 100%;
  178. height: 300rpx;
  179. font-size: 28rpx;
  180. line-height: 1.6;
  181. padding: 20rpx;
  182. background: #f8f8f8;
  183. border-radius: 12rpx;
  184. }
  185. .word-count {
  186. position: absolute;
  187. right: 44rpx;
  188. bottom: 44rpx;
  189. font-size: 24rpx;
  190. color: #999;
  191. }
  192. }
  193. .upload-area {
  194. background: #fff;
  195. border-radius: 16rpx;
  196. padding: 24rpx;
  197. margin-bottom: 30rpx;
  198. .title {
  199. font-size: 32rpx;
  200. color: #333;
  201. margin-bottom: 20rpx;
  202. .subtitle {
  203. font-size: 24rpx;
  204. color: #999;
  205. }
  206. }
  207. .image-list {
  208. display: flex;
  209. flex-wrap: wrap;
  210. gap: 16rpx;
  211. margin-bottom: 20rpx;
  212. .image-item {
  213. width: 200rpx;
  214. height: 200rpx;
  215. position: relative;
  216. .preview {
  217. width: 100%;
  218. height: 100%;
  219. border-radius: 12rpx;
  220. }
  221. .delete-btn {
  222. position: absolute;
  223. top: -16rpx;
  224. right: -16rpx;
  225. width: 40rpx;
  226. height: 40rpx;
  227. background: rgba(0, 0, 0, 0.5);
  228. border-radius: 50%;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. .fa {
  233. color: #fff;
  234. font-size: 24rpx;
  235. }
  236. }
  237. }
  238. .upload-btn {
  239. width: 200rpx;
  240. height: 200rpx;
  241. background: #f8f8f8;
  242. border-radius: 12rpx;
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. .fa {
  247. font-size: 48rpx;
  248. color: #999;
  249. }
  250. }
  251. }
  252. .tips {
  253. font-size: 24rpx;
  254. color: #999;
  255. line-height: 1.6;
  256. }
  257. }
  258. .submit-btn {
  259. width: 100%;
  260. height: 88rpx;
  261. background: #000;
  262. border-radius: 44rpx;
  263. color: #fff;
  264. font-size: 32rpx;
  265. display: flex;
  266. align-items: center;
  267. justify-content: center;
  268. margin-top: 60rpx;
  269. &:active {
  270. opacity: 0.9;
  271. }
  272. }
  273. }
  274. </style>