addcomment.vue 4.0 KB

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