<template>
  <vxe-table
    size="mini"
    border
    stripe
    ref="table"
    :height="height"
    :row-config="{isCurrent: true,isHover: true}"
    :data="data">
    <vxe-column field="id" title="内部订单号" width="100" fixed="left">
      <template #default="{ row }">
        <div class="col-cont">
          <span>{{ row.id }}</span>
          <div class="update">
            <div class="tag-update" @click="detail(row)">详</div>
          </div>
        </div>
      </template>
    </vxe-column>
    <!-- <vxe-column field="sourceId" title="线上订单号" width="140"> </vxe-column> -->
    <vxe-column field="product" title="商品" width="140">
      <template #default="{ row }">
        <el-badge :value="item.qty" class="item-pro" type="primary" :max="99" v-for="(item,index) of row.items" :key="index">
          <el-image  style="width: 28px; height: 28px">
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </el-badge>
      </template>
    </vxe-column>
    <vxe-column field="businessType" title="订单分类" width="120"></vxe-column>
    <!-- <vxe-column field="type" title="订单类型" width="120">
      <template #default="{ row }">
        <span v-if="row.type == 'Common'">普通订单</span>
        <span v-if="row.type == 'Reissue'">补发订单</span>
        <span v-if="row.type == 'DistributionPlus'">分销Plus</span>
        <span v-if="row.type == 'SupplyPlus'">供销Plus</span>
        <span v-if="row.type == 'Exchange'">换货订单</span>
      </template>
    </vxe-column> -->
    <vxe-column field="status" title="订单状态" width="120">
      <template #default="{ row }">
        <span v-if="row.status == 'WaitPay'">待付款</span>
        <span v-if="row.status == 'Delivering'">发货中</span>
        <span v-if="row.status == 'Merged'">被合并</span>
        <span v-if="row.status == 'Question'" style="color:red">异常</span>
        <span v-if="row.status == 'Split'">被拆分</span>
        <span v-if="row.status == 'WaitOuterSent'">等供销商|外仓发货</span>
        <span v-if="row.status == 'WaitConfirm'">已付款待审核</span>
        <span v-if="row.status == 'WaitFConfirm'">已客审待财审</span>
        <span v-if="row.status == 'Sent'">已发货</span>
        <span v-if="row.status == 'Cancelled'">取消</span>
      </template>
    </vxe-column>
    <!-- <vxe-column field="sourceFrom" title="订单来源" width="120">
      <template #default="{ row }">
        {{ getFromText(row.sourceFrom) }}
      </template>
    </vxe-column> -->
    <vxe-column field="shipment" title="跨境买家指定物流" width="120"></vxe-column>
    <vxe-column field="chosenChannel" title="实发快递渠道" width="120"></vxe-column>
    <vxe-column field="logisticsId" title="快递单号" width="120"></vxe-column>
    <vxe-column field="logisticsCompany" title="快递公司" width="120"></vxe-column>
    <vxe-column field="logisticsCompanyId" title="物流公司编码" width="120"></vxe-column>
    <vxe-column field="internationalLogisticsId" title="国际物流单号" width="120"></vxe-column>
    <vxe-column field="skus" title="skus" width="120"></vxe-column>
    <vxe-column field="weight" title="重量" width="70"></vxe-column>
    <vxe-column field="isCod" title="是否货到付款" width="120">
      <template #default="{ row }">
        {{ row.isCod == 1 ? '是' :' 否' }}
      </template>
    </vxe-column>
    <vxe-column field="sendDate" title="发货日期" width="120"></vxe-column>
    <vxe-column field="signTime" title="预计送达时间" width="120"></vxe-column>
    <vxe-column field="endTime" title="确认收货时间" width="120"></vxe-column>
    <vxe-column field="receiverAddress" title="收货地址" show-overflow width="120"></vxe-column>
    <vxe-column field="receiverName" title="收件人" show-overflow width="120"></vxe-column>
    <vxe-column field="receiverMobile" title="手机" show-overflow width="120"></vxe-column>
    <vxe-column field="buyerMessage" title="买家留言" show-overflow width="120"></vxe-column>
    <vxe-column field="wmsCoId" title="发货仓编号" show-overflow width="120"></vxe-column>
    <vxe-column field="payDate" title="支付时间" width="140"></vxe-column>
    <vxe-column field="freeAmount" title="抵扣金额" width="120"></vxe-column>
    <vxe-column field="payAmount" title="应付+运费" width="120">
      <template #default="{ row }">
        <span>{{ row.payAmount }}</span> <br/>
        <span style="color: #b9b8b8;">{{ row.freight?row.freight:0 }}</span>
      </template>
    </vxe-column>
    <vxe-column field="paidAmount" title="实付金额" width="120"></vxe-column>
    <vxe-column field="shopBuyerId" title="买家昵称" show-overflow width="120"></vxe-column>
    <vxe-column field="openId" title="平台买家唯一值" show-overflow width="120"></vxe-column>
    <vxe-column field="buyerPaidAmount" title="总买家实付" width="120"></vxe-column>
    <vxe-column field="sellerIncomeAmount" title="总卖家实收" width="120"></vxe-column>
    <vxe-column field="questionType" title="问题类型" width="120"></vxe-column>
    <vxe-column field="questionDesc" title="问题描述" width="120"></vxe-column>
    <vxe-column field="shopName" title="店铺" width="120"></vxe-column>
    <!-- <vxe-column field="invoiceType" title="发票类型" width="120"></vxe-column> -->
    <vxe-column field="invoiceTitle" title="发票抬头+税号" width="120">
      <template #default="{ row }">
        <span>{{ row.invoiceTitle }}</span> <br/>
        <span style="color: #b9b8b8;">{{ row.buyerTaxNo }}</span><br/>
        <span>{{ row.invoiceType }}</span>
      </template>
    </vxe-column>
    <vxe-column field="drpCoIdFrom" title="分销商编号" width="120"></vxe-column>
    <vxe-column field="drpCoIdTo" title="供销商编号" width="120"></vxe-column>
    <vxe-column field="orderDate" title="订单日期" width="120">
      <template #default="{ row }">
        {{ formatDate(row.orderDate) }}
      </template>
    </vxe-column>
    <vxe-column field="remark" title="订单备注" width="120"></vxe-column>
    <vxe-column field="note" title="线下备注" width="120"></vxe-column>
  </vxe-table>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import Format from '@/benyun/utils/dateFormat'
@Component
export default class OrderTable extends Vue {
  @Prop()
  data!:Array<any>
  height=null

  sourceFrom:any={
    'ERP':'手工下单',
    'COPY':'复制',
    'MERGE':'合并',
    'SPLIT':'拆分；拆分还原',
    'MOBILE':'导入',
    'drp-s':'供销推送',
    'drp-d':'分销推送',
    'KWAISHOP':'快手；微商城',
    'PINDUODUO':'拼多多',
    'TOUTIAOFXG':'头条放心购',
    'JUSHUITAN':'聚水潭'
  }
  //订单来源转换文字信息
  getFromText(f:any){
    let t='';
    if(f){
      let arr:Array<any>=f.split(',');
      for(const item of arr){
        if(this.sourceFrom[item]){
          if(t){
            t = t + ' , ' + this.sourceFrom[item]
          }else{
            t = this.sourceFrom[item]
          }
        }
      }
    }
    return t;
  }
  formatDate(v:string){
    return Format(v,'yyyy-MM-dd');
  }
  mounted(){
    this.$nextTick(() => {
      this.height = (this as any).$el.offsetHeight;
      (this.$refs.table as any).recalculate();
    })
  }
  detail(row:any){
    this.$emit('detail',row)
  }
}
</script>

<style lang="scss" scoped>
.detail{
  color: #0089ff;
  cursor: pointer;
}
.col-cont{
  // display: flex;
  // justify-content: space-between;
  // align-items: center;
  // flex-direction: column;
  .update{
    display: flex;
    justify-content: flex-end;
    width: 100%;
    visibility: hidden;
  }
  .tag-update{
    height: 24px;
    width: 24px;
    font-size: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    background-color:#2d99f7;
    color: #FFF;
    flex-shrink: 0;
    margin-left: 4px;
    cursor: pointer;
  }
  .tag-update:hover{
    opacity: 0.7;
  }
}
</style>

<style lang="scss">
.row--hover{
  .update{
    visibility:visible !important;
  }
}
.row--current{
  .update{
    visibility:visible !important;
  }
}
.image-slot{
  .el-icon-picture-outline{
    font-size: 28px;
    color: #999;
  }
}
.item-pro{
  .el-badge__content{
    z-index: 1;
  }
}
</style>