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. ★
  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. import config from '@/config.js'
  90. export default {
  91. data() {
  92. return {
  93. executionId: null,
  94. execution: null,
  95. loading: true,
  96. assessorRating: 0,
  97. assessorComment: '',
  98. plannerRating: 0,
  99. plannerComment: '',
  100. ratingTexts: ['很差', '较差', '一般', '满意', '非常满意']
  101. }
  102. },
  103. computed: {
  104. canSubmit() {
  105. // 至少评估师评分必须填写
  106. return this.assessorRating > 0
  107. }
  108. },
  109. onLoad(options) {
  110. if (options.executionId) {
  111. this.executionId = options.executionId
  112. this.loadExecution()
  113. }
  114. },
  115. methods: {
  116. async loadExecution() {
  117. this.loading = true
  118. try {
  119. const res = await uni.request({
  120. url: `${config.API_BASE_URL}/api/dan-execution/detail/${this.executionId}`,
  121. method: 'GET',
  122. header: {
  123. 'Authorization': `Bearer ${uni.getStorageSync('token')}`
  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>