<template>
  <div class="pop">
    <status1View v-if="step == 1" />
    <status2View :status2="status2" v-if="step == 2" />
    <status3View :status2="status2" :handleList="handleList" v-if="step == 3" />
  </div>
</template>
<script>
import status1View from "./components/status1.vue";
import status2View from "./components/status2.vue";
import status3View from "./components/status3.vue";
import { getWorkOrderList } from "@/api/work";
export default {
  components: {
    status1View,
    status2View,
    status3View
  },
  data () {
    return {
      status3: {},
      status6: {},
    }
  },
  computed: {
    status2() {
      if (!this.status3.id && !this.status6.id) {
        return {}
      }
      var time3 = new Date((this.status3.insert_datetime || '0').replace(new RegExp(/-/gm), "/")).getTime()
      var time6 = new Date((this.status6.insert_datetime || '0').replace(new RegExp(/-/gm), "/")).getTime()
      return time3 > time6 ? this.status3 : this.status6
    },
    handleList() {
      return this.status2.handleList || []
    },
    step() {
      if (this.status2.status == 6) {
        return 3
      }
      if (this.status2.id) {
        return 2
      }
      return 1
    }
  },
  created () {
    this.getWorkOrderList()
  },
  methods: {
    getWorkOrderList() {
      getWorkOrderList({
        pageNum: 1,
        pageSize: 1,
        type: 100,
        status: 3
      }).then(res => {
        var list = res.list || []
        var obj = list[0] || {}
        if (obj.content) {
          obj.content = JSON.parse(obj.content)
        }
        this.status3 = obj
      }).catch(() => {
      })
      getWorkOrderList({
        pageNum: 1,
        pageSize: 1,
        type: 100,
        status: 6
      }).then(res => {
        var list = res.list || []
        var obj = list[0] || {}
        if (obj.content) {
          obj.content = JSON.parse(obj.content)
        }
        this.status6 = obj
      }).catch(() => {
      })
    },
  }
}
</script>
<style lang="less" scoped>
.pop {
  padding: 30px 20px 20px;
}
</style>