<template>
  <el-drawer
    title="订单脚印"
    ref="orderStep"
    :reverse="true"
    :visible.sync="drawer"
    :append-to-body="appendToBody"
    :with-header="false">
    <span style="display: block;position:fixed;top: 10px;width: 100%;z-index: 9999;margin:0 10px; padding:10px;background-color: white;margin-top: -10px">{{collection.orderCode }} - {{collection.orderName}}</span>
    <el-button  v-if="visible" @click="goToBottom" size="mini" type="primary" style="margin: 10px;margin-top: 60px">到底部</el-button>
    <el-timeline style="width: 90%;margin-top: 40px">
      <el-timeline-item
v-for="step in stepList"
                        :timestamp="timeString ? (step.workTime).substring(0,19):step.workMan+'  '+(step.workTime).substring(0,19)"
                        placement="top">
        <el-card class="stepList">
          <h4 style="margin: 5px 0">{{ step.workMemo }}</h4>
          <template v-if="step.workExplain && step.workExplain.substring(0, 6) == 'qrcode'">
            <img :src="step.workExplain.substring(7, step.workExplain.length)" width="100" height="100">
          </template>
          <template v-else>
            <p v-html="step.workExplain"></p>
          </template>
        </el-card>
      </el-timeline-item>

    </el-timeline>
    <el-button  v-if="visible"  @click="goToTop" size="mini" type="primary" style="margin: 10px">到顶部</el-button>
  </el-drawer>
</template>

<script>
import { getOrderStepList } from '@/api/order/orderList'

export default {
  name: 'OrderStep',
  props: {
    appendToBody: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      idOrder: '',
      drawer: false,
      stepList: [],
      timeString: '',
      visible: false,
      collection: {}
    }
  },
  mounted() {
  },
  methods: {
    // 获取脚印
    getOrderStep() {
      const _that = this
      _that.drawer = true
      var data = {
        idOrder: _that.idOrder
      }
      // console.log(data);
      getOrderStepList(data).then(response => {
        console.log(response)
        const data = response.data
        _that.stepList = data
        _that.collection = response.collection

        this.$nextTick(() => {
          if(document.querySelector('.el-drawer__body').scrollHeight>window.innerHeight){
            _that.visible = true
          }
        })
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    goToTop() {
      // console.log(document.querySelector('.el-drawer__body').scrollHeight);
      document.querySelector('.el-drawer__body').scrollTop = 0
    },
    goToBottom() {
      // console.log(document.querySelector('.el-drawer__body').scrollHeight);
      document.querySelector('.el-drawer__body').scrollTop = document.querySelector('.el-drawer__body').scrollHeight
    }
  }
}
</script>

<style scoped>

</style>
