<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <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="businessStatus">
        <el-input v-model="queryParams.businessStatus" placeholder="请输入经营状态" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="项目业态" prop="business">
        <el-select v-model="businessArr" placeholder="请选择项目业态" multiple clearable>
          <el-option v-for="dict in dict.type.risk_project_business" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="所属区域" prop="deptId">
        <treeselect v-model="queryParams.deptId" :options="deptOptions" :show-count="true" placeholder="请选择所属区域"
          style="width: 250px" />
      </el-form-item>
      <el-form-item label="所在城市" prop="city">
        <el-input v-model="queryParams.city" placeholder="请输入所在城市" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input v-model="queryParams.address" placeholder="请输入详细地址" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="物业" prop="propertyManagement">
        <el-select v-model="queryParams.propertyManagement" placeholder="请选择是否为物业" clearable>
          <el-option key="1" label="是" value="true" />
          <el-option key="0" label="否" value="false" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </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>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="name" />
      <el-table-column label="项目类型" align="center" prop="type" />
      <el-table-column label="项目业态" align="center" prop="business" />
      <el-table-column label="所属区域" align="center" prop="deptName" />
      <el-table-column label="所在城市" align="center" prop="city" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status" />
        </template>
      </el-table-column>
      <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="showDetail(scope.row)">查看风险台账</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" />
  </div>
</template>

<script>
import { listProject } from "@/api/ledger/project/";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Project",
  dicts: ["sys_normal_disable", "data_source", "risk_project_business"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      userTotal: 0,
      // 基础数据-项目表格数据
      projectList: [],
      // 部门树选项
      deptOptions: undefined,
      // 弹出层标题
      title: "",
      // 用户表格数据
      userList: null,
      // 是否显示弹出层
      open: false,
      powerOpen: false,
      businessArr: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        type: null,
        deptId: null,
        city: null,
        address: null,
        source: null,
        status: null,
      },
      queryUserParams: {
        pageNum: 1,
        pageSize: 10,
        projectId: undefined,
        userName: undefined,
      },
      // 表单参数
      form: {
        businessStatus: "",
      },
      // 表单校验
      rules: {},
      projectId: "",
      userPost: null,
      postList: [],
      userInfoData: {},

    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询基础数据-项目列表 */
    getList() {
      this.loading = true;
      if (this.businessArr) {
        this.queryParams.business = this.businessArr.join(',');
      }
      listProject(this.queryParams).then((response) => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        type: null,
        deptId: null,
        city: null,
        address: null,
        source: null,
        status: 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();
    },
    showDetail(obj) {
      this.$router.push({
        name: "riskDetail",
        params: {
          projectId: obj.id,
        },
      });
    },
  },
};
</script>
