index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="complaint-submit-page">
  3. <nav-bar :title="praiseFlag ? '发表评价' : '提交投诉'" color="#000"></nav-bar>
  4. <view class="page-content">
  5. <!-- 评价类型切换 -->
  6. <view class="type-card card-shadow">
  7. <view class="type-item" :class="{ 'active': !praiseFlag }" @click="praiseFlag = false">
  8. <view class="icon-wrap bad">
  9. <text class="type-emoji">{{ !praiseFlag ? '👎' : '👎🏻' }}</text>
  10. </view>
  11. <text class="type-text">不赞</text>
  12. <text class="type-sub" v-if="!praiseFlag">投诉</text>
  13. </view>
  14. <view class="type-divider"></view>
  15. <view class="type-item" :class="{ 'active': praiseFlag }" @click="praiseFlag = true">
  16. <view class="icon-wrap good">
  17. <text class="type-emoji">{{ praiseFlag ? '👍' : '👍🏻' }}</text>
  18. </view>
  19. <text class="type-text">赞</text>
  20. <text class="type-sub" v-if="praiseFlag">好评</text>
  21. </view>
  22. </view>
  23. <!-- 内容输入 -->
  24. <view class="form-section card-shadow">
  25. <view class="section-title">
  26. <text class="title-text">{{ praiseFlag ? '评价详情' : '投诉原因' }}</text>
  27. <text class="title-tip">必填</text>
  28. </view>
  29. <textarea class="content-textarea" v-model="reason"
  30. :placeholder="praiseFlag ? '请记录您的满意点,帮助履约师提升服务质量...' : '请详细描述您遇到的问题,我们会尽快为您处理...'"
  31. maxlength="500"></textarea>
  32. <view class="word-count">{{ reason.length }}/500</view>
  33. </view>
  34. <!-- 图片上传 -->
  35. <view class="form-section card-shadow">
  36. <view class="section-title">
  37. <text class="title-text">凭证图片</text>
  38. <text class="title-tip gray">最多6张</text>
  39. </view>
  40. <view class="upload-grid">
  41. <view class="upload-item" v-for="(img, index) in imageList" :key="index">
  42. <image :src="img" mode="aspectFill" @click="previewImage(index)"></image>
  43. <view class="delete-icon" @click.stop="removeImage(index)">
  44. <uni-icons type="closeempty" size="12" color="#fff"></uni-icons>
  45. </view>
  46. </view>
  47. <view class="upload-add" v-if="imageList.length < 6" @click="chooseImage">
  48. <uni-icons type="plusempty" size="32" color="#ccc"></uni-icons>
  49. <text class="add-text">上传凭证</text>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 订单信息提示 -->
  54. <view class="order-info-bar">
  55. <text>关联订单:{{ orderCode }}</text>
  56. </view>
  57. </view>
  58. <!-- 底部按钮 -->
  59. <view class="bottom-bar">
  60. <button class="submit-btn" :class="{ 'is-praise': praiseFlag }" @click="handleConfirmSubmit"
  61. :loading="submitting">
  62. {{ praiseFlag ? '确认赞' : '确认不赞' }}
  63. </button>
  64. </view>
  65. </view>
  66. </template>
  67. <script setup>
  68. import { ref } from 'vue'
  69. import { onLoad } from '@dcloudio/uni-app'
  70. import navBar from '@/components/nav-bar/index.vue'
  71. import { addComplaint } from '@/api/fulfiller/complaint'
  72. import { BASE_URL, DEFAULT_HEADERS } from '@/utils/config'
  73. /**
  74. * 投诉/评价提交页面 (参考网页端设计)
  75. * @Author: Antigravity
  76. */
  77. const orderId = ref('')
  78. const orderCode = ref('')
  79. const fulfillerId = ref('')
  80. const praiseFlag = ref(false)
  81. const reason = ref('')
  82. const imageList = ref([]) // 预览用 URL 列表
  83. const ossIdList = ref([]) // 提交用 OSS ID 列表
  84. const submitting = ref(false)
  85. onLoad((options) => {
  86. if (options.orderId) orderId.value = options.orderId
  87. if (options.orderCode) orderCode.value = options.orderCode
  88. if (options.fulfillerId) fulfillerId.value = options.fulfillerId
  89. })
  90. // 选择图片
  91. const chooseImage = () => {
  92. uni.chooseImage({
  93. count: 6 - imageList.value.length,
  94. sizeType: ['compressed'],
  95. success: (res) => {
  96. const tempFiles = res.tempFiles
  97. uploadFiles(tempFiles)
  98. }
  99. })
  100. }
  101. // 上传图片到服务器
  102. const uploadFiles = (tempFiles) => {
  103. uni.showLoading({ title: '上传中...' })
  104. const token = uni.getStorageSync('token') || ''
  105. const uploadPromises = tempFiles.map(file => {
  106. return new Promise((resolve, reject) => {
  107. uni.uploadFile({
  108. url: BASE_URL + '/resource/oss/upload',
  109. filePath: file.path,
  110. name: 'file',
  111. header: {
  112. ...DEFAULT_HEADERS,
  113. 'Authorization': `Bearer ${token}`
  114. },
  115. success: (res) => {
  116. const data = JSON.parse(res.data)
  117. if (data.code === 200) {
  118. resolve({ url: data.data.url, ossId: data.data.ossId })
  119. } else {
  120. reject(data.msg || '上传失败')
  121. }
  122. },
  123. fail: (err) => reject('请求失败')
  124. })
  125. })
  126. })
  127. Promise.all(uploadPromises).then(results => {
  128. imageList.value = [...imageList.value, ...results.map(r => r.url)]
  129. ossIdList.value = [...ossIdList.value, ...results.map(r => r.ossId)]
  130. uni.hideLoading()
  131. }).catch(err => {
  132. uni.hideLoading()
  133. uni.showToast({ title: String(err), icon: 'none' })
  134. })
  135. }
  136. const previewImage = (index) => {
  137. uni.previewImage({
  138. current: index,
  139. urls: imageList.value
  140. })
  141. }
  142. const removeImage = (index) => {
  143. imageList.value.splice(index, 1)
  144. ossIdList.value.splice(index, 1)
  145. }
  146. const handleConfirmSubmit = async () => {
  147. if (!reason.value.trim()) {
  148. uni.showToast({ title: praiseFlag.value ? '请输入评价内容' : '请输入投诉原因', icon: 'none' })
  149. return
  150. }
  151. if (!orderId.value || !fulfillerId.value) {
  152. uni.showToast({ title: '订单数据不完整,无法提交', icon: 'none' })
  153. return
  154. }
  155. submitting.value = true
  156. try {
  157. const payload = {
  158. orderId: orderId.value,
  159. fulfiller: fulfillerId.value,
  160. reason: reason.value,
  161. photos: ossIdList.value.join(','),
  162. praiseFlag: praiseFlag.value
  163. }
  164. await addComplaint(payload)
  165. uni.showToast({ title: '提交成功', icon: 'success' })
  166. setTimeout(() => {
  167. uni.navigateBack()
  168. }, 1500)
  169. } catch (error) {
  170. console.error('提交失败:', error)
  171. // 500提示已经在全局处理
  172. } finally {
  173. submitting.value = false
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .complaint-submit-page {
  179. min-height: 100vh;
  180. background-color: #f8f9fb;
  181. }
  182. .page-content {
  183. padding: 30rpx;
  184. }
  185. .card-shadow {
  186. background: #fff;
  187. border-radius: 24rpx;
  188. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.02);
  189. margin-bottom: 30rpx;
  190. }
  191. /* 类型切换卡片 */
  192. .type-card {
  193. display: flex;
  194. align-items: center;
  195. height: 140rpx;
  196. padding: 0 16rpx;
  197. .type-item {
  198. flex: 1;
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. justify-content: center;
  203. gap: 8rpx;
  204. transition: all 0.3s;
  205. height: 110rpx;
  206. border-radius: 20rpx;
  207. &.active {
  208. background-color: #f6f6f6;
  209. .type-text {
  210. font-weight: bold;
  211. color: #333;
  212. font-size: 30rpx;
  213. }
  214. .type-emoji {
  215. transform: scale(1.3);
  216. }
  217. .type-sub {
  218. opacity: 1;
  219. }
  220. }
  221. .icon-wrap {
  222. width: 64rpx;
  223. height: 64rpx;
  224. border-radius: 50%;
  225. display: flex;
  226. align-items: center;
  227. justify-content: center;
  228. }
  229. .icon-wrap.bad {
  230. background: rgba(244, 67, 54, 0.08);
  231. }
  232. .icon-wrap.good {
  233. background: rgba(76, 175, 80, 0.08);
  234. }
  235. .type-emoji {
  236. font-size: 36rpx;
  237. line-height: 1;
  238. transition: transform 0.3s ease;
  239. }
  240. .type-text {
  241. font-size: 28rpx;
  242. color: #999;
  243. transition: all 0.3s;
  244. }
  245. .type-sub {
  246. font-size: 20rpx;
  247. color: #bbb;
  248. opacity: 0;
  249. transition: opacity 0.3s;
  250. }
  251. }
  252. .type-divider {
  253. width: 2rpx;
  254. height: 60rpx;
  255. background: linear-gradient(180deg, transparent, #EEEEEE, transparent);
  256. border-radius: 2rpx;
  257. }
  258. }
  259. /* 表单板块 */
  260. .form-section {
  261. padding: 32rpx;
  262. .section-title {
  263. display: flex;
  264. align-items: center;
  265. gap: 12rpx;
  266. margin-bottom: 24rpx;
  267. .title-text {
  268. font-size: 30rpx;
  269. font-weight: bold;
  270. color: #333;
  271. }
  272. .title-tip {
  273. font-size: 20rpx;
  274. color: #F44336;
  275. background: rgba(244, 67, 54, 0.1);
  276. padding: 2rpx 10rpx;
  277. border-radius: 4rpx;
  278. &.gray {
  279. color: #999;
  280. background: #f5f5f5;
  281. }
  282. }
  283. }
  284. .content-textarea {
  285. width: 100%;
  286. height: 260rpx;
  287. font-size: 28rpx;
  288. color: #333;
  289. line-height: 1.6;
  290. background-color: #fafafa;
  291. border-radius: 16rpx;
  292. padding: 20rpx;
  293. box-sizing: border-box;
  294. }
  295. .word-count {
  296. text-align: right;
  297. font-size: 22rpx;
  298. color: #ccc;
  299. margin-top: 12rpx;
  300. }
  301. }
  302. /* 图片上传网格 */
  303. .upload-grid {
  304. display: grid;
  305. grid-template-columns: repeat(3, 1fr);
  306. gap: 20rpx;
  307. .upload-item {
  308. position: relative;
  309. aspect-ratio: 1;
  310. border-radius: 12rpx;
  311. overflow: hidden;
  312. image {
  313. width: 100%;
  314. height: 100%;
  315. }
  316. .delete-icon {
  317. position: absolute;
  318. right: 0;
  319. top: 0;
  320. width: 36rpx;
  321. height: 36rpx;
  322. background: rgba(0, 0, 0, 0.5);
  323. border-bottom-left-radius: 12rpx;
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. }
  328. }
  329. .upload-add {
  330. aspect-ratio: 1;
  331. border-radius: 12rpx;
  332. border: 2rpx dashed #EEEEEE;
  333. display: flex;
  334. flex-direction: column;
  335. align-items: center;
  336. justify-content: center;
  337. background: #fafafa;
  338. .add-text {
  339. font-size: 22rpx;
  340. color: #ccc;
  341. margin-top: 8rpx;
  342. }
  343. }
  344. }
  345. .order-info-bar {
  346. padding: 10rpx 0;
  347. font-size: 24rpx;
  348. color: #bbb;
  349. text-align: center;
  350. }
  351. /* 底部按钮 */
  352. .bottom-bar {
  353. position: fixed;
  354. left: 0;
  355. right: 0;
  356. bottom: 0;
  357. background: #fff;
  358. padding: 24rpx 40rpx;
  359. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  360. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.03);
  361. .submit-btn {
  362. height: 96rpx;
  363. line-height: 96rpx;
  364. border-radius: 48rpx;
  365. background: #333;
  366. color: #fff;
  367. font-size: 32rpx;
  368. font-weight: bold;
  369. border: none;
  370. transition: all 0.3s;
  371. &::after {
  372. border: none;
  373. }
  374. &.is-praise {
  375. background: #FF9500;
  376. color: #fff;
  377. }
  378. &:active {
  379. transform: scale(0.98);
  380. opacity: 0.9;
  381. }
  382. }
  383. }
  384. </style>