<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="complaintList && complaintList.length">
            <view class="div complaint-item"  v-for="(item, index) in complaintList" :key="index">
            	<view class="head">
            		<view class="type">{{item.complain_subject_content}}</view>
            		<view class="time">{{ $moment.unix(item.complain_datetime).format('YYYY年MM月DD日') }}</view>
            	</view>
            	<view class="goods_info" @click="goNavigate('/pages/home/goodsdetail/Goodsdetail',{goods_id:item.order_goods_id})">
            		<view class="image-wrapper" :style="'width:'+windowWidth+'px;height:'+windowWidth+'px;flex:0 0 ' + windowWidth + 'px'">
            			<image mode="aspectFit" class="img" :src="goodsList[item.order_goods_id].goods_image_url"/>
            		</view>
            		<view class="p-info">
            			<view class="goods_name">{{goodsList[item.order_goods_id].goods_name}}</view>
            			<view class="goods_price">￥{{goodsList[item.order_goods_id].goods_price}}</view>
            		</view>
            	</view>
            	<view class="div complaint-info">
            		<view class="complaint_content"><text>投诉内容：</text>{{item.complain_content}}</view>
            	</view>
                <view class="div complaint-btn">
                    <view class="div btn-wrapper"><view class="div common-btn btn-1" v-if="item.complain_state=='10'" @click="cancelComplaint(item.complain_id)">取消</view></view>
                    <view class="div btn-wrapper" v-if="item.complain_state==30">
                        <view class="div common-btn btn-1" @click="handleComplain(item.complain_id)">提交仲裁</view>
                    </view>
                    <view class="div btn-wrapper"><view class="div common-btn btn-2" @click="goNavigate('/pages/seller/complaint/ComplaintForm',{complain_id:item.complain_id})">查看</view></view>
                </view>
            </view>
        </view>
        <empty-record v-else-if="complaintList && !complaintList.length"></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 { urlencode } from '@/util/common'

import SellerBase from '../SellerBase'

import EmptyRecord from '../../EmptyRecord'
import { getComplaintList, cancelComplaint, handleComplain } from '../../../api/sellerCompliant'
export default {
  name: 'BillList',
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  windowWidth: function () {
    const res = uni.getSystemInfoSync()
    var width=res.windowWidth
    var size=getFontSize()
    return (width-3*.6*size)/4
  }
  },
  data(){
    return {
      navHeight: 0,
      dialog:{},
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      complaintList: false, // 商品列表
      goodsList: false
    }
  },
  onShow () {
    this.reload()
  },
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  methods:{
    closeDialog(){
    },
    confirmDialog(value){
        cancelComplaint(this.dialog.data).then(res => {
          uni.showToast({icon:'none',title: res.message})
          this.reload()
        }).catch(function (error) {
          uni.showToast({icon:'none',title: error.message})
        })
    },
    goNavigate(path,query=false){
      uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
    },
    goBack(){uni.navigateBack({delta:1})},
    handleComplain (complaint_id) {
      handleComplain(complaint_id).then(res => {
        uni.showToast({icon:'none',title: res.message})
        this.reload()
      }).catch(function (error) {
        uni.showToast({icon:'none',title: error.message})
      })
    },
    cancelComplaint (order_id) {
      this.dialog={content:'你确定要取消吗？',data:order_id}
      this.$refs.confirm.open()
    },
    getComplaintList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getComplaintList(params).then(res => {
        uni.hideLoading()
        if (res) {
          if (ispush && this.complaintList) {
            this.complaintList = this.complaintList.concat(res.result.complaint_list)
            this.goodsList = Object.assign(this.goodsList, res.result.goods_list)
          } else {
            this.complaintList = res.result.complaint_list
            this.goodsList = res.result.goods_list
          }
          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.loading = false
        this.getComplaintList(true)
      }
    },
    reload () {
      // 重新加载数据
      this.params.page = 0
      this.isMore = true
      this.complaintList = false
      this.loadMore()
    }

  }
}
</script>

<style scoped lang="scss">
	.scroll-view-wrapper{display: flex;flex-direction: column;}
	.scroll-view{flex:1}
    .complaint-item{
    	background:#fff;
    	border-bottom:1px solid #e1e1e1;
    	margin-top: $modelSpace;
    	border-radius: .5rem;
    	padding: 0 $pageSpace;
    	box-sizing: border-box;
    	.head{
    		padding: .3rem 0;
    		display: flex;
    		align-items: center;
    		.type{
    			font-size: .8rem;
    			color: #333;
    		}
    		.time{
    			font-size: .6rem;
    			color: #999;
    			margin-left: auto;
    		}
    	}
    	.goods_info{
    		display: flex;
    		box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.06);
    		.image-wrapper{
    			border-radius: .5rem;
    			overflow: hidden;
    		}
    		.p-info{
    			margin-left: .5rem;
    			.goods_name{
    				color: #333;
    				font-size: .7rem; 
    				line-height: .8rem;
    				height: 1.6rem;
    				margin-top: .4rem;
    				overflow: hidden;
    				display: -webkit-box;
    				-webkit-box-orient: vertical;
    				-webkit-line-clamp: 2;
    				padding: 0 .3rem;
    				box-sizing: border-box;
    			}
    			.goods_price{
    				color: $primaryColor;
    				font-size: .8rem;
    				margin-top: 1rem;
    			}
    		}
    	}
    	.complaint-info{
    		padding: $modelSpace 0;
    		.complaint_content{
    			font-size: .7rem;
    			color: #666;
    			text{
    				color: #333;
    			}
    		}
    	}
    	.complaint-btn{
    		padding:.5rem;
    		border-top:1px solid #e4e4e4;
    		display: flex;
    		justify-content: flex-end;
    		.btn-1{border:1px solid $primaryColor;color:$primaryColor;min-width: 2rem}
    		.btn-2{border:1px solid #333;color:#333;min-width: 2rem}
    		.btn-wrapper{
    			margin-left:.5rem
    		}
    		.buyer-info{
    			flex:1;
    			font-size:$subFontSize;
    			line-height:1.4rem
    		}
    	}
    }
</style>
