rating.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/${this.executionId}`,
  119. method: 'GET',
  120. header: {
  121. 'Authorization': `Bearer ${uni.getStorageSync('token')}`
  122. }
  123. })
  124. if (res.data.code === 200) {
  125. this.execution = res.data.data
  126. } else {
  127. uni.showToast({ title: res.data.message || '加载失败', icon: 'none' })
  128. }
  129. } catch (e) {
  130. console.error('加载执行记录失败', e)
  131. uni.showToast({ title: '网络错误', icon: 'none' })
  132. } finally {
  133. this.loading = false
  134. }
  135. },
  136. setAssessorRating(rating) {
  137. this.assessorRating = rating
  138. },
  139. setPlannerRating(rating) {
  140. this.plannerRating = rating
  141. },
  142. async submitRating() {
  143. if (!this.canSubmit) {
  144. uni.showToast({ title: '请至少为评估师评分', icon: 'none' })
  145. return
  146. }
  147. try {
  148. const data = {
  149. executionId: this.executionId,
  150. assessorId: this.execution.assessorId,
  151. assessorRating: this.assessorRating,
  152. assessorComment: this.assessorComment
  153. }
  154. if (this.execution.plannerId) {
  155. data.plannerId = this.execution.plannerId
  156. data.plannerRating = this.plannerRating
  157. data.plannerComment = this.plannerComment
  158. }
  159. const res = await uni.request({
  160. url: `${config.API_BASE_URL}/api/dan-execution/rate`,
  161. method: 'POST',
  162. header: {
  163. 'Authorization': `Bearer ${uni.getStorageSync('token')}`,
  164. 'Content-Type': 'application/json'
  165. },
  166. data: data
  167. })
  168. if (res.data.code === 200) {
  169. uni.showToast({ title: '评价成功', icon: 'success' })
  170. setTimeout(() => {
  171. uni.navigateBack()
  172. }, 1500)
  173. } else {
  174. uni.showToast({ title: res.data.message || '评价失败', icon: 'none' })
  175. }
  176. } catch (e) {
  177. console.error('提交评价失败', e)
  178. uni.showToast({ title: '网络错误', icon: 'none' })
  179. }
  180. },
  181. goBack() {
  182. uni.navigateBack()
  183. }
  184. }
  185. }
  186. </script>
  187. <style scoped>
  188. .container {
  189. padding: 40rpx;
  190. background: #f5f5f5;
  191. min-height: 100vh;
  192. }
  193. .header {
  194. margin-bottom: 40rpx;
  195. }
  196. .title {
  197. font-size: 40rpx;
  198. font-weight: bold;
  199. color: #333;
  200. display: block;
  201. margin-bottom: 10rpx;
  202. }
  203. .subtitle {
  204. font-size: 28rpx;
  205. color: #999;
  206. }
  207. .loading, .empty {
  208. text-align: center;
  209. padding: 100rpx 0;
  210. color: #999;
  211. }
  212. .rating-section {
  213. background: white;
  214. border-radius: 20rpx;
  215. padding: 40rpx;
  216. margin-bottom: 30rpx;
  217. }
  218. .section-header {
  219. display: flex;
  220. align-items: center;
  221. margin-bottom: 30rpx;
  222. }
  223. .section-icon {
  224. width: 48rpx;
  225. height: 48rpx;
  226. border-radius: 12rpx;
  227. margin-right: 16rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. position: relative;
  232. }
  233. .assessor-section-icon {
  234. background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  235. }
  236. .assessor-section-icon::after {
  237. content: '';
  238. width: 20rpx;
  239. height: 20rpx;
  240. border: 4rpx solid #2196f3;
  241. border-radius: 50%;
  242. position: absolute;
  243. }
  244. .planner-section-icon {
  245. background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  246. }
  247. .planner-section-icon::after {
  248. content: '';
  249. width: 20rpx;
  250. height: 20rpx;
  251. border: 4rpx solid #4caf50;
  252. border-radius: 50%;
  253. position: absolute;
  254. }
  255. .section-title {
  256. font-size: 32rpx;
  257. font-weight: bold;
  258. color: #333;
  259. }
  260. .rating-stars {
  261. display: flex;
  262. align-items: center;
  263. margin-bottom: 30rpx;
  264. }
  265. .star-label {
  266. font-size: 28rpx;
  267. color: #666;
  268. margin-right: 20rpx;
  269. }
  270. .stars {
  271. display: flex;
  272. gap: 12rpx;
  273. }
  274. .star {
  275. font-size: 60rpx;
  276. color: #e0e0e0;
  277. transition: color 0.2s ease, text-shadow 0.2s ease;
  278. line-height: 1;
  279. }
  280. .star:active {
  281. transform: scale(1.15);
  282. }
  283. .star.active {
  284. color: #ffc107;
  285. text-shadow: 0 0 8rpx rgba(255, 193, 7, 0.4);
  286. }
  287. .rating-text {
  288. font-size: 24rpx;
  289. color: #ff9800;
  290. margin-left: 16rpx;
  291. font-weight: bold;
  292. }
  293. .comment-input {
  294. margin-top: 20rpx;
  295. }
  296. .textarea {
  297. width: 100%;
  298. min-height: 200rpx;
  299. padding: 20rpx;
  300. border: 2rpx solid #e0e0e0;
  301. border-radius: 10rpx;
  302. font-size: 28rpx;
  303. box-sizing: border-box;
  304. }
  305. .actions {
  306. display: flex;
  307. flex-direction: column;
  308. gap: 20rpx;
  309. margin-top: 40rpx;
  310. }
  311. .btn-primary, .btn-outline {
  312. border-radius: 20rpx;
  313. font-size: 32rpx;
  314. padding: 30rpx;
  315. text-align: center;
  316. }
  317. .btn-primary {
  318. background: #1E3A5F;
  319. color: white;
  320. border: none;
  321. }
  322. .btn-primary:disabled {
  323. background: #ccc;
  324. }
  325. .btn-outline {
  326. background: white;
  327. color: #666;
  328. border: 2rpx solid #ddd;
  329. }
  330. </style>