rating.vue 8.2 KB

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