<template>
  <div>
    <!-- 选择项目 -->
    <el-dialog
      title="选择项目"
      :visible.sync="showProjectItem"
      width="800px"
      append-to-body
    >
      <el-table
        class="tableWrapper"
        @row-click="clickRow"
        ref="multipleTable"
        :data="poolList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />

        <!-- <el-table-column label="主键id" align="center" prop="id" /> -->
        <el-table-column label="项目名称" width="150" align="center" prop="projectName">
          <template slot-scope="scope">
            <div :title="scope.row.projectName">
              {{ scope.row.projectName }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="渠道"
          align="center"
          prop="tProjectChannel.channelName"
        >
          <template slot-scope="scope">
            <div :title="scope.row.tProjectChannel.channelName">
              {{ scope.row.tProjectChannel.channelName }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="所属组别"
          align="center"
          prop="tProjectChannel.channelGroup"
        >
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.project_group"
              :value="scope.row.tProjectChannel.channelGroup"
            />
          </template>
        </el-table-column>
        <!-- <el-table-column label="项目编号" align="center" prop="projectCode" /> -->

        <el-table-column label="投资负责人" align="center" prop="investHead" />
        <el-table-column label="项目阶段" align="center" prop="projectStage">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.project_stage"
              :value="scope.row.projectStage"
            />
          </template>
        </el-table-column>
        <el-table-column label="项目状态" align="center" prop="projectState">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.project_state"
              :value="scope.row.projectState"
            />
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="projectItemTotal > 0"
        :total="projectItemTotal"
        :page.sync="projectQueryParams.pageNum"
        :limit.sync="projectQueryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit" v-preventReClick
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listPool } from "@/api/invest/pool";
export default {
  props: {
    // showProjectItem: {
    //   type: Boolean,
    //   default: false,
    // },
  },
  dicts: ["project_group", "project_stage", "project_state"],
  data() {
    return {
      showProjectItem: false,
      // 总条数
      projectItemTotal: 0,
      poolList: [],
      projectQueryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "createTime",
        isAsc: "desc",
      },

      // 选中数组
      ids: [],
      idsName: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    clickRow(row) {
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      if (selection.length > 1) {
        this.$modal.msg("只能选择一个项目");
        this.$refs.multipleTable.clearSelection();
        return;
      }
      if (this.ids.length == 0) {
        this.ids = selection;
      } else {
        this.$modal.msg("只能选择一个项目");
        this.ids = [];
        // multipleTable与table的ref绑定的一样
        this.$refs.multipleTable.clearSelection();
      }
    },
    /** 查询项目池列表 */
    getList() {
      listPool(this.projectQueryParams).then((response) => {
        this.poolList = response.rows;
        this.projectItemTotal = response.total;
      });
    },
    submit() {
      // console.log("确定", this.ids);
      this.$emit("getProjectInfo", this.ids);
      this.showProjectItem = false;
    },
    cancel() {
      this.showProjectItem = false;
    },
  },
};
</script>