evaluate.vue 3.5 KB

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