<template>
  <div class="app-container">
    <div class="app-header-top" style="width: 100%;float: right;margin-bottom: 10px;">
      <div class="app-title">发货记录</div>
      <el-button type="primary" icon="el-icon-back" style="float: right;" @click="backToList">返回</el-button>
    </div>
    <el-card v-for="(record,index) in recordList" :key="index" class="box-card" style="margin: 0 auto;">
      <div class="refund-item">
        <el-table :data="record.logisticsRecordList" border fit highlight-current-row :show-header="false">
          <el-table-column label="商品图片" align="center" prop="image" width="140">
            <template slot-scope="{row}">
              <el-popover
                placement="top-start"
                title=""
                width="120"
                trigger="hover"
              >
                <img :src="row.image" alt="" style="width:100px;height:100px;">
                <img slot="reference" :src="row.image" alt="" style="width:50px;height:50px;">
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="商品名" align="center" prop="productName" />
          <el-table-column label="规格" align="center" prop="unit" />
          <el-table-column label="购买数量" align="center" prop="buyNum" />
          <el-table-column label="发货数量" align="center" prop="num" />
        </el-table>
        <h1 class="refund-item-title">物流详情</h1>
        <el-collapse accordion>
          <el-collapse-item
            v-for="(express,exIndex) in record.logisticsInformationList"
            :key="exIndex"
            :title="`快递公司：${express.logisticsCompanyName} 物流单号： ${express.nu}`
            "
            name="1"
          >
            <p v-for="(text,textIndex) in hanldeExpress(express.info)" :key="textIndex">
              {{ text.time }}{{ text.context }}
            </p>
          </el-collapse-item>
        </el-collapse>
      </div>
    </el-card>
  </div>
</template>

<script>
import { deliverDetails } from '@/api/order'
export default {
  name: 'DeliverRecord',
  filters: {

  },
  data() {
    return {
      recordList: []
    }
  },
  computed: {
    orderId: function() {
      return this.$route.query.orderId * 1
    },
    shopOrderId() {
      return this.$route.query.shopOrderId * 1
    }
  },
  created() {
    this.deliverDetails({ orderId: this.orderId, shopOrderId: this.shopOrderId })
  },
  methods: {
    // 付款单详情
    async deliverDetails(orderId) {
      try {
        const res = await deliverDetails(orderId)
        console.log('res', res)
        this.recordList = res.data
      } catch (error) {
        console.log('error', error)
      }
    },
    hanldeExpress(express) {
      // 处理物流信息
      return JSON.parse(express)
    },
    backToList() {
      this.$store.dispatch('tagsView/delView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({ path: '/order/detail', query: { orderId: this.orderId }})
        })
      })
    }
  }
}
</script>

<style scoped>
  .app-title{
    line-height: 36px;
    font-size: 26px;
    font-weight: bold;
    color: #409EFF;
    text-align: center;
    margin: 0;
    float: left;
  }
  .box-card{
    margin-top: 20px;
    font-size: 14px;
  }
  .box-row{
    padding: 10px 0;
  }
  .box-row .dropdown{
    margin-top: -10px;
  }
  .refund-item{
    padding: 10px 0;
  }
  .refund-item-title{
    line-height: 24px;
    font-size: 14px;
    color: #409EFF;
  }
  .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;
  }
</style>

