rating.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="container">
  3. <!-- 头部 -->
  4. <view class="header">
  5. <text class="title">服务评价</text>
  6. <text class="subtitle">请对我们的服务进行评价</text>
  7. </view>
  8. <!-- 加载状态 -->
  9. <view v-if="loading" class="loading">
  10. <text>加载中...</text>
  11. </view>
  12. <!-- 评价表单 -->
  13. <view v-if="!loading && execution" class="rating-form">
  14. <!-- 评估师评价 -->
  15. <view v-if="execution.assessorId" class="rating-section">
  16. <view class="section-header">
  17. <view class="section-icon assessor-section-icon"></view>
  18. <text class="section-title">评估师服务评价</text>
  19. </view>
  20. <view class="rating-stars">
  21. <text class="star-label">评分:</text>
  22. <view class="stars">
  23. <text
  24. v-for="i in 5"
  25. :key="i"
  26. class="star"
  27. :class="{ active: assessorRating >= i }"
  28. @click="setAssessorRating(i)">
  29. </text>
  30. </view>
  31. <text v-if="assessorRating > 0" class="rating-text">{{ ratingTexts[assessorRating - 1] }}</text>
  32. </view>
  33. <view class="comment-input">
  34. <textarea
  35. v-model="assessorComment"
  36. placeholder="请分享您的服务体验(选填)"
  37. maxlength="500"
  38. class="textarea"
  39. />
  40. </view>
  41. </view>
  42. <!-- 规划师评价 -->
  43. <view v-if="execution.plannerId" class="rating-section">
  44. <view class="section-header">
  45. <view class="section-icon planner-section-icon"></view>
  46. <text class="section-title">规划师服务评价</text>
  47. </view>
  48. <view class="rating-stars">
  49. <text class="star-label">评分:</text>
  50. <view class="stars">
  51. <text
  52. v-for="i in 5"
  53. :key="i"
  54. class="star"
  55. :class="{ active: plannerRating >= i }"
  56. @click="setPlannerRating(i)">
  57. </text>
  58. </view>
  59. <text v-if="plannerRating > 0" class="rating-text">{{ ratingTexts[plannerRating - 1] }}</text>
  60. </view>
  61. <view class="comment-input">
  62. <textarea
  63. v-model="plannerComment"
  64. placeholder="请分享您的服务体验(选填)"
  65. maxlength="500"
  66. class="textarea"
  67. />
  68. </view>
  69. </view>
  70. <!-- 提交按钮 -->
  71. <view class="actions">
  72. <button class="btn-primary" @click="submitRating" :disabled="!canSubmit">
  73. 提交评价
  74. </button>
  75. <button class="btn-outline" @click="goBack">
  76. 返回
  77. </button>
  78. </view>
  79. </view>
  80. <!-- 无数据 -->
  81. <view v-if="!loading && !execution" class="empty">
  82. <text>暂无可评价的服务</text>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import config from '@/config.js'
  88. export default {
  89. data() {
  90. return {
  91. executionId: null,
  92. execution: null,
  93. loading: true,
  94. assessorRating: 0,
  95. assessorComment: '',
  96. plannerRating: 0,
  97. plannerComment: '',
  98. ratingTexts: ['很差', '较差', '一般', '满意', '非常满意']
  99. }
  100. },
  101. computed: {
  102. canSubmit() {
  103. // 至少评估师评分必须填写
  104. return this.assessorRating > 0
  105. }
  106. },
  107. onLoad(options) {
  108. if (options.executionId) {
  109. this.executionId = options.executionId
  110. this.loadExecution()
  111. }
  112. },
  113. methods: {
  114. async loadExecution() {
  115. this.loading = true
  116. try {
  117. const res = await uni.request({
  118. url: `${config.API_BASE_URL}/api/dan-execution/detail`,
  119. method: 'POST',
  120. data: { executionId: this.executionId },
  121. header: {
  122. 'Authorization': `Bearer ${uni.getStorageSync('token')}`,
  123. 'Content-Type': 'application/json'
  124. }
  125. })
  126. if (res.data.code === 200) {
  127. this.execution = res.data.data
  128. } else {
  129. uni.showToast({ title: res.data.message || '加载失败', icon: 'none' })
  130. }
  131. } catch (e) {
  132. console.error('加载执行记录失败', e)
  133. uni.showToast({ title: '网络错误', icon: 'none' })
  134. } finally {
  135. this.loading = false
  136. }
  137. },
  138. setAssessorRating(rating) {
  139. this.assessorRating = rating
  140. },
  141. setPlannerRating(rating) {
  142. this.plannerRating = rating
  143. },
  144. async submitRating() {
  145. if (!this.canSubmit) {
  146. uni.showToast({ title: '请至少为评估师评分', icon: 'none' })
  147. return
  148. }
  149. try {
  150. const data = {
  151. executionId: this.executionId,
  152. assessorId: this.execution.assessorId,
  153. assessorRating: this.assessorRating,
  154. assessorComment: this.assessorComment
  155. }
  156. if (this.execution.plannerId) {
  157. data.plannerId = this.execution.plannerId
  158. data.plannerRating = this.plannerRating
  159. data.plannerComment = this.plannerComment
  160. }
  161. const res = await uni.request({
  162. url: `${config.API_BASE_URL}/api/dan-execution/rate`,
  163. method: 'POST',
  164. header: {
  165. 'Authorization': `Bearer ${uni.getStorageSync('token')}`,
  166. 'Content-Type': 'application/json'
  167. },
  168. data: data
  169. })
  170. if (res.data.code === 200) {
  171. uni.showToast({ title: '评价成功', icon: 'success' })
  172. setTimeout(() => {
  173. uni.navigateBack()
  174. }, 1500)
  175. } else {
  176. uni.showToast({ title: res.data.message || '评价失败', icon: 'none' })
  177. }
  178. } catch (e) {
  179. console.error('提交评价失败', e)
  180. uni.showToast({ title: '网络错误', icon: 'none' })
  181. }
  182. },
  183. goBack() {
  184. uni.navigateBack()
  185. }
  186. }
  187. }
  188. </script>
  189. <style scoped>
  190. .container {
  191. padding: 40rpx;
  192. background: #f5f5f5;
  193. min-height: 100vh;
  194. }
  195. .header {
  196. margin-bottom: 40rpx;
  197. }
  198. .title {
  199. font-size: 40rpx;
  200. font-weight: bold;
  201. color: #333;
  202. display: block;
  203. margin-bottom: 10rpx;
  204. }
  205. .subtitle {
  206. font-size: 28rpx;
  207. color: #999;
  208. }
  209. .loading, .empty {
  210. text-align: center;
  211. padding: 100rpx 0;
  212. color: #999;
  213. }
  214. .rating-section {
  215. background: white;
  216. border-radius: 20rpx;
  217. padding: 40rpx;
  218. margin-bottom: 30rpx;
  219. }
  220. .section-header {
  221. display: flex;
  222. align-items: center;
  223. margin-bottom: 30rpx;
  224. }
  225. .section-icon {
  226. width: 48rpx;
  227. height: 48rpx;
  228. border-radius: 12rpx;
  229. margin-right: 16rpx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. position: relative;
  234. }
  235. .assessor-section-icon {
  236. background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  237. }
  238. .assessor-section-icon::after {
  239. content: '';
  240. width: 20rpx;
  241. height: 20rpx;
  242. border: 4rpx solid #2196f3;
  243. border-radius: 50%;
  244. position: absolute;
  245. }
  246. .planner-section-icon {
  247. background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  248. }
  249. .planner-section-icon::after {
  250. content: '';
  251. width: 20rpx;
  252. height: 20rpx;
  253. border: 4rpx solid #4caf50;
  254. border-radius: 50%;
  255. position: absolute;
  256. }
  257. .section-title {
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. color: #333;
  261. }
  262. .rating-stars {
  263. display: flex;
  264. align-items: center;
  265. margin-bottom: 30rpx;
  266. }
  267. .star-label {
  268. font-size: 28rpx;
  269. color: #666;
  270. margin-right: 20rpx;
  271. }
  272. .stars {
  273. display: flex;
  274. gap: 12rpx;
  275. }
  276. .star {
  277. font-size: 60rpx;
  278. color: #e0e0e0;
  279. transition: color 0.2s ease, text-shadow 0.2s ease;
  280. line-height: 1;
  281. }
  282. .star:active {
  283. transform: scale(1.15);
  284. }
  285. .star.active {
  286. color: #ffc107;
  287. text-shadow: 0 0 8rpx rgba(255, 193, 7, 0.4);
  288. }
  289. .rating-text {
  290. font-size: 24rpx;
  291. color: #ff9800;
  292. margin-left: 16rpx;
  293. font-weight: bold;
  294. }
  295. .comment-input {
  296. margin-top: 20rpx;
  297. }
  298. .textarea {
  299. width: 100%;
  300. min-height: 200rpx;
  301. padding: 20rpx;
  302. border: 2rpx solid #e0e0e0;
  303. border-radius: 10rpx;
  304. font-size: 28rpx;
  305. box-sizing: border-box;
  306. }
  307. .actions {
  308. display: flex;
  309. flex-direction: column;
  310. gap: 20rpx;
  311. margin-top: 40rpx;
  312. }
  313. .btn-primary, .btn-outline {
  314. border-radius: 20rpx;
  315. font-size: 32rpx;
  316. padding: 30rpx;
  317. text-align: center;
  318. }
  319. .btn-primary {
  320. background: #1E3A5F;
  321. color: white;
  322. border: none;
  323. }
  324. .btn-primary:disabled {
  325. background: #ccc;
  326. }
  327. .btn-outline {
  328. background: white;
  329. color: #666;
  330. border: 2rpx solid #ddd;
  331. }
  332. </style>