evaluate.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="page-wrap">
  3. <u-navbar
  4. title="发表评价"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <view class="product u-flex" v-for="(item,index) in orderDetails.detailList" :key="item.id">
  11. <u--image :showLoading="true" :src="item.mainImg" width="180rpx" height="180rpx"></u--image>
  12. <view class="text">
  13. <view class="up">
  14. <view class="name ellipsis-2">{{item.goodsName}}</view>
  15. <view class="info">
  16. {{item.specification}}
  17. {{item.unit}}
  18. </view>
  19. </view>
  20. <!-- <view class="down u-flex u-row-between">
  21. <view class="left">
  22. <text class="price">¥ <text class="price-num">{{item.price}}</text></text>
  23. </view>
  24. </view> -->
  25. </view>
  26. </view>
  27. <view class="rate-wrap u-flex">
  28. <text class="rate-title">商品评价</text>
  29. <u-rate count="5" v-model="params.star" active-color="#FFBE00" size="20"></u-rate>
  30. <text class="rate-text">{{params.star|rateText}}</text>
  31. </view>
  32. <u--textarea v-model="params.contentText" height="200rpx" maxlength="200" placeholder="如实描述商品和使用感受,更受欢迎" ></u--textarea>
  33. <view class="upload-wrap">
  34. <u-upload
  35. width="140rpx"
  36. height="140rpx"
  37. :fileList="fileList"
  38. @beforeRead="beforeRead"
  39. @afterRead="afterRead"
  40. @delete="deletePic"
  41. :previewImage="true"
  42. multiple
  43. name="name"
  44. :maxCount="5"
  45. ></u-upload>
  46. </view>
  47. <view class="full-btn" @click="submit">提交评价</view>
  48. </view>
  49. </template>
  50. <script>
  51. import {uploadImg} from '../utils/uploadImg.js'
  52. export default {
  53. data() {
  54. return {
  55. id:'',
  56. params:{
  57. orderId:'',
  58. orderDetailId:'',
  59. star:5,
  60. contentText:'',
  61. contentImgList:[]
  62. },
  63. fileList:[],
  64. orderDetails:{},
  65. staticUrl:this.$commonConfig.staticUrl,
  66. }
  67. },
  68. onShow() {
  69. },
  70. onLoad(page) {
  71. console.log('page',page);
  72. this.params.orderId = page.id;
  73. this.getOrderDetails(this.params.orderId)
  74. },
  75. methods: {
  76. getOrderDetails(id){
  77. this.$u.api.orderDetails({id:id}).then(res=>{
  78. this.orderDetails = res.data
  79. this.params.orderDetailId= res.data.detailList[0]?.id
  80. console.log('orderDetails',JSON.parse(JSON.stringify(res.data)));
  81. }).catch(err=>{
  82. console.log('getOrderDetails',err);
  83. })
  84. },
  85. // 新增图片
  86. async afterRead(event){
  87. //使用这个封装
  88. const result = await uploadImg(event,this.fileList)
  89. // let parseResult = JSON.parse(result.data).data;
  90. let item = this.fileList[result.fileListLen]
  91. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  92. status: 'success',
  93. message: '成功',
  94. url: JSON.parse(result.data).data
  95. }));
  96. },
  97. // 删除图片
  98. deletePic(event) {
  99. this.fileList.splice(event.index, 1)
  100. },
  101. submit(){
  102. this.params.contentImgList = this.fileList.map(item =>{
  103. console.log('contentImgList===',item);
  104. if(item.message=='成功'){
  105. return item.url.url
  106. }
  107. });
  108. this.$u.api.addGoodsComment(this.params).then(res=>{
  109. console.log('res',res.data);
  110. uni.showToast({
  111. title:res.msg,
  112. complete() {
  113. uni.navigateBack()
  114. }
  115. });
  116. }).catch(err=>{
  117. console.log('addGoodsComment',err);
  118. })
  119. console.log('params',this.params);
  120. }
  121. }
  122. }
  123. </script>
  124. <style>
  125. page{
  126. background-color: #F5F5F5;
  127. }
  128. </style>
  129. <style lang="scss" scoped>
  130. .product{
  131. background-color: #fff;
  132. margin-bottom: 0;
  133. }
  134. .rate-wrap{
  135. background-color: #fff;
  136. margin-bottom: 20rpx;
  137. padding: 20rpx;
  138. .rate-title{
  139. font-size: 30rpx;
  140. color: #333;
  141. font-weight: 600;
  142. margin-right: 20rpx;
  143. }
  144. .rate-text{
  145. font-size: 26rpx;
  146. margin-left: 20rpx;
  147. color: #ccc;
  148. }
  149. }
  150. .upload-wrap{
  151. margin-top: 40rpx;
  152. padding: 20rpx;
  153. background-color: #fff;
  154. }
  155. </style>