rating.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  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. import fontScaleMixin from '@/mixins/font-scale.js'
  91. export default {
  92. mixins: [fontScaleMixin],
  93. data() {
  94. return {
  95. executionId: null,
  96. execution: null,
  97. loading: true,
  98. assessorRating: 0,
  99. assessorComment: '',
  100. plannerRating: 0,
  101. plannerComment: '',
  102. ratingTexts: ['很差', '较差', '一般', '满意', '非常满意']
  103. }
  104. },
  105. computed: {
  106. canSubmit() {
  107. // 至少评估师评分必须填写
  108. return this.assessorRating > 0
  109. }
  110. },
  111. onLoad(options) {
  112. if (options.executionId) {
  113. this.executionId = options.executionId
  114. this.loadExecution()
  115. }
  116. },
  117. methods: {
  118. async loadExecution() {
  119. this.loading = true
  120. try {
  121. const res = await uni.request({
  122. url: `${config.API_BASE_URL}/api/dan-execution/detail`,
  123. method: 'POST',
  124. data: { executionId: this.executionId },
  125. header: {
  126. 'Authorization': `Bearer ${uni.getStorageSync('token')}`,
  127. 'Content-Type': 'application/json'
  128. }
  129. })
  130. if (res.data.code === 200) {
  131. this.execution = res.data.data
  132. } else {
  133. uni.showToast({ title: res.data.message || '加载失败', icon: 'none' })
  134. }
  135. } catch (e) {
  136. console.error('加载执行记录失败', e)
  137. uni.showToast({ title: '网络错误', icon: 'none' })
  138. } finally {
  139. this.loading = false
  140. }
  141. },
  142. setAssessorRating(rating) {
  143. this.assessorRating = rating
  144. },
  145. setPlannerRating(rating) {
  146. this.plannerRating = rating
  147. },
  148. async submitRating() {
  149. if (!this.canSubmit) {
  150. uni.showToast({ title: '请至少为评估师评分', icon: 'none' })
  151. return
  152. }
  153. try {
  154. const data = {
  155. executionId: this.executionId,
  156. assessorId: this.execution.assessorId,
  157. assessorRating: this.assessorRating,
  158. assessorComment: this.assessorComment
  159. }
  160. if (this.execution.plannerId) {
  161. data.plannerId = this.execution.plannerId
  162. data.plannerRating = this.plannerRating
  163. data.plannerComment = this.plannerComment
  164. }
  165. const res = await uni.request({
  166. url: `${config.API_BASE_URL}/api/dan-execution/rate`,
  167. method: 'POST',
  168. header: {
  169. 'Authorization': `Bearer ${uni.getStorageSync('token')}`,
  170. 'Content-Type': 'application/json'
  171. },
  172. data: data
  173. })
  174. if (res.data.code === 200) {
  175. uni.showToast({ title: '评价成功', icon: 'success' })
  176. setTimeout(() => {
  177. uni.navigateBack()
  178. }, 1500)
  179. } else {
  180. uni.showToast({ title: res.data.message || '评价失败', icon: 'none' })
  181. }
  182. } catch (e) {
  183. console.error('提交评价失败', e)
  184. uni.showToast({ title: '网络错误', icon: 'none' })
  185. }
  186. },
  187. goBack() {
  188. uni.navigateBack()
  189. }
  190. }
  191. }
  192. </script>
  193. <style scoped lang="scss">
  194. .container {
  195. padding: 40rpx;
  196. background: $facade-fill-2;
  197. min-height: 100vh;
  198. }
  199. .header {
  200. margin-bottom: 40rpx;
  201. }
  202. .title {
  203. font-size: calc(40rpx * var(--font-scale, 1));
  204. font-weight: bold;
  205. color: $facade-text-strong;
  206. display: block;
  207. margin-bottom: 10rpx;
  208. }
  209. .subtitle {
  210. font-size: calc(28rpx * var(--font-scale, 1));
  211. color: $facade-text-muted;
  212. }
  213. .loading, .empty {
  214. text-align: center;
  215. padding: 100rpx 0;
  216. color: $facade-text-muted;
  217. }
  218. .rating-section {
  219. background: white;
  220. border-radius: 24rpx;
  221. padding: 40rpx;
  222. margin-bottom: $uni-space-lg;
  223. }
  224. .section-header {
  225. display: flex;
  226. align-items: center;
  227. margin-bottom: $uni-space-lg;
  228. }
  229. .section-icon {
  230. width: 48rpx;
  231. height: 48rpx;
  232. border-radius: 16rpx;
  233. margin-right: 16rpx;
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. position: relative;
  238. }
  239. .assessor-section-icon {
  240. background: linear-gradient(135deg, $mat-blue-tint, $mat-blue-light);
  241. }
  242. .assessor-section-icon::after {
  243. content: '';
  244. width: 20rpx;
  245. height: 20rpx;
  246. border: 4rpx solid $mat-blue-base;
  247. border-radius: 50%;
  248. position: absolute;
  249. }
  250. .planner-section-icon {
  251. background: linear-gradient(135deg, $mat-green-tint, $mat-green-100);
  252. }
  253. .planner-section-icon::after {
  254. content: '';
  255. width: 20rpx;
  256. height: 20rpx;
  257. border: 4rpx solid $mat-green;
  258. border-radius: 50%;
  259. position: absolute;
  260. }
  261. .section-title {
  262. font-size: calc(32rpx * var(--font-scale, 1));
  263. font-weight: bold;
  264. color: $facade-text-strong;
  265. }
  266. .rating-stars {
  267. display: flex;
  268. align-items: center;
  269. margin-bottom: $uni-space-lg;
  270. }
  271. .star-label {
  272. font-size: calc(28rpx * var(--font-scale, 1));
  273. color: $facade-text-body;
  274. margin-right: 20rpx;
  275. }
  276. .stars {
  277. display: flex;
  278. gap: 12rpx;
  279. }
  280. .star {
  281. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  282. color: $facade-hairline;
  283. transition: color 0.2s ease, text-shadow 0.2s ease;
  284. line-height: 1;
  285. }
  286. .star:active {
  287. transform: scale(1.15);
  288. }
  289. .star.active {
  290. color: $status-warning-amber;
  291. text-shadow: 0 0 8rpx rgba(255, 193, 7, 0.4);
  292. }
  293. .rating-text {
  294. font-size: calc(24rpx * var(--font-scale, 1));
  295. color: $mat-orange-base;
  296. margin-left: 16rpx;
  297. font-weight: bold;
  298. }
  299. .comment-input {
  300. margin-top: 20rpx;
  301. }
  302. .textarea {
  303. width: 100%;
  304. min-height: 200rpx;
  305. padding: 20rpx;
  306. border: 2rpx solid $facade-hairline;
  307. border-radius: 8rpx;
  308. font-size: calc(28rpx * var(--font-scale, 1));
  309. box-sizing: border-box;
  310. }
  311. .actions {
  312. display: flex;
  313. flex-direction: column;
  314. gap: 20rpx;
  315. margin-top: 40rpx;
  316. }
  317. .btn-primary, .btn-outline {
  318. border-radius: 24rpx;
  319. font-size: calc(32rpx * var(--font-scale, 1));
  320. padding: $uni-space-page;
  321. text-align: center;
  322. }
  323. .btn-primary {
  324. background: $accent-navy;
  325. color: white;
  326. border: none;
  327. }
  328. .btn-primary:disabled {
  329. background: $facade-text-ghost;
  330. }
  331. .btn-outline {
  332. background: white;
  333. color: $facade-text-body;
  334. border: 2rpx solid $facade-border-soft;
  335. }
  336. </style>