rating.vue 8.0 KB

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