rating.vue 8.1 KB

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