<template>
  <div v-loading="isLoading">
    <cy-steps :steps-data="stepList"></cy-steps>
    <el-collapse v-if="stepList.length" v-model="activeNames" @change="handleChange">
      <el-collapse-item v-for="(item, index) in stepList" :id="index" :key="index" :name="index">
        <template slot="title">
          <cy-view-bar
            :view-bar-data="{ ...item.businessProcessingLogVo, formBusinessName: item.formBusinessName, index: index + 1 }"
          >
          </cy-view-bar>
        </template>
        <template v-if="item.formBusinessName == '采购合同录入'">
          <step-1 :info="item.obj"></step-1>
        </template>
        <template v-if="item.formBusinessName == '采购合同审核'">
          <purchase-contract-review-content :info="item.obj" :is-view="true" />
        </template>
        <template v-if="item.formBusinessName.includes('采购合同签署') || item.formBusinessName.includes('采购合同变更签署')">
          <step-2 :info="item.obj"></step-2>
        </template>
        <template v-if="item.formBusinessName == '采购合同变更终审' || item.formBusinessName == '采购合同终审'">
          <sign-review-content :info="item.obj" :is-view="true" />
        </template>
        <template v-if="item.formBusinessName == '采购合同变更录入'">
          <step-3 :info="item.obj"></step-3>
        </template>
        <template v-if="item.formBusinessName == '采购合同变更审核'">
          <change-contract-review-content :info="item.obj" :is-view="true" />
        </template>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import PurchaseContractReviewContent from './components/PurchaseContractReviewContent.vue'
import ChangeContractReviewContent from './components/ChangeContractReviewContent.vue'
import SignReviewContent from './components/SignReviewContent.vue'
import Step1 from './stepComponents/Step1.vue'
import Step2 from './stepComponents/Step2.vue'
import Step3 from './stepComponents/Step3.vue'
import request from '@/utils/request'
import collapseMix from '@/mixins/collapseSeeMix'

export default {
  components: {
    SignReviewContent, Step1, PurchaseContractReviewContent, Step2, Step3, ChangeContractReviewContent
  },
  mixins: [collapseMix],
  data() {
    return {
      stepList: [],
      activeNames: [],
      isLoading: false
    }
  },
  mounted() {
    this.getStepList()
  },
  methods: {
    getStepList() {
      this.isLoading = true
      request({
        url: '/businessProcessingTask/doBusinessHistoryView',
        method: 'get',
        params: { businessKey: this.$route.query.infoId, businessType: 'PurchContract', Loading: true }
      }).then(({ data }) => {
        data.forEach(item => {
          if (item.obj) {
            item.obj.mathId = Math.random()
          } else {
            item.obj = { mathId: Math.random() }
          }
        })
        this.stepList = data || []
        this.isLoading = false
      })
    }
  }
}
</script>

<style lang="scss">

</style>
