goods-evaluate.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="">
  3. <view class="gap"></view>
  4. <view class="state-area dflex padding bg-main">
  5. <view class="item margin-right-sm" :class="{ active: state == item.name }" v-for="(item, index) in stateDatas" :key="index" @click="change(item)">
  6. <text style="font-size: 26rpx;">{{ item.name }}({{ item.cnt }})</text>
  7. </view>
  8. </view>
  9. <view class="gap"></view>
  10. <!-- 评价区 -->
  11. <view class="evaluate-area">
  12. <view class="padding-lr padding-top bg-main">
  13. <view class="eva-box dflex-s padding-bottom-lg" v-for="(item, index) in evaluateDatas" :key="index">
  14. <image class="portrait border-radius-c" :src="item.userImg"></image>
  15. <view class="right-area flex1 padding-left-sm">
  16. <view class="dflex-b ft-dark">
  17. <view class="dflex">
  18. <text class="name margin-right">{{ item.createBy }}</text>
  19. <use-rate :value="item.reviewCnt" disabled></use-rate>
  20. </view>
  21. <text class="time fs-xs">{{ $api.format(item.createTime, 'yyyy-MM-dd') }}</text>
  22. </view>
  23. <view class="fs-sm ft-main padding-top-xs padding-bottom-sm">{{ item.reviewContent }}</view>
  24. <view class="dflex dflex-wrap-w">
  25. <image
  26. class="border-radius-xs"
  27. v-if="item.reviewImgs.indexOf(',') != -1"
  28. mode="aspectFill"
  29. :lazy-load="true"
  30. :src="item.reviewImgs.substring(0, item.reviewImgs.indexOf(','))"
  31. @click="preview(item.reviewImgs.substring(0, item.reviewImgs.indexOf(',')))"
  32. ></image>
  33. <image class="border-radius-xs" v-else mode="aspectFill" :lazy-load="true" :src="item.reviewImgs" @click="preview(item.reviewImgs)"></image>
  34. </view>
  35. <view class="">
  36. <text class="fs-xs ft-dark">{{ item.goods_type || '套餐1' }}</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {pingjia } from '../../utils/api_goods.js'
  46. export default {
  47. data() {
  48. return {
  49. // 评价状态
  50. stateDatas: [
  51. {name:'全部',cnt:''},
  52. {name:'好评',cnt:''},
  53. {name:'中评',cnt:''},
  54. {name:'差评',cnt:''},
  55. ],
  56. // 评价数据
  57. evaluateDatas: [],
  58. // 商品ID
  59. goods_id: 0,
  60. // 评价类型
  61. state: '全部'
  62. };
  63. },
  64. onLoad(res) {
  65. this.goods_id = res.id;
  66. this.loadData();
  67. },
  68. methods: {
  69. loadData() {
  70. this.stateDatas[0].cnt=0
  71. this.stateDatas[1].cnt=0
  72. this.stateDatas[2].cnt=0
  73. this.stateDatas[3].cnt=0
  74. this.evaluateDatas=[]
  75. if(this.state=='全部'){
  76. var type=''
  77. }else if(this.state=='好评'){
  78. var type='3'
  79. }else if(this.state=='中评'){
  80. var type='2'
  81. }else if(this.state=='差评'){
  82. var type='1'
  83. }
  84. //商品评价
  85. var data = '?goodsId=' + this.goods_id+'&reviewType='+type
  86. pingjia(data).then((res) => {
  87. console.log('评价', res)
  88. if (res.success) {
  89. // 商品评价
  90. this.evaluateDatas = res.data.list
  91. if (res.data.evaluate_cnt) this.evaluateTitle = `评价(${res.data.evaluate_cnt})`
  92. this.stateDatas[0].cnt=this.evaluateDatas.length
  93. for(var i=0;i<this.evaluateDatas.length;i++){
  94. if(this.evaluateDatas[i].reviewType=='3'){
  95. this.stateDatas[1].cnt++
  96. }else if(this.evaluateDatas[i].reviewType=='2'){
  97. this.stateDatas[2].cnt++
  98. }else if(this.evaluateDatas[i].reviewType=='1'){
  99. this.stateDatas[3].cnt++
  100. }
  101. }
  102. }
  103. })
  104. // const $ = this.$dbcmd.aggregate;
  105. // this.$db['usemall-goods-comment']
  106. // .collection()
  107. // .aggregate()
  108. // .match({
  109. // goods_id: $.eq(this.goods_id),
  110. // state: '显示'
  111. // })
  112. // .group({
  113. // _id: '$review_type',
  114. // num: $.sum(1)
  115. // })
  116. // .end()
  117. // .then(res => {
  118. // let __stateDatas = [];
  119. // let total = 0;
  120. // res.result.data.forEach(x => {
  121. // __stateDatas.push({ name: x._id, cnt: x.num });
  122. // total += x.num;
  123. // });
  124. // this.stateDatas = [{ name: '全部', cnt: total }, ...__stateDatas];
  125. // });
  126. // this.$db['usemall-goods-comment']
  127. // .where({
  128. // goods_id: this.goods_id,
  129. // state: '显示'
  130. // })
  131. // .whereif(this.state != '全部', { review_type: this.state })
  132. // .tolist({ rows: 30, orderby: 'create_time desc' })
  133. // .then(res => {
  134. // if (res.code === 200) {
  135. // this.evaluateDatas = res.datas;
  136. // }
  137. // });
  138. },
  139. change(options) {
  140. this.state = options.name;
  141. this.loadData();
  142. },
  143. preview(imgs) {
  144. console.log(imgs)
  145. if (!imgs) return;
  146. uni.previewImage({
  147. current: 0,
  148. urls: [imgs],
  149. longPressActions: {
  150. itemList: ['发送给朋友', '保存图片', '收藏'],
  151. success: function(data) {
  152. console.log(res);
  153. },
  154. fail: function(err) {
  155. console.log(err);
  156. }
  157. }
  158. });
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="scss">
  164. @import url('/packageShang/components/iconfont/iconfont.css');
  165. @import url('/packageShang/common/common.scss');
  166. page {
  167. background: $page-color-base;
  168. }
  169. .state-area {
  170. .item {
  171. text {
  172. padding: 10rpx 20rpx;
  173. border: 1px solid #f0f0f0;
  174. border-radius: 30rpx;
  175. }
  176. &:last-child {
  177. margin-right: 0;
  178. }
  179. }
  180. }
  181. .evaluate-area {
  182. .portrait {
  183. flex-shrink: 0;
  184. width: 80rpx;
  185. height: 80rpx;
  186. }
  187. .right-area {
  188. image {
  189. margin-right: 10rpx;
  190. margin-bottom: 10rpx;
  191. height: 200rpx;
  192. width: 30%;
  193. }
  194. }
  195. }
  196. </style>