<!--
  @description: 招标人代表信息库-列表
  @Modifier: haofengxian
  @routerPath: /informationbase/representativeTendereeList
  @date: 2020-5-8-11:20
-->
<template>
  <div>
    <table-crud
      :search-form="searchForm"
      search-label-width="110px"
      @on-load="loadData"
    >
      <template v-slot:header>
        招标人代表信息库
      </template>
      <template v-slot:search="search">
        <el-form-item ref="name" label="姓名" prop="name">
          <el-input
            v-model.trim="searchForm.name"
            placeholder="姓名"
            width="228px"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item ref="userName" label="用户名" prop="userName">
          <el-input
            v-model.trim="searchForm.userName"
            placeholder="用户名"
            width="228px"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
        <el-form-item ref="workCompany" label="单位名称" prop="workCompany">
          <el-input
            v-model.trim="searchForm.workCompany"
            placeholder="单位名称"
            width="228px"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" plain @click="addBidderInfo">
            新 增
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="name"
            label="姓名"
            width="160"
          />
          <el-table-column
            header-align="center"
            prop="userName"
            label="用户名"
            min-width="230"
          />
          <el-table-column
            header-align="center"
            prop="sex"
            label="性别"
            min-width="75"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.sex==='00'">男</span>
              <span v-if="scope.row.sex==='01'">女</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="工作单位"
            prop="workCompany"
            align="left"
            min-width="200"
          />
          <el-table-column
            label="职称"
            prop="technicalTitle"
            align="center"
            min-width="110"
          >
            <template slot-scope="scope">
              <span v-for="(item,index) in technicalTitleList" v-if="scope.row.technicalTitle===item.typecode" :key="index">{{ item.typename }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="状态"
            prop="useStatus"
            align="center"
            min-width="110"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.useStatus==='00'">已保存</span>
              <span v-if="scope.row.useStatus==='01'">已生效</span>
              <span v-if="scope.row.useStatus==='02'">作废</span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            width="200"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.useStatus!=='00'"
                type="primary"
                @click.stop="checkBidderInfo(scope.row.id)"
              >
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.useStatus==='00'"
                type="primary"
                @click.stop="editBidderInfo(scope.row.id)"
              >
                [修改]
              </el-link>
              <el-link
                v-if="scope.row.useStatus==='01'"
                type="primary"
                @click.stop="editBidderInfo(scope.row.id)"
              >
                [变更]
              </el-link>
              <el-link
                v-if="scope.row.useStatus==='01'"
                type="primary"
                @click.stop="createUserName(scope.row.id)"
              >
                [创建用户名]
              </el-link>
              <el-link
                v-if="scope.row.useStatus!=='01'"
                type="primary"
                @click.stop="deleteBidder(scope.row.id)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
  </div>
</template>

<script>
/* 接口*/
import { queryRepresentListPage, deleteRepresentInfoById } from '@api/common/user'
import { tendereeTypeGroup } from '../mixins/tendereeTypeGroup'
export default {
  name: 'RepresentativeTendereeList',
  mixins: [tendereeTypeGroup],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        workCompany: '', // 工作单位
        userName: '', // 用户名
        name: '' // 招标人姓名
      },
      tableData: []
    }
  },
  methods: {
    // 获取数据
    loadData(params, callback) {
      queryRepresentListPage(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {

      })
    },
    // 查看
    checkBidderInfo(id) {
      this.$router.push({
        path: '/informationbase/representativeTendereeDetail',
        name: 'RepresentativeTendereeDetail',
        params: { id }
      })
    },
    // 编辑
    editBidderInfo(id) {
      this.$router.push({
        path: '/informationbase/representativeTendereeUpdate',
        name: 'RepresentativeTendereeUpdate',
        params: { id }
      })
    },
    // 删除
    deleteBidder(id) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        deleteRepresentInfoById(id).then(res => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          // 获取列表信息
          this.loadData()
        })
      }).catch(() => {
      })
    },
    // 创建用户名
    createUserName(id) {
      this.$router.push({
        path: '/informationbase/submitCreateUserNameAdd',
        name: 'SubmitCreateUserName',
        params: { id }
      })
    },
    // 新增
    addBidderInfo() {
      this.$router.push({
        path: '/informationbase/representativeTendereeUpdate'
      })
    }
  }
}
</script>

<style scoped>

</style>
