add.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!-- 评价 -->
  2. <template>
  3. <s-layout title="评价">
  4. <view>
  5. <view v-for="(item, index) in state.orderInfo.items" :key="item.id">
  6. <view>
  7. <view class="commont-from-wrap">
  8. <!-- 评价商品 -->
  9. <s-goods-item
  10. :img="item.picUrl"
  11. :title="item.spuName"
  12. :skuText="item.properties.map((property) => property.valueName).join(' ')"
  13. :price="item.payPrice"
  14. :num="item.count"
  15. />
  16. </view>
  17. <view class="form-item">
  18. <!-- 评分 -->
  19. <view class="star-box ss-flex ss-col-center">
  20. <view class="star-title ss-m-r-40">商品质量</view>
  21. <uni-rate v-model="state.commentList[index].descriptionScores" />
  22. </view>
  23. <view class="star-box ss-flex ss-col-center">
  24. <view class="star-title ss-m-r-40">服务态度</view>
  25. <uni-rate v-model="state.commentList[index].benefitScores" />
  26. </view>
  27. <!-- 评价 -->
  28. <view class="area-box">
  29. <uni-easyinput :inputBorder="false" type="textarea" maxlength="120" autoHeight
  30. v-model="state.commentList[index].content"
  31. placeholder="宝贝满足你的期待吗?说说你的使用心得,分享给想买的他们吧~" />
  32. <!-- TODO 卢越:【评论】文件上传 -->
  33. <view class="img-box">
  34. <s-uploader v-model:url="state.commentList[index].images" fileMediatype="image"
  35. limit="9" mode="grid" :imageStyles="{ width: '168rpx', height: '168rpx' }" @success="(payload) => uploadSuccess(payload, index)" />
  36. </view>
  37. </view>
  38. <view class="checkbox-container">
  39. <checkbox-group @change="(event) => toggleAnonymous(index, event)">
  40. <label>
  41. <checkbox value="anonymousChecked" />
  42. 匿名评论
  43. </label>
  44. </checkbox-group>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <su-fixed bottom placeholder>
  51. <view class="foot_box ss-flex ss-row-center ss-col-center">
  52. <button class="ss-reset-button post-btn ui-BG-Main-Gradient ui-Shadow-Main" @tap="onSubmit">
  53. 发布
  54. </button>
  55. </view>
  56. </su-fixed>
  57. </s-layout>
  58. </template>
  59. <script setup>
  60. import sheep from '@/sheep';
  61. import { onLoad } from '@dcloudio/uni-app';
  62. import { reactive, ref } from 'vue';
  63. import OrderApi from '@/sheep/api/trade/order';
  64. const state = reactive({
  65. orderInfo: {},
  66. commentList: [],
  67. id: null
  68. });
  69. /**
  70. * 切换是否匿名
  71. *
  72. * @param commentIndex 当前评论下标
  73. * @param event 复选框事件
  74. */
  75. function toggleAnonymous(commentIndex, event) {
  76. state.commentList[commentIndex].anonymous = event.detail.value[0] === 'anonymousChecked';
  77. }
  78. /**
  79. * 发布评论
  80. *
  81. * @returns {Promise<void>}
  82. */
  83. async function onSubmit() {
  84. // 顺序提交评论
  85. for (const comment of state.commentList) {
  86. await OrderApi.createOrderItemComment(comment);
  87. }
  88. // 都评论好,返回
  89. sheep.$router.back();
  90. }
  91. /**
  92. * 图片添加到表单
  93. *
  94. * @param payload 上传成功后的回调数据
  95. * @param commentIndex 当前评论的下标
  96. */
  97. function uploadSuccess(payload, commentIndex) {
  98. state.commentList[commentIndex].picUrls = state.commentList[commentIndex].images;
  99. }
  100. onLoad(async (options) => {
  101. if (!options.id) {
  102. sheep.$helper.toast(`缺少订单信息,请检查`);
  103. return
  104. }
  105. state.id = options.id;
  106. const { code, data } = await OrderApi.getOrder(state.id);
  107. if (code !== 0) {
  108. sheep.$helper.toast('无待评价订单');
  109. return
  110. }
  111. // 处理评论
  112. data.items.forEach((item) => {
  113. state.commentList.push({
  114. anonymous: false,
  115. orderItemId: item.id,
  116. descriptionScores: 5,
  117. benefitScores: 5,
  118. content: '',
  119. picUrls: []
  120. });
  121. });
  122. state.orderInfo = data;
  123. });
  124. </script>
  125. <style lang="scss" scoped>
  126. // 评价商品
  127. .goods-card {
  128. margin: 10rpx 0;
  129. padding: 20rpx;
  130. background: #fff;
  131. }
  132. // 评论,选择图片
  133. .form-item {
  134. background: #fff;
  135. .star-box {
  136. height: 100rpx;
  137. padding: 0 25rpx;
  138. }
  139. .star-title {
  140. font-weight: 600;
  141. }
  142. }
  143. .area-box {
  144. width: 690rpx;
  145. min-height: 306rpx;
  146. background: rgba(249, 250, 251, 1);
  147. border-radius: 20rpx;
  148. padding: 28rpx;
  149. margin: auto;
  150. .img-box {
  151. margin-top: 20rpx;
  152. }
  153. }
  154. .checkbox-container{
  155. padding: 10rpx;
  156. }
  157. .post-btn {
  158. width: 690rpx;
  159. line-height: 80rpx;
  160. border-radius: 40rpx;
  161. color: rgba(#fff, 0.9);
  162. margin-bottom: 20rpx;
  163. }
  164. </style>