<template>
  <view>
    <Navbar title="工程详情" />
    <u-tabs
      :list="tabList"
      @click="clickTab"
      :current="currentIndex"
      :activeStyle="{ fontWeight: 500, fontSize: '14px', color: '#0F274B' }"
      :inactiveStyle="{ fontWeight: 400, fontSize: '12px', color: 'rgba(15, 39, 75, 0.5)' }"
      style="margin: 0 10px"
    />
    <ProjectInfoDetails v-show="currentIndex === 0" :proInfo="proInfo" />
    <SupervisorInfo
      v-if="proInfo.proType == '2' && currentIndex === 1"
      :supervisorUnitId="proInfo.supervisorUnitId"
      :proId="proId"
      :enterpriseQualificationList="enterpriseQualificationList"
    />
    <div v-for="(item, index) in filterTabList" :key="index">
      <ContractorInfo
        v-if="currentIndex === (proInfo.proType == 2 ? index + 2 : index + 1)"
        :proId="proId"
        :id="item.value"
      />
    </div>
  </view>
</template>

<script>
import ProjectInfoDetails from './components/ProjectInfoDetails'
import SupervisorInfo from './components/SupervisorInfo'
import ContractorInfo from './components/ContractorInfo'
import { proDetails, selectFile } from '@/api/project'

export default {
  components: { ProjectInfoDetails, SupervisorInfo, ContractorInfo },
  data() {
    return {
      currentIndex: 0,
      tabList: [{ name: '工程详情' }],
      filterTabList: [],
      proId: '',
      proInfo: {},
      enterpriseQualificationList: []
    }
  },
  onLoad(opt) {
    opt = JSON.parse(opt.params)
    console.log('🚀 opt ---', opt)
    this.proId = opt.proId
    this.getInfo()
    this.getEnterpriseQualification()
  },
  created() {},
  methods: {
    // 切换tab
    clickTab(item) {
      console.log('clickTab', item)
      this.currentIndex = item.index
    },
    // 获取工程详情
    getInfo() {
      console.log('🚀 this.proId ---', this.proId)
      proDetails({ proId: this.proId }).then(res => {
        console.log('🚀 ~ proDetails ~ res:', res)
        this.proInfo = res.projectInfo[0]
        if (this.proInfo.proType == '2') {
          this.tabList.push({ name: '监理信息' })
        }
        if (this.proInfo.consArr.length > 0) {
          this.proInfo.consArr.forEach((item, index) => {
            // this.tabList.push({ name: item.label, value: item.value })
            this.tabList.push({ name: '承包商' + (index + 1), value: item.value })
          })
        }
        setTimeout(() => {
          this.filterTabList = this.tabList.filter(item => item.name !== '工程详情' && item.name !== '监理信息')
        }, 0)
      })
    },
    // 获取-企业资质-监理单位
    getEnterpriseQualification() {
      const params = {
        id: this.proId,
        classification: '1',
        fromType: '1',
        informationType: '1'
      }
      selectFile(params).then(res => {
        console.log('获取-企业资质 ->', res)
        // if (!res.data) return
        if (res.code === 200 && res.data.length > 0) {
          this.enterpriseQualificationList = res.data
          console.log('🚀 ~ selectFile ~ this.获取-企业资质:', this.enterpriseQualificationList)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
