<template>
  <div class="refund-manage">
    <router-view />
    <template v-if="!$route.params.id">
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleTabClick">
        <!-- <el-tab-pane label="退款明细" name="deatils"></el-tab-pane> -->
        <el-tab-pane label="待处理" name="pending"></el-tab-pane>
        <el-tab-pane label="全部" name="all"></el-tab-pane>
        <div class="search">
          <div class="left"></div>
          <div class="right">
            <template v-if="activeName === 'all'">
              <div>
                <el-input v-model="search.searchNumber" style="width: 250px" placeholder="请输入业务编号/保理合同编号" clearable />
              </div>
              <div>
                <el-input v-model="search.fastSearch" style="width: 300px" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable></el-input>
              </div>
              <div>
                <el-select
                  v-model="search.status"
                  placeholder="请选择业务状态"
                  clearable
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in constant.projectInitiationStatus"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="leftBtn">
                <el-button type="primary" @click="fetchData">查询</el-button>
              </div>
            </template>
          </div>
        </div>
        <cy-comm-table
          ref="commTable"
          v-loading="loading"
          :columns="getTableColumns"
          :table-options="getTableOptions"
          :data="tableData"
          :count="total"
        />
      </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 { mapGetters } from 'vuex'
import indexTable from './indexTable'
import { queryRefundList } from '@/api/refundManage'

export default {
  name: 'Demo',
  mixins: [indexTable],
  data() {
    return {
      loading: false,
      activeName: 'pending',
      getStatusList: [],

      search: {
        businessNumber: '',
        customerName: '',
        simpleClassName: 'RefundManagement',
        difference: 'pending'
      },
      timeAxisParams: {
        businessKey: '',
        businessType: 'RefundManagement'
      }
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'constant'
    ])
  },
  created() {
    this.$store.dispatch('getConstant', ['projectInitiationStatus'])
    this.fetchData()
  },
  methods: {
    // 列表查询
    fetchData() {
      this.loading = true
      const params = {
        ...this.search,
        page: this.page || 1,
        rows: this.size || 10
      }
      queryRefundList(params).then(response => {
        this.loading = false
        if (response && response.data) {
          this.tableData = response.data.rows
          this.total = response.data.records
        }
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          return false
        }
      })
    },
    handlerOperate(type, row) {
      console.log(type)
      console.log(row)
      if (type === 'timeAxis') {
        this.timeAxisClick(row)
        return
      }
      if (type === 'edit') {
        if (row.taskName === '退款审核') {
          this.$router.push({
            name: 'RefundApprove',
            params: {
              id: row.id
            },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '退款申请') {
          this.$router.push({
            name: 'RefundApply',
            params: {
              id: row.id
            },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '' && row.financingAmount > 0) {
          this.$router.push({
            name: 'RefundApply',
            params: {
              id: row.id
            },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        }
      }
      if (type === 'see') {
        this.$router.push({
          name: 'RefundView',
          params: {
            id: row.id
          }
        })
      }
    },
    timeAxisClick(row) {
      this.timeAxisParams.businessKey = row.id
      this.$refs.timeAxisDialog.show = true
      this.$nextTick(() => {
        this.$refs.timeAxis.fetchData()
      })
    },
    handleTabClick(tab) {
      this.activeName = tab.name
      this.search.difference = tab.name
      this.fetchData()
    }
  }
}
</script>

<style lang="scss" scoped>
.refund-manage {

}
</style>
