index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <page title="意见反馈" ref="pageRef" nav-color="#fff">
  3. <view class="container">
  4. <view class="pageWrapper">
  5. <view class="type-selector">
  6. <view
  7. class="type-item"
  8. :class="{ active: feedbackType === 'BUG' }"
  9. @click="feedbackType = 'BUG'"
  10. >
  11. BUG
  12. </view>
  13. <view
  14. class="type-item"
  15. :class="{ active: feedbackType === '建议' }"
  16. @click="feedbackType = '建议'"
  17. >
  18. 建议
  19. </view>
  20. <view
  21. class="type-item"
  22. :class="{ active: feedbackType === '投诉' }"
  23. @click="feedbackType = '投诉'"
  24. >
  25. 投诉
  26. </view>
  27. <view
  28. class="type-item"
  29. :class="{ active: feedbackType === '其他' }"
  30. @click="feedbackType = '其他'"
  31. >
  32. 其他
  33. </view>
  34. </view>
  35. <view class="input-wrapper">
  36. <textarea
  37. class="input"
  38. v-model="feedbackContent"
  39. :maxlength="maxContentLength"
  40. placeholder="请输入您的反馈内容,我们将及时为您处理。"
  41. ></textarea>
  42. <view class="input-count">
  43. <view class="num" :class="{ count: feedbackContent.length > 0 }">
  44. {{ feedbackContent.length }}
  45. </view>
  46. /{{ maxContentLength }}
  47. </view>
  48. </view>
  49. <view class="line"></view>
  50. <view class="image-upload">
  51. <view class="image-item" v-for="(image, index) in imageList" :key="index">
  52. <image :src="image" mode="aspectFill" class="img"></image>
  53. <view class="delete-btn" @click="deleteImage(index)">
  54. <image class="upload-icon" :src="resource.delete"></image>
  55. </view>
  56. </view>
  57. <view class="upload-btn" v-if="imageList.length < maxImageCount">
  58. <view class="upload-img" @click="chooseImage">
  59. <image class="upload-icon" :src="resource.upload"></image>
  60. </view>
  61. </view>
  62. <view class="input-count">
  63. <view class="num" :class="{ count: imageList.length > 0 }">
  64. {{ imageList.length }}
  65. </view>
  66. /{{ maxImageCount }}
  67. </view>
  68. </view>
  69. <view class="submit-btn" @click="submitFeedback">提交</view>
  70. </view>
  71. </view>
  72. </page>
  73. </template>
  74. <script>
  75. import resource from '@/utils/resource'
  76. export default {
  77. data() {
  78. return {
  79. resource,
  80. feedbackType: 'BUG',
  81. feedbackContent: '',
  82. maxContentLength: 3000,
  83. imageList: [],
  84. maxImageCount: 3,
  85. uploadImg: null
  86. }
  87. },
  88. mounted() {},
  89. methods: {
  90. chooseImage() {
  91. wx.chooseImage({
  92. count: this.maxImageCount - this.imageList.length,
  93. success: (res) => {
  94. this.imageList = this.imageList.concat(res.tempFilePaths)
  95. console.log(res)
  96. const promises = this.imageList.map((tempFilePath) => {
  97. return new Promise((resolve, reject) => {
  98. wx.uploadFile({
  99. url: this.$service.base.apis.UPLOAD, //仅为示例,非真实的接口地址
  100. filePath: tempFilePath,
  101. name: 'file',
  102. header: {
  103. Authentication: this.$store.getters.token
  104. },
  105. formData: {
  106. appId: 'supermart',
  107. folder: 'avatar'
  108. },
  109. success: (uploadRes) => {
  110. resolve(JSON.parse(uploadRes.data))
  111. },
  112. fail: (err) => {
  113. reject(err)
  114. }
  115. })
  116. })
  117. })
  118. Promise.all(promises)
  119. .then((urls) => {
  120. this.uploadImg = urls.map((item) => item.data.url).join(',')
  121. })
  122. .catch((err) => {
  123. console.error('上传失败', err)
  124. })
  125. }
  126. })
  127. },
  128. deleteImage(index) {
  129. this.imageList.splice(index, 1)
  130. },
  131. async submitFeedback(loading = true) {
  132. if (this.feedbackContent) {
  133. await this.$service.base
  134. .feedbackSubmit(
  135. {
  136. type: this.feedbackType,
  137. text: this.feedbackContent,
  138. image: this.uploadImg
  139. },
  140. loading
  141. )
  142. .then((res) => {
  143. this.$message.success('提交成功!')
  144. setTimeout(() => {
  145. this.$router.back()
  146. }, 500)
  147. })
  148. } else {
  149. this.$message.warn('反馈内容是必填的!')
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .container {
  157. padding: 30rpx;
  158. .pageWrapper{
  159. background-color: #fff;
  160. padding: 30rpx;
  161. border-radius: 18rpx;
  162. }
  163. }
  164. .type-selector {
  165. display: flex;
  166. justify-content: flex-start;
  167. margin: 10rpx 0;
  168. }
  169. .type-item {
  170. padding: 10rpx 20rpx;
  171. margin-right: 20rpx;
  172. border-radius: 40rpx;
  173. font-size: 28rpx;
  174. color: #666;
  175. background-color: #f8f8f8;
  176. cursor: pointer;
  177. }
  178. .type-item.active {
  179. background: #fec433;
  180. color: #000;
  181. }
  182. .input-wrapper {
  183. position: relative;
  184. margin-bottom: 20rpx;
  185. }
  186. .input {
  187. width: 100%;
  188. height: 300rpx;
  189. padding: 20rpx;
  190. border-radius: 10rpx;
  191. font-size: 28rpx;
  192. line-height: 1.5;
  193. resize: none;
  194. }
  195. .input-count {
  196. position: absolute;
  197. bottom: 10rpx;
  198. right: 10rpx;
  199. font-size: 24rpx;
  200. color: #999;
  201. }
  202. .num {
  203. display: inline;
  204. }
  205. .count {
  206. color: #fec433;
  207. }
  208. .line {
  209. margin-bottom: 20rpx;
  210. border-bottom: 1rpx solid #ccc;
  211. }
  212. .image-upload {
  213. display: flex;
  214. flex-wrap: no-wrap;
  215. margin-bottom: 20rpx;
  216. position: relative;
  217. }
  218. .upload-btn {
  219. width: 30%;
  220. height: 200rpx;
  221. margin-right: 5%;
  222. margin-bottom: 5%;
  223. display: flex;
  224. justify-content: center;
  225. align-items: center;
  226. border: 1rpx solid #ccc;
  227. border-radius: 16rpx;
  228. font-size: 28rpx;
  229. color: #666;
  230. cursor: pointer;
  231. }
  232. .upload-img {
  233. width: 76rpx;
  234. height: 76rpx;
  235. }
  236. .upload-icon {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. .image-item {
  241. position: relative;
  242. width: 30%;
  243. height: 200rpx;
  244. margin-right: 5%;
  245. margin-bottom: 5%;
  246. border-radius: 16rpx;
  247. .img {
  248. max-height: 100%;
  249. border-radius: 16px;
  250. }
  251. }
  252. .delete-btn {
  253. position: absolute;
  254. top: -10rpx;
  255. right: -10rpx;
  256. width: 40rpx;
  257. height: 40rpx;
  258. border-radius: 50%;
  259. cursor: pointer;
  260. }
  261. .submit-btn {
  262. position: fixed;
  263. bottom: 94rpx;
  264. left: 50%;
  265. transform: translateX(-50%);
  266. width: 502rpx;
  267. height: 88rpx;
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. background: #fec433;
  272. color: #000;
  273. border-radius: 44rpx;
  274. font-size: 32rpx;
  275. font-weight: 500;
  276. line-height: 88rpx;
  277. cursor: pointer;
  278. }
  279. </style>