<template>
  <a-layout>
    <a-layout-sider id="dxdcAside" width="300px">
      <provTreeList
        :rootCode="'1'"
        :style="{ 'max-height': dxdcAsideHeight + 'px' }"
        @provTreeSelectChange="provTreeSelectChangeHandler"></provTreeList>
    </a-layout-sider>
    <div style="min-width: 79%; height: 100%;" :class="{'user-manage': true}">
      <div class="search-wrapper">
        <a-form layout="inline" ref="form">
          <a-form-item label="用户名称" style="min-width: 200px;">
            <a-input v-model:value="searchObj.persName" allow-clear />
          </a-form-item>
          <a-form-item label="行政区划" style="min-width: 200px;" v-if="isNational">
            <a-input v-model:value="searchObj.orgNm" allow-clear />
          </a-form-item>
          <a-form-item label="手机号" style="min-width: 190px;">
            <a-input v-model:value="searchObj.mobilenumb" allow-clear />
          </a-form-item>
          <a-form-item label="用户角色" style="min-width: 250px;">
            <a-select
              v-model:value="searchObj.roleIds"
              placeholder="请选择"
              mode="multiple"
              allow-clear
              :maxTagCount="1"
              :filter-option="filterOption">
              <a-select-option v-for="(role ,index) in searchRoleList" :key="index" :value="role.id">{{ role.roleName }}</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" @click="getMemberList()">查询</a-button>
          </a-form-item>
          <!-- <a-form-item>
            <a-button type="primary" v-if="hasPriv" @click="toAddMember('添加')">添加</a-button>
          </a-form-item>
          <a-form-item>
            <a-button type="primary" v-if="hasPriv" @click="batchImport()">导入</a-button>
          </a-form-item> -->
          <!-- 人员基础信息批量导入弹窗 -->
          <ren-yuan-cha-xun-pl
            v-if="showRenYuanChaXunPl"
            @closePlDialog="closePlDialog"
            :persNameStr="searchObj.persName"
            :orgNmStr="searchObj.orgNm"
            :pageStr="searchObj.pageNum"></ren-yuan-cha-xun-pl>
        </a-form>
      </div>
      <a-table
        :data-source="memberList"
        ref="ptMultipleTable"
        :columns="columns"
        :pagination="false"
        row-key="guid"
        style="width: 100%;"
        :style="{ height: tableHeight + 'px' }"
        :scroll="{ x: true, y: tableHeight - 60 }"
        bordered>
        <template #bodyCell="{ column, record }">
          <template v-if="column.dataIndex === 'persName'">
            <a-tooltip placement="top">
              <template #title>{{ record.persName }}</template>
              <span class="ellipsis140">{{ record.persName }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'loginname'">
            <a-tooltip placement="top">
              <template #title>{{ record.loginname }}</template>
              <span class="ellipsis140">{{ record.loginname }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'orgNm'">
            <a-tooltip placement="top">
              <template #title>{{ record.orgNames ? record.orgNames : record.orgNm }}</template>
              <span class="ellipsis160">{{ record.orgNames ? record.orgNames : record.orgNm }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'admDuty'">
            <a-tooltip placement="top">
              <template #title>{{ record.admDuty }}</template>
              <span class="ellipsis80">{{ record.admDuty }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'dpnm'">
            <a-tooltip placement="top">
              <template #title>{{ record.dpnm }}</template>
              <span class="ellipsis130">{{ record.dpnm }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'sex'">
            <a-tooltip placement="top">
              <template #title>{{ sexFormatter(record) }}</template>
              <span class="ellipsis50">{{ sexFormatter(record) }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'idnm'">
            <a-tooltip placement="top">
              <template #title>{{ record.idnm }}</template>
              <span class="ellipsis130">{{ record.idnm }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'persType'">
            <a-tooltip placement="top">
              <template #title>{{ persTypeFilter(record.persType) }}</template>
              <span class="ellipsis100">{{ persTypeFilter(record.persType) }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'roles'">
            <a-tooltip placement="top">
              <template #title>{{ record.roles }}</template>
              <span class="ellipsis120">{{ record.roles }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'mobilenumb'">
            <a-tooltip placement="top">
              <template #title>{{ record.mobilenumb }}</template>
              <span class="ellipsis120">{{ record.mobilenumb }}</span>
            </a-tooltip>
          </template>
          <template v-else-if="column.dataIndex === 'imgurl'">
            <a href="javascript:;" @click="openPhoto(record)">{{ record.imgurl ? '查看' : '' }}</a>
          </template>
          <template v-else-if="column.dataIndex === 'action'">
            <a-button size="small" type="danger" ghost @click="handleEdit(record)">权限</a-button>
            <a-button size="small" type="primary" ghost @click="toAddMember('编辑',record)">编辑</a-button>
            <a-button size="small" type="primary" ghost @click="toAddMemberOrgan(record)" v-if="isNational">机构</a-button>
            <a-button size="small" type="primary" ghost @click="toAddTask(record)" v-if="isNational || perType == '1'">任务</a-button>
            <a-button size="small" type="danger" ghost @click="deleteMember(record)">删除</a-button>
          </template>
        </template>
      </a-table>
      <a-pagination
        show-size-changer
        :pageSize="searchObj.pageSize"
        @update:pageSize="searchObj.pageSize = $event"
        :total="total"
        :page-size-options="['10', '20', '30', '40']"
        :show-total="total => `共${total}条`"
        @showSizeChange="handleSizeChange"
        @change="handleCurrentChange"
        style="margin-top: 10px;" />
      <!-- 关联权限弹窗 -->
      <a-modal :title="dialogTitle" :open="dialogFormVisible" @cancel="dialogFormVisible = false" width="70%">
        <a-form :model="editUser" :label-col="{span: 6}" :wrapper-col="{span: 18}">
          <a-form-item label="用户名称">
            <a-input v-model:value="editUser.persName" allow-clear read-only/>
          </a-form-item>
          <a-form-item label="归属系统">
            <a-select v-model:value="editUser.ownerSystem" placeholder="请选择" disabled>
              <a-select-option v-for="(system,index) in privDict.systemFlagt" :key="index" :value="system.value">{{ system.name }}</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="人员类型">
            <a-select v-model:value="editUser.persType" placeholder="请选择" disabled>
              <a-select-option v-for="(system,index) in privDict.persType" :key="index" :value="system.value">{{ system.name }}</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="用户角色">
            <a-select
              v-model:value="editUser.roleIds"
              placeholder="请选择"
              mode="multiple"
              allow-clear
              :filter-option="filterOption">
              <a-select-option v-for="(role, index) in roleList" :key="index" :value="role.id">{{ role.roleName }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-form>
        <div slot="footer" class="dialog-footer">
          <a-button @click="dialogFormVisible = false">取 消</a-button>
          <a-button type="primary" @click="updateUserInfo">确 定</a-button>
        </div>
      </a-modal>
    </div>
    <!-- 添加/编辑人员弹窗 -->
    <a-modal :title="curOperate+'人员'" :open="memberInfoDialog" @cancel="closeMemberDialog">
      <a-form :model="addObj" :label-col="{span: 6}" :wrapper-col="{span: 18}" :rules="rules">
        <a-form-item label="人员名称" required>
          <a-input v-model:value="addObj.persName" />
        </a-form-item>
        <a-form-item label="归属系统">
          <a-select v-model:value="addObj.ownerSystem" placeholder="请选择">
            <a-select-option v-for="(system,index) in privDict.systemFlag" :key="index" :value="system.value">{{ system.name
            }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="人员类型">
          <a-select v-model:value="addObj.persType" placeholder="请选择">
            <a-select-option v-for="(system,index) in privDict.persType" :key="index" :value="system.value">{{ system.name
            }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="性别">
          <a-select v-model:value="addObj.sex" placeholder="请选择性别">
            <a-select-option value="1">男</a-select-option>
            <a-select-option value="2">女</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="所属机构">
          <a-input v-model:value="addObj.orgNm" placeholder="请选择机构" read-only />
          <provTreeList rootCode :style="{'max-height':dxdcAsideHeight+'px'}" @provTreeSelectChange="selectJigouCodeSingle">
          </provTreeList>
        </a-form-item>
        <a-form-item label="所属部门">
          <a-input v-model:value="addObj.dpnm" />
        </a-form-item>
        <a-form-item label="职务">
          <a-input v-model:value="addObj.admDuty" />
        </a-form-item>
        <a-form-item label="职称">
          <a-input v-model:value="addObj.dppost" />
        </a-form-item>
        <a-form-item label="工作证号">
          <a-input v-model:value="addObj.idnm" />
        </a-form-item>
        <a-form-item label="毕业院校">
          <a-input v-model:value="addObj.school" />
        </a-form-item>
        <a-form-item label="专业">
          <a-input v-model:value="addObj.specialty" />
        </a-form-item>
        <a-form-item label="政治面貌">
          <a-input v-model:value="addObj.plst" />
        </a-form-item>
        <a-form-item label="出生日期">
          <a-date-picker v-model:value="addObj.bornDate" placeholder="选择日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></a-date-picker>
        </a-form-item>
        <a-form-item label="手机号" prop="mobilenumb">
          <a-input v-model:value="addObj.mobilenumb" />
        </a-form-item>
        <a-form-item label="邮件">
          <a-input v-model:value="addObj.email" />
        </a-form-item>
        <a-form-item label="照片">
          <a-input id="file" type="file" />
        </a-form-item>
        <a-form-item label="用户名">
          <a-input v-model:value="addObj.loginname" :read-only="curOperate == '编辑'"/>
        </a-form-item>
        <a-form-item label="密码">
          <a-input v-model:value="addObj.password" />
        </a-form-item>
        <a-form-item label="加密密码">
          <a-input v-model:value="addObj.mdPwd" read-only />
        </a-form-item>
        <a-form-item label="备注">
          <a-input v-model:value="addObj.remark" read-only />
        </a-form-item>
      </a-form>
      <div slot="footer" class="dialog-footer">
        <a-button @click="memberInfoDialog = false">取 消</a-button>
        <a-button type="primary" @click="addMember">确 定</a-button>
      </div>
    </a-modal>
    <!-- 关联所属机构弹窗 -->
    <a-modal title="关联机构" :open="dialogOrganVisible" @cancel="dialogOrganVisible = false">
      <a-form :model="organObj" :label-col="{span: 6}" :wrapper-col="{span: 18}">
        <a-form-item label="授权单位">
          <a-input v-model:value="organObj.orgNm" read-only />
          <provTreeListMultiple
            :rootCode="'1'"
            :orgIdLists="orgIdLists"
            :checkStrictly="true"
            :style="{'max-height':dxdcAsideHeight+'px'}"
            @provTreeSelectChange="selectJigouCode"
            v-if="dialogOrganVisible">
          </provTreeListMultiple>
        </a-form-item>
      </a-form>
      <div slot="footer" class="dialog-footer">
        <a-button @click="dialogOrganVisible = false">取 消</a-button>
        <a-button type="primary" @click="updateUserOrgan">确 定</a-button>
      </div>
    </a-modal>
    <add-task-com
      v-if="taskDialogVisible"
      @closeTaskDialog="closeTaskDialog"
      :personTaskInfo="personTaskInfo"></add-task-com>
    <!-- 工作证弹窗 -->
    <a-modal title="工作证" :open="showWorkCard" @cancel="showWorkCard = false" width="30%" :footer="null">
      <div class="work_card">
        <img :src="workCardImgUrl" alt style="max-width: 300px;">
        <h3>{{ personInfo.persName }}</h3>
        <div>
          <p>
            <span class="label">单位：</span>
            <span>{{ personInfo.orgNm }}</span>
          </p>
          <p>
            <span class="label">职务：</span>
            <span>{{ personInfo.admDuty }}</span>
          </p>
          <p>
            <span class="label">职称：</span>
            <span>{{ personInfo.dppost }}</span>
          </p>
          <p>
            <span class="label">工作证件号：</span>
            <span>{{ personInfo.idnm }}</span>
          </p>
        </div>
      </div>
    </a-modal>
  </a-layout>
</template>

<script>
import { hostUrl } from '../../utils/global_variable.js';
import request from '../../utils/gw_ajax_request.js';
import provTreeList from '../../widgets/jigouTreeList.vue';
import provTreeListMultiple from '../../widgets/jigouTreeListMultiple.vue';
// import JsEncrypt from "jsencrypt";
import renYuanChaXunPl from '../duChaDuiXiang/chaXun/renYuanChaXun_piliang.vue';
import addTaskCom from './addTaskDialog.vue';
export default {
  data() {
    var checkTel = (rule, value, callback) => {
      var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/; // 座机
      var isMob = /^[1][3,4,5,7,8][0-9]{9}$/; // 座机格式
      if (!isMob.test(value) && !isPhone.test(value)) {
        callback(new Error('请输入合理电话'));
      } else {
        callback();
      }
    };
    return {
      tableHeight: window.innerHeight - 240,
      dxdcMainHeight: window.innerHeight - 197,
      dxdcAsideHeight: window.innerHeight - 90,
      menuData: 'user',
      memberList: [],
      total: 0,
      searchObj: {
        persName: '',
        orgNm: '',
        orgId: '',
        mobilenumb: '',
        pageSize: 10,
        pageNum: 1,
        curUserId: '',
        roleIds: [],
      },
      editUser: {
        persName: '',
        userId: '',
        roleIds: [],
        ownerSystem: '',
        persType: '',
      },
      organObj: {
        orgNm: '',
        orgId: '',
        persId: '',
      },
      orgIdLists: [],
      dialogOrganVisible: false,
      privDict: {
        privType: [],
        systemFlag: [],
        persType: [
          { name: '管理员', value: '1' },
          { name: '机构领导', value: '2' },
          { name: '督查人员', value: '3' },
          { name: '稽察人员', value: '4' },
        ],
      },
      roleList: [],
      dialogFormVisible: false,
      dialogTitle: '修改',
      // 督查人员信息修改
      addObj: {
        persName: '',
        ownerSystem: '',
        persType: '',
        sex: '',
        orgNm: '',
        orgId: '',
        dpnm: '',
        admDuty: '',
        dppost: '',
        idnm: '',
        school: '',
        specialty: '',
        plst: '',
        bornDate: '',
        mobilenumb: '',
        email: '',
        imgurl: '',
        remark: '',
        telnumb: '',
        isAdmin: '0',
        permission: '0',
        loginname: '',
        password: '',
        mdPwd: '',
      },
      memberInfoDialog: false,
      addform: [],
      formLabelWidth: '120px',
      curOperate: '',
      isSelected: false,
      changeJigou: false,
      hasPhone: [
        {
          label: '有',
          value: '1',
        },
        {
          label: '无',
          value: '2',
        },
      ],
      phoneIsNull: '1',
      showWorkCard: false,
      workCardImgUrl: '',
      personInfo: {
        persName: '',
        orgNm: '',
        admDuty: '',
        dppost: '',
        idnm: '',
      },
      showRenYuanChaXunPl: false,
      personTaskInfo: {
        orgIds: '',
        orgNames: '',
        persId: '',
      },
      taskDialogVisible: false,
      pubKey: '',
      rules: {
        mobilenumb: [{ validator: checkTel, trigger: 'blur', required: true }],
      },
      perType: localStorage.getItem('persType'), // perType=1 时展示任务按钮
      columns: [
        {
          title: '人员姓名',
          dataIndex: 'persName',
          width: 140,
          align: 'center',
          fixed: 'left',
        },
        {
          title: '用户名',
          dataIndex: 'loginname',
          width: 140,
          align: 'center',
        },
        {
          title: '机构名称',
          dataIndex: 'orgNm',
          width: 160,
          align: 'center',
        },
        {
          title: '职务',
          dataIndex: 'admDuty',
          width: 80,
          align: 'center',
        },
        {
          title: '部门名称',
          dataIndex: 'dpnm',
          width: 130,
          align: 'center',
        },
        {
          title: '性别',
          dataIndex: 'sex',
          width: 50,
          align: 'center',
        },
        {
          title: '工作证件号',
          dataIndex: 'idnm',
          width: 130,
          align: 'center',
        },
        {
          title: '人员类型',
          dataIndex: 'persType',
          width: 100,
          align: 'center',
        },
        {
          title: '所属角色',
          dataIndex: 'roles',
          width: 120,
          align: 'center',
        },
        {
          title: '手机号',
          dataIndex: 'mobilenumb',
          width: 120,
          align: 'center',
        },
        {
          title: '照片',
          dataIndex: 'imgurl',
          width: 70,
          align: 'center',
        },
      ],
      searchRoleList: [],
      readOnlyRole: localStorage.getItem('readOnlyRole'),
    };
  },
  components: {
    provTreeList: provTreeList,
    provTreeListMultiple: provTreeListMultiple,
    renYuanChaXunPl: renYuanChaXunPl,
    addTaskCom: addTaskCom,
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
    hasPriv() {
      return hasPriv('manage');
    },
    organCode() {
      return localStorage.getItem('currentRlcode')
        ? localStorage.getItem('currentRlcode')
        : '';
    },
    organNm() {
      return localStorage.getItem('currentOrgNm')
        ? localStorage.getItem('currentOrgNm')
        : '';
    },
    isNational() {
      return this.organCode.indexOf('00') == 0;
    },
    orgId() {
      if (this.isNational) {
        return '1';
      } else {
        return localStorage.getItem('currentOrgId')
          ? localStorage.getItem('currentOrgId')
          : '';
      }
    },
    hostUrl() {
      return hostUrl;
    },
  },
  created() {
    this.getRoleList();
    if (this.hasPriv) {
      this.columns.push({
        title: '操作',
        dataIndex: 'action',
        width: 360,
        align: 'center',
        fixed: 'right',
      });
    }
  },
  mounted() {
    this.getDict();
    this.searchObj.orgNm = this.isNational ? '' : this.organNm;
    this.getMemberList();
  },
  methods: {
    getMemberList() {
      this.searchObj.curUserId = this.persId;
      if (this.searchObj.orgId == '') {
        this.searchObj.orgId = this.orgId;
      }
      request
        .post('/bis/insp/listByCurUser', this.searchObj)
        .then((res) => {
          if (res.success) {
            this.memberList = res.data.list;
            this.total = res.data.total;
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    getCurRole(userId) {
      userId || this.persId;
      request
        .post(`/sys/roles/list-by-user`, { id: userId, pageSize: 200 })
        .then((res) => {
          if (res.success) {
            this.roleList = res.data.list;
            this.roleList.forEach((ele) => {
              if (ele.id && ele.currentUser) {
                this.editUser.roleIds.push(ele.id);
              }
            });
          }
        });
    },
    getRoleList() {
      request
        .post(`/sys/roles/list-by-user`, {
          id: this.persId,
          pageSize: 200,
          operateType: 1,
        })
        .then((res) => {
          if (res.success) {
            this.searchRoleList = res.data.list;
          }
        });
    },
    handleEdit(rowData) {
      this.dialogTitle = '修改';
      this.editUser.persName = rowData.persName;
      this.editUser.userId = rowData.guid;
      this.editUser.roleIds = [];
      this.editUser.ownerSystem = rowData.ownerSystem;
      this.editUser.persType = rowData.persType;
      this.getCurRole(rowData.guid);
      // this.getRoleList()
      this.dialogFormVisible = true;
    },
    updateUserInfo() {
      const paramsObj = {
        guid: this.editUser.userId,
        roleIds: this.editUser.roleIds,
        ownerSystem: this.editUser.ownerSystem,
        persType: this.editUser.persType,
      };
      request
        .post(`/bis/insp/updateUser`, paramsObj)
        .then((res) => {
          if (res.success) {
            this.$message.success('修改成功');
            this.editUser.roleIds = [];
            this.dialogFormVisible = false;
            this.getMemberList();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    toAddMemberOrgan(row) {
      this.dialogOrganVisible = true;
      if (row.orgIds) {
        this.orgIdLists = row.orgIds.split(',');
      } else if (row.orgId) {
        this.orgIdLists = row.orgId.split(',');
      } else {
        this.orgIdLists = [];
      }
      this.organObj.persId = row.guid;
      this.organObj.orgId = this.orgIdLists;
      this.organObj.orgNm = row.orgNames;
    },
    toAddTask(row) {
      this.taskDialogVisible = true;
      this.personTaskInfo.orgIds = row.orgIds ? row.orgIds : row.orgId;
      this.personTaskInfo.orgNames = row.orgNames ? row.orgNames : row.orgNm;
      this.personTaskInfo.persId = row.guid;
    },
    closeTaskDialog() {
      this.taskDialogVisible = false;
    },
    updateUserOrgan() {
      const organObj = {
        inspPersOrgList: [],
      };
      this.organObj.orgId.forEach((ele) => {
        organObj.inspPersOrgList.push({
          orgId: ele,
          persId: this.organObj.persId,
        });
      });
      request
        .post(`/bis/insp/add/presorg`, organObj.inspPersOrgList)
        .then((res) => {
          if (res.success) {
            this.$message.success('关联成功');
            this.dialogOrganVisible = false;
            this.getMemberList();
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    getDict() {
      /* request.post('dc/insp/grw/getGrwDic').then(res=>{
        if(res.success){
          this.privDict.privType = res.data.privType
          // this.privDict.systemFlag = res.data.systemFlag
        }else{
          this.$message.warning(res.message)
        }
      }).catch(error=>{
          this.$message.warning(res.message)
      }) */
      request
        .get(`/sys/privs/getSysFlagByUserId?userId=${this.persId}`)
        .then((res) => {
          if (res.success) {
            this.privDict.systemFlag = res.data;
          } else {
            this.$message.warning(res.message);
          }
        })
        .catch((error) => {
          this.$message.warning(error.message);
        });
    },
    systemFilter(item) {
      if (!item) {
        return '';
      }
      let system;
      this.privDict.systemFlag.forEach((ele) => {
        if (item == ele.value) {
          system = ele.name;
        }
      });
      return system;
    },
    handleDelete() {},
    handleSizeChange(size, val) {
      this.searchObj.pageSize = val;
      this.getMemberList();
    },
    handleCurrentChange(val) {
      this.searchObj.pageNum = val;
      this.getMemberList();
    },
    provTreeSelectChangeHandler(params) {
      this.isSelected = true;
      this.addObj.orgId = params.code;
      this.addObj.orgNm = params.name;
      this.searchObj.orgId = params.code;
      this.searchObj.orgNm = params.name;
      this.getMemberList();
    },
    sexFormatter: (row, column) =>
      row.sex == 2 ? '女' : row.sex == 1 ? '男' : '',
    // 督查人员
    toAddMember(type, row) {
      this.curOperate = type;
      const rowObj = {};
      Object.assign(rowObj, row);
      if (this.curOperate == '编辑') {
        request.get(`bis/insp/${rowObj.guid}`).then((res) => {
          if (res.success) {
            this.addObj = res.data;
            this.addObj.orgNm = row.orgNames ? row.orgNames : row.orgNm;
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        this.toGetPubKey();
        for (var obj in this.addObj) {
          if (obj != 'orgId' && obj != 'orgNm') {
            this.addObj[obj] = '';
          }
        }
        this.addObj.orgId = this.addObj.orgId
          ? this.addObj.orgId
          : localStorage.getItem('currentOrgId');
        this.addObj.orgNm = this.addObj.orgNm
          ? this.addObj.orgNm
          : localStorage.getItem('currentOrgNm');
      }
      this.memberInfoDialog = true;
    },
    addMember() {
      const form = new FormData();
      form.append('file', document.getElementById('file').files[0]);
      for (var obj in this.addObj) {
        if (this.addObj[obj] == 'null' || !this.addObj[obj]) {
          this.addObj[obj] = '';
        }
      }
      if (!this.addObj.persName) {
        this.$message.info('请输入人员名称');
        return;
      }
      if (!this.addObj.mobilenumb) {
        this.$message.info('请输入手机号');
        return;
      }
      if (this.curOperate == '编辑') {
        var editUrl = `/bis/insp/update?persName=${
          this.addObj.persName
        }&ownerSystem=${this.addObj.ownerSystem}&persType=${this.addObj.persType}&permission=${this.addObj.permission}
          &guid=${this.addObj.guid}&sex=${
            this.addObj.sex
          }&orgNm=${this.addObj.orgNm}&orgId=${this.addObj.orgId}&dpnm=${
            this.addObj.dpnm
          }&admDuty=${this.addObj.admDuty}&dppost=${this.addObj.dppost}&idnm=${
            this.addObj.idnm
          }&school=${this.addObj.school}&specialty=${this.addObj.specialty}&plst=${
            this.addObj.plst
          }&bornDate=${this.addObj.bornDate}&mobilenumb=${
            this.addObj.mobilenumb
          }&email=${this.addObj.email}&password=${this.addObj.password}`;
      } else if (this.curOperate == '编辑') {
        var editUrl = `/bis/insp/update?persName=${
          this.addObj.persName
        }&ownerSystem=${this.addObj.ownerSystem}&persType=${this.addObj.persType}&permission=${this.addObj.permission}&guid=${this.addObj.guid}&sex=${
          this.addObj.sex
        }&orgNm=${this.addObj.orgNm}&orgId=${this.addObj.orgId}&dpnm=${
          this.addObj.dpnm
        }&admDuty=${this.addObj.admDuty}&dppost=${this.addObj.dppost}&idnm=${
          this.addObj.idnm
        }&school=${this.addObj.school}&specialty=${this.addObj.specialty}&plst=${
          this.addObj.plst
        }&bornDate=${this.addObj.bornDate}&mobilenumb=${
          this.addObj.mobilenumb
        }&email=${this.addObj.email}&pubKey=${this.addObj.pubKey}&password=${this.addObj.password}`;
      }
      if (this.curOperate == '添加') {
        var insertUrl = `/bis/insp/insert?persName=${
          this.addObj.persName
        }&ownerSystem=${this.addObj.ownerSystem}&persType=${this.addObj.persType}&permission=${this.addObj.permission}&sex=${this.addObj.sex}&orgNm=${
          this.addObj.orgNm
        }&orgId=${this.addObj.orgId}&dpnm=${this.addObj.dpnm}&admDuty=${
          this.addObj.admDuty
        }&dppost=${this.addObj.dppost}&idnm=${this.addObj.idnm}&school=${
          this.addObj.school
        }&specialty=${this.addObj.specialty}&plst=${this.addObj.plst}&bornDate=${
          this.addObj.bornDate
        }&mobilenumb=${this.addObj.mobilenumb}&email=${this.addObj.email}&pubKey=${this.pubKey}&loginname=${this.addObj.loginname}&password=${this.addObj.password}`;

        request
          .post(insertUrl, form, {
            headers: { 'Content-Type': 'multipart/form-data' },
          })
          .then((res) => {
            if (res.success) {
              this.getMemberList();
              this.addObj.orgId = '';
              this.addObj.orgNm = '';
              this.memberInfoDialog = false;
              this.$message.success('添加成功');
            } else {
              this.$message.error(res.message);
            }
          });
      } else if (this.curOperate == '编辑') {
        request
          .post(editUrl, form, {
            headers: { 'Content-Type': 'multipart/form-data' },
          })
          .then((res) => {
            if (res.success) {
              this.getMemberList();
              this.addObj.orgId = '';
              this.addObj.orgNm = '';
              this.memberInfoDialog = false;
              this.$message.success('修改成功');
            } else {
              this.$message.error(res.message);
            }
          });
      }
    },
    deleteMember(row) {
      this.$confirm({
        title: '提示',
        content: '确定删除该人员吗?',
        okType: 'warning',
        onOk: () => {
          request.post(`/bis/insp/delete/${row.guid}`).then((res) => {
            if (res.success) {
              this.getMemberList();
              this.memberInfoDialog = false;
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
            }
          });
        },
      });
    },
    openPhoto(scope) {
      this.showWorkCard = true;
      this.personInfo = scope;
      if (scope.imgurl) {
        // this.workCardImgUrl = 'http://slbdc.mwr.gov.cn/upload/huaiwei/74e492aea63749c88c124214627e7e24.png'
        this.workCardImgUrl = this.hostUrl + scope.imgurl;
        // window.open(this.hostUrl + scope.row.imgurl)
      }
    },
    selectJigouCode(params) {
      const orgIds = [];
      const orgNms = [];
      if (params.length) {
        params.forEach((ele) => {
          orgIds.push(ele.code);
          orgNms.push(ele.name);
        });
      }
      this.organObj.orgId = orgIds;
      this.organObj.orgNm = orgNms.join(',');
    },
    selectJigouCodeSingle(params) {
      this.addObj.orgId = params.code;
      this.addObj.orgNm = params.name;
    },
    closeMemberDialog() {
      this.addObj.orgId = '';
      this.addObj.orgNm = '';
      this.memberInfoDialog = false;
    },
    batchImport() {
      this.showRenYuanChaXunPl = true;
    },
    closePlDialog() {
      this.showRenYuanChaXunPl = false;
    },
    toGetPubKey() {
      request.post('/bis/insp/getPubKey').then((res) => {
        if (res.success) {
          this.pubKey = res.data.key;
        }
      });
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    persTypeFilter(val) {
      if (!val) return '';
      if (val == '1') {
        return '管理员';
      } else if (val == '2') {
        return '机构领导';
      } else if (val == '3') {
        return '督查人员';
      } else if (val == '4') {
        return '稽察人员';
      }
    },
  },
};
</script>

<style lang='less' scoped>
.user-manage {
  padding: 20px;
  box-sizing: border-box;

  .search-wrapper {}
}

.work_card {
  text-align: center;
}

.work_card img {
  max-width: 120px;
}

.work_card h3 {
  text-align: center;
  line-height: 40px;
  margin-bottom: 6px;
}

.work_card>div {
  width: 90%;
  margin: 0 auto;
}

.work_card p {
  text-align: left;
  line-height: 32px;
}

.work_card p .label {
  display: inline-block;
  min-width: 120px;
  text-align: right;
}

.work_card p span:last-child {
  display: inline-block;
  min-width: 160px;
  line-height: 30px;
  border-bottom: solid 1px #ccc;
}

.full_width {
  width: 100% !important;
}
:deep(.ant-layout-sider),
:deep(.ant-layout-header),
:deep(.ant-layout-content) {
  background: #fff;
}
:deep(.ant-table-pagination) {
  float: left;
}
:deep(.ant-table-thead>tr>th),
:deep(.ant-table-tbody>tr>td) {
  padding: 0;
  height: 60px;
}
.ellipsis50 {
  display: block;
  width: 48px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis80 {
  display: block;
  width: 78px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis100 {
  display: block;
  width: 98px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis120 {
  display: block;
  width: 118px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis130 {
  display: block;
  width: 128px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis140 {
  display: block;
  width: 138px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis160 {
  display: block;
  width: 158px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.ellipsis200 {
  display: block;
  width: 198px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
:deep(.ant-table-scroll) {
  position: relative;
  z-index: 1;
}

:deep(.ant-table-fixed-left),
:deep(.ant-table-fixed-right) {
  z-index: 2;
}
</style>
