evaluate.vue 3.6 KB

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