index.vue 8.2 KB

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