<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 member-order-list">
	  <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="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 order-body" v-if="refund_list && refund_list.length">
		<view class="div list" v-for="(item, index) in refund_list" :key="item.refund_id">
			<view class="div" @click="goNavigate('/pages/seller/refund/RefundView',{refund_id:item.refund_id})">
				<view class="div tips-body">
					<text class="span tips"> 申请时间: {{ $moment.unix(item.add_time).format('YYYY年MM月DD日') }} </text>
					<text class="span title tips statusTips" >
						店铺{{ item.seller_state_text }}，平台{{ item.refund_state_text }}
					</text>
				</view>
				<view class="div order-image multiple" v-if="item.goods_list.length > 1">
					<view class="div imagebox">
						<image mode="aspectFit" class="img" v-for="(image,index) in item.goods_list" :key="index" :src="image.goods_img_480" />
					</view>
				</view>
				<view class="div order-image" v-else-if="item.goods_list.length == 1">
					<view class="div goods_info" v-for="(image,index) in item.goods_list" :key="index"> 
						<view class="div img-wrapper">
							<image mode="aspectFit" class="img" :src="image.goods_img_480" />
						</view>
						<view class="p goods_name">{{image.goods_name}}</view>
						<view class="p goods_price">
							<view class="price">￥{{item.refund_amount}}</view>
						</view>
					</view>
				</view>
				<view class="div amount">
					退款金额 :  <text class="amount_icon">￥</text><text class="i">{{ item.refund_amount }}</text
				>
				</view>
			</view>
			<view class="div order-list-opratio">
				<!-- 锁定-->
					<text class="button" v-if="item.seller_state == 1" @click="goNavigate('/pages/seller/refund/RefundForm',{refund_id:item.refund_id,refund_type,refund_type})">处理</text>
					<text class="button" v-if="item.seller_state == 2 && item.return_type == 2 && item.goods_state == 2" @click="receive(item.refund_id)">已收货</text>
					<text class="button" v-if="item.seller_state == 2 && item.return_type == 2 && item.goods_state == 2 && item.delay_time>0" @click="unreceive(item.refund_id)">未收货</text>
					<text class="button" v-if="item.invoice_no && item.express_id>0" @click="goNavigate('/pages/seller/refund/RefundDeliver',{refund_id:item.refund_id})">物流跟踪</text>
			</view>
		</view>
    </view>
    <empty-record v-if="refund_list && !refund_list.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 { getRefundList,receiveRefund } from '../../../api/sellerRefund'

import EmptyRecord from '../../EmptyRecord'
export default {
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  name: 'SellerRefundList',
  data(){
    return {
      navHeight: 0,
      dialog:{},
      refund_type: '',
      title: '',
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      order_id: 0,
      stateType: '',
      orderDetailVisible: false,
      refund_list: false

    }
  },

  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().height
    // #endif
  },
  computed:{

  fontSize(){

    return getFontSize()

  },

  },
  onLoad: function (option) {
	this.refund_type = option.refund_type
	this.title = option.refund_type == 2 ? '退货' : '退款'
  },
  onShow(){
    this.reload()
  },

  methods:{
	  closeDialog(){
	  },
	  confirmDialog(value){
      switch(this.dialog.condition){
        case 1:
			  receiveRefund(this.dialog.data,4).then(res => {
				  this.reload()
			  }).catch(function (error) {
				  uni.showToast({icon:'none',title: error.message})
			  })
          break
        case 2:
			  receiveRefund(this.dialog.data,3).then(res => {
				  this.reload()
			  }).catch(function (error) {
				  uni.showToast({icon:'none',title: error.message})
			  })
          break
      }
	  },
	  goNavigate(path,query=false){
	    uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
	  },
	  goBack(){uni.navigateBack({delta:1})},
	  loadMore () {
		  this.loading = true
		  this.params.page = ++this.params.page
		  if (this.isMore) {
			  this.loading = false
			  this.getRefundList(false)
		  }
	  },
    reload () {
      // 重新加载数据
      this.params.page = 0
      this.isMore = true
      this.refund_list = false
      this.loadMore()
    },
	  receive (orderId) {
		  this.dialog={condition:1,content:'确定已收到货吗？',data:orderId}
		  this.$refs.confirm.open()
	  },
	  unreceive (orderId) {
		  this.dialog={condition:2,content:'确定未收到货吗？',data:orderId}
		  this.$refs.confirm.open()
	  },
    getRefundList (ifReplace) {
      uni.showLoading({ title: '加载中' })
      if (ifReplace) {
		  this.loading = false
		  this.params.page = 1
		  this.isMore = true
      }

      getRefundList(this.params, this.refund_type).then(res => {
        uni.hideLoading()
			  if (res.result.hasmore) {
				  this.isMore = true
			  } else {
				  this.isMore = false
			  }

        let tRefundGroup = res.result.refund_list

        if (tRefundGroup) {
          if (ifReplace || !this.refund_list) {
            this.refund_list = tRefundGroup
          } else {
            this.refund_list = this.refund_list.concat(tRefundGroup)
          }
        }
      }).catch(function (error) {
        uni.hideLoading()
        uni.showToast({icon:'none',title: error.message})
      })
    }
  }
}
</script>
<style  lang="scss" scoped>
.scroll-view-wrapper{display: flex;flex-direction: column;}
.scroll-view{flex:1}
.member-order-list {
	.order-body {
		.list {
			width: 100%;
			margin-top:0.5rem;
			.tips-body {
				height: 2.2rem;
				background: rgba(255, 255, 255, 1);
				box-shadow:0 0.5px 0 0 rgba(232, 234, 237, 1);
				display: flex;
				justify-content: space-between;
				padding:0 0.75rem 0 0.5rem;
				.tips {
					font-size:$subFontSize;
					color: #333;
					line-height: 2.2rem;
				}
				.statusTips {
					color: $primaryColor;
				}
				.img {
					width: 3.8rem;
					height: 3rem;
				}
			}
			.order-image {
				height: 4.55rem;
				background: rgba(250, 250, 250, 1);
				width: 100%;
				overflow: auto;
				white-space: nowrap;
				.goods_info{
						height:4rem;
						margin-bottom: .5rem;
						display: flex;
						align-items: center;
						padding-right: $pageSpace;
						.img-wrapper{
							width: 3rem;
							height: 3rem;
							margin: .85rem .6rem .5rem .3rem;
							.img{
								width: 3rem;
								height: 3rem;
								border-radius: 1px;
							}
						}
						.goods_name{
							white-space: normal;
							overflow: hidden;
							height: 2rem;
							width: 10rem;
							font-size: .7rem;
						}
						.goods_price{
							margin-left: auto;
							padding-right: .75rem;
							text-align: right;
							.price{
								font-size:$subFontSize;
								color: rgba(78, 84, 93, 1);
							}
						}
					}
				}
				.multiple{
					.imagebox{
						width: 100%;
						overflow-x: auto;
						white-space: nowrap;
						.img{
							width: 3rem;
							height:3rem;
							margin: .85rem .3rem .5rem;
							display: inline-block;
						}
					}
				}
			.amount {
				font-size:$subFontSize;
				color: rgba(78, 84, 93, 1);
				line-height: 2.2rem;
				height: 2.2rem;
				background-color: #fff;
				padding:0 0.75rem 0 0;
				border-bottom: 1px solid #e8eaed;
				box-sizing: border-box;
				text-align: right;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				.amount_icon{
					font-size:$subFontSize;
					color: $primaryColor;
				}
				.i {
					font-size:$h2;
					color:$primaryColor;
					padding-left:0.15rem;
					font-style: normal;
					&.freight {
						color: #333;
						font-size:$fontSize;
					}
				}
			}
		}
		.loading-wrapper {
			text-align: center;
			.p {
				color: #c3c3c3;
				font-size:$fontSize;
				font-weight: 'Regular';
				margin: 0.5rem auto;
			}
		}
	}
	.mint-popup {
		width: 100%;
		height: 11.75rem;
	}
}
.order-list-opratio{height: 2.2rem;display: flex;justify-content: flex-end;background: rgba(255, 255, 255, 1);border-radius: 0.1rem;}
.order-list-opratio .button{width: 4.5rem;height: 1.5rem;font-size:$subFontSize;border-radius: 0.7rem;margin: 0.35rem 0.75rem 0.35rem 0;background-color: #fff;border: 1px solid #ccc;box-shadow: 0 3px 6px 0 rgba(0,0,0,.05);display:flex;align-items:center;justify-content:center;}
.order-list-opratio .line_red{background-color: #fff;color: #f2270c;border: 1px solid #f2270c;box-shadow: 0 3px 6px 0 rgba(242,39,12,.1);}

</style>
