index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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 >= 5;
  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. this.types = [
  87. { label: '系统投诉', value: 'complaint' },
  88. { label: '改进建议', value: 'suggestion' },
  89. { label: '其他反馈', value: 'other' }
  90. ];
  91. this.formData.type = 'complaint';
  92. }
  93. },
  94. goBack() { uni.navigateBack(); },
  95. chooseImage() {
  96. const count = 6 - this.formData.images.length;
  97. uni.chooseImage({
  98. count,
  99. sizeType: ['compressed'],
  100. success: async (res) => {
  101. const paths = res.tempFilePaths;
  102. this.uploading = true;
  103. try {
  104. for (const path of paths) {
  105. const preview = path;
  106. const placeholderIndex = this.formData.images.length;
  107. this.formData.images.push(preview);
  108. this.imageOssMap.push(null);
  109. try {
  110. const uploadRes = await uploadFile(path);
  111. this.formData.images.splice(placeholderIndex, 1, uploadRes.url);
  112. this.imageOssMap.splice(placeholderIndex, 1, uploadRes.ossId);
  113. } catch (err) {
  114. this.formData.images.splice(placeholderIndex, 1);
  115. this.imageOssMap.splice(placeholderIndex, 1);
  116. uni.showToast({ title: '图片上传失败', icon: 'none' });
  117. }
  118. }
  119. } finally {
  120. this.uploading = false;
  121. }
  122. }
  123. });
  124. },
  125. removeImage(index) {
  126. this.formData.images.splice(index, 1);
  127. this.imageOssMap.splice(index, 1);
  128. },
  129. previewImage(index) {
  130. uni.previewImage({
  131. urls: this.formData.images,
  132. current: index
  133. });
  134. },
  135. async handleSubmit() {
  136. if (!this.isFormValid) return;
  137. try {
  138. uni.showLoading({ title: '提交中' });
  139. const payload = {
  140. feedbackType: this.formData.type,
  141. content: this.formData.content,
  142. images: this.imageOssMap.filter(id => id !== null).join(',')
  143. };
  144. await submitComplaint(payload);
  145. uni.hideLoading();
  146. uni.showToast({ title: '反馈成功', icon: 'success' });
  147. setTimeout(() => { uni.navigateBack(); }, 1500);
  148. } catch (e) {
  149. uni.hideLoading();
  150. uni.showToast({ title: e.message || '提交失败', icon: 'none' });
  151. }
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped>
  157. .complaint-root {
  158. width: 100vw;
  159. height: 100vh;
  160. background: #f8fafb;
  161. display: flex;
  162. flex-direction: column;
  163. overflow: hidden;
  164. }
  165. .custom-navbar {
  166. background: #fff;
  167. width: 100%;
  168. flex-shrink: 0;
  169. border-bottom: 1rpx solid #f0f0f0;
  170. }
  171. .nav-content {
  172. height: 44px;
  173. display: flex;
  174. align-items: center;
  175. justify-content: space-between;
  176. padding: 0 30rpx;
  177. }
  178. .back-area {
  179. width: 60rpx;
  180. height: 44px;
  181. display: flex;
  182. align-items: center;
  183. }
  184. .back-arrow {
  185. width: 22rpx;
  186. height: 22rpx;
  187. border-left: 4rpx solid #333;
  188. border-bottom: 4rpx solid #333;
  189. transform: rotate(45deg);
  190. margin-left: 10rpx;
  191. }
  192. .nav-title {
  193. font-size: 34rpx;
  194. font-weight: bold;
  195. color: #333;
  196. }
  197. .right-placeholder {
  198. width: 60rpx;
  199. }
  200. .scroll-container {
  201. flex: 1;
  202. height: 0;
  203. width: 100%;
  204. position: relative;
  205. }
  206. .scroll-content {
  207. width: 100%;
  208. height: 100%;
  209. }
  210. .form-body {
  211. padding: 30rpx;
  212. }
  213. .section-card {
  214. background: #fff;
  215. border-radius: 24rpx;
  216. padding: 40rpx 30rpx;
  217. margin-bottom: 30rpx;
  218. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.02);
  219. }
  220. .section-title {
  221. font-size: 30rpx;
  222. font-weight: bold;
  223. color: #1a1a1a;
  224. margin-bottom: 30rpx;
  225. border-left: 8rpx solid #C1001C;
  226. padding-left: 20rpx;
  227. line-height: 1.2;
  228. }
  229. .type-grid {
  230. display: flex;
  231. gap: 20rpx;
  232. }
  233. .type-item {
  234. flex: 1;
  235. height: 80rpx;
  236. background: #f5f6f8;
  237. border-radius: 12rpx;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. font-size: 28rpx;
  242. color: #666;
  243. border: 2rpx solid #f5f6f8;
  244. transition: all 0.2s;
  245. }
  246. .type-item.active {
  247. background: rgba(193, 0, 28, 0.05);
  248. color: #C1001C;
  249. border-color: #C1001C;
  250. font-weight: bold;
  251. }
  252. .content-input {
  253. width: 100%;
  254. height: 300rpx;
  255. background: #f9fafb;
  256. border-radius: 16rpx;
  257. padding: 24rpx;
  258. box-sizing: border-box;
  259. font-size: 30rpx;
  260. color: #333;
  261. }
  262. .word-count {
  263. text-align: right;
  264. font-size: 24rpx;
  265. color: #ccc;
  266. margin-top: 12rpx;
  267. }
  268. .upload-grid {
  269. display: grid;
  270. grid-template-columns: repeat(3, 1fr);
  271. gap: 20rpx;
  272. }
  273. .img-item {
  274. position: relative;
  275. width: 100%;
  276. padding-top: 100%;
  277. }
  278. .img-item image {
  279. position: absolute;
  280. top: 0;
  281. left: 0;
  282. width: 100%;
  283. height: 100%;
  284. border-radius: 16rpx;
  285. }
  286. .del-btn {
  287. position: absolute;
  288. top: -10rpx;
  289. right: -10rpx;
  290. width: 40rpx;
  291. height: 40rpx;
  292. background: rgba(0, 0, 0, 0.5);
  293. border-radius: 50%;
  294. display: flex;
  295. align-items: center;
  296. justify-content: center;
  297. z-index: 10;
  298. }
  299. .close-icon {
  300. color: #fff;
  301. font-size: 30rpx;
  302. line-height: 1;
  303. }
  304. .add-btn {
  305. width: 100%;
  306. padding-top: 100%;
  307. border: 2rpx dashed #ddd;
  308. border-radius: 16rpx;
  309. display: flex;
  310. flex-direction: column;
  311. align-items: center;
  312. justify-content: center;
  313. position: relative;
  314. background: #fcfcfc;
  315. }
  316. .add-icon {
  317. position: absolute;
  318. top: 35%;
  319. left: 50%;
  320. transform: translateX(-50%);
  321. font-size: 60rpx;
  322. color: #bbb;
  323. }
  324. .add-txt {
  325. position: absolute;
  326. bottom: 20%;
  327. left: 50%;
  328. transform: translateX(-50%);
  329. font-size: 22rpx;
  330. color: #999;
  331. }
  332. .footer-bar {
  333. background: #fff;
  334. padding: 30rpx 40rpx calc(30rpx + env(safe-area-inset-bottom));
  335. flex-shrink: 0;
  336. border-top: 1rpx solid #f0f0f0;
  337. }
  338. .submit-btn {
  339. width: 100%;
  340. height: 96rpx;
  341. background: #C1001C;
  342. color: #fff;
  343. border-radius: 48rpx;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. font-size: 32rpx;
  348. font-weight: bold;
  349. border: none;
  350. }
  351. .submit-btn[disabled] {
  352. background: #edb3bb !important;
  353. color: rgba(255, 255, 255, 0.6) !important;
  354. }
  355. .bottom-placeholder {
  356. height: 40rpx;
  357. }
  358. </style>