<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="4" :xs="24">
        <div class="from_tree">
          <div class="head-container">
            <el-input
              v-model="deptName"
              placeholder="请输入部门名称"
              clearable
              size="small"
              prefix-icon="el-icon-search"
              style="margin-bottom: 20px"
            />
          </div>
          <div class="head-container">
            <el-tree
              :props="defaultProps"
              :expand-on-click-node="false"
              :filter-node-method="filterNode"
              ref="tree"
              lazy
              :load="loadNode"
              @node-click="handleNodeClick"
              node-key="id"
              :default-expanded-keys="defaultExpandKeys"
              :current-node-key="defaultActive"
              highlight-current
            />
          </div>
        </div>
      </el-col>
      <el-col :span="20" :xs="24">
        <div class="from_table">
          <el-form
            :model="queryParams"
            ref="queryForm"
            :inline="true"
            v-show="showSearch"
          >
            <el-form-item label="名称" prop="name">
              <el-input
                v-model="queryParams.name"
                placeholder="请输入名称"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>

            <el-form-item label="类型" prop="type">
              <el-select
                v-model="queryParams.type"
                placeholder="请选择类型"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in dict.type.b_person_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="分色" prop="color">
              <el-select
                v-model="queryParams.color"
                placeholder="请选择分色"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in dict.type.b_color_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>

            <!-- <el-form-item label="最后1次核酸日期">
            <el-date-picker
              v-model="daterangeHesuanTime"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item> -->
            <el-form-item>
              <el-button
                class="search_btn"
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button
                class="agin_btn"
                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="new"
                size="mini"
                @click="handleAdd"
                v-hasPermi="['taicangpop:person:add']"
                >新增</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="revise"
                size="mini"
                :disabled="single"
                @click="handleUpdate"
                v-hasPermi="['taicangpop:person:edit']"
                >修改</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="remove"
                size="mini"
                :disabled="multiple"
                @click="handleDelete"
                v-hasPermi="['taicangpop:person:remove']"
                >删除</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="export"
                size="mini"
                :loading="exportLoading"
                @click="handleExport"
                v-hasPermi="['taicangpop:person:export']"
                >导出</el-button
              >
            </el-col>
            <!-- 暂时隐藏，不给客户使用 -->
            <!-- <el-col :span="1.5">
              <el-button type="export" size="mini" @click="loadFile"
                >批量导入</el-button
              >
            </el-col> -->
            <right-toolbar
              :showSearch.sync="showSearch"
              @queryTable="getList"
            ></right-toolbar>
          </el-row>

          <el-table
            v-loading="loading"
            :data="personList"
            @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="deptname" />
            <el-table-column
              label="楼栋名称"
              align="center"
              prop="buildingname"
            />
            <el-table-column label="住户名称" align="center" prop="housename" />
            <el-table-column label="名字" align="center" prop="name" />
            <!-- <el-table-column label="身份证" align="center" prop="credentialNo" /> -->
            <!-- <el-table-column label="楼栋id" align="center" prop="buildingId" /> -->
            <!-- <el-table-column label="住户id" align="center" prop="houseId" /> -->
            <el-table-column label="类型" align="center" prop="type">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.b_person_type"
                  :value="scope.row.type"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="联系电话"
              align="center"
              prop="phone"
              width="200"
            />
            <el-table-column label="分色" align="center" prop="color">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.b_color_type"
                  :value="scope.row.color"
                />
              </template>
            </el-table-column>
            <el-table-column label="党员" align="center" prop="isD" />
            <el-table-column label="困难户" align="center" prop="isK" />
            <el-table-column label="退役军人" align="center" prop="isJ" />
            <el-table-column label="信访户" align="center" prop="isX" />
            <!-- <el-table-column
              label="最后1次核酸日期"
              align="center"
              prop="hesuanTime"
              width="180"
            >
              <template slot-scope="scope">
                <span>{{
                  parseTime(scope.row.hesuanTime, "{y}-{m}-{d}")
                }}</span>
              </template>
            </el-table-column> -->
            <!-- <el-table-column
            label="工作单位"
            align="center"
            prop="workunit"
          /> -->
            <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
            <el-table-column
              label="操作"
              align="center"
              fixed="right"
              class-name="small-padding fixed-width"
              width="200"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-zoom-in"
                  @click="handleInfo(scope.row)"
                  >查看</el-button
                >
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"
                  v-hasPermi="['taicangpop:person:edit']"
                  >修改</el-button
                >
                <el-button
                  class="table_icon_text"
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"
                  v-hasPermi="['taicangpop:person: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
            :close-on-click-modal="false"
            :destroy-on-close="true"
          >
            <el-form
              ref="form"
              :model="form"
              :rules="rules"
              label-width="auto"
              class="data_container"
            >
              <el-form-item label="名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入名称" />
              </el-form-item>
              <el-form-item label="身份证" prop="credentialNo">
                <el-input
                  v-model="form.credentialNo"
                  placeholder="请输入身份证"
                />
              </el-form-item>
              <el-form-item label="组团" prop="deptId">
                <treeselect
                  :value="value"
                  v-model="form.deptId"
                  :options="deptOptions"
                  :show-count="true"
                  placeholder="请选择归属组团"
                  @select="treeSelect"
                />
              </el-form-item>
              <el-form-item label="楼栋" prop="buildingId">
                <el-select
                  v-model="form.buildingId"
                  placeholder="请输入楼栋"
                  filterable
                  @change="selectBuildingChange"
                >
                  <el-option
                    v-for="dict in buildingList"
                    :key="parseInt(dict.id)"
                    :label="dict.name"
                    :value="parseInt(dict.id)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="住户" prop="houseId">
                <el-select
                  v-model="form.houseId"
                  placeholder="请输入住户"
                  filterable
                >
                  <el-option
                    v-for="dict in houselist"
                    :key="parseInt(dict.id)"
                    :label="dict.name"
                    :value="parseInt(dict.id)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="联系电话" prop="phone">
                <el-input v-model="form.phone" placeholder="请输入联系电话" />
              </el-form-item>
              <el-form-item label="类型" prop="type">
                <el-select
                  v-model="form.type"
                  placeholder="请选择类型"
                  @change="changeType"
                >
                  <el-option
                    v-for="dict in dict.type.b_person_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="分色" prop="color">
                <!-- //默认 -->
                <el-select
                  v-model="form.color"
                  placeholder="请选择分色"
                  v-if="!form.type"
                >
                  <el-option
                    v-for="dict in []"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
                <!-- 户籍 -->
                <el-select
                  v-model="form.color"
                  placeholder="请选择分色"
                  v-if="form.type === '1' || form.type === 1"
                >
                  <el-option
                    v-for="dict in dict.type.b_census_color_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
                <!-- 流动 -->
                <el-select
                  v-model="form.color"
                  placeholder="请选择分色"
                  :disabled="false"
                  v-if="form.type === '2' || form.type === 2"
                >
                  <el-option
                    v-for="dict in dict.type.b_flow_color_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="党员" prop="isD">
                <el-select v-model="form.isD" placeholder="请选择是否党员">
                  <el-option
                    v-for="dict in isD"
                    :key="dict.value"
                    :label="dict.name"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="困难户" prop="isK">
                <el-select v-model="form.isK" placeholder="请选择是否困难户">
                  <el-option
                    v-for="dict in isK"
                    :key="dict.value"
                    :label="dict.name"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="退役军人" prop="isJ">
                <el-select v-model="form.isJ" placeholder="请选择是退役军人">
                  <el-option
                    v-for="dict in isJ"
                    :key="dict.value"
                    :label="dict.name"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="信访户" prop="isX">
                <el-select v-model="form.isX" placeholder="请选择信访户">
                  <el-option
                    v-for="dict in isX"
                    :key="dict.value"
                    :label="dict.name"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- <el-form-item label="最后1次核酸日期" prop="hesuanTime">
                <el-date-picker
                  clearable
                  size="small"
                  v-model="form.hesuanTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择最后1次核酸日期"
                >
                </el-date-picker>
              </el-form-item> -->
              <el-form-item label="工作单位" prop="workunit">
                <el-input
                  v-model="form.workunit"
                  type="textarea"
                  placeholder="请输入内容"
                />
              </el-form-item>
              <el-form-item label="备注" prop="remark">
                <el-input
                  v-model="form.remark"
                  type="textarea"
                  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>
          <!-- 导入文件 -->
          <el-dialog
            title="请选择文件"
            :visible.sync="fileOpen"
            width="500px"
            append-to-body
            :close-on-click-modal="false"
            :destroy-on-close="true"
            @close="closeFile"
          >
            <fileUpload v-model="file" :logo="'Upload'" />
          </el-dialog>
          <!-- 详情样式 -->
          <el-dialog
            title="详情信息"
            :visible.sync="infoOpen"
            width="500px"
            append-to-body
            :close-on-click-modal="false"
            :destroy-on-close="true"
          >
            <el-descriptions
              title="居民详情"
              :column="1"
              border
              class="textData"
            >
              <el-descriptions-item label="名称">{{
                form.name
              }}</el-descriptions-item>
              <el-descriptions-item label="身份证号">{{
                form.credentialNo
              }}</el-descriptions-item>
              <el-descriptions-item label="所属网格">{{
                form.parentname
              }}</el-descriptions-item>
              <el-descriptions-item label="苑名称">{{
                form.deptname
              }}</el-descriptions-item>
              <el-descriptions-item label="楼名称">{{
                form.buildingname
              }}</el-descriptions-item>
              <el-descriptions-item label="室名称">{{
                form.housename
              }}</el-descriptions-item>
              <el-descriptions-item label="类型">{{
                form.type == 1 ? "户籍" : "流动"
              }}</el-descriptions-item>
              <el-descriptions-item label="联系电话">{{
                form.phone
              }}</el-descriptions-item>
              <el-descriptions-item label="分色">{{
                form.colorname
              }}</el-descriptions-item>
              <el-descriptions-item label="党员">{{
                form.isD == 1 ? "是" : form.isD == 0 ? "否" : ""
              }}</el-descriptions-item>
              <el-descriptions-item label="困难户">{{
                form.isK == 1 ? "是" : form.isK == 0 ? "否" : ""
              }}</el-descriptions-item>
              <el-descriptions-item label="退役军人">{{
                form.isJ == 1 ? "是" : form.isJ == 0 ? "否" : ""
              }}</el-descriptions-item>
              <el-descriptions-item label="信访户">{{
                form.isX == 1 ? "是" : form.isX == 0 ? "否" : ""
              }}</el-descriptions-item>
              <!-- <el-descriptions-item label="最后1次核酸日期">{{
                form.hesuanTime
              }}</el-descriptions-item> -->
              <el-descriptions-item label="工作单位">{{
                form.workunit
              }}</el-descriptions-item>
              <el-descriptions-item label="备注">{{
                form.remark
              }}</el-descriptions-item>
            </el-descriptions>
          </el-dialog>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {
  listPerson,
  getPerson,
  delPerson,
  addPerson,
  updatePerson,
  exportPerson,
} from "@/api/taicangpop/person";
import { treeselect, listDept } from "@/api/system/dept";
import { listBuilding } from "@/api/taicangpop/building";
import { listHouse } from "@/api/taicangpop/house";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
//校正
import check from "@/utils/regex/index.js";

export default {
  name: "Person",
  dicts: [
    "b_person_type",
    "b_color_type",
    "b_census_color_type",
    "b_flow_color_type",
  ],
  components: { Treeselect },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      file: "",
      value: "",
      infoBoole: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 居民管理表格数据
      personList: [],
      // 部门名称
      deptName: undefined,
      // 部门树选项
      deptOptions: undefined,
      defaultProps: {
        children: "children",
        label: "label",
        isLeaf: "leaf",
      },
      isD: [
        {
          name: "是",
          value: 1,
        },
        {
          name: "否",
          value: 0,
        },
      ],
      isK: [
        {
          name: "是",
          value: 1,
        },
        {
          name: "否",
          value: 0,
        },
      ],
      isJ: [
        {
          name: "是",
          value: 1,
        },
        {
          name: "否",
          value: 0,
        },
      ],
      isX: [
        {
          name: "是",
          value: 1,
        },
        {
          name: "否",
          value: 0,
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      fileOpen: false,
      infoOpen: false,
      // 部门权限id时间范围
      daterangeHesuanTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        credentialNo: null,
        buildingId: null,
        houseId: null,
        type: null,
        color: null,
        isD: null,
        isK: null,
        isJ: null,
        isX: null,
        hesuanTime: null,
        deptId: undefined,
      },
      defaultExpandKeys: [], //默认展开项
      defaultActive: "",
      buildingList: [],
      houselist: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "组团名称不能为空", trigger: "change" },
        ],
        name: [{ required: true, message: "名称不能为空", trigger: "change" }],
        credentialNo: [
          { required: true, message: "身份证不能为空", trigger: "blur" },
          {
            validator: check.formRegex.idCard,
            trigger: "blur",
          },
        ],
        buildingId: [
          { required: true, message: "楼栋id不能为空", trigger: "blur" },
        ],
        houseId: [
          { required: true, message: "住户id不能为空", trigger: "blur" },
        ],
        type: [{ required: true, message: "类型不能为空", trigger: "change" }],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {
            validator: check.formRegex.checkPhone,
            trigger: "change",
          },
        ],
        color: [{ required: true, message: "分色不能为空", trigger: "change" }],
      },
      fileList: [],
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {},
  methods: {
    //类型户籍
    changeType(val) {
      this.form.color = null;
    },
    closeFile() {
      this.file = "";
    },
    loadFile() {
      this.fileOpen = true;
    },
    treeSelect(node, instanceId) {
      //   console.log(this.form.deptId, "aaaaaa");
      if (!node.children) {
        this.form.deptId = node.id;
        let queryBuildingParams = {
          deptId: node.id,
        };
        this.getBuildingList(queryBuildingParams);
      } else {
        this.form.deptId = null;
      }
    },
    /** 查询楼栋管理列表 */
    getBuildingList(queryBuildingParams) {
      listBuilding(queryBuildingParams).then((response) => {
        this.buildingList = response.rows;
      });
    },
    selectBuildingChange(val) {
      //   console.log(val);
      let queryHouseParams = {
        buildingId: val,
        deptId: this.deptId,
      };
      this.getHouseList(queryHouseParams);
    },
    /** 查询楼栋管理列表 */
    getHouseList(queryHouseParams) {
      // this.queryHouseParams
      listHouse(queryHouseParams).then((response) => {
        this.houselist = response.rows;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect(node, resolve) {
      treeselect().then((response) => {
        this.deptOptions = response.data;
        let datas = response.data;
        datas.forEach((item) => {
          item.children = item.children;
          item.label = item.label;
          item.id = item.id;
          item.parentId = item.id;
        });
        this.defaultExpandKeys.push(datas[0].id);
        return resolve(datas);
      });
    },
    loadNode(node, resolve) {
      this.defaultExpandKeys = []; //清除默认展开项
      this.defaultActive = "";
      if (node.level == 0) {
        this.getTreeselect(node, resolve);
      }
      if (node.level > 0 && node.level < 5) {
        let queryParam = {
          parentId: node.data.id,
        };
        this.reqListDept(queryParam, resolve);
      }
      // 5级子节点根据id获取接口数据
      else if (node.level == 5) {
        let queryParam = {
          deptId: node.data.id,
        };
        this.reqListBuilding(queryParam, resolve);
      } // 6级子节点根据id获取接口数据
      else if (node.level == 6) {
        let queryParam = {
          buildingId: node.data.id,
          deptId: node.data.parentId,
        };
        this.reqListHouse(queryParam, resolve);
        // console.log(resolve, "完毕");
      } else {
        return resolve([]); // 加上这个，防止在该节点没有子节点时一直转圈的问题发生。
      }
    },
    reqListDept(queryParam, resolve) {
      listDept(queryParam).then((res) => {
        let datas = res.data;
        // console.log(datas);
        datas.forEach((item) => {
          item.children = item.children;
          item.label = item.deptName;
          item.id = item.deptId;
          item.parentId = item.parentId;
        });
        this.defaultExpandKeys.push(datas[0].id);
        return resolve(datas);
      });
    },
    // 请求楼栋表
    reqListBuilding(queryParam, resolve) {
      listBuilding(queryParam).then((res) => {
        let datas = res.rows;
        // console.log(datas);
        datas.forEach((item) => {
          item.children = item.children;
          item.label = item.name;
          item.id = item.id;
          item.parentId = item.deptId;
        });
        this.defaultExpandKeys.push(datas[0].id);
        return resolve(datas);
      });
    },
    // 请求住户表
    reqListHouse(queryParam, resolve) {
      listHouse(queryParam).then((res) => {
        let datas = res.rows;

        datas.forEach((item) => {
          item.label = item.name;
          item.id = item.id;
          item.parentId = item.deptId;
          item.leaf = true;
        });
        this.defaultActive = res.rows[0].id;
        // console.log("默认选中项", this.defaultActive);
        //需要注意的是setCurrentKey函数必须要放到$nextTick里面，要不然tree还未渲染上，是找不到defaultActive的
        this.$nextTick(() => {
          this.$refs.tree.setCurrentKey(this.defaultActive);
        });
        //默认请求list项
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          deptId: datas[0].parentId,
          houseId: datas[0].id,
          buildingId: datas[0].buildingId,
        };
        this.getList();
        return resolve(datas);
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data, node) {
      //苑
      if (node.level == 5) {
        let deptId = //默认请求list项
          (this.queryParams = {
            pageNum: 1,
            pageSize: 10,
            deptId: data.id,
          });
        this.getList();
      } // 栋
      else if (node.level == 6) {
        //默认请求list项
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          deptId: data.deptId,
          buildingId: data.id,
        };
        this.getList();
      } // 室
      else if (node.level == 7) {
        //默认请求list项
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          deptId: data.parentId,
          buildingId: data.buildingId,
          houseId: data.id,
        };
        this.getList();
      }
    },
    /** 查询居民管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeHesuanTime && "" != this.daterangeHesuanTime) {
        this.queryParams.params["beginHesuanTime"] =
          this.daterangeHesuanTime[0];
        this.queryParams.params["endHesuanTime"] = this.daterangeHesuanTime[1];
      }
      listPerson(this.queryParams).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        credentialNo: null,
        buildingId: null,
        houseId: null,
        type: null,
        phone: null,
        color: null,
        isD: 0,
        isK: 0,
        isJ: 0,
        isX: 0,
        hesuanTime: null,
        workunit: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        userId: null,
        deptId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeHesuanTime = [];
      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 = "添加居民管理";
    },
    /** 查看详情*/
    handleInfo(row) {
      this.reset();
      const id = row.id || this.ids;
      getPerson(id).then((response) => {
        this.form = response.data;
        this.infoOpen = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPerson(id).then((response) => {
        this.form = response.data;
        // console.log("室", this.form);
        let Data = {
          deptId: this.form.deptId,
        };
        listBuilding(Data).then((res) => {
          this.buildingList = res.rows;
        });
        let queryParam = {
          buildingId: this.form.buildingId,
          deptId: this.form.deptId,
        };
        listHouse(queryParam).then((res) => {
          this.houselist = res.rows;
          this.open = true;
        });
        this.title = "修改居民管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updatePerson(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.userId = JSON.parse(
              sessionStorage.getItem("USER_INFO")
            ).userId;
            addPerson(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 delPerson(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有居民管理数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportPerson(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.from_table {
  padding-right: 10px;
}
</style>
<style lang="scss" scoped>
::v-deep .el-descriptions-row th {
  text-align: center !important;
  width: 130px !important;
}
::v-deep .textData {
  padding-bottom: 10px;
}
</style>
