<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="所属网格" prop="deptId">
        <treeselect v-model="queryParams.deptId" :options="deptOptions" :disable-branch-nodes="true" style="width:215px;"
                    placeholder="请选择所属网格"/>
      </el-form-item>
      <el-form-item label="场所名称" prop="csName">
        <el-input
          v-model="queryParams.csName"
          placeholder="请输入场所名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行业类别" prop="hyType">
        <el-select
          v-model="queryParams.hyType"
          placeholder="行业类别"
          clearable
          style="width:100%"
        >
          <el-option
            v-for="dict in dict.type.szxc_hy_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="场所类型" prop="csType">
        <el-select
          v-model="queryParams.csType"
          placeholder="场所类型"
          clearable
          style="width:100%"
        >
          <el-option
            v-for="dict in dict.type.szxv_cs_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商住一体" prop="szyt">
        <el-select
          v-model="queryParams.szyt"
          placeholder="商住一体"
          clearable
          style="width:100%"
        >
          <el-option
            v-for="dict in dict.type.szxc_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="法人姓名" prop="frName">
        <el-input
          v-model="queryParams.frName"
          placeholder="请输入法人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="tyshxyCode">
        <el-input
          v-model="queryParams.tyshxyCode"
          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="['szxc:csmanage: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="['szxc:csmanage: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="['szxc:csmanage: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="['szxc:csmanage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="csmanageList" @selection-change="handleSelectionChange" border>
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column label="ID" align="center" prop="id" min-width="60"/>
      <el-table-column label="所属网格" align="center" prop="deptName" min-width="120" show-overflow-tooltip/>
      <el-table-column label="场所名称" align="center" prop="csName" min-width="120" show-overflow-tooltip/>
      <el-table-column label="行业类别" align="center" prop="hyType" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.szxc_hy_type" :value="scope.row.hyType"/>
        </template>
      </el-table-column>
      <el-table-column label="场所类型" align="center" prop="csType" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.szxv_cs_type" :value="scope.row.csType"/>
        </template>
      </el-table-column>
      <el-table-column label="场所地址" align="center" prop="csAddress" min-width="160" show-overflow-tooltip/>
      <el-table-column label="员工数量" align="center" prop="employeeNum" min-width="120" show-overflow-tooltip/>
      <el-table-column label="商住一体" align="center" prop="szyt" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span v-if="scope.row.szyt==='0'">是</span>
          <span v-if="scope.row.szyt==='1'">否</span>
        </template>
      </el-table-column>
      <el-table-column label="房屋类型" align="center" prop="fwType" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.szxc_fw_type" :value="scope.row.fwType"/>
        </template>
      </el-table-column>
      <el-table-column label="法人姓名" align="center" prop="frName" min-width="120" show-overflow-tooltip/>
      <el-table-column label="成立日期" align="center" prop="clDate" min-width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.clDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="营业期限" align="center" prop="yyqx" min-width="120"/>
      <el-table-column label="统一社会信用代码" align="center" prop="tyshxyCode" min-width="160" show-overflow-tooltip/>
      <el-table-column label="营业执照" align="center" prop="yyzzPicture" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.yyzzPicture" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" min-width="160" show-overflow-tooltip/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="180" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['szxc:csmanage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['szxc:csmanage:remove']"
          >删除</el-button>

          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" style="margin-left: 6px">
            <el-button size="mini" type="text">更多操作</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleYg">场所员工</el-dropdown-item>
              <el-dropdown-item command="handleFzr">场所负责人</el-dropdown-item>
              <el-dropdown-item command="handleFw">关联房屋</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </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="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="125px">

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="所属网格" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :disable-branch-nodes="true"
                          placeholder="请选择所属网格" style="width:100%;" @select="selectedTree"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场所名称" prop="csName">
              <el-input v-model="form.csName" placeholder="请输入场所名称" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="行业类别" prop="hyType">
              <el-select
                v-model="form.hyType"
                placeholder="行业类别"
                clearable
                style="width:100%"
              >
                <el-option
                  v-for="dict in dict.type.szxc_hy_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场所类型" prop="csType">
              <el-select
                v-model="form.csType"
                placeholder="场所类型"
                clearable
                style="width:100%"
              >
                <el-option
                  v-for="dict in dict.type.szxv_cs_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="场所地址" prop="csAddress">
              <el-input v-model="form.csAddress" placeholder="请输入场所地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工数量" prop="employeeNum">
              <el-input v-model="form.employeeNum" placeholder="请输入员工数量" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="商住一体" prop="szyt">
              <el-radio-group v-model="form.szyt">
                <el-radio
                  v-for="dict in dict.type.szxc_yes_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="房屋类型" prop="fwType">
              <el-select
                v-model="form.fwType"
                placeholder="房屋类型"
                clearable
                style="width:100%"
              >
                <el-option
                  v-for="dict in dict.type.szxc_fw_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="法人姓名" prop="frName">
              <el-input v-model="form.frName" placeholder="请输入法人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成立日期" prop="clDate">
              <el-date-picker clearable style="width: 100%;"
                              v-model="form.clDate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择成立日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="营业期限" prop="yyqx">
              <el-checkbox v-model="cq_checked" style="margin-right: 15px;" @change="cqChange">长期</el-checkbox>
              <el-date-picker clearable v-if="!cq_checked"
                              v-model="form.yyqx"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择营业期限">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="tyshxyCode">
              <el-input v-model="form.tyshxyCode" placeholder="请输入统一社会信用代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="营业执照" prop="yyzzPicture">
          <image-upload v-model="form.yyzzPicture"/>
        </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="csyg.visible" width="1000px" append-to-body>
      <el-table v-loading="csyg.loading" :data="csyg.list" border>
        <el-table-column label="场所名称" align="center" prop="csName" min-width="120" show-overflow-tooltip/>
        <el-table-column label="员工姓名" align="center" prop="ygName" min-width="120" show-overflow-tooltip/>
        <el-table-column label="手机号" align="center" prop="phone" min-width="120" show-overflow-tooltip/>
        <el-table-column label="身份证号" align="center" prop="cardId" min-width="150" show-overflow-tooltip/>
        <el-table-column label="性别" align="center" prop="sex" min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
          </template>
        </el-table-column>
        <el-table-column label="是否党员" align="center" prop="dyOrNot" min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.szxc_yes_no" :value="scope.row.dyOrNot"/>
          </template>
        </el-table-column>
        <el-table-column label="现居住地" align="center" prop="currentAddress" min-width="160" show-overflow-tooltip/>
        <el-table-column label="省" align="center" prop="province" min-width="120" show-overflow-tooltip/>
        <el-table-column label="市" align="center" prop="city" min-width="120" show-overflow-tooltip/>
        <el-table-column label="县" align="center" prop="county" min-width="120" show-overflow-tooltip/>
        <el-table-column label="户籍地址" align="center" prop="hjAddress" min-width="160" show-overflow-tooltip/>
      </el-table>
    </el-dialog>

    <el-dialog title="场所负责人" :visible.sync="csfzr.visible" width="1000px" append-to-body>
      <el-table v-loading="csfzr.loading" :data="csfzr.list" border>
        <el-table-column label="场所名称" align="center" prop="csName"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="负责人类型" align="center" prop="fzrType"  min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.szxc_fzr_type" :value="scope.row.fzrType"/>
          </template>
        </el-table-column>
        <el-table-column label="负责人姓名" align="center" prop="fzrName"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="手机号" align="center" prop="phone"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="身份证号" align="center" prop="cardId"  min-width="150" show-overflow-tooltip/>
        <el-table-column label="性别" align="center" prop="sex"  min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
          </template>
        </el-table-column>
        <el-table-column label="是否党员" align="center" prop="dyOrNot"  min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            <dict-tag :options="dict.type.szxc_yes_no" :value="scope.row.dyOrNot"/>
          </template>
        </el-table-column>
        <el-table-column label="现居住地" align="center" prop="currentAddress"  min-width="160" show-overflow-tooltip/>
        <el-table-column label="省" align="center" prop="province"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="市" align="center" prop="city"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="县" align="center" prop="county"  min-width="120" show-overflow-tooltip/>
        <el-table-column label="户籍地址" align="center" prop="hjAddress"  min-width="160" show-overflow-tooltip/>
      </el-table>
    </el-dialog>

    <el-dialog title="关联房屋" :visible.sync="csfw.visible" width="1000px" append-to-body>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="csfwAdd"
          >新增</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="csfw.loading" :data="csfw.list" border>
        <el-table-column label="房屋名称" align="center" prop="fwName" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="120px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="csfwUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="csfwDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 添加或修改关联房屋对话框 -->
    <el-dialog :title="csfw.title" :visible.sync="csfw.open" width="500px" append-to-body>
      <el-form ref="csfwForm" :model="csfw.form" :rules="csfw.rules" label-width="100px">
        <el-form-item label="房屋" prop="fwName">
          <el-input readonly
                    placeholder="请选择房屋"
                    v-model="csfw.form.fwName">
            <el-button slot="append" icon="el-icon-search" @click="fwxxSelect"></el-button>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="csfwSubmit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择房屋信息" :visible.sync="fwxx.visible" width="900px" append-to-body>
      <el-alert title="双击选择房屋" type="warning" :closable="false"></el-alert>
      <el-table v-loading="fwxx.loading" :data="fwxx.list" border @cell-dblclick="fwxxDblclick">
        <el-table-column label="所属网格" align="center" prop="deptName" />
        <el-table-column label="户主姓名" align="center" prop="ownerName" />
        <el-table-column label="身份证号" align="center" prop="cardId" />
        <el-table-column label="小区名称" align="center" prop="houseName" />
        <el-table-column label="楼栋名称" align="center" prop="ldName" />
        <el-table-column label="单元" align="center" prop="unit" />
        <el-table-column label="门牌号" align="center" prop="doorNo" />
      </el-table>
      <pagination
        v-show="fwxx.total>0"
        :total="fwxx.total"
        :page.sync="fwxx.queryParams.pageNum"
        :limit.sync="fwxx.queryParams.pageSize"
        @pagination="getlistHouseinfo"
      />
    </el-dialog>

  </div>
</template>

<script>
import { listCsmanage, getCsmanage, delCsmanage, addCsmanage, updateCsmanage } from "@/api/szxc/csmanage";
import { listEmplyees } from "@/api/szxc/emplyees";
import { listResponse } from "@/api/szxc/response";
import { listCs_fw, getCs_fw, delCs_fw, addCs_fw, updateCs_fw } from "@/api/szxc/cs_fw";
import { listHouseinfo } from "@/api/szxc/houseinfo";
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Csmanage",
  components: { Treeselect },
  dicts: ['szxc_hy_type', 'szxv_cs_type', 'szxc_fw_type', 'szxc_yes_no', 'szxc_fzr_type', 'sys_user_sex'],
  data() {
    return {
      cq_checked: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 场所管理表格数据
      csmanageList: [],
      // 组织树选项
      deptOptions: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        csName: null,
        hyType: null,
        csType: null,
        csAddress: null,
        employeeNum: null,
        szyt: null,
        fwType: null,
        frName: null,
        clDate: null,
        yyqx: null,
        tyshxyCode: null,
        yyzzPicture: null,
        deptId: null,
        deptName: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
      },
      // 场所员工信息
      csyg: {
        visible: false,
        // 遮罩层
        loading: false,
        // 查询列表
        list: [],
        // 选中信息
        selectedRow: null,
      },
      // 场所负责人信息
      csfzr: {
        visible: false,
        // 遮罩层
        loading: false,
        // 查询列表
        list: [],
        // 选中信息
        selectedRow: null,
      },
      // 场所房屋关联信息
      csfw: {
        visible: false,
        // 遮罩层
        loading: false,
        // 查询列表
        list: [],
        // 选中信息
        selectedRow: null,
        // 弹出框
        open: false,
        // 弹出层标题
        title: '',
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          cardNum: [
            {required: true, message: "银行卡号不能为空", trigger: "blur"}
          ],
        },
      },
      // 房屋信息
      fwxx: {
        visible: false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        queryParams:{
          pageNum: 1,
          pageSize: 10
        },
        // 查询列表
        list: [],
        // 选中数据
        selectRow: null
      },
    }
  },
  created() {
    this.getList();
    this.getDeptTree();
  },
  methods: {
    /** 查询组织下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    selectedTree(node){
      this.form.deptId = node.id;
      this.form.deptName = node.label;
    },
    /** 查询场所管理列表 */
    getList() {
      this.loading = true;
      listCsmanage(this.queryParams).then(response => {
        this.csmanageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        csName: null,
        hyType: null,
        csType: null,
        csAddress: null,
        employeeNum: null,
        szyt: null,
        fwType: null,
        frName: null,
        clDate: null,
        yyqx: null,
        tyshxyCode: null,
        yyzzPicture: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deptId: null,
        deptName: null,
        userId: 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 = "添加场所管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCsmanage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改场所管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.cq_checked){
            this.form.yyqx = '长期';
          }
          if (this.form.id != null) {
            updateCsmanage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCsmanage(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 delCsmanage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('szxc/csmanage/export', {
        ...this.queryParams
      }, `csmanage_${new Date().getTime()}.xlsx`)
    },
    // 长期选择
    cqChange(){
      this.form.yyqx = ''
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleYg":
          this.handleYg(row);
          break;
        case "handleFzr":
          this.handleFzr(row);
          break;
        case "handleFw":
          this.handleFw(row);
          break;
        default:
          break;
      }
    },
    // 场所员工信息
    handleYg(row){
      this.csyg.selectedRow = row;
      this.csyg.visible = true;
      this.getlistEmplyees();
    },
    /** 查询场所员工信息列表 */
    getlistEmplyees() {
      listEmplyees({
        pageNum: 1,
        pageSize: 100000000,
        csId: this.csyg.selectedRow.id
      }).then(response => {
        this.csyg.list = response.rows
      });
    },
    // 场所负责人
    handleFzr(row){
      this.csfzr.selectedRow = row;
      this.csfzr.visible = true;
      this.getlistResponse();
    },
    /** 查询场所员工信息列表 */
    getlistResponse() {
      listResponse({
        pageNum: 1,
        pageSize: 100000000,
        csId: this.csfzr.selectedRow.id
      }).then(response => {
        this.csfzr.list = response.rows
      });
    },
    // 场所房屋信息
    handleFw(row){
      this.csfw.selectedRow = row
      this.csfw.visible = true;
      this.getlistCs_fw()
    },
    /** 查询场所房屋关联列表 */
    getlistCs_fw() {
      this.csfw.loading = true;
      listCs_fw(this.queryParams).then(response => {
        this.csfw.list = response.rows;
        this.csfw.total = response.total;
        this.csfw.loading = false;
      });
    },
    // 添加房屋
    csfwAdd(){
      this.resetForm("csfwForm");
      this.csfw.form = {
        id: null,
        csId: this.csfw.selectedRow.id,
        fwId: null,
        fwName: null
      };
      this.csfw.title = '添加房屋';
      this.csfw.open = true;
    },
    /** 修改房屋按钮操作 */
    csfwUpdate(row) {
      this.csfw.form = row;
      this.csfw.title = '修改房屋';
      this.csfw.open = true;
    },
    /** 删除房屋按钮操作 */
    csfwDelete(row) {
      this.$modal.confirm('是否确认删除房屋为【"' + row.fwName + '"】的数据项？').then(function() {
        return delCs_fw(row.id);
      }).then(() => {
        this.getlistCs_fw();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    // 添加提交房屋
    csfwSubmit(){
      this.$refs["csfwForm"].validate(valid => {
        if (valid) {
          if (this.csfw.form.id != null) {
            updateCs_fw(this.csfw.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.csfw.open = false;
              this.getlistCs_fw();
            });
          } else {
            this.csfw.form.defaultCard = '1'
            addCs_fw(this.csfw.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.csfw.open = false;
              this.getlistCs_fw();
            });
          }
        }
      });
    },
    // 点击选择房屋
    fwxxSelect(){
      this.fwxx.visible = true;
      this.getlistHouseinfo()
    },
    /** 查询房屋信息列表 */
    getlistHouseinfo() {
      this.fwxx.loading = true;
      listHouseinfo(this.fwxx.queryParams).then(response => {
        this.fwxx.list = response.rows;
        this.fwxx.total = response.total;
        this.fwxx.loading = false;
      });
    },
    // 房屋信息查询
    fwxxQuery(){
      this.fwxx.queryParams.pageNum = 1;
      this.getlistHouseinfo();
    },
    // 房屋选择 选中数据
    fwxxDblclick(row) {
      this.fwxx.selectRow = row;
      this.csfw.form.fwId = row.id;
      this.csfw.form.fwName = row.houseName;
      this.fwxx.visible = false
    },
  }
};
</script>
