<template>
  <div class="bidding-management">
    <template>
      <div class="search">
        <div class="left" />
        <div class="right">
          <template>
            <div>
              <el-input v-model="search.businessNumber" placeholder="请输入业务编号" clearable />
            </div>
            <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" placeholder="请输入项目名称/主企业名称/核心企业名称" clearable />
            </div>
            <div class="right-btn">
              <el-button type="primary" @click="fetchData">查询</el-button>
              <el-button type="primary" icon="el-icon-plus" @click="modifyClick('create')">创建招投标项目</el-button>
            </div>
          </template>
        </div>
      </div>
      <cy-comm-table
        ref="commTable"
        v-loading="loading"
        :columns="columns"
        :table-options="tableOptions"
        :data="tableData"
        :count="total"
        parent-component="BiddingManagement"
      />
    </template>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import indexTable from './indexTable'
import { getBiddingManagementList, getStatus } from '@/api/myTrade/biddingManagement/biddingManagement'
export default {
  name: 'BiddingManagement',
  mixins: [indexTable],
  data() {
    return {
      loading: false,
      statusList: [],
      tableData: [],
      page: 1,
      size: 10,
      total: 0,
      search: {
        businessNumber: '',
        status: '',
        fastSearch: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  mounted() {
    this.fetchData()
    this.getStatusList()
  },
  methods: {
    fetchData() {
      this.loading = true
      const params = {
        ...this.search,
        page: this.page,
        rows: this.size
      }
      getBiddingManagementList(params).then(({ data }) => {
        this.tableData = data.rows
        this.total = data.records
        this.loading = false
      })
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          return false
        }
      })
    },
    handlerOperate(type, row) {
      // if (row.stage === '业务创建' || type === 'see') {
      if (type === 'see') {
        this.$router.push({
          name: 'MyTradeBiddingManagementBiddingView',
          params: { id: 'children' },
          query: {
            module: '招投标管理',
            id: row.id,
            type,
            taskName: row.stage
          }
        })
      } else {
        this.$router.push({
          name: 'MyTradeBiddingManagementCreateBidding',
          params: { id: 'children' },
          query: {
            module: '招投标管理',
            id: row.id,
            type,
            taskName: row.stage
          }
        })
      }
      // }
    },
    modifyClick() {
      this.$router.push({
        name: 'MyTradeBiddingManagementCreateBidding',
        params: { id: 'child' },
        query: {
          module: '招投标管理',
          taskName: '业务创建'
        }
      })
    },
    getStatusList() {
      getStatus({ parentCode: 'projectInitiationStatus' }).then(response => {
        this.statusList = response.data
      })
    }
  }
}
</script>

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

}
</style>
