<template>
  <div>
    <el-row>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="88px">
        <el-form-item label="项目类型" prop="projectType">
          <el-select v-model="projectType" clearable filterable placeholder="请输入项目类型" size="large"
            style="width: 240px" @keyup.enter.native="handleQuery()">
            <el-option v-for="item in typeList" :key="item.typeId" :label="item.typeName" :value="item.typeName"/>
          </el-select>
        </el-form-item>
        <el-form-item label="项目编号" prop="projectNumber">
          <el-input v-model="queryParams.projectNumber" placeholder="请输入项目编号" clearable
            @keyup.enter.native="handleQuery()" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable
            @keyup.enter.native="handleQuery()" />
        </el-form-item>
        <el-form-item label="项目负责人" prop="projectLeader">
          <el-select v-model="queryParams.projectLeader" clearable filterable placeholder="请输入项目负责人" size="large"
            style="width: 240px" @keyup.enter.native="handleQuery()">
            <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery()">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>

    <el-table ref="chooseProject" v-loading="loading" :data="projectList" @selection-change="handleSelectionChange"
      :row-key="getRowKeys">
      <el-table-column type="selection" width="50" align="center" :reserve-selection="true" />
      <el-table-column label="项目编号" align="center" key="projectNumber" prop="projectNumber" />
      <el-table-column label="项目名称" align="center" key="projectName" prop="projectName" :show-overflow-tooltip="true" />
      <el-table-column label="项目负责人" align="center" key="projectLeader" prop="projectLeaderUser.nickName"
        :show-overflow-tooltip="true" />
      <el-table-column label="甲方单位" align="center" key="partyA" prop="partyA.partyAName" :show-overflow-tooltip="true" />
      <el-table-column label="项目类型" align="center" key="projectType" prop="projectType" />
    </el-table>
    <div style="text-align: right;" class="mt20 mr20">
      <el-pagination @current-change="getList" :current-page.sync="queryParams.pageNum"
        :page-size="queryParams.pageSize" layout="total, prev, pager, next" :total="total">
      </el-pagination>
    </div>
    <div>
      已选项目：<el-tag v-for="item in chooseProject" style="margin: 5px;" :key="item.projectId">{{ item.projectNumber + '-'
        + item.projectName }}</el-tag>
    </div>
    <div style="text-align: center;margin-top: 20px;">
      <el-button type="primary" @click="confirmChoose">确认选择</el-button>
      <el-button @click="clearChoose">清空选择</el-button>
    </div>
  </div>
</template>

<script>
import { listProject, submitProject, modifyProject, delProject } from "@/api/oa/project/project";
import { listUser, getUser } from '@/api/system/user'
export default {
  props: {
    
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNumber: '',
        projectLeader: undefined,
        projectName: '',
      },
      projectType: '测绘',
      typeList: [{typeId: 1, typeName: "测绘"}, {typeId: 2, typeName: "勘察"}],
      projectList: [],
      userList: [],
      total: 0,
      loading: true,
      chooseProject: []
    }
  },
  created() {
    this.getList();
    this.getUserList();
  },
  methods: {
    // 查询项目列表
    getList() {
      this.loading = true
      if (this.projectType == '测绘') {
        this.queryParams.undertakingDept = undefined
      }
      if (this.projectType == '勘察') {
        this.queryParams.undertakingDept = 113
      }
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 查询用户列表 */
    getUserList() {
      listUser({ pageNum: 1, pageSize: 9999 }).then(res => {
        this.userList = res.rows
      })
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleSelectionChange(val) {
      this.chooseProject = val
    },
    getRowKeys(row) {
      return row.projectId;
    },
    confirmChoose() {
      this.$emit('chooseProject', this.chooseProject)
    },
    clearChoose() {
      this.$refs.chooseProject.clearSelection();
    }
  },
}
</script>

<style lang="scss" scoped></style>