userComment.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="container">
  3. <!-- 服务评价标题(固定在最上方) -->
  4. <view class="evaluation-title">服务评价:</view>
  5. <!-- 图片和信息区域 -->
  6. <view class="info-section">
  7. <up-image :show-loading="true" :src="src" width="80px" height="80px" @click="click"
  8. class="info-image"></up-image>
  9. <view class="info-text">
  10. <text class="project-name">服务类型:{{ projectName }}</text>
  11. <text class="volunteer-name">姓名:{{ volunteerName }}</text>
  12. </view>
  13. </view>
  14. <!-- 评分区域 - 修改为星星和文字都在左边 -->
  15. <view class="rating-section">
  16. <view class="rating-item">
  17. <text class="rating-label">服务礼仪:</text>
  18. <up-rate :count="count" v-model="IfonForm.protocolScore" count="5" class="rating-stars"></up-rate>
  19. </view>
  20. <view class="rating-item">
  21. <text class="rating-label">着装整洁:</text>
  22. <up-rate :count="count" v-model="IfonForm.clothingScore" count="5" class="rating-stars"></up-rate>
  23. </view>
  24. <view class="rating-item">
  25. <text class="rating-label">专业能力:</text>
  26. <up-rate :count="count" v-model="IfonForm.abilityScore" count="5" class="rating-stars"></up-rate>
  27. </view>
  28. <view class="rating-item">
  29. <text class="rating-label">服务质量:</text>
  30. <up-rate :count="count" v-model="IfonForm.qualityScore" count="5" class="rating-stars"></up-rate>
  31. </view>
  32. </view>
  33. <!-- 图片上传区域 -->
  34. <view class="upload-section">
  35. <view class="upload-box">
  36. <view class="upload-img-item" v-for="(item, index) in fileList" :key="item.url">
  37. <view class="delete-icon" @click="deletePic(index)">
  38. <up-icon name="close-circle-fill" color="#f64a1f" size="18"></up-icon>
  39. </view>
  40. <img class="upload-img" :src="item.url" :alt="item.fileName">
  41. </view>
  42. <img src="/static/img/upload.png" alt="" class="upload-img" @click="uploadClick('img')"
  43. v-if="fileList.length < 10">
  44. </view>
  45. </view>
  46. <!-- 文本区域 -->
  47. <up-textarea v-model="IfonForm.userReview" placeholder="请输入评论内容" class="comment-textarea"></up-textarea>
  48. <!-- 发布按钮 -->
  49. <view class="button-section">
  50. <up-button type="error" text="发布" @click="handlButClick" class="submit-button"></up-button>
  51. </view>
  52. </view>
  53. </template>
  54. <script setup>
  55. import {
  56. onMounted,
  57. ref
  58. } from 'vue';
  59. import {
  60. usersUserFinishOrder
  61. } from "@/api/userList.js";
  62. import {
  63. onLoad,
  64. } from '@dcloudio/uni-app';
  65. import {
  66. wxUploadFile
  67. } from '@/utils/wxRequest.js'
  68. const count = ref(4);
  69. const fileList = ref([]);
  70. const src = ref('');
  71. const projectName = ref('');
  72. const volunteerName = ref('');
  73. const IfonForm = ref({
  74. protocolScore: 0, //服务礼仪
  75. clothingScore: 0, //服装整洁
  76. abilityScore: 0, //专业能力
  77. qualityScore: 0, //服务质量
  78. userReview: '',
  79. })
  80. // 删除图片
  81. const deletePic = (event) => {
  82. fileList.value.splice(event.index, 1);
  83. };
  84. const uploadClick = async (type) => {
  85. const res = await wxUploadFile(type);
  86. fileList.value = [...fileList.value, ...res];
  87. console.log('xxxxres', res, fileList.value);
  88. }
  89. const handlButClick = async () => {
  90. // 提取所有图片的 URL
  91. const imageUrls = fileList.value.map(item => item.url);
  92. const volunteerInfoId = IfonForm.value.volunteerInfoId;
  93. const secondOrderId = IfonForm.value.secondOrderId;
  94. try {
  95. const params = {
  96. ...IfonForm.value,
  97. images: imageUrls,
  98. volunteerInfoId: volunteerInfoId,
  99. secondOrderId: secondOrderId,
  100. }
  101. console.log(params, 'params>>>')
  102. const res = await usersUserFinishOrder(params)
  103. if (res.code == 200) {
  104. uni.showToast({
  105. title: '评价提交成功',
  106. icon: 'success'
  107. });
  108. setTimeout(() => {
  109. uni.navigateBack({
  110. delta: 1
  111. })
  112. }, 2000)
  113. } else {
  114. console.log('提交失败')
  115. }
  116. } catch (e) {
  117. uni.showToast({
  118. title: '提交失败,请重试',
  119. icon: 'error'
  120. });
  121. }
  122. }
  123. onLoad(async (options) => {
  124. const data = JSON.parse(decodeURIComponent(options.data));
  125. console.log(data, '》》》》》》 获取传递的 listData');
  126. // 设置图片
  127. if (data.volunteerInfo?.volunteerPicture) {
  128. src.value = data.volunteerInfo.volunteerPicture;
  129. } else {
  130. src.value = '/static/default-avatar.png';
  131. }
  132. // 设置项目名称和志愿者姓名
  133. projectName.value = data.volunteerInfo?.projectName || '未知项目';
  134. volunteerName.value = data.volunteerInfo?.name || '未知姓名';
  135. const secondOrderList = data.secondOrderList || [];
  136. // 获取第一个 secondOrderId
  137. const secondOrderId = secondOrderList.length > 0 ? secondOrderList[0].secondOrderId : null;
  138. // 如果 secondOrderId 存在,则设置到 IfonForm 中
  139. if (secondOrderId) {
  140. IfonForm.value.secondOrderId = secondOrderId;
  141. }
  142. // 获取 volunteerInfoId
  143. const volunteerInfoId = data.volunteerInfo?.volunteerInfoId || data.volunteerInfoId;
  144. IfonForm.value.volunteerInfoId = volunteerInfoId;
  145. });
  146. </script>
  147. <style scoped>
  148. .container {
  149. display: flex;
  150. flex-direction: column;
  151. padding: 20rpx;
  152. }
  153. .evaluation-title {
  154. font-size: 32rpx;
  155. font-weight: bold;
  156. margin-bottom: 30rpx;
  157. }
  158. .info-section {
  159. display: flex;
  160. align-items: center;
  161. margin-bottom: 30rpx;
  162. }
  163. .info-image {
  164. margin-right: 20rpx;
  165. }
  166. .info-text {
  167. display: flex;
  168. flex-direction: column;
  169. flex: 1;
  170. }
  171. .project-name,
  172. .volunteer-name {
  173. font-size: 28rpx;
  174. margin-bottom: 10rpx;
  175. }
  176. .rating-section {
  177. margin-bottom: 30rpx;
  178. }
  179. .rating-item {
  180. display: flex;
  181. align-items: center;
  182. margin-bottom: 20rpx;
  183. }
  184. .rating-label {
  185. font-size: 28rpx;
  186. margin-right: 15rpx;
  187. min-width: 120rpx;
  188. /* 保持标签宽度一致 */
  189. }
  190. .rating-stars {
  191. margin-left: 0;
  192. /* 移除左边距,使星星紧贴文字 */
  193. }
  194. .comment-textarea {
  195. margin-bottom: 20rpx;
  196. }
  197. .upload-section {
  198. margin-bottom: 30rpx;
  199. }
  200. .upload-box {
  201. display: flex;
  202. flex-wrap: wrap;
  203. }
  204. .upload-img-item {
  205. position: relative;
  206. margin-right: 20rpx;
  207. margin-bottom: 20rpx;
  208. }
  209. .delete-icon {
  210. position: absolute;
  211. top: -10rpx;
  212. right: -10rpx;
  213. z-index: 1;
  214. }
  215. .upload-img {
  216. width: 150rpx;
  217. height: 150rpx;
  218. border-radius: 8rpx;
  219. }
  220. .button-section {
  221. display: flex;
  222. justify-content: flex-end;
  223. }
  224. .submit-button {
  225. width: 200rpx;
  226. }
  227. </style>