index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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" :loading="submitting">
  61. {{ praiseFlag ? '确认赞' : '确认不赞' }}
  62. </button>
  63. </view>
  64. </view>
  65. </template>
  66. <script setup>
  67. import { ref } from 'vue'
  68. import { onLoad } from '@dcloudio/uni-app'
  69. import navBar from '@/components/nav-bar/index.vue'
  70. import { addComplaint } from '@/api/fulfiller/complaint'
  71. import { BASE_URL, DEFAULT_HEADERS } from '@/utils/config'
  72. /**
  73. * 投诉/评价提交页面 (参考网页端设计)
  74. * @Author: Antigravity
  75. */
  76. const orderId = ref('')
  77. const orderCode = ref('')
  78. const fulfillerId = ref('')
  79. const praiseFlag = ref(false)
  80. const reason = ref('')
  81. const imageList = ref([])
  82. const submitting = ref(false)
  83. onLoad((options) => {
  84. if (options.orderId) orderId.value = options.orderId
  85. if (options.orderCode) orderCode.value = options.orderCode
  86. if (options.fulfillerId) fulfillerId.value = options.fulfillerId
  87. })
  88. // 选择图片
  89. const chooseImage = () => {
  90. uni.chooseImage({
  91. count: 6 - imageList.value.length,
  92. sizeType: ['compressed'],
  93. success: (res) => {
  94. const tempFiles = res.tempFiles
  95. uploadFiles(tempFiles)
  96. }
  97. })
  98. }
  99. // 上传图片到服务器
  100. const uploadFiles = (tempFiles) => {
  101. uni.showLoading({ title: '上传中...' })
  102. const token = uni.getStorageSync('token') || ''
  103. const uploadPromises = tempFiles.map(file => {
  104. return new Promise((resolve, reject) => {
  105. uni.uploadFile({
  106. url: BASE_URL + '/resource/oss/upload',
  107. filePath: file.path,
  108. name: 'file',
  109. header: {
  110. ...DEFAULT_HEADERS,
  111. 'Authorization': `Bearer ${token}`
  112. },
  113. success: (res) => {
  114. const data = JSON.parse(res.data)
  115. if (data.code === 200) {
  116. resolve(data.data.url)
  117. } else {
  118. reject(data.msg || '上传失败')
  119. }
  120. },
  121. fail: (err) => reject('请求失败')
  122. })
  123. })
  124. })
  125. Promise.all(uploadPromises).then(urls => {
  126. imageList.value = [...imageList.value, ...urls]
  127. uni.hideLoading()
  128. }).catch(err => {
  129. uni.hideLoading()
  130. uni.showToast({ title: String(err), icon: 'none' })
  131. })
  132. }
  133. const previewImage = (index) => {
  134. uni.previewImage({
  135. current: index,
  136. urls: imageList.value
  137. })
  138. }
  139. const removeImage = (index) => {
  140. imageList.value.splice(index, 1)
  141. }
  142. const handleConfirmSubmit = async () => {
  143. if (!reason.value.trim()) {
  144. uni.showToast({ title: praiseFlag.value ? '请输入评价内容' : '请输入投诉原因', icon: 'none' })
  145. return
  146. }
  147. if (!orderId.value || !fulfillerId.value) {
  148. uni.showToast({ title: '订单数据不完整,无法提交', icon: 'none' })
  149. return
  150. }
  151. submitting.value = true
  152. try {
  153. const payload = {
  154. orderId: orderId.value,
  155. fulfiller: fulfillerId.value,
  156. reason: reason.value,
  157. photos: imageList.value.join(','),
  158. praiseFlag: praiseFlag.value
  159. }
  160. await addComplaint(payload)
  161. uni.showToast({ title: '提交成功', icon: 'success' })
  162. setTimeout(() => {
  163. uni.navigateBack()
  164. }, 1500)
  165. } catch (error) {
  166. console.error('提交失败:', error)
  167. // 500提示已经在全局处理
  168. } finally {
  169. submitting.value = false
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .complaint-submit-page {
  175. min-height: 100vh;
  176. background-color: #f8f9fb;
  177. }
  178. .page-content {
  179. padding: 30rpx;
  180. }
  181. .card-shadow {
  182. background: #fff;
  183. border-radius: 24rpx;
  184. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.02);
  185. margin-bottom: 30rpx;
  186. }
  187. /* 类型切换卡片 */
  188. .type-card {
  189. display: flex;
  190. align-items: center;
  191. height: 140rpx;
  192. padding: 0 16rpx;
  193. .type-item {
  194. flex: 1;
  195. display: flex;
  196. flex-direction: column;
  197. align-items: center;
  198. justify-content: center;
  199. gap: 8rpx;
  200. transition: all 0.3s;
  201. height: 110rpx;
  202. border-radius: 20rpx;
  203. &.active {
  204. background-color: #f6f6f6;
  205. .type-text { font-weight: bold; color: #333; font-size: 30rpx; }
  206. .type-emoji { transform: scale(1.3); }
  207. .type-sub { opacity: 1; }
  208. }
  209. .icon-wrap {
  210. width: 64rpx; height: 64rpx; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  211. }
  212. .icon-wrap.bad { background: rgba(244,67,54,0.08); }
  213. .icon-wrap.good { background: rgba(76,175,80,0.08); }
  214. .type-emoji { font-size: 36rpx; line-height: 1; transition: transform 0.3s ease; }
  215. .type-text { font-size: 28rpx; color: #999; transition: all 0.3s; }
  216. .type-sub { font-size: 20rpx; color: #bbb; opacity: 0; transition: opacity 0.3s; }
  217. }
  218. .type-divider { width: 2rpx; height: 60rpx; background: linear-gradient(180deg, transparent, #EEEEEE, transparent); border-radius: 2rpx; }
  219. }
  220. /* 表单板块 */
  221. .form-section {
  222. padding: 32rpx;
  223. .section-title {
  224. display: flex; align-items: center; gap: 12rpx; margin-bottom: 24rpx;
  225. .title-text { font-size: 30rpx; font-weight: bold; color: #333; }
  226. .title-tip {
  227. font-size: 20rpx; color: #F44336; background: rgba(244,67,54,0.1);
  228. padding: 2rpx 10rpx; border-radius: 4rpx;
  229. &.gray { color: #999; background: #f5f5f5; }
  230. }
  231. }
  232. .content-textarea {
  233. width: 100%; height: 260rpx; font-size: 28rpx; color: #333; line-height: 1.6;
  234. background-color: #fafafa; border-radius: 16rpx; padding: 20rpx; box-sizing: border-box;
  235. }
  236. .word-count { text-align: right; font-size: 22rpx; color: #ccc; margin-top: 12rpx; }
  237. }
  238. /* 图片上传网格 */
  239. .upload-grid {
  240. display: grid;
  241. grid-template-columns: repeat(3, 1fr);
  242. gap: 20rpx;
  243. .upload-item {
  244. position: relative; aspect-ratio: 1; border-radius: 12rpx; overflow: hidden;
  245. image { width: 100%; height: 100%; }
  246. .delete-icon {
  247. position: absolute; right: 0; top: 0; width: 36rpx; height: 36rpx;
  248. background: rgba(0,0,0,0.5); border-bottom-left-radius: 12rpx;
  249. display: flex; align-items: center; justify-content: center;
  250. }
  251. }
  252. .upload-add {
  253. aspect-ratio: 1; border-radius: 12rpx; border: 2rpx dashed #EEEEEE;
  254. display: flex; flex-direction: column; align-items: center; justify-content: center;
  255. background: #fafafa;
  256. .add-text { font-size: 22rpx; color: #ccc; margin-top: 8rpx; }
  257. }
  258. }
  259. .order-info-bar {
  260. padding: 10rpx 0; font-size: 24rpx; color: #bbb; text-align: center;
  261. }
  262. /* 底部按钮 */
  263. .bottom-bar {
  264. position: fixed; left: 0; right: 0; bottom: 0;
  265. background: #fff; padding: 24rpx 40rpx; padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  266. box-shadow: 0 -4rpx 16rpx rgba(0,0,0,0.03);
  267. .submit-btn {
  268. height: 96rpx; line-height: 96rpx; border-radius: 48rpx;
  269. background: #333; color: #fff; font-size: 32rpx; font-weight: bold; border: none;
  270. transition: all 0.3s;
  271. &::after { border: none; }
  272. &.is-praise { background: #FF9500; color: #fff; }
  273. &:active { transform: scale(0.98); opacity: 0.9; }
  274. }
  275. }
  276. </style>