evaluate.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. @beforeRead="beforeRead"
  38. @afterRead="afterRead"
  39. @delete="deletePic"
  40. :previewImage="true"
  41. multiple
  42. name="name"
  43. :maxCount="5"
  44. ></u-upload>
  45. </view>
  46. <view class="full-btn" @click="submit">提交评价</view>
  47. </view>
  48. </template>
  49. <script>
  50. import {uploadImg} from '../utils/uploadImg.js'
  51. export default {
  52. data() {
  53. return {
  54. id:'',
  55. params:{
  56. orderId:'',
  57. star:5,
  58. contentText:'',
  59. contentImgList:[]
  60. },
  61. fileList:[],
  62. orderDetails:{},
  63. staticUrl:this.$commonConfig.staticUrl,
  64. }
  65. },
  66. onShow() {
  67. },
  68. onLoad(page) {
  69. console.log('page',page);
  70. this.params.orderId = page.id;
  71. this.getOrderDetails(this.params.orderId)
  72. },
  73. methods: {
  74. getOrderDetails(id){
  75. this.$u.api.orderDetails({id:id}).then(res=>{
  76. this.orderDetails = res.data
  77. console.log('orderDetails',JSON.parse(JSON.stringify(res.data)));
  78. }).catch(err=>{
  79. console.log('getOrderDetails',err);
  80. })
  81. },
  82. // 新增图片
  83. async afterRead(event){
  84. //使用这个封装
  85. const result = await uploadImg(event,this.fileList)
  86. // let parseResult = JSON.parse(result.data).data;
  87. let item = this.fileList[result.fileListLen]
  88. this.fileList.splice(result.fileListLen, 1, Object.assign(item, {
  89. status: 'success',
  90. message: '成功',
  91. url: JSON.parse(result.data).data
  92. }));
  93. },
  94. // 删除图片
  95. deletePic(event) {
  96. this.fileList.splice(event.index, 1)
  97. },
  98. submit(){
  99. this.params.contentImgList = this.fileList.map(item =>{
  100. console.log('contentImgList===',item);
  101. if(item.message=='成功'){
  102. return item.url.url
  103. }
  104. });
  105. this.$u.api.addGoodsComment(this.params).then(res=>{
  106. console.log('res',res.data);
  107. uni.showToast({
  108. title:res.msg,
  109. complete() {
  110. uni.navigateBack()
  111. }
  112. });
  113. }).catch(err=>{
  114. console.log('addGoodsComment',err);
  115. })
  116. console.log('params',this.params);
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. page{
  123. background-color: #F5F5F5;
  124. }
  125. </style>
  126. <style lang="scss" scoped>
  127. .product{
  128. background-color: #fff;
  129. margin-bottom: 0;
  130. }
  131. .rate-wrap{
  132. background-color: #fff;
  133. margin-bottom: 20rpx;
  134. padding: 20rpx;
  135. .rate-title{
  136. font-size: 30rpx;
  137. color: #333;
  138. font-weight: 600;
  139. margin-right: 20rpx;
  140. }
  141. .rate-text{
  142. font-size: 26rpx;
  143. margin-left: 20rpx;
  144. color: #ccc;
  145. }
  146. }
  147. .upload-wrap{
  148. margin-top: 40rpx;
  149. padding: 20rpx;
  150. background-color: #fff;
  151. }
  152. </style>