<template>
  <div class="app-container">
    <el-card v-if="cmReturnedPurchaseList.length === 0" class="box-card" style="height: 100px;line-height: 100px; text-align:center;color: #999;">暂无退款退货详情记录~</el-card>
    <template v-else>
      <div v-for="(cmReturn,index) in cmReturnedPurchaseList" id="printBox" :key="index">
        <!-- <el-card class="box-card" style="margin: 5px auto;">
          <div class="refund-item">
            <h1 class="refund-item-title">审核信息</h1>
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>审核人：</b> {{ cmReturn.reviewUserName }}</el-col>
              <el-col :span="4"><b>审核时间：</b> {{ cmReturn.confirmReturnTime ? cmReturn.confirmReturnTime :'--' }}</el-col>
              <el-col :span="15"><b>审核备注：</b> {{ cmReturn.reviewRemarks ? cmReturn.reviewRemarks :'--' }}</el-col>
            </el-row>
          </div>
        </el-card> -->
        <el-card class="box-card" style="margin: 5px auto;">
          <div class="refund-item">
            <h1 class="refund-item-title">申请信息</h1>
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>申请人：</b> {{ cmReturn.applicationUserNam ? cmReturn.applicationUserNam :'--' }}</el-col>
              <el-col :span="4"><b>申请时间：</b> {{ cmReturn.returnTime ? cmReturn.returnTime :'--' }}</el-col>
              <el-col :span="15"><b>退款备注：</b> {{ cmReturn.remarks ? cmReturn.remarks :'--' }}</el-col>
            </el-row>
          </div>
        </el-card>
        <el-card class="box-card" style="margin: 5px auto;">
          <div class="refund-item">
            <h1 class="refund-item-title">退款信息</h1>
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>退款编号：</b> {{ cmReturn.returnedNo }}</el-col>
              <el-col :span="4"><b>申请时间：</b> {{ cmReturn.returnTime }}</el-col>
              <el-col :span="15"><b>申请金额</b> ¥{{ cmReturn.refundFee | amountfilters }} </el-col>
            </el-row>
            <h1 class="refund-item-title">退款方式</h1>
            <el-row :gutter="24" class="box-row">
              <el-col v-if="cmReturn.returnedWay*1===4" :span="4"><b>未支付无退款</b> </el-col>
              <template v-else-if="cmReturn.returnedWay*1===1">
                <template v-if="cmReturn.refundOnlineFee*1 !== 0">
                  <el-col :span="5">
                    <b>线上退回:</b>
                    <span>¥{{ cmReturn.refundOnlineFee | amountfilters }}</span>
                  </el-col>
                </template>
                <template v-if="cmReturn.refundOfflineFee*1 !== 0">
                  <el-col :span="5">
                    <b>线下转账：</b>
                    <span>¥{{ cmReturn.refundOfflineFee | amountfilters }}</span>
                  </el-col>
                  <!-- <el-col :span="4"><b>开户名：</b><span>{{ cmReturn.bankAccountName }}</span> </el-col>
                  <el-col :span="4"><b>账号：</b> <span>{{ cmReturn.bankAccountNo }}</span> </el-col>
                  <el-col :span="4"><b>开户行：</b> <span>{{ cmReturn.openBank }}</span> </el-col>
                  <el-col :span="4"><b>账户类型：</b> <span>{{ cmReturn.bankAccountType*1 === 1 ? '公账' : '私账' }}</span> </el-col> -->
                </template>
              </template>
              <span v-else>----</span>
            </el-row>
          </div>
        </el-card>
        <el-card class="box-card" style="margin: 5px auto;">
          <div class="refund-item">
            <!-- <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>订单编号(ID)：</b> {{ order.orderNo }}({{ order.orderId }})</el-col>
              <el-col :span="4"><b>下单时间：</b> {{ order.orderTime }}</el-col>
              <el-col :span="6"><b>机构名称：</b> {{ order.clubName }}</el-col>
              <el-col :span="9">
                <b>订单状态：</b>
                <template v-if="['11','12','13','21','22','23','31','32','33'].indexOf(order.status)>=0">
                  <el-tag type="success" size="small">交易中</el-tag>
                </template>
                <template v-else>
                  <el-tag :type="order.status*1===6?'info':''" size="small">{{ order.status | orderStatusFilter }}</el-tag>
                </template>
              </el-col>
            </el-row>
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>订单金额：</b> {{ order.payTotalFee }}</el-col>
              <el-col :span="4"><b>应收金额：</b> {{ order.payableAmount }}</el-col>
              <el-col :span="15"><b>机构运费：</b>  <span>{{ order.postageInfo }}</span></el-col>
            </el-row>
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>收款状态:</b>
                <el-tag v-if="order.receiptStatus*1===1" type="danger" size="small">待收款</el-tag>
                <el-tag v-if="order.receiptStatus*1===2" type="warning" size="small">部分收款</el-tag>
                <el-tag v-if="order.receiptStatus*1===3" type="success" size="small">已收款</el-tag>
              </el-col>
              <el-col :span="4"><b>退款状态:</b>
                <el-tag v-if="order.refundType*1===1" type="warning" size="small">部分退款</el-tag>
                <el-tag v-else-if="order.refundType*1===2" type="danger" size="small">已退款</el-tag>
                <el-tag v-else type="info" size="small">无退款</el-tag>
              </el-col>
              <el-col :span="6"><b>发货状态:</b>
                <el-tag v-if="order.sendOutStatus*1===1" type="danger" size="small">待发货</el-tag>
                <el-tag v-if="order.sendOutStatus*1===2" type="warning" size="small">部分发货</el-tag>
                <el-tag v-if="order.sendOutStatus*1===3" type="success" size="small">已发货</el-tag>
              </el-col>
              <el-col :span="9"><b>退款状态：</b>
                <el-tag v-if="order.refundType*1===1" type="warning" size="small">部分退款</el-tag>
                <el-tag v-else-if="order.refundType*1===2" type="danger" size="small">已退款</el-tag>
                <el-tag v-else type="info" size="small">无退款</el-tag>
              </el-col>
            </el-row> -->
            <el-row :gutter="24" class="box-row">
              <el-col :span="5"><b>机构:</b> {{ order.bpOrderUserinfo.name }}</el-col>
              <el-col :span="4"><b>收货人:</b> {{ order.bpOrderUserinfo.shouHuoRen }}</el-col>
              <el-col :span="6"><b>手机:</b> {{ order.bpOrderUserinfo.mobile }}</el-col>
              <el-col :span="9"><b>地址:</b> {{ order.bpOrderUserinfo.province +' '+ order.bpOrderUserinfo.city +' '+ order.bpOrderUserinfo.town +' '+ order.bpOrderUserinfo.address }}</el-col>
            </el-row>
            <el-table :data="cmReturn.shopOrderReturnedList" border fit highlight-current-row default-expand-all :header-cell-style="{background:'#e9f3f7',color:'#606266'}">
              <el-table-column label="商品信息" type="expand" width="80px">
                <template slot-scope="{row}">
                  <el-table :data="row.cmReturnedPurchaseProductList" border fit highlight-current-row :header-cell-style="{background:'#f9f9f9',color:'#606266'}">
                    <el-table-column label="商品图片" align="center" prop="image" width="100">
                      <template slot-scope="scope">
                        <el-popover
                          placement="top-start"
                          title=""
                          width="120"
                          trigger="hover"
                        >
                          <img :src="scope.row.mainImage" alt="" style="width:100px;height:100px;">
                          <img slot="reference" :src="scope.row.mainImage" alt="" style="width:50px;height:50px;">
                        </el-popover>
                      </template>
                    </el-table-column>
                    <el-table-column label="商品名" align="center" prop="name" />
                    <el-table-column label="规格" align="center" prop="unit" />
                    <el-table-column label="购买数量" align="center" prop="num" width="100" />
                    <el-table-column label="单价" align="center" prop="price" />
                    <el-table-column label="总额" align="center" prop="totalAmount" />
                    <el-table-column label="已发货" align="center" prop="sendOutNum" width="100" />
                    <el-table-column label="已退货" align="center" prop="returnedPurchaseProductNum" width="100" />
                    <el-table-column label="本次退货" align="center" prop="actualReturnedNum" width="100" />
                    <el-table-column label="待发货" align="center" prop="notOutStore" width="100" />
                    <el-table-column label="已取消" align="center" prop="cancelProductNum" width="100" />
                    <el-table-column label="本次取消" align="center" prop="actualCancelNum" width="100" />
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column label="子订单编号(ID)" align="center" prop="shopOrderNos" width="240">
                <template slot-scope="{row}">
                  <span>{{ row.shopOrderNo }}({{ row.shopOrderId }})</span>
                </template>
              </el-table-column>
              <el-table-column label="子订单金额" align="center" prop="productAmount" />
              <el-table-column label="发货状态" align="center" prop="sendOutStatus">
                <template slot-scope="{row}">
                  <el-tag v-if="row.sendOutStatus*1===1" type="danger" size="small">待发货</el-tag>
                  <el-tag v-if="row.sendOutStatus*1===2" type="warning" size="small">部分发货</el-tag>
                  <el-tag v-if="row.sendOutStatus*1===3" type="success" size="small">已发货</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="付款状态" align="center" prop="receiptStatus">
                <template slot-scope="{row}">
                  <el-tag v-if="row.payStatus*1===1" type="danger" size="small">待付款</el-tag>
                  <el-tag v-if="row.payStatus*1===2" type="warning" size="small">部分付款</el-tag>
                  <el-tag v-if="row.payStatus*1===3" type="success" size="small">已付款</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="运费" align="center">
                <template>
                  {{ order.newShopOrders[0].postageInfo }}
                </template>
              </el-table-column>
              <el-table-column label="退款状态" align="center">
                <template>
                  <el-tag v-if="order.newShopOrders[0].orderStatusFlag*1===1" type="info" size="small">无退款</el-tag>
                  <el-tag v-if="order.newShopOrders[0].orderStatusFlag*1===2" type="warning" size="small">退款中</el-tag>
                  <el-tag v-if="order.newShopOrders[0].orderStatusFlag*1===3" type="success" size="small">已退款</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="供应商" align="center" prop="shopName" />
            </el-table>
          </div>
        </el-card>
      </div>
    </template>
  </div>
</template>

<script>
import { organizeToRecturnRecordByOrderId } from '@/api/finance'
export default {
  name: 'RefundRecord',
  filters: {
    statusFilter(status) {
      const map = {
        0: '待付款',
        1: '已付款',
        2: '审核不通过'
      }
      return map[status]
    }
  },
  data() {
    return {
      order: {},
      repacts: {},
      products: [],
      cmReturnedPurchase: {},
      cmReturnedPurchaseList: []
    }
  },
  computed: {
    orderId: function() {
      return this.$route.query.orderId * 1
    },
    shopOrderId() {
      return this.$route.query.shopOrderId * 1
    }
  },
  created() {
    this.organizeToRecturnRecordByOrderId()
  },
  methods: {
    async organizeToRecturnRecordByOrderId() {
      try {
        const res = await organizeToRecturnRecordByOrderId({ orderId: this.orderId, shopOrderId: this.shopOrderId })
        this.order = res.data.order
        this.cmReturnedPurchase = res.data.cmReturnedPurchase
        this.cmReturnedPurchaseList = res.data.cmReturnedPurchaseList
        console.log('res', res)
      } catch (error) {
        console.log('error', error)
      }
    }
  }
}
</script>

<style scoped lang="scss">
  .app-title{
    line-height: 36px;
    font-size: 26px;
    font-weight: bold;
    color: #409EFF;
    text-align: center;
  }
  .box-card{
    margin-top: 20px;
    font-size: 14px;
  }
  .box-row{
    padding: 10px 0;
  }
  .box-row .dropdown{
    margin-top: -10px;
  }
  .refund-item{
    padding: 5px 0;
  }
  .refund-item-title{
    line-height: 24px;
    font-size: 14px;
    color: #409EFF;
    margin: 0;
  }
  .order-item{
    background:#f7f7f7;
    margin-bottom: 20px;
    padding: 10px 15px;
    border-radius: 5px;
  }
  .product-row{
    padding: 10px 0;
    background: #EBEEF5;
    border-top: 1px dashed #DCDFE6;
  }
  .op-item{
    padding: 5px 0;
  }
  .el-span-warning{
  color: #E6A23C;
  }
  .el-span-success{
    color: #67C23A;
  }
  .el-span-danger{
    color: #F56C6C;
  }
  ::v-deep .el-table__expanded-cell[class*=cell]{
    padding:10px 10px !important;
  }
  ::v-deep .el-card__body{
    padding: 5px 20px !important;
  }
</style>

