<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
<seller-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
    <view class="div common-header-wrap">
        <view class="status-holder"></view>
        <view :style="'height:'+navHeight+'px'"></view>
        <view class="common-header-holder"></view>
        <view class="common-header-fixed">
        <title-header />
        <uni-nav-bar title="评价管理" class="common-header" left-icon="back" @clickLeft="goBack()">
        </uni-nav-bar>
    </view>
    </view>
<view class="scroll-view div" style="position:relative">
    <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" @scrolltolower="loadMore" scroll-y="true">
        <view class="div"  v-if="evaluate_list.length > 0">
        <view class="div mb-5 evaluate-item"  v-for="(item, index) in evaluate_list" :key="index">
            <view class="div evaluate-info">
                <view class="div p-img">
                    <image mode="aspectFit" class="img" :src="item.geval_goodsimage_url"/>
                </view>
                <view class="div p-info">
                    <uni-rate :size="18" :readonly="true" :value="item.geval_scores"/>
                    <view class="div name">{{item.geval_content}}</view>
                    <view class="div explain">{{item.geval_explain}}</view>
                </view>
            </view>
            <view class="div evaluate-btn">
                <view class="div buyer-info">{{item.geval_frommembername}} 发表于 {{ $moment.unix(item.geval_addtime).format('YYYY年MM月DD日') }}</view>
                <view class="div btn-wrapper"><view class="div common-btn ds-button-small btn" v-if="!item.geval_explain" @click="goExplain(item.geval_id)">解释</view></view>
            </view>
        </view>
        </view>
        <empty-record v-else></empty-record>
    </scroll-view>
</view>
</view>
<uni-popup background-color="#fff" ref="confirm" type="dialog">
    <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
</uni-popup>
</seller-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import SellerBase from '../SellerBase'

import EmptyRecord from '../../EmptyRecord'
import { getEvaluateList, addExplain } from '../../../api/sellerEvaluate'

export default {
  name: 'Goodsonline',
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      dialog:{},
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      pageTotal: 1, // 总页数
      evaluate_list: [], // 商品列表
      keyword: '',
      goods_type: '',
      search_type: ''

    }
  },
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  created () {
	this.loadMore()
  },
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  methods:{
    closeDialog(){
    },
    confirmDialog(value){
        addExplain(this.dialog.data, value).then(res => {
          uni.showToast({icon:'none',title: res.message})
          this.reload()
        }).catch(function (error) {
          uni.showToast({icon:'none',title: error.message})
        })
    },
    goBack(){uni.navigateBack({delta:1})},
    setOrderNavActive (index) {
      this.goods_type = index
      this.reload()
    },
    getGoodsList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getEvaluateList(params).then(res => {
        uni.hideLoading()

        if (ispush) {
          this.evaluate_list = this.evaluate_list.concat(res.result.goodsevallist)
        } else {
          this.evaluate_list = res.result.goodsevallist
        }
        this.pageTotal = res.result.page_total
        if (res.result.hasmore) {
          this.isMore = true
        } else {
          this.isMore = false
        }
      }).catch(error=>{
          uni.hideLoading()
          uni.showToast({icon:'none',title: error.message})
      })
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore && this.params.page <= this.pageTotal) {
        this.loading = false
        this.getGoodsList(true)
      }
    },
    goExplain (geval_id) {
      this.dialog={mode:'input',content:'请输入解释',data:geval_id}
      this.$refs.confirm.open()
    },
    reload () {
      // 重新加载数据
      this.params.page = 0
      this.isMore = true
      this.evaluate_list = []
      this.loadMore()
    }
  }
}
</script>

<style scoped lang="scss">
	.scroll-view-wrapper{display: flex;flex-direction: column;}
	.scroll-view{flex:1}
    .evaluate-item{background:#fff;}
    .evaluate-info{padding:.5rem;display: flex}
    .evaluate-info .p-img{width:4rem;}
    .evaluate-info .p-img .img{width:4rem;height:4rem;border-radius:.4rem}
    .evaluate-info .p-info{flex:1;margin-left:1rem;}
    .evaluate-info .p-info .name{font-size:$subFontSize;}
    .evaluate-info .p-info .explain{font-size:$subFontSize;color:$primaryColor;margin-top:.5rem}
    .evaluate-btn{padding:.5rem;border-top:1px solid #e4e4e4;display: flex}
    .evaluate-btn .btn-wrapper{width:3rem;}
    .evaluate-btn .btn{float: right}
    .evaluate-btn .buyer-info{flex:1;font-size:$subFontSize;line-height:1.65rem}
</style>
