<template>
  <div class="app-container">

    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal">
      <el-menu-item index="1" @click="backToList">用户退款列表</el-menu-item>
      <el-menu-item index="2">用户退款详情</el-menu-item>
    </el-menu>

    <h1>退款单</h1>
    <el-card v-for="refund in refundList" :key="refund.orderID" class="box-card">
      <div class="refund-item">
        <el-row :gutter="24" class="box-row">
          <el-col :span="6"><b>退款编号:</b> {{ refund.returnedNo }}</el-col>
          <el-col :span="6"><b>申请时间:</b> <template v-if="refund.returnTime">{{ refund.returnTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</template></el-col>
          <el-col :span="6"><b>申请金额:</b> ¥{{ refund.refundFee | toThousandFilter }}</el-col>
          <el-col :span="6"><b>退款状态:</b>
            <el-tag v-if="refund.status*1===1" type="warning" size="small">待审核</el-tag>
            <el-tag v-if="refund.status*1===2" type="danger" size="small">审核不通过</el-tag>
            <el-tag v-if="refund.status*1===3" type="success" size="small">审核通过</el-tag>
          </el-col>
        </el-row>
        <el-row :gutter="24" class="box-row">
          <el-col :span="20"><b>退款方式:</b>
            <template v-if="refund.returnedWay*1===4">未支付无退款</template>
            <template v-else-if="refund.returnedWay*1===1">
              <span v-if="refund.refundBalanceFee*1 !== 0">余额账户:¥{{ refund.refundBalanceFee | toThousandFilter }}</span>
              <span v-if="refund.refundOnlineFee*1 !== 0">线上退回:¥{{ refund.refundOnlineFee | toThousandFilter }}</span>
              <span v-if="refund.refundOfflineFee*1 !== 0">线下转账:¥{{ refund.refundOfflineFee | toThousandFilter }}</span>
            </template>
            <template v-else>----</template>
          </el-col>
        </el-row>
        <template v-if="refund.returnedWay*1===1 && refund.refundOfflineFee*1!==0">
          <el-row :gutter="24" class="box-row">
            <el-col v-if="refund.refundFee" :span="12"><b>退款银行:</b>
              <template v-if="refund.payType*1===1">建设银行7297</template>
              <template v-else-if="refund.payType*1===2">中信银行0897</template>
              <template v-else-if="refund.payType*1===3">中信银行7172</template>
              <template v-else-if="refund.payType*1===4">广发银行0115</template>
              <template v-else-if="refund.payType*1===5">广发银行5461</template>
            </el-col>
            <el-col v-else :span="12">暂无支付方式</el-col>
          </el-row>
          <el-row :gutter="24" class="box-row">
            <el-col :span="6"><b>开户名:</b> {{ refund.bankAccountName ? refund.bankAccountName : '' }}</el-col>
            <el-col :span="6"><b>账号:</b> {{ refund.bankAccountNo ? refund.bankAccountNo : '' }}</el-col>
            <el-col :span="6"><b>开户行:</b> {{ refund.openBank ? refund.openBank : '' }}</el-col>
            <el-col :span="6"><b>账户类型:</b>
              <el-tag v-if="refund.bankAccountType*1===1" type="warning" size="small">公账</el-tag>
              <el-tag v-if="refund.bankAccountType*1===2" type="danger" size="small">私账</el-tag>
            </el-col>
          </el-row>
        </template>
      </div>

      <div class="refund-item">
        <template v-if="order">
          <el-row :gutter="24" class="box-row">
            <el-col :span="6"><b>订单编号(ID):</b> {{ order.orderNo + '(' + order.orderID + ')' }}</el-col>
            <el-col :span="6"><b>下单时间:</b> <template v-if="order.orderTime">{{ order.orderTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</template></el-col>
            <el-col :span="6"><b>订单状态:</b>
              <template v-if="['11','12','13','21','22','23','31','32','33'].indexOf(order.status)>=0">
                <el-tag type="success" size="small">{{ '交易中('+statusObj[order.status]+')' }}</el-tag>
              </template>
              <template v-else>
                <el-tag :type="order.status*1===6?'info':''" size="small">{{ statusObj[order.status] }}</el-tag>
              </template>
            </el-col>
            <el-col v-if="order.bpOrderUserinfo" :span="6"><b>买家:</b> {{ order.bpOrderUserinfo.name }}</el-col>
          </el-row>
          <el-row :gutter="24" class="box-row">
            <el-col :span="6"><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="6"><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-row>
          <el-row v-if="order.bpOrderUserinfo" :gutter="24" class="box-row">
            <el-col :span="6"><b>收货人:</b> {{ order.bpOrderUserinfo.shouHuoRen }}</el-col>
            <el-col :span="6"><b>手机:</b> {{ order.bpOrderUserinfo.mobile }}</el-col>
            <el-col :span="12"><b>地址:</b> {{ order.bpOrderUserinfo.province +' '+ order.bpOrderUserinfo.city +' '+ order.bpOrderUserinfo.town +' '+ order.bpOrderUserinfo.address }}</el-col>
          </el-row>

          <div v-for="shopOrder in refund.shopOrderReturnedList" :key="shopOrder.shopOrderID" class="order-item">
            <el-row :gutter="22" class="box-row">
              <el-col :span="9"><b>子订单号(ID):</b> {{ shopOrder.shopOrderNo + '(' + shopOrder.shopOrderID + ')' }}</el-col>
              <el-col :span="5"><b>子订单金额:</b> ¥{{ shopOrder.needPayAmount | toThousandFilter }}</el-col>
              <el-col :span="5"><b>付款状态:</b>
                <el-tag v-if="shopOrder.payStatus*1===1" type="danger" size="small">待付款</el-tag>
                <el-tag v-if="shopOrder.payStatus*1===2" type="warning" size="small">部分付款</el-tag>
                <el-tag v-if="shopOrder.payStatus*1===3" type="success" size="small">已付款</el-tag>
              </el-col>
              <el-col :span="5"><b>发货状态:</b>
                <el-tag v-if="shopOrder.sendOutStatus*1===1" type="danger" size="small">待发货</el-tag>
                <el-tag v-if="shopOrder.sendOutStatus*1===2" type="warning" size="small">部分发货</el-tag>
                <el-tag v-if="shopOrder.sendOutStatus*1===3" type="success" size="small">已发货</el-tag>
              </el-col>
            </el-row>
            <el-row :gutter="22" class="box-row">
              <el-col :span="22"><b>供应商:</b> {{ shopOrder.shopName }}</el-col>
            </el-row>
            <el-row v-for="op in shopOrder.cmReturnedPurchaseProductList" :key="op.orderProductID" :gutter="22" class="product-row">
              <el-col :span="2">
                <img :src="op.mainImage" width="60" alt="">
              </el-col>
              <el-col :span="7">{{ op.name }}</el-col>
              <el-col :span="5">
                <div class="op-item"><b>数量</b>{{ op.productID*1!==999 ? ('(赠品数): x'+op.num+'('+op.presentNum+')') : (': x'+op.num) }}</div>
                <div v-if="op.productID*1!==999" class="op-item">规格: {{ op.unit }}</div>
              </el-col>
              <el-col v-if="op.productID*1!==999" :span="5">
                <div class="op-item"><b>单价:</b> ¥{{ op.price | toThousandFilter }}</div>
                <div class="op-item"><b>总额:</b> ¥{{ op.totalFee | toThousandFilter }}</div>
              </el-col>
              <el-col v-if="op.productID*1!==999" :span="5">
                <div v-if="order.sendOutStatus*1 === 2 || order.sendOutStatus*1 === 3" class="op-item"><b>已发/已收:</b> {{ ((op.num ? op.num : 0) - (op.notOutStore ? op.notOutStore : 0)) + '/' + op.receivedNum }}</div>
              </el-col>
            </el-row>
          </div>
        </template>
      </div>
      <!-- <div class="refund-item"><el-card v-if="order && order.orderInvoice" class="box-card">
        <el-row :gutter="24" class="box-row">
          <b>发票信息:</b>
          <template v-if="order.orderInvoice.type*1===0">不需要发票</template>
          <template v-else-if="order.orderInvoice.type*1===1">普通发票</template>
          <template v-else-if="order.orderInvoice.type*1===2">增值税发票</template>
        </el-row>
        <el-row v-if="order.orderInvoice.invoiceTitleType*1===0" :gutter="24" class="box-row">
          <el-col :span="6"><b>个人抬头:</b>{{ order.orderInvoice.invoiceTitle }}</el-col>
        </el-row>
        <el-row v-if="order.orderInvoice.invoiceTitleType*1===1" :gutter="24" class="box-row">
          <el-col :span="6"><b>企业抬头:</b>{{ order.orderInvoice.invoiceTitle }}</el-col>
          <el-col :span="6"><b>纳税人识别号:</b>{{ order.orderInvoice.corporationTaxNum }}</el-col>
        </el-row>
        <template v-if="order.orderInvoice.type*1===2">
          <el-row :gutter="24" class="box-row">
            <el-col :span="6"><b>单位名称:</b>{{ order.orderInvoice.invoiceTitle }}</el-col>
            <el-col :span="6"><b>纳税人识别号:</b>{{ order.orderInvoice.corporationTaxNum }}</el-col>
            <el-col :span="6"><b>注册地址:</b>{{ order.orderInvoice.registeredAddress }}</el-col>
          </el-row>
          <el-row :gutter="24" class="box-row">
            <el-col :span="6"><b>注册电话:</b>{{ order.orderInvoice.registeredPhone }}</el-col>
            <el-col :span="6"><b>开户银行:</b>{{ order.orderInvoice.openBank }}</el-col>
            <el-col :span="6"><b>银行账号:</b>{{ order.orderInvoice.bankAccountNo }}</el-col>
          </el-row>
        </template>
      </el-card></div>-->

      <div class="refund-item">
        <h3>审核信息</h3>
        <el-row :gutter="24" class="box-row">
          <el-col :span="6"><b>审核人:</b> {{ refund.reviewUserName }}</el-col>
          <el-col :span="6"><b>审核时间:</b> {{ refund.confirmReturnTime }}</el-col>
          <el-col :span="6"><b>审核备注:</b> {{ refund.reviewRemarks ? refund.reviewRemarks : '无' }}</el-col>
        </el-row>
        <el-row v-if="refund.reviewImage1 || refund.reviewImage2 || refund.reviewImage3 || refund.reviewImage4 || refund.reviewImage5 " :gutter="24" class="box-row">
          <el-col :span="4"><b>审核凭证:</b></el-col>
          <el-col :span="20">
            <img v-if="refund.reviewImage1" :src="refund.reviewImage1" width="65" alt="">
            <img v-if="refund.reviewImage2" :src="refund.reviewImage2" width="65" alt="">
            <img v-if="refund.reviewImage3" :src="refund.reviewImage3" width="65" alt="">
            <img v-if="refund.reviewImage4" :src="refund.reviewImage4" width="65" alt="">
            <img v-if="refund.reviewImage5" :src="refund.reviewImage5" width="65" alt="">
          </el-col>
        </el-row>
      </div>
      <div class="refund-item">
        <h3>申请信息</h3>
        <el-row :gutter="24" class="box-row">
          <el-col :span="6"><b>申请人:</b> {{ refund.applicationUserName }}</el-col>
          <el-col :span="6"><b>申请时间:</b> <template v-if="refund.returnTime">{{ refund.returnTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</template></el-col>
          <el-col :span="6"><b>退款备注:</b> {{ refund.remarks ? refund.remarks : '无' }}</el-col>
        </el-row>
        <el-row v-if="refund.image1 || refund.image2 || refund.image3 || refund.image4 || refund.image5 " :gutter="24" class="box-row">
          <el-col :span="4"><b>申请凭证:</b></el-col>
          <el-col :span="20">
            <img v-if="refund.image1" :src="refund.image1" width="65" alt="">
            <img v-if="refund.image2" :src="refund.image2" width="65" alt="">
            <img v-if="refund.image3" :src="refund.image3" width="65" alt="">
            <img v-if="refund.image4" :src="refund.image4" width="65" alt="">
            <img v-if="refund.image5" :src="refund.image5" width="65" alt="">
          </el-col>
        </el-row>
      </div>
      <div class="refund-item">
        <el-row :gutter="24" class="box-row">
          <el-col :span="6"><b>申请退款金额:</b> ¥{{ refund.refundFee | toThousandFilter }}</el-col>
          <el-col :span="6"><b>财务签名:</b></el-col>
          <el-col :span="6"><b>总经理签名:</b></el-col>
        </el-row>
      </div>
    </el-card>

    <template>
      <el-backtop style="right: 40px; bottom: 40px;">
        <i class="el-icon-upload2" />
      </el-backtop>
    </template>
  </div>
</template>

<script>
import { getRefundDetail } from '@/api/order'
export default {
  data() {
    return {
      activeIndex: '2',
      bpClauses: [],
      order: null,
      refundList: [],
      statusObj: {
        '0': '待确认',
        '4': '交易完成',
        '5': '订单完成',
        '6': '已关闭',
        '7': '交易全退',
        '11': '待收款、待发货',
        '12': '待收款、部分发货',
        '13': '待收款、全部发货',
        '21': '部分收款、待发货',
        '22': '部分收款、部分发货',
        '23': '部分收款、全部发货',
        '31': '全部收款、待发货',
        '32': '全部收款、部分发货',
        '33': '全部收款、全部发货'
      }
    }
  },
  computed: {
    orderID: function() {
      return this.$route.query.orderID
    },
    refundId: function() {
      return this.$route.params.id
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      getRefundDetail({ id: this.refundId, orderID: this.orderID }).then(response => {
        this.order = response.data.order
        this.bpClauses = response.data.bpClauses
        this.refundList = response.data.cmReturnedPurchaseList
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    backToList() {
      this.$store.dispatch('tagsView/delView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({
            path: '/order/refund'
          })
        })
      })
    }
  }
}
</script>

<style scoped>
  h1{
    color: #409EFF;
    font-size: 24px;
    text-align: center;
  }
  h3{
    color: #409EFF;
    font-size: 16px;
    margin: 0;
  }
  .box-card{
    margin-top: 20px;
    font-size: 14px;
  }
  .box-row{
    padding: 10px 0;
  }
  .refund-item{
    border-bottom:1px dashed #E4E7ED;
    margin-bottom: 20px;
  }
  .order-item{
    border-bottom: 1px solid #DCDFE6;
    background:#F2F6FC;
    margin-top: 20px;
    padding: 5px 15px 0;
    border-radius: 5px;
  }
  .product-row{
    padding: 10px 0;
    background: #EBEEF5;
    border-top: 1px dashed #DCDFE6;
  }
  .op-item{
    padding: 5px 0;
  }
</style>

