<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="任务名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入任务名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属区域" prop="createDeptId">
        <treeselect
          v-model="queryParams.createDeptId"
          :options="deptOptions"
          :show-count="true"
          placeholder="请选择所属区域"
          style="width: 250px"
        />
      </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="createUserName">
        <el-input v-model="queryParams.createUserName" placeholder="请输入创建人员名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="负责人名称" prop="leaderUserName">
        <el-input v-model="queryParams.leaderUserName" 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-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="任务名称" align="left" prop="name"  width="220px"/>
      <el-table-column label="项目名称" align="left" prop="projectName" width="220px"/>
      <el-table-column label="楼栋名称" align="left" prop="buildingNames" width="220px">
      <template slot-scope="scope">

       <el-popover
           placement="top-start"
           title="楼栋名称"
           width="200"
           trigger="hover"
           :content="scope.row.buildingNames">
           <span slot="reference">{{ scope.row.buildingNames.length>25?scope.row.buildingNames.substring(0,25)+"...":scope.row.buildingNames}}</span>
         </el-popover>
      </template>
      </el-table-column>

     <!-- <el-table-column label="创建人员" align="center" prop="createUserName" />
      <el-table-column label="创建单位" align="center" prop="createDeptName" /> -->
      <el-table-column label="负责人" align="center" prop="leaderUserName" />
      <el-table-column label="执行人员" align="center" prop="workUserNames" />
      <el-table-column label="开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="statusName" >
        <template slot-scope="scope">
        
          <div>
          		<div v-if="scope.row.statusName=='项目完成'"><el-tag type="info">项目完成</el-tag></div>
          		<div v-else-if="scope.row.statusName=='审批任务'"><el-tag >审批任务</el-tag></div>
              <div v-else-if="scope.row.statusName=='任务待执行'"><el-tag type="warning">任务待执行</el-tag></div>
              <div v-else-if="scope.row.statusName=='验收任务'"><el-tag type="success">验收任务</el-tag></div>
              <div v-else><el-tag type="danger">{{scope.row.statusName}}</el-tag></div>
          	</div>
        </template>
        </el-table-column>
      <el-table-column label="操作" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <router-link :to="'/risk/plan/ledgerdata/index/' + scope.row.id" class="link-type">
            <el-button size="mini" type="text" icon="el-icon-view">详情</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
  import {
    listPlan,
    addPlan,
    updatePlan
  } from "@/api/risk/plan";

  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  import { deptTreeSelect } from "@/api/system/user";
  export default {
    name: "Plan",
  components: {
    Treeselect,
  },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 风险计划表格数据
        planList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          isLedger:"ledger",
          name: null,
          createDeptId: null,
          projectName: null,
          createUserName: null,
          leaderUserName: null,
          workUserName: null,
          createDeptId: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        deptOptions: []
      };
    },
    created() {
      this.getList();
      this.getDeptTree();
    },
    methods: {
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
      /** 查询风险计划列表 */
      getList() {
        this.loading = true;
        listPlan(this.queryParams).then((response) => {
          this.planList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          isLedger:"ledger",
          name: null,
          createDeptId: null,
          projectName: null,
          createUserName: null,
          leaderUserName: null,
          workUserName: null,
          createDeptId: 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;
      },
    },
  };
</script>
