<template>
  <div class="acceptance-management">
    <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>
        <el-tab-pane label="全部" name="all"></el-tab-pane>
        <div>
          <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-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>
                  <el-input v-model="search.fastSearch" style="width: 300px" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable></el-input>
                </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="columns"
            :table-options="getTableOptions"
            :data="tableData"
            :count="total"
            parent-component="AcceptanceManagement"
          />
        </div>
      </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 { exportFile } from '@/utils/index'
import { mapGetters } from 'vuex'
import indexTable from './indexTable'
import { acceptancePendingList, acceptanceAllList, download, downloadBook } from '@/api/acceptanceManagement/index'
export default {
  name: 'AcceptanceManagement',
  mixins: [indexTable],
  data() {
    return {
      loading: false,
      activeName: 'pending',
      getStatusList: [],

      search: {
        searchNumber: '',
        status: '',
        fastSearch: ''
      },
      timeAxisParams: {
        businessKey: '',
        businessType: 'AcceptanceSheet'
      }
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'constant'
    ])
  },
  created() {
    this.$store.dispatch('getConstant', ['projectInitiationStatus'])
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.loading = true
      if (this.activeName === 'pending') {
        const params = {
          page: this.page,
          rows: this.size,
          simpleClassName: 'AcceptanceSheet'
        }
        acceptancePendingList(params).then(({ rows, records }) => {
          this.loading = false
          this.tableData = rows
          this.total = records
        })
      } else if (this.activeName === 'all') {
        this.loading = true
        const params = {
          page: this.page,
          rows: this.size,
          simpleClassName: 'AcceptanceSheet',
          ...this.search
        }
        acceptanceAllList(params).then(({ rows, records }) => {
          this.loading = false
          this.tableData = rows
          this.total = records
        })
      }
    },
    handleTabClick(tab) {
      this.activeName = tab.name
      if (this.activeName === 'pending') {
        this.page = 1
        this.fetchData()
      } else if (this.activeName === 'all') {
        this.page = 1
        this.search.searchNumber = ''
        this.search.fastSearch = ''
        this.search.status = ''
        this.fetchData()
      }
    },
    handlerOperate(type, row) {
      if (type === 'edit') {
        if (row.taskName === '法务审核') {
          this.$router.push({
            name: 'AccepetanceLegalReview',
            params: { id: 'children' },
            query: {
              taskName: row.taskName,
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '单价变更审核') {
          this.$router.push({
            name: 'AccepetanceAdjustReview',
            params: { id: 'children' },
            query: {
              taskName: row.taskName,
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '业务审核') {
          this.$router.push({
            name: 'AccepetanceBusinessReview',
            params: { id: row.id },
            query: {
              taskName: row.taskName,
              id: row.id,
              taskId: row.taskId
            }
          })
        }
      } else if (type === 'timeAxis') {
        this.timeAxisClick(row)
        return
      } else if (type === 'see') {
        this.$router.push({
          name: 'AcceptanceManagementView',
          params: { id: 'children' },
          query: {
            id: row.id
          }
        })
      } else if (type === 'download') {
        download({ acceptanceBasicInfoId: row.id }).then((data) => {
          exportFile(data)
        })
        return
      } else if (type === 'downloadBook') {
        downloadBook({ acceptanceBasicInfoId: row.id }).then((data) => {
          exportFile(data)
        })
        return
      }
    },
    timeAxisClick(row) {
      this.timeAxisParams.businessKey = row.id
      this.$refs.timeAxisDialog.show = true
      this.$nextTick(() => {
        this.$refs.timeAxis.fetchData()
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.purchase-contract-management {

}
</style>
