<template>
  <div class="project-credit">
    <router-view />
    <template v-if="!$route.params.id">
      <el-tabs v-model="creditType" class="type-tabs">
        <el-tab-pane label="项目信息" name="project" />
        <el-tab-pane label="核心企业" name="coreEnterprise" />
      </el-tabs>
      <transition name="fade-transform" mode="out-in">
        <template v-if="creditType === 'project'">
          <el-tabs v-model="activeName" type="border-card" @tab-click="handleTabClick">
            <el-tab-pane label="待处理" name="pending" />
            <el-tab-pane label="全部" name="all" />
            <div class="search">
              <div class="left" />
              <div class="right">
                <template v-if="activeName === 'all'">
                  <div>
                    <el-select v-model="search.status" placeholder="请选择状态" clearable>
                      <el-option
                        v-for="item in constant.c_project_and_enterprise_status"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                      />
                    </el-select>
                  </div>
                  <div />
                  <div>
                    <el-input v-model="search.fastSearch" style="width: 300px" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable />
                  </div>
                  <div class="leftBtn">
                    <el-button type="primary" @click="fetchData('all')">查询</el-button>
                  </div>
                </template>
              </div>
            </div>
            <cy-comm-table
              ref="commTable"
              :columns="activeName === 'pending'? columns : columnsAll"
              :data="tableData"
              :count="total"
              :table-options="getTableOptions"
              parent-component="ProjectCredit"
            />
          </el-tabs>
        </template>

        <template v-if="creditType === 'coreEnterprise'">
          <core-enterprise-list></core-enterprise-list>
        </template>
      </transition>

    </template>
    <cy-dialog ref="timeAxisDialog" title="进度时间轴" top="15vh">
      <cy-time-axis ref="timeAxis" :time-axis-params="timeAxisParams"></cy-time-axis>
    </cy-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { exportFile } from '@/utils/index'
import { projectInfoPendingList, projectInfoAllList, download } from '@/api/creditManage/projectManage'
import indexTable from './indexTable'
export default {
  name: 'ProjectCredit',
  components: {
    CoreEnterpriseList: () => import('../coreEnterprise/index')
  },
  mixins: [indexTable],
  data() {
    return {
      creditType: 'project',
      activeName: 'pending',
      total: 20,
      search: {
        status: '',
        fastSearch: ''
      },
      timeAxisParams: {
        businessKey: '',
        businessType: 'ProjectInformation'
      },
      tableOptions: {
        maxHeight: 'calc(100vh - 470px)',
        height: 'calc(100vh - 470px)'
      }
    }
  },
  computed: {
    ...mapGetters(['constant'])
  },
  created() {
    this.$store.dispatch('getConstant', ['c_project_and_enterprise_status'])
  },
  mounted() {
    this.fetchData('pending')
  },
  methods: {
    fetchData(type) {
      this.loading = true
      if (type === 'pending' || this.activeName === 'pending') {
        const params = {
          page: this.page,
          rows: this.size,
          simpleClassName: 'ProjectInformation'
        }
        projectInfoPendingList(params).then(({ rows, records }) => {
          this.loading = false
          this.tableData = rows
          this.total = records
        })
      } else if (type === 'all' || this.activeName === 'all') {
        const params = {
          page: this.page,
          rows: this.size,
          fastSearch: this.search.fastSearch,
          status: this.search.status
        }
        projectInfoAllList(params).then(({ rows, records }) => {
          this.loading = false
          this.tableData = rows
          this.total = records
        })
      }
    },
    handleTabClick(tab) {
      this.activeName = tab.name
      this.page = 1
      this.search.fastSearch = ''
      this.search.status = ''
      this.fetchData(tab.name)
    },
    handlerOperate(type, row) {
      const { id, taskId } = row
      if (type === 'report') {
        this.$router.push({
          name: 'ProjectAdmittance',
          params: { id },
          query: {
            id
          }
        })
      } else if (type === 'edit') {
        this.$router.push({
          name: 'DueReview',
          params: { id },
          query: {
            id,
            taskId,
            reviewType: 'project'
          }
        })
      } else if (type === 'timeAxis') {
        this.timeAxisClick(row)
        return
      } else if (type === 'download') {
        download({ id: row.id }).then((data) => {
          exportFile(data)
        })
        return
      } else if (type === 'view') {
        this.$router.push({
          name: 'ProjectView',
          params: { id },
          query: {
            id
          }
        })
      }
    },
    timeAxisClick(row) {
      this.timeAxisParams.businessKey = row.id
      this.$refs.timeAxisDialog.show = true
      this.$nextTick(() => {
        this.$refs.timeAxis.fetchData()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.project-credit {
.type-tabs {
  margin-bottom: 5px;
}
}
</style>
