<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 constant.projectInitiationStatus"
                  :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"
      />
    </template>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import indexTable from './indexTable'
import { getSalesContractManagementList } from '@/api/myTrade/salesContractManagement/salesContractManagement'
export default {
  name: 'BiddingManagement',
  mixins: [indexTable],
  data() {
    return {
      loading: false,
      getStatusList: [],
      page: 1,
      size: 10,
      search: {
        businessNumber: '',
        status: '',
        fastSearch: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'constant'
    ])
  },
  created() {
    this.$store.dispatch('getConstant', ['projectInitiationStatus'])
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.loading = true
      const params = {
        ...this.search,
        page: this.page,
        rows: this.size
      }
      getSalesContractManagementList(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 (type === 'see') {
        this.$router.push({
          name: 'SalesContractManagementSee',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            id: row.id,
            type,
            module: '销售合同管理'
          }
        })
        return
      }
      if (row.stage === '销售合同创建') {
        this.$router.push({
          name: 'SalesContractManagementCreateSalesContract',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            id: row.id,
            type,
            module: '销售合同管理'
          }
        })
      } else if (row.stage === '销售合同录入') {
        this.$router.push({
          name: 'SalesContractManagementSalesContractAdd',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            type,
            id: row.id
          }
        })
      }
      if (type === 'change') {
        this.$router.push({
          name: 'SalesContractManagementChangecreateSalesContract',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            id: row.id,
            type,
            module: '销售合同管理'
          }
        })
      } else if (row.stage === '变更信息录入') {
        this.$router.push({
          name: 'SalesContractManagementChangeSalesContractAdd',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            id: row.id,
            type
          }
        })
      } else if (row.stage === '签署确认' || row.stage === '变更签署确认') {
        this.$router.push({
          name: 'SalesContractManagementSignConfirmation',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            businessKey: row.id,
            type
          }
        })
      } else if (row.stage === '变更合同创建') {
        this.$router.push({
          name: 'SalesContractManagementChangecreateSalesContract',
          params: { id: 'child' },
          query: {
            taskName: row.stage,
            id: row.id,
            type: 'change'
          }
        })
      }
    },
    modifyClick() {
      this.$router.push({
        name: 'SalesContractManagementCreateSalesContract',
        params: { id: 'child' },
        query: {
          module: '销售合同管理',
          taskName: '销售合同创建'
        }
      })
    }
  }
}
</script>

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

}
</style>
