ReviewPopup.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <up-popup
  3. v-model:show="visible"
  4. mode="bottom"
  5. :round="20"
  6. :closeable="true"
  7. :closeOnClickOverlay="true"
  8. @close="onClose"
  9. >
  10. <view class="review-popup">
  11. <view class="popup-header">
  12. <trans class="title" _t="商品评价" />
  13. </view>
  14. <view class="popup-content">
  15. <!-- 评价内容 -->
  16. <view class="review-section">
  17. <view class="section-title">
  18. <trans _t="评价内容" />
  19. </view>
  20. <up-textarea
  21. v-model="reviewContent"
  22. :placeholder="t('分享你的使用感受,帮助其他买家选择')"
  23. :maxlength="500"
  24. :count="true"
  25. :autoHeight="true"
  26. :minHeight="120"
  27. ></up-textarea>
  28. </view>
  29. <!-- 图片上传 -->
  30. <view class="image-section">
  31. <view class="section-title">
  32. <trans _t="上传图片" />
  33. </view>
  34. <imageUpload v-model="imageList" :maxCount="maxImages" multiple />
  35. </view>
  36. <!-- 评分 -->
  37. <!-- <view class="rating-section">
  38. <view class="section-title">商品评分</view>
  39. <view class="rating-wrapper">
  40. <up-rate
  41. v-model="rating"
  42. :count="5"
  43. :size="20"
  44. activeColor="#ff6b35"
  45. inactiveColor="#e4e7ed"
  46. :readonly="false"
  47. ></up-rate>
  48. <text class="rating-text">{{ getRatingText(rating) }}</text>
  49. </view>
  50. </view> -->
  51. </view>
  52. <view class="popup-footer">
  53. <view class="btn-group">
  54. <view class="btn cancel-btn" @click="onClose">
  55. <trans _t="取消" />
  56. </view>
  57. <view class="btn submit-btn" @click="submitReview">
  58. <trans _t="提交" />
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </up-popup>
  64. </template>
  65. <script setup>
  66. import { ref, computed, watch } from "vue";
  67. import { Toast } from "@/utils";
  68. import { t } from "@/locale";
  69. import { SHOP_ADD_COMMENTS } from "@/api";
  70. import imageUpload from "@/components/imageUpload";
  71. const props = defineProps({
  72. // 评价ID
  73. id: {
  74. type: [String, Number],
  75. default: "",
  76. },
  77. maxImages: {
  78. type: Number,
  79. default: 6,
  80. },
  81. });
  82. const emit = defineEmits(["close", "submit"]);
  83. const visible = ref(false);
  84. const reviewContent = ref("");
  85. const imageList = ref([]);
  86. const rating = ref(5);
  87. // 是否可以提交
  88. const canSubmit = computed(() => {
  89. return reviewContent.value.trim().length > 0 && imageList.value.length;
  90. });
  91. // 打开弹框
  92. const open = (data = {}) => {
  93. visible.value = true;
  94. // 重置数据
  95. reviewContent.value = "";
  96. imageList.value = [];
  97. };
  98. // 关闭弹框
  99. const onClose = () => {
  100. visible.value = false;
  101. emit("close");
  102. };
  103. // 提交评价
  104. const submitReview = async () => {
  105. let images = "";
  106. if (imageList.value.length) {
  107. images = imageList.value.map((item) => item.url).join(",");
  108. }
  109. try {
  110. const submitData = {
  111. orderid: props.id,
  112. content: reviewContent.value.trim(),
  113. images: images,
  114. };
  115. const res = await SHOP_ADD_COMMENTS(submitData);
  116. Toast(res.msg);
  117. emit("submit", submitData);
  118. onClose();
  119. } catch (error) {
  120. console.error("提交评价失败:", error);
  121. Toast(error.msg || "提交失败,请重试");
  122. }
  123. };
  124. // 暴露方法
  125. defineExpose({
  126. open,
  127. close: onClose,
  128. });
  129. </script>
  130. <style lang="less" scoped>
  131. .review-popup {
  132. background: var(--light);
  133. border-radius: 20rpx 20rpx 0 0;
  134. max-height: 80vh;
  135. display: flex;
  136. flex-direction: column;
  137. }
  138. .popup-header {
  139. padding: 32rpx 32rpx 0;
  140. text-align: center;
  141. border-bottom: 1px solid #f0f0f0;
  142. .title {
  143. font-size: 32rpx;
  144. font-weight: 600;
  145. color: var(--text);
  146. line-height: 80rpx;
  147. }
  148. }
  149. .popup-content {
  150. flex: 1;
  151. padding: 32rpx;
  152. overflow-y: auto;
  153. }
  154. .product-info {
  155. display: flex;
  156. align-items: center;
  157. gap: 24rpx;
  158. padding: 24rpx;
  159. background: #f8f9fa;
  160. border-radius: 16rpx;
  161. margin-bottom: 32rpx;
  162. .product-img {
  163. width: 120rpx;
  164. height: 120rpx;
  165. border-radius: 12rpx;
  166. }
  167. .product-details {
  168. flex: 1;
  169. display: flex;
  170. flex-direction: column;
  171. gap: 8rpx;
  172. .product-title {
  173. font-size: 28rpx;
  174. font-weight: 600;
  175. color: var(--text);
  176. line-height: 1.4;
  177. display: -webkit-box;
  178. -webkit-line-clamp: 2;
  179. -webkit-box-orient: vertical;
  180. overflow: hidden;
  181. }
  182. .product-spec {
  183. font-size: 24rpx;
  184. color: var(--text-02);
  185. }
  186. }
  187. }
  188. .review-section,
  189. .image-section,
  190. .rating-section {
  191. margin-bottom: 32rpx;
  192. .section-title {
  193. font-size: 28rpx;
  194. font-weight: 600;
  195. color: var(--text);
  196. margin-bottom: 16rpx;
  197. }
  198. }
  199. .image-upload {
  200. .upload-tip {
  201. font-size: 24rpx;
  202. color: var(--text-02);
  203. }
  204. }
  205. .rating-wrapper {
  206. display: flex;
  207. align-items: center;
  208. gap: 16rpx;
  209. .rating-text {
  210. font-size: 28rpx;
  211. color: var(--text);
  212. }
  213. }
  214. .popup-footer {
  215. padding: 24rpx 32rpx;
  216. border-top: 1px solid #f0f0f0;
  217. .btn-group {
  218. display: flex;
  219. gap: 16rpx;
  220. .btn {
  221. flex: 1;
  222. height: 88rpx;
  223. border-radius: 16rpx;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. font-size: 28rpx;
  228. font-weight: 600;
  229. }
  230. .cancel-btn {
  231. background: #f5f5f5;
  232. color: var(--text);
  233. }
  234. .submit-btn {
  235. background: var(--black);
  236. color: var(--light);
  237. &.disabled {
  238. background: #ccc;
  239. color: #999;
  240. }
  241. }
  242. }
  243. }
  244. </style>