<template>
  <el-dialog title="物流详情" :visible.sync="visible" width="800px" @closed="$emit('close')">
    <div class="logistics-info">
      <div>
        <span class="key">快递公司：</span>
        <span>{{ logisticsCompanyName || '--' }}</span>
      </div>
      <div>
        <span class="key">快递单号：</span>
        <span>{{ logisticCode || '--' }}</span>
        <el-button class="ml15" type="text" v-clipboard:copy="data.logisticCode" v-clipboard:success="onCopy" v-clipboard:error="onError">复制</el-button>
      </div>
    </div>
    <div v-if="logisticsList.length>0" class="logistics-step">
      <h3>派送中</h3>
      <el-timeline class="hollow logistics-list">
        <el-timeline-item
          v-for="(activity, index) in logisticsList"
          :key="index"
          :color="index===0?'':'#c0c4cc'">
          <div class="logistics-line-step">
            <span class="time">{{ activity.acceptTime || '--' }}</span>
            <p class="content">{{ activity.acceptStation }}</p>
          </div>
        </el-timeline-item>
      </el-timeline>
    </div>
    <div v-else class="empty_block"></div>
  </el-dialog>
</template>

<script>
import fetch from '@/api/performance.js';
const { getLogisticsInfo } = fetch;
export default {
  props: {
    data: Object
  },
  data() {
    return {
      visible: false,
      logisticsList: [],
      logisticsCompanyName: '',
      logisticCode: ''
    };
  },
  mounted() {
    this.visible = true;
    this.getInfo();
  },
  methods: {
    async getInfo() {
      let { result } = await getLogisticsInfo({
        companyCode: this.data.logisticsCompanyCode/* 'YD' */,
        logisticsNo: this.data.logisticsNo/* '4312317986451' */,
      });
      this.logisticsList = result.traces || [];
      this.logisticsList.reverse();
      this.logisticsCompanyName = result.logisticsCompanyName;
      this.logisticCode = result.logisticCode;
    }
  }
};
</script>

<style lang="scss" scoped>
.empty_block::after {
  content: '暂无物流信息';
}
.logistics-info {
  display: flex;
  &>div {
    flex: 1;
  }
  span {
    display: inline-block;
  }
  span + span {
    margin-left: 10px;
  }
}
.logistics-step {
  margin-top: 24px;
  background: #fafafa;
  padding: 15px 0px;
  h3 {
    color: #303133;
    font-size: 16px;
    border-bottom: 1px solid #dcdfe6;
    padding: 0 20px 15px 20px;
  };
  .logistics-list {
    height: 328px;
    overflow-y: auto;
    padding: 20px
  };
  .logistics-item {
    position: relative;
    padding-bottom: 10px;
  }
  .logistics-line-step {
    display: flex;
    font-size: 12px;
  }
  .logistics-line-step .time {
    margin-right: 20px;
    width: 160px;
    line-height: 22px;
    font-weight: 500;
    color: #303133;
  }
  .logistics-line-step .content {
    color: #303133;
    flex: 1;
    line-height: 22px;
  }
}
</style>
