<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="项目名称" prop="porjectName">
        <el-input
          v-model="queryParams.porjectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属组别" prop="porjectGroup">
        <el-select v-model="queryParams.porjectGroup" placeholder="请选择所属组别" clearable>
          <el-option
            v-for="dict in dict.type.porject_group"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目编号" prop="porjectCode">
        <el-input
          v-model="queryParams.porjectCode"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="渠道" prop="channel">
        <el-input
          v-model="queryParams.channel"
          placeholder="请输入渠道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="初次接触日期" prop="contactDate">
        <el-date-picker clearable
          v-model="queryParams.contactDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择初次接触日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="立项通过日期" prop="projectDate">
        <el-date-picker clearable
          v-model="queryParams.projectDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择立项通过日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="投决通过日期" prop="decisionDate">
        <el-date-picker clearable
          v-model="queryParams.decisionDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择投决通过日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目所属公司" prop="company">
        <el-input
          v-model="queryParams.company"
          placeholder="请输入项目所属公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目联系人" prop="projectContacts">
        <el-input
          v-model="queryParams.projectContacts"
          placeholder="请输入项目联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投资负责人" prop="investHead">
        <el-input
          v-model="queryParams.investHead"
          placeholder="请输入投资负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="历次融资" prop="previousFinancing">
        <el-input
          v-model="queryParams.previousFinancing"
          placeholder="请输入历次融资"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目融资阶段" prop="financingStage">
        <el-input
          v-model="queryParams.financingStage"
          placeholder="请输入项目融资阶段"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预期融资金额" prop="financingMoney">
        <el-input
          v-model="queryParams.financingMoney"
          placeholder="请输入预期融资金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预期融资时间" prop="financingDate">
        <el-date-picker clearable
          v-model="queryParams.financingDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预期融资时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="投前估值" prop="investValuation">
        <el-input
          v-model="queryParams.investValuation"
          placeholder="请输入投前估值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预计投资金额" prop="investMoney">
        <el-input
          v-model="queryParams.investMoney"
          placeholder="请输入预计投资金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投资价值" prop="investWorth">
        <el-input
          v-model="queryParams.investWorth"
          placeholder="请输入投资价值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['invest:pool:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['invest:pool:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['invest:pool:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['invest:pool:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :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="项目名称" align="center" prop="porjectName" />
      <el-table-column label="所属组别" align="center" prop="porjectGroup">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.porject_group" :value="scope.row.porjectGroup"/>
        </template>
      </el-table-column>
      <el-table-column label="项目编号" align="center" prop="porjectCode" />
      <el-table-column label="渠道" align="center" prop="channel" />
      <el-table-column label="初次接触日期" align="center" prop="contactDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contactDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="立项通过日期" align="center" prop="projectDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="投决通过日期" align="center" prop="decisionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.decisionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目所属行业" align="center" prop="industry" />
      <el-table-column label="项目所属公司" align="center" prop="company" />
      <el-table-column label="项目联系人" align="center" prop="projectContacts" />
      <el-table-column label="投资负责人" align="center" prop="investHead" />
      <el-table-column label="历次融资" align="center" prop="previousFinancing" />
      <el-table-column label="项目融资阶段" align="center" prop="financingStage" />
      <el-table-column label="预期融资金额" align="center" prop="financingMoney" />
      <el-table-column label="预期融资时间" align="center" prop="financingDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.financingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="投前估值" align="center" prop="investValuation" />
      <el-table-column label="预计投资金额" align="center" prop="investMoney" />
      <el-table-column label="投资类型" align="center" prop="investType" />
      <el-table-column label="投资策略" align="center" prop="investPloy" />
      <el-table-column label="投资价值" align="center" prop="investWorth" />
      <el-table-column label="项目阶段" align="center" prop="projectStage" />
      <el-table-column label="项目状态" align="center" prop="projectState" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['invest:pool:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['invest:pool:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目池对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="porjectName">
          <el-input v-model="form.porjectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="所属组别" prop="porjectGroup">
          <el-select v-model="form.porjectGroup" placeholder="请选择所属组别">
            <el-option
              v-for="dict in dict.type.porject_group"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="录入日期" prop="recordDate">
          <el-date-picker clearable
            v-model="form.recordDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择录入日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目编号" prop="porjectCode">
          <el-input v-model="form.porjectCode" placeholder="请输入项目编号" />
        </el-form-item>
        <el-form-item label="渠道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入渠道" />
        </el-form-item>
        <el-form-item label="初次接触日期" prop="contactDate">
          <el-date-picker clearable
            v-model="form.contactDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择初次接触日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="立项通过日期" prop="projectDate">
          <el-date-picker clearable
            v-model="form.projectDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择立项通过日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="投决通过日期" prop="decisionDate">
          <el-date-picker clearable
            v-model="form.decisionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择投决通过日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目所属公司" prop="company">
          <el-input v-model="form.company" placeholder="请输入项目所属公司" />
        </el-form-item>
        <el-form-item label="项目情况描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入项目情况描述" />
        </el-form-item>
        <el-form-item label="项目联系人" prop="projectContacts">
          <el-input v-model="form.projectContacts" placeholder="请输入项目联系人" />
        </el-form-item>
        <el-form-item label="投资负责人" prop="investHead">
          <el-input v-model="form.investHead" placeholder="请输入投资负责人" />
        </el-form-item>
        <el-form-item label="历次融资" prop="previousFinancing">
          <el-input v-model="form.previousFinancing" placeholder="请输入历次融资" />
        </el-form-item>
        <el-form-item label="项目融资阶段" prop="financingStage">
          <el-input v-model="form.financingStage" placeholder="请输入项目融资阶段" />
        </el-form-item>
        <el-form-item label="融资条件" prop="financingCondition">
          <el-input v-model="form.financingCondition" placeholder="请输入融资条件" />
        </el-form-item>
        <el-form-item label="预期融资金额" prop="financingMoney">
          <el-input v-model="form.financingMoney" placeholder="请输入预期融资金额" />
        </el-form-item>
        <el-form-item label="预期融资时间" prop="financingDate">
          <el-date-picker clearable
            v-model="form.financingDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预期融资时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="投资亮点" prop="investSparkle">
          <el-input v-model="form.investSparkle" placeholder="请输入投资亮点" />
        </el-form-item>
        <el-form-item label="投前估值" prop="investValuation">
          <el-input v-model="form.investValuation" placeholder="请输入投前估值" />
        </el-form-item>
        <el-form-item label="预计投资金额" prop="investMoney">
          <el-input v-model="form.investMoney" placeholder="请输入预计投资金额" />
        </el-form-item>
        <el-form-item label="投资价值" prop="investWorth">
          <el-input v-model="form.investWorth" placeholder="请输入投资价值" />
        </el-form-item>
        <el-form-item label="股权架构" prop="shareholding">
          <el-input v-model="form.shareholding" placeholder="请输入股权架构" />
        </el-form-item>
        <el-form-item label="备注" prop="mark">
          <el-input v-model="form.mark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="状态" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { listPool, getPool, delPool, addPool, updatePool } from "@/api/invest/pool";

export default {
  name: "Pool",
  dicts: ['porject_group'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目池表格数据
      poolList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        porjectName: null,
        porjectGroup: null,
        porjectCode: null,
        channel: null,
        contactDate: null,
        projectDate: null,
        decisionDate: null,
        industry: null,
        company: null,
        projectContacts: null,
        investHead: null,
        previousFinancing: null,
        financingStage: null,
        financingMoney: null,
        financingDate: null,
        investValuation: null,
        investMoney: null,
        investType: null,
        investPloy: null,
        investWorth: null,
        projectStage: null,
        projectState: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目池列表 */
    getList() {
      this.loading = true;
      listPool(this.queryParams).then(response => {
        this.poolList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        porjectName: null,
        porjectGroup: null,
        recordDate: null,
        porjectCode: null,
        channel: null,
        contactDate: null,
        projectDate: null,
        decisionDate: null,
        industry: null,
        company: null,
        description: null,
        projectContacts: null,
        investHead: null,
        previousFinancing: null,
        financingStage: null,
        financingCondition: null,
        financingMoney: null,
        financingDate: null,
        investSparkle: null,
        investValuation: null,
        investMoney: null,
        investType: null,
        investPloy: null,
        investWorth: null,
        shareholding: null,
        projectStage: null,
        projectState: null,
        mark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      // this.open = true;
      // this.title = "添加项目池";
      
      this.$router.push({ path: '/invest/pool/add',query: { id: 1 }})
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPool(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目池";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePool(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPool(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目池编号为"' + ids + '"的数据项？').then(function() {
        return delPool(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('invest/pool/export', {
        ...this.queryParams
      }, `pool_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
