<!-- Goodsreview.vue -->
<template>
	<view
		id="review"
		ref="review"
		class="div ui-review-wrapper ui-detail-common"
		@click="getGoodsEvaluation()"
	>
		<view class="div main-content"><flex-line :is-link="true" :show-border="true"><text class="span line-name">评价</text></flex-line></view>
		<view class="div goods-review-body">
			<review-list :list="reviewList"></review-list>
		</view>
	</view>
</template>

<script>
import { urlencode } from '@/util/common'
import ReviewList from './ReviewList'
import flexLine from '../../../flexLine'
import { getReviewList } from '../../../../api/homegoodsdetail'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      reviewList: []
    }
  },

  computed: {
    ...mapState({
      currentProductId: state => state.goodsdetail.currentProductId
    })
  },

  components: {
	  flexLine,
    ReviewList
  },

  created () {
    this.getReviewList()
  },
	mounted () {
        setTimeout(() => {
        const reviewinfo = uni.createSelectorQuery().in(this)
        reviewinfo.select('#review').boundingClientRect(res =>{
            this.$emit('reviewposition',res.top - res.height);
        }).exec();
        }, 500); 
	},
  methods: {
    ...mapMutations({
      changeIndex: 'changeIndex'
    }),

    getReviewList () {
      getReviewList(this.currentProductId,'',1).then(res => {
        if (res) {
          this.reviewList = res.result.goods_eval_list
        }
      })
    },

    /* 评论 */
    getGoodsEvaluation () {
		uni.navigateTo({ url: '/pages/home/goodsdetail/GoodsEvaluation'+'?'+urlencode( { 'goods_id': this.currentProductId } )})
	},
  }
}
</script>

<style lang="scss" scoped>
	.main-content{padding:0 $pageSpace;background-color: #fff;}
.ui-review-wrapper {
	.goods-review-body {
		background: #ffffff;
	}
}
</style>
