<template>
  <div class="bidding-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 label="全部" name="all" />
        <div class="search">
          <div class="left" />
          <div class="right">
            <template v-if="activeName === 'all'">
              <div>
                <el-input v-model="search.businessNo" 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 />
              </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="BiddingManagement"
        />
      </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 { getList } from '@/api/dictionary'
export default {
  name: 'BiddingManagement',
  mixins: [indexTable],
  data() {
    return {
      loading: false,
      activeName: 'pending',
      getStatusList: [],
      page: 1,
      size: 10,
      search: {
        businessNo: '',
        status: '',
        fastSearch: '',
        difference: 'pending',
        simpleClassName: 'BiddingBasicInfo'
      },
      timeAxisParams: {
        businessKey: '',
        businessType: 'BiddingBasicInfo'
      },
      btnPermission: JSON.parse(sessionStorage.getItem('buttons')) || []
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'constant'
    ])
  },
  created() {
    this.$store.dispatch('getConstant', ['projectInitiationStatus'])
  },
  mounted() {
    if (!this.$route.params.id) {
      this.fetchData()
    }
  },
  methods: {
    fetchData(type) {
      // if (type === 'search') {
      //   this.deepSearch = JSON.parse(JSON.stringify(this.search))
      // }
      // if (Object.keys(this.deepSearch).length !== 0) {
      //   this.search = JSON.parse(JSON.stringify(this.deepSearch))
      // }
      this.loading = true
      const params = {
        ...this.search,
        page: this.page,
        rows: this.size
      }
      getList(params).then((data) => {
        console.log(data)
        const { rows, records } = data.data
        this.loading = false
        this.tableData = rows
        this.total = records
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          return false
        }
      })
    },
    handlerOperate(type, row) {
      if (type === 'timeAxis') {
        this.timeAxisClick(row)
        return
      }
      if (type === 'see') {
        this.$router.push({
          name: 'BiddingManagementSee',
          params: { id: 'children' },
          query: {
            id: row.id,
            taskId: row.taskId
          }
        })
      }
      if (type === 'edit') {
        if (row.taskName === '模板审核') {
          this.$router.push({
            name: 'BiddingManagementTemplateReview',
            params: { id: 'children' },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '保证方式确认') {
          this.$router.push({
            name: 'BiddingManagementGuaranteeConfirm',
            params: { id: 'children' },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '保证金收款确认') {
          this.$router.push({
            name: 'BiddingManagementMarginCollectionConfirm',
            params: { id: 'children' },
            query: {
              id: row.id,
              taskId: row.taskId,
              openAmount: row.openAmount,
              type
            }
          })
        } else if (row.taskName === '中标确认') {
          this.$router.push({
            name: 'BiddingManagementSuccessfulBidderConfirm',
            params: { id: 'children' },
            query: {
              id: row.id,
              taskId: row.taskId
            }
          })
        } else if (row.taskName === '保证金退款确认') {
          this.$router.push({
            name: 'BiddingManagementMarginRefundConfirm',
            params: { id: 'children' },
            query: {
              id: row.id,
              taskId: row.taskId,
              openAmount: row.openAmount,
              type
            }
          })
        } else if (row.statusName === '发起招标') {
          this.$router.push({
            name: 'BiddingManagementInitiateBidding',
            params: { id: 'children' }
          })
        }
      }
    },
    handleTabClick(tab) {
      this.search.businessNo = ''
      this.search.status = ''
      this.search.fastSearch = ''
      this.search.difference = tab.name
      this.activeName = tab.name
      this.fetchData()
    },
    timeAxisClick(row) {
      this.timeAxisParams.businessKey = row.id
      this.$refs.timeAxisDialog.show = true
      this.$nextTick(() => {
        this.$refs.timeAxis.fetchData()
      })
    }
  }
}
</script>

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

}
</style>
