index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="complaint-root">
  3. <erp-nav-bar title="提交反馈" />
  4. <view class="scroll-container">
  5. <scroll-view scroll-y class="scroll-content" :show-scrollbar="false">
  6. <view class="form-body">
  7. <view class="section-card">
  8. <view class="section-title">反馈类型</view>
  9. <view class="type-grid">
  10. <view class="type-item" v-for="item in types" :key="item.value"
  11. :class="{ active: formData.type === item.value }" @click="formData.type = item.value">
  12. <text>{{ item.label }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="section-card">
  17. <view class="section-title">反馈内容</view>
  18. <textarea class="content-input" v-model="formData.content" placeholder="请详细描述您遇到的问题或改进建议..."
  19. maxlength="500"></textarea>
  20. <view class="word-count">{{ formData.content.length }}/500</view>
  21. </view>
  22. <view class="section-card">
  23. <view class="section-title">上传图片 (最多6张)</view>
  24. <view class="upload-grid">
  25. <view class="img-item" v-for="(img, index) in formData.images" :key="index">
  26. <image :src="img" mode="aspectFill" @click="previewImage(index)"></image>
  27. <view class="del-btn" @click.stop="removeImage(index)">
  28. <view class="close-icon">×</view>
  29. </view>
  30. </view>
  31. <view class="add-btn" v-if="formData.images.length < 6" @click="chooseImage">
  32. <text class="add-icon">+</text>
  33. <text class="add-txt">添加图片</text>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="bottom-placeholder"></view>
  39. </scroll-view>
  40. </view>
  41. <view class="footer-bar">
  42. <button class="submit-btn" :disabled="!isFormValid" @click="handleSubmit">提交反馈</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import ErpNavBar from '@/components/erp-nav-bar.vue';
  48. import { submitComplaint } from '@/api/system/complaint.js';
  49. import { getDictByType } from '@/api/system/dict.js';
  50. import { uploadFile } from '@/api/resource/oss.js';
  51. export default {
  52. components: { ErpNavBar },
  53. data() {
  54. return {
  55. types: [],
  56. uploading: false,
  57. imageOssMap: [],
  58. formData: {
  59. type: '',
  60. content: '',
  61. images: []
  62. }
  63. }
  64. },
  65. computed: {
  66. isFormValid() {
  67. return !this.uploading && this.formData.type && this.formData.content && this.formData.content.trim().length >= 1;
  68. }
  69. },
  70. onLoad() {
  71. this.loadTypes();
  72. },
  73. methods: {
  74. async loadTypes() {
  75. try {
  76. const res = await getDictByType('sys_complaint_type');
  77. if (res && res.data) {
  78. this.types = res.data.map(d => ({ label: d.dictLabel, value: d.dictValue }));
  79. if (this.types.length) this.formData.type = this.types[0].value;
  80. }
  81. } catch (e) {
  82. uni.showToast({ title: e || '加载反馈类型失败', icon: 'none' });
  83. this.types = [
  84. { label: '系统投诉', value: 'complaint' },
  85. { label: '改进建议', value: 'suggestion' },
  86. { label: '其他反馈', value: 'other' }
  87. ];
  88. this.formData.type = 'complaint';
  89. }
  90. },
  91. goBack() { uni.navigateBack(); },
  92. chooseImage() {
  93. const count = 6 - this.formData.images.length;
  94. uni.chooseImage({
  95. count,
  96. sizeType: ['compressed'],
  97. success: async (res) => {
  98. const paths = res.tempFilePaths;
  99. this.uploading = true;
  100. try {
  101. for (const path of paths) {
  102. const preview = path;
  103. const placeholderIndex = this.formData.images.length;
  104. this.formData.images.push(preview);
  105. this.imageOssMap.push(null);
  106. try {
  107. const uploadRes = await uploadFile(path);
  108. this.formData.images.splice(placeholderIndex, 1, uploadRes.url);
  109. this.imageOssMap.splice(placeholderIndex, 1, uploadRes.ossId);
  110. } catch (err) {
  111. this.formData.images.splice(placeholderIndex, 1);
  112. this.imageOssMap.splice(placeholderIndex, 1);
  113. uni.showToast({ title: err || '图片上传失败', icon: 'none' });
  114. }
  115. }
  116. } finally {
  117. this.uploading = false;
  118. }
  119. }
  120. });
  121. },
  122. removeImage(index) {
  123. this.formData.images.splice(index, 1);
  124. this.imageOssMap.splice(index, 1);
  125. },
  126. previewImage(index) {
  127. uni.previewImage({
  128. urls: this.formData.images,
  129. current: index
  130. });
  131. },
  132. async handleSubmit() {
  133. if (!this.isFormValid) return;
  134. try {
  135. uni.showLoading({ title: '提交中' });
  136. const payload = {
  137. feedbackType: this.formData.type,
  138. content: this.formData.content,
  139. images: this.imageOssMap.filter(id => id !== null).join(',')
  140. };
  141. await submitComplaint(payload);
  142. uni.hideLoading();
  143. uni.showToast({ title: '反馈成功', icon: 'success' });
  144. setTimeout(() => { uni.navigateBack(); }, 1500);
  145. } catch (e) {
  146. uni.hideLoading();
  147. uni.showToast({ title: e || '提交失败', icon: 'none' });
  148. }
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped>
  154. .complaint-root {
  155. width: 100vw;
  156. height: 100vh;
  157. background: #f8fafb;
  158. display: flex;
  159. flex-direction: column;
  160. overflow: hidden;
  161. }
  162. .scroll-container {
  163. flex: 1;
  164. height: 0;
  165. width: 100%;
  166. position: relative;
  167. }
  168. .scroll-content {
  169. width: 100%;
  170. height: 100%;
  171. }
  172. .form-body {
  173. padding: 30rpx;
  174. }
  175. .section-card {
  176. background: #fff;
  177. border-radius: 24rpx;
  178. padding: 40rpx 30rpx;
  179. margin-bottom: 30rpx;
  180. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.02);
  181. }
  182. .section-title {
  183. font-size: 30rpx;
  184. font-weight: bold;
  185. color: #1a1a1a;
  186. margin-bottom: 30rpx;
  187. border-left: 8rpx solid #C1001C;
  188. padding-left: 20rpx;
  189. line-height: 1.2;
  190. }
  191. .type-grid {
  192. display: flex;
  193. gap: 20rpx;
  194. }
  195. .type-item {
  196. flex: 1;
  197. height: 80rpx;
  198. background: #f5f6f8;
  199. border-radius: 12rpx;
  200. display: flex;
  201. align-items: center;
  202. justify-content: center;
  203. font-size: 28rpx;
  204. color: #666;
  205. border: 2rpx solid #f5f6f8;
  206. transition: all 0.2s;
  207. }
  208. .type-item.active {
  209. background: rgba(193, 0, 28, 0.05);
  210. color: #C1001C;
  211. border-color: #C1001C;
  212. font-weight: bold;
  213. }
  214. .content-input {
  215. width: 100%;
  216. height: 300rpx;
  217. background: #f9fafb;
  218. border-radius: 16rpx;
  219. padding: 24rpx;
  220. box-sizing: border-box;
  221. font-size: 30rpx;
  222. color: #333;
  223. }
  224. .word-count {
  225. text-align: right;
  226. font-size: 24rpx;
  227. color: #ccc;
  228. margin-top: 12rpx;
  229. }
  230. .upload-grid {
  231. display: grid;
  232. grid-template-columns: repeat(3, 1fr);
  233. gap: 20rpx;
  234. }
  235. .img-item {
  236. position: relative;
  237. width: 100%;
  238. padding-top: 100%;
  239. }
  240. .img-item image {
  241. position: absolute;
  242. top: 0;
  243. left: 0;
  244. width: 100%;
  245. height: 100%;
  246. border-radius: 16rpx;
  247. }
  248. .del-btn {
  249. position: absolute;
  250. top: -10rpx;
  251. right: -10rpx;
  252. width: 40rpx;
  253. height: 40rpx;
  254. background: rgba(0, 0, 0, 0.5);
  255. border-radius: 50%;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. z-index: 10;
  260. }
  261. .close-icon {
  262. color: #fff;
  263. font-size: 30rpx;
  264. line-height: 1;
  265. }
  266. .add-btn {
  267. width: 100%;
  268. padding-top: 100%;
  269. border: 2rpx dashed #ddd;
  270. border-radius: 16rpx;
  271. display: flex;
  272. flex-direction: column;
  273. align-items: center;
  274. justify-content: center;
  275. position: relative;
  276. background: #fcfcfc;
  277. }
  278. .add-icon {
  279. position: absolute;
  280. top: 35%;
  281. left: 50%;
  282. transform: translateX(-50%);
  283. font-size: 60rpx;
  284. color: #bbb;
  285. }
  286. .add-txt {
  287. position: absolute;
  288. bottom: 20%;
  289. left: 50%;
  290. transform: translateX(-50%);
  291. font-size: 22rpx;
  292. color: #999;
  293. }
  294. .footer-bar {
  295. background: #fff;
  296. padding: 30rpx 40rpx calc(30rpx + env(safe-area-inset-bottom));
  297. flex-shrink: 0;
  298. border-top: 1rpx solid #f0f0f0;
  299. }
  300. .submit-btn {
  301. width: 100%;
  302. height: 96rpx;
  303. background: #C1001C;
  304. color: #fff;
  305. border-radius: 48rpx;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. font-size: 32rpx;
  310. font-weight: bold;
  311. border: none;
  312. }
  313. .submit-btn[disabled] {
  314. background: #edb3bb !important;
  315. color: rgba(255, 255, 255, 0.6) !important;
  316. }
  317. .bottom-placeholder {
  318. height: 40rpx;
  319. }
  320. </style>