<template>
  <div class="project-credit">
    <router-view />
    <template v-if="!$route.params.id">
      <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 statusList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </div>
              <div>
                <el-input v-model="search.fastSearch" style="width: 350px" placeholder="请输入项目名称/主企业名称/核心企业名称/业务编号" clearable />
              </div>
              <div class="leftBtn">
                <el-button type="primary" @click="page = 1, fetchData()">查询</el-button>
              </div>
            </template>
          </div>
        </div>
        <cy-comm-table
          ref="commTable"
          :columns="getTableColumn"
          :data="tableData"
          :count="total"
          parent-component="ProjectCredit"
          :table-options="getTableOptions"
        />
      </el-tabs>
    </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 indexTable from './indexTable'
import request from '@/utils/request'
export default {
  name: 'ProjectCredit',
  mixins: [indexTable],
  data() {
    return {
      activeName: 'pending',
      search: {
        fastSearch: '',
        status: ''
      },
      timeAxisParams: {
        businessKey: '',
        businessType: 'CreditResolution'
      },
      statusList: [],
      btnPermission: JSON.parse(sessionStorage.getItem('buttons')) || []
    }
  },
  computed: {
    getTableColumn() {
      const list = this.activeName == 'all' ? this.columnsAll : this.columns
      return list
    }
  },
  mounted() {
    this.fetchData()
    this.getStatusList()
  },
  methods: {
    getStatusList() {
      request({
        url: '/dictionary/do_findByParentCode',
        method: 'get',
        params: { parentCode: 'projectInitiationStatus' }
      }).then(({ data }) => {
        this.statusList = data || []
      })
    },
    fetchData() {
      request({
        url: this.activeName == 'all' ? '/creditResolution/allList' : '/businessProcessingTask/doMyPendingList',
        data: {
          page: this.page,
          rows: this.size,
          simpleClassName: 'CreditResolution',
          ...this.search
        },
        method: 'post'
      }).then(({ rows, total }) => {
        this.tableData = rows || []
        this.total = total
      })
    },
    handleTabClick(tab) {
      this.search.fastSearch = ''
      this.search.status = ''
      this.activeName = tab.name
      this.fetchData()
    },
    handlerOperate(type, row) {
      if (type === 'see') {
        this.$router.push({
          name: 'ResolutionDetail',
          params: { id: 'child', infoId: row.id, taskId: row.taskId }
        })
      } else if (type === 'edit') {
        this.$router.push({
          name: row.taskName == '授信决议确认' ? 'CreditResolutionConfirm' : row.taskName == '复议调整申请' ? 'ReviewAdjustment' : row.taskName == '复议调整审批' ? 'ReviewApproval' : 'CreditResolution',
          params: { id: 'child', infoId: row.id, taskId: row.taskId }
        })
      } else if (type == 'timeAxis') {
        this.timeAxisClick(row)
      }
    },
    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 {

}
</style>
