<template>
    <pro-form ref="formRef_form" :model="formData_form" :rules="formRules_form" label-width="120px">
        <div id="toolbar_1471594884085" class="datagrid-toolbar">
            <pro-button v-show="showFlag_9FDC4996_6721_4E44_A973_668EC4697165" id="9FDC4996-6721-4E44-A973-668EC4697165"
                size="small" :icon="h(SaveOutlined)" @ajaxSuccess="AfterSuccess"
                @beforeSubmit="beforeSubmit">保存</pro-button>
            <pro-button id="D88D8BDC-6C03-4653-8AFC-93C6F296EF99" size="small"
                :icon="h(RollbackOutlined)">关闭</pro-button>
        </div>
        <pro-tabs type="editable-card" v-model:activeKey="proTabActice_tab_1514275826312" :hideAdd="true"
            id="tab_1514275826312" class="easyui-tabs"
            data-options='width:800,height:600,fit:true,border:true,toolPosition:"left",tabPosition:"top"'>
            <pro-tab-pane label="基本信息" name="基本信息" :closable="true">
                <pro-form-grid>
                    <pro-date-picker :ref="(el) => formRefs.rpt_date = el"
                        :formItemProps="{ label: '制表日期', prop: 'rpt_date' }" v-model:value="formData_form.rpt_date"
                        type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />

                    <pro-input :ref="(el) => formRefs.usertype_no_zh = el"
                        :formItemProps="{ label: '用户类型', prop: 'usertype_no_zh' }"
                        v-model:value="formData_form.usertype_no_zh" :disabled="true" :editable="false"></pro-input>
                    <pro-select-tree :ref="(el) => formRefs.user_dep_no = el"
                        :formItemProps="{ label: '用户所属部门', prop: 'user_dep_no' }"
                        v-model:value="formData_form.user_dep_no"
                        :props="{ value: 'id', label: 'name' }"></pro-select-tree>
                    <pro-input :ref="(el) => formRefs.user_key = el"
                        :formItemProps="{ label: '用户编号', prop: 'user_key' }"
                        v-model:value="formData_form.user_key"></pro-input>
                    <pro-input :ref="(el) => formRefs.user_name = el"
                        :formItemProps="{ label: '用户名称', prop: 'user_name' }"
                        v-model:value="formData_form.user_name"></pro-input>
                    <pro-select :ref="(el) => formRefs.login_mode = el"
                        :formItemProps="{ label: '登录模式', prop: 'login_mode' }" v-model:value="formData_form.login_mode"
                        tableName="com_user_info" colName="login_mode"></pro-select>
                    <pro-input :ref="(el) => formRefs.passwd = el" :formItemProps="{ label: '密码', prop: 'passwd' }"
                        v-model:value="formData_form.passwd" :disabled="true" :editable="false"></pro-input>
                    <pro-select :ref="(el) => formRefs.unlock_mode = el"
                        :formItemProps="{ label: '解锁模式', prop: 'unlock_mode' }"
                        v-model:value="formData_form.unlock_mode" tableName="com_user_info"
                        colName="unlock_mode"></pro-select>
                    <pro-select :ref="(el) => formRefs.id_type = el" :formItemProps="{ label: '证件类型', prop: 'id_type' }"
                        v-model:value="formData_form.id_type" tableName="com_user_info" colName="id_type"></pro-select>
                    <pro-input :ref="(el) => formRefs.id_no = el" :formItemProps="{ label: '证件编号', prop: 'id_no' }"
                        v-model:value="formData_form.id_no"></pro-input>
                    <pro-select :ref="(el) => formRefs.use_yn = el" :formItemProps="{ label: '启用标志', prop: 'use_yn' }"
                        v-model:value="formData_form.use_yn" :disabled="true" tableName="com_user_info"
                        colName="use_yn"></pro-select>
                    <pro-input v-show="false" :ref="(el) => formRefs.no = el"
                        :formItemProps="{ label: '内部标识', prop: 'no' }" v-model:value="formData_form.no"
                        :editable="false"></pro-input>
                    <pro-select v-show="false" :ref="(el) => formRefs.is_trader = el"
                        :formItemProps="{ label: '是否交易员', prop: 'is_trader' }" v-model:value="formData_form.is_trader"
                        :readonly="true" :disabled="true" tableName="com_user_info" colName="is_trader"></pro-select>
                    <pro-input :ref="(el) => formRefs.email = el" :formItemProps="{ label: '邮箱', prop: 'email' }"
                        v-model:value="formData_form.email"></pro-input>
                    <pro-input :ref="(el) => formRefs.phone_no = el" :formItemProps="{ label: '手机号', prop: 'phone_no' }"
                        v-model:value="formData_form.phone_no"></pro-input>
                    <pro-input :ref="(el) => formRefs.pwd_days = el"
                        :formItemProps="{ label: '密码有效天数', prop: 'pwd_days' }"
                        v-model:value="formData_form.pwd_days"></pro-input>
                    <pro-input :ref="(el) => formRefs.pwd_err_cnt = el"
                        :formItemProps="{ label: '输入密码次数', prop: 'pwd_err_cnt' }"
                        v-model:value="formData_form.pwd_err_cnt"></pro-input>
                    <pro-select v-show="false" :ref="(el) => formRefs.is_lock = el"
                        :formItemProps="{ label: '用户锁定', prop: 'is_lock' }" v-model:value="formData_form.is_lock"
                        :readonly="true" :disabled="true" tableName="com_user_info" colName="is_lock"></pro-select>
                    <pro-input v-show="false" :ref="(el) => formRefs.role_no = el"
                        :formItemProps="{ label: '已选岗位列表', prop: 'role_no' }"
                        v-model:value="formData_form.role_no"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.rows = el"
                        :formItemProps="{ label: 'data_rows', prop: 'rows' }"
                        v-model:value="formData_form.rows"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.cope_type = el"
                        :formItemProps="{ label: '是否全局', prop: 'cope_type' }"
                        v-model:value="formData_form.cope_type"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.usertype_no = el"
                        :formItemProps="{ label: '用户类型内部编号', prop: 'usertype_no' }"
                        v-model:value="formData_form.usertype_no"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.setrole_yn = el"
                        :formItemProps="{ label: '是否可设置岗位', prop: 'setrole_yn' }"
                        v-model:value="formData_form.setrole_yn"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.role_rows = el"
                        :formItemProps="{ label: '已选岗位数据', prop: 'role_rows' }"
                        v-model:value="formData_form.role_rows"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.role_dep_nos = el"
                        :formItemProps="{ label: '已选岗位机构关系', prop: 'role_dep_nos' }"
                        v-model:value="formData_form.role_dep_nos"></pro-input>
                    <pro-input v-show="false" :ref="(el) => formRefs.pageInterfaceNo = el"
                        :formItemProps="{ label: '菜单编号', prop: 'pageInterfaceNo' }"
                        v-model:value="formData_form.pageInterfaceNo"></pro-input>
                </pro-form-grid>
            </pro-tab-pane>
            <pro-tab-pane label="岗位及数据权限" name="岗位及数据权限" :closable="false">
                <pro-table ref="tableRef_grid1514277480927" :queryRule="queryRule_grid1514277480927"
                    :columns="columns_grid1514277480927" :singleSelect="false" :stripe="true">
                    <template v-slot:header="">
                        <pro-input :ref="(el) => formRefs.role_name = el"
                            :formItemProps="{ label: '岗位名称', prop: 'role_name' }"
                            v-model:value="formData_form.role_name"></pro-input>
                        <pro-select-tree :ref="(el) => formRefs.dep_rel = el"
                            :formItemProps="{ label: '关联机构', prop: 'dep_rel' }" v-model:value="formData_form.dep_rel"
                            :props="{ value: 'id', label: 'name' }"></pro-select-tree>
                        <pro-select :ref="(el) => formRefs.rel_yn = el"
                            :formItemProps="{ label: '是否关联', prop: 'rel_yn' }" v-model:value="formData_form.rel_yn"
                            tableName="com_user_info" colName="rel_yn"></pro-select>
                        <pro-button id="547BBD3B-F9F1-4226-A313-0FBA942F6C50" size="small"
                            :icon="h(SearchOutlined)">查询</pro-button>
                    </template>
                </pro-table>
            </pro-tab-pane>
            <pro-tab-pane label="数据权限" name="数据权限" :closable="false">
                <pro-table ref="tableRef_grid1514277696180" :queryRule="queryRule_grid1514277696180"
                    :columns="columns_grid1514277696180" :singleSelect="true" :stripe="true"
                    :showTableHead="false"></pro-table>
            </pro-tab-pane>
            <pro-tab-pane label="密码重置" name="密码重置" :closable="false">
                <pro-form-grid>
                    <pro-input :ref="(el) => formRefs.reset_user_key = el"
                        :formItemProps="{ label: '用户编号', prop: 'reset_user_key' }"
                        v-model:value="formData_form.reset_user_key" :disabled="true" :editable="false"></pro-input>
                    <pro-input-password :ref="(el) => formRefs.reset_passwd = el"
                        :formItemProps="{ label: '重置密码', prop: 'reset_passwd' }"
                        v-model:value="formData_form.reset_passwd"></pro-input-password>
                </pro-form-grid>
            </pro-tab-pane>
        </pro-tabs>
    </pro-form>
</template>
<script setup lang="jsx">
import { ref, onMounted, h } from 'vue';
import settings from '@/settings';
import request from '@/utils/request';
import { SaveOutlined, RollbackOutlined, SearchOutlined } from "@ant-design/icons-vue";
const systemPrefix = settings.systemPrefix;
var treeLoad = false;
var ini_tlrno_yn = "jsp语法格式化";
var changeKeyFlag = 'N';
var lastLength = '';
var validateType = '';
var pages = [];
/* 数据权限 */

// //自定义取得下拉选择的值
// var json = window.parent.paramDateTooLength();
// var user_no = json.no;
//自定义取得下拉选择的值
var levels = {};
var currentIndex = 0;
var validatePreFix = '';
/**
 * 解决在搜索框内搜索机构，选中机构时触发校验key值
 * add by yexinghai 20190222
 */

var validateKeyTypeFlag = '';
var rsFlag = '';
/**
 * 具体的校验key值重复方法
 * add by yexinghai 20190222
 */
const showFlag_9FDC4996_6721_4E44_A973_668EC4697165 = ref(true);
const formData_form = ref({
    rpt_date: "",
    usertype_no_zh: "${com_user_info.usertype_no_zh}",
    user_dep_no: "${com_user_info.dep_no}",
    user_key: "${com_user_info.key}",
    user_name: "${com_user_info.name}",
    login_mode: "${com_user_info.login_mode}",
    passwd: "******",
    unlock_mode: "${com_user_info.unlock_mode}",
    id_type: "${com_user_info.id_type}",
    id_no: "${com_user_info.id_no}",
    use_yn: "${com_user_info.use_yn}",
    no: "${com_user_info.no}",
    is_trader: "${com_user_info.is_trader}",
    email: "${com_user_info.email}",
    phone_no: "${com_user_info.phone_no}",
    pwd_days: "${com_user_info.pwd_days}",
    pwd_err_cnt: "${com_user_info.pwd_err_cnt}",
    is_lock: "${com_user_info.is_lock}",
    role_no: "${com_user_role_rel.role_no}",
    rows: "",
    cope_type: "",
    usertype_no: "${com_user_info.usertype_no}",
    setrole_yn: "",
    role_rows: "",
    role_dep_nos: "",
    pageInterfaceNo: "",
    role_name: "",
    dep_rel: "",
    rel_yn: "",
    reset_user_key: "${com_user_info.key}",
    reset_passwd: ""
});
const formRules_form = ref({
    rpt_date: [{
        required: true,
        trigger: "change"
    }],
    usertype_no_zh: [{
        required: true,
        trigger: "change"
    }],
    user_dep_no: [{
        required: true,
        trigger: "change"
    }],
    user_key: [{
        required: true,
        trigger: "change"
    }],
    user_name: [{
        required: true,
        trigger: "change"
    }],
    login_mode: [{
        required: true,
        trigger: "change"
    }],
    unlock_mode: [{
        required: true,
        trigger: "change"
    }],
    id_type: [{
        required: true,
        trigger: "change"
    }],
    id_no: [{
        required: true,
        trigger: "change"
    }],
    is_trader: [{
        required: true,
        trigger: "change"
    }],
    pwd_days: [{
        required: true,
        trigger: "change"
    }],
    pwd_err_cnt: [{
        required: true,
        trigger: "change"
    }],
    reset_user_key: [{
        required: true,
        trigger: "change"
    }]
});
const formRef_form = ref(null);
const formRefs = ref({
    rpt_date: "",
    usertype_no_zh: "",
    user_dep_no: "",
    user_key: "",
    user_name: "",
    login_mode: "",
    passwd: "",
    unlock_mode: "",
    id_type: "",
    id_no: "",
    use_yn: "",
    no: "",
    is_trader: "",
    email: "",
    phone_no: "",
    pwd_days: "",
    pwd_err_cnt: "",
    is_lock: "",
    role_no: "",
    rows: "",
    cope_type: "",
    usertype_no: "",
    setrole_yn: "",
    role_rows: "",
    role_dep_nos: "",
    pageInterfaceNo: "",
    role_name: "",
    dep_rel: "",
    rel_yn: "",
    reset_user_key: "",
    reset_passwd: ""
});
onMounted(() => {
    // getUserTypeInfo();
    // $.ajax({
    //     url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/GetUserKeyValidateController.do',
    //     type: "POST",
    //     async: false,
    //     dataType: 'json',
    //     success: function (rs) {
    //         console.log(rs);
    //         lastLength = rs.length;
    //         validateType = rs.validateType;
    //     }
    // });
    // formData_form.value.pageInterfaceNo = 'jsp语法格式化';
    // if (ini_tlrno_yn == 'Y') {
    //     //如果修改的用户是初始化的用户，则用户类型、用户所属部门、用户数据权限都不能修改，用户编号和用户名称可以修改
    //     $("#user_dep_no").combotree({
    //         disabled: true
    //     });
    //     $('#id_no').textbox({
    //         required: false
    //     }); //如果修改的初始化的用户，则证件编号可以不输入 update by yexinghai 20190819
    // }
    // $("#user_dep_no").combotree({
    //     onSelect: function (val) {
    //         var canChange = checkTask();
    //         if ("no" == canChange) {
    //             changeKeyFlag = 'Y';
    //             validateKey();
    //             changeKeyFlag = 'N';
    //         }
    //         var setrole_yn = formData_form.value.setrole_yn;
    //         findDeps(setrole_yn);
    //     }
    // });
});
//提交前获取选中的角色
function beforeSubmit (form, param) {
    var oldDepNo = "jsp语法格式化";
    var dep_no = formData_form.value.user_dep_no;
    var userTypeNo = "jsp语法格式化";
    if (oldDepNo != dep_no && "5" != userTypeNo) {
        //非普通柜员类型修改所属机构，校验该用户在原始机构下是否有未完成的任务 add by yexinghai 20190401
        var canChange = checkTask();
        if ("no" != canChange) {
            formData_form.value.user_dep_no = "";
            return false;
        }
    }
    if (validateKeyTypeFlag == '1') {
        alert("用户编号规则不符合要求", false);
        return false;
    }
    if (rsFlag == '"0002"') {
        alert("用户编号重复，请重新选择所属机构", false);
        formData_form.value.user_dep_no = "";
        formData_form.value.user_dep_no = "";
        return false;
    }
    if (rsFlag == '"009"') {
        formData_form.value.user_key = "";
        alert("用户编号长度应该为" + lastLength + "!");
        return false;
    }
    var user_no = jsp语法格式化;
    param.key = formData_form.value.user_key;
    param.no = formData_form.value.no;
    param.name = formData_form.value.user_name;
    param.dep_no = formData_form.value.user_dep_no;
    param.is_lock = "jsp语法格式化";
    var Name = formData_form.value.user_name;
    var lenName = Name.length;
    var isTrue = true;
    var role_name = "";
    for (var i = 0; i < lenName; i++) {
        if (Name.charAt(i) == ' ') {
            alert("用户名称不能有空格", false);
            return false;
        }
    }
    if (checkedKey.length > 0) {
        // console.log(checkedKey); ajax判断去掉勾选的岗位是否有未完成的业务
        $.ajax({
            method: 'GET',
            dataType: 'json',
            async: false,
            data: {
                "no": user_no,
                "keys": checkedKey.toString()
            },
            url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserRoleCheckBeforeSubmitController.do',
            success: function (result) {
                if (result == "success") { } else {
                    role_name = result;
                    isTrue = false;
                }
            }
        });
    }
    if (!isTrue) {
        alert("岗位[" + role_name + "]中有未完成业务,请检查");
        return false;
    }
    formData_form.value.role_dep_nos = JSON.stringify(checkedRowNo);
    var rows = tableRef_grid1514277480927.value.getChecked();
    formData_form.value.role_rows = JSON.stringify(rows);
    $("#grid1514277696180").datagrid("endEdit", currentIndex);
    var data_rows = tableRef_grid1514277696180.value.getTableData();
    formData_form.value.rows = JSON.stringify(data_rows);
    var isValid = validataTab($("#tab_1514275826312"));
    return isValid;
}
const tableRef_grid1514277480927 = ref(null);
const columns_grid1514277480927 = ref([{
    prop: "key",
    label: "岗位编号",
    align: "left",
    'min-width': "70"
}, {
    prop: "name",
    label: "岗位名称",
    align: "left",
    'min-width': "120"
}, {
    prop: "role_dep_no",
    label: "岗位与机构关联关系内部编号",
    align: "left",
    'min-width': "0"
}, {
    prop: "dep_no",
    label: "关联机构",
    align: "left",
    'min-width': "150"
}, {
    prop: "user_role",
    label: "数据权限",
    align: "center",
    'min-width': "50",
    render: ({ value, record, index }) => formstyle(value, record, index)
}, {
    prop: "dep_role",
    label: "数据权限数据",
    align: "center",
    'min-width': "100"
}, {
    prop: "flag",
    label: "数据权限修改标志",
    align: "center",
    'min-width': "100"
}]);
async function queryRule_grid1514277480927 (payload, params) {
    //向后台请求表格数据
    // const resp = await this.getData(payload,params);
    //实际开发需要将上面的函数替换成自己的函数，并将下面一行代码删除掉
    const resp = {
        total: 0,
        data: []
    };
    return {
        current: payload.pageIndex,
        pageSize: payload.pageSize,
        total: resp.total,
        data: resp.data
    };
}
const tableRef_grid1514277696180 = ref(null);
const columns_grid1514277696180 = ref([{
    prop: "name",
    label: "机构关系类型",
    align: "",
    'min-width': "192"
}, {
    prop: "level_name_show",
    label: "当前数据权限",
    align: "center",
    'min-width': "212"
}, {
    prop: "level_name",
    label: "修改后数据权限",
    align: "center",
    'min-width': "172"
}]);
async function queryRule_grid1514277696180 (payload, params) {
    //向后台请求表格数据
    // const resp = await this.getData(payload,params);
    //实际开发需要将上面的函数替换成自己的函数，并将下面一行代码删除掉
    const resp = {
        total: 0,
        data: []
    };
    return {
        current: payload.pageIndex,
        pageSize: payload.pageSize,
        total: resp.total,
        data: resp.data
    };
}
const proTabActice_tab_1514275826312 = ref("基本信息");
/**function onChange(){
      var Key=$('#user_key').val();
      var Name=$('#user_name').val();
      var lenName=Name.length;
      var lenKey=Key.length;
      for(var i=0;i<lenKey;i++){
          if(Key.charAt(i)==' ')
          {
                  alert("用户号不能有空格");
          }
      }
      for(var i=0;i<lenName;i++){
          if(Name.charAt(i)==' ')
          {
                  alert("用户名称不能有空格",false);
          }
      }
}**/

function aa () {
    showFlag_9FDC4996_6721_4E44_A973_668EC4697165.value = true;
}
//根据是否设置岗位显示
function ifSetRole () {
    if (true) {
        showFlag_9FDC4996_6721_4E44_A973_668EC4697165.value = false;
        showFlag_9FDC4996_6721_4E44_A973_668EC4697165.value = false;
    }
    formData_form.value.rpt_date;
    formData_form.value.rpt_date = '';
    var usertype_no = formData_form.value.usertype_no;
    var setrole_yn = formData_form.value.setrole_yn;
    var cope_type = formData_form.value.cope_type;
    //如果选择用户类型下允许设置岗位，则展示【岗位及数据权限】页面；对于用户类型是不允许设置岗位，则展示【数据权限】
    if ('Y' == setrole_yn) {
        proTabActice_tab_1514275826312.value = "岗位及数据权限"
            ;
        findRoles();
    } else if ('N' == setrole_yn) {
        proTabActice_tab_1514275826312.value = "数据权限"
            ;
        findDeps(setrole_yn);
    }
}
function findDeps (setrole_yn) {
    //初始化汇总关系列表
    var no = formData_form.value.no;
    var setrole_yn = formData_form.value.setrole_yn;
    var usertype_no = formData_form.value.usertype_no;
    var dep_no = "";
    var dep_no1 = formData_form.value.user_dep_no;
    var depTree = $('#user_dep_no').combotree('tree');
    var nodes = depTree.tree("getSelected");
    if (!isEmpty(nodes)) {
        var dep_no2 = nodes.dep_no;
        dep_no = dep_no2;
    } else {
        dep_no = dep_no1;
    }
    $.ajax({
        method: 'GET',
        dataType: 'json',
        async: false,
        url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserDataRightListsController.do?pageInterfaceNo=jsp语法格式化&no=' + no + '&setrole_yn=' + setrole_yn + '&&dep_no=' + dep_no + "&usertype_no=" + usertype_no,
        success: function (rs) {
            if (rs.resultFlag == "0000") {
                tableRef_grid1514277696180.value.loadData(undefined);
            } else {
                loadListInfo([]);
            }
        }
    });
}
function getUserTypeInfo () {
    var usertype_no = formData_form.value.usertype_no;
    $.ajax({
        method: 'GET',
        dataType: 'json',
        async: false,
        url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserTypeQuery.do?usertype_no=' + usertype_no,
        success: function (rs) {
            if (rs != null) {
                formData_form.value.cope_type = rs.cope_type;
                formData_form.value.setrole_yn = rs.setrole_yn;
                ifSetRole();
            } else {
                alert("获取当前用户类型为空");
            }
        }
    });
}
//判断该用户在原始所属部门是否有未完成的任务 add by yexinghai 20190315
function checkTask () {
    var userNo = "jsp语法格式化";
    var userTypeNo = "jsp语法格式化";
    var canChange = "";
    var oldDepNo = "jsp语法格式化";
    var depTree = $('#user_dep_no').combotree('tree');
    var nodes = depTree.tree("getSelected");
    var dep_no = nodes.dep_no;
    if ("5" != userTypeNo && oldDepNo != dep_no) {
        $.ajax({
            type: "post",
            dataType: "json",
            async: false,
            data: {
                userNo: userNo
            },
            url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/ExistTaskController.do',
            success: function (data) {
                canChange = data.noTask;
                oldDepName = data.depName;
                if ("no" != data.noTask) {
                    alert("该用户在机构:" + oldDepName + "下还有未完成的任务，请先将已认领的任务处理完毕或者释放后再做此交易");
                    formData_.value.dep_no = "";
                }
            }
        });
    }
    return canChange;
}
function getRoles () {
    $.ajax({
        type: "post",
        dataType: "json",
        async: false,
        data: {
            no: formData_form.value.no
        },
        url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserRelateRoleNoController.do',
        success: function (data) {
            formData_form.value.role_no = data.role_no;
            formData_form.value.role_dep_nos = data.role_dep_no;
        },
        error: function (data) {
            alert("获取当前用户岗位出错，错误信息：" + data.message);
        }
    });
    var role_dep_Nos = formData_form.value.role_dep_nos;
    formData_form.value.role_dep_nos = aavb;
    formData_form.value.role_dep_nos = 'aavb';
    var readyRole_DepNos = role_dep_Nos.split(",");
    checkedRowNo = checkedRowNo.concat(readyRole_DepNos);
    checkRow();
}
function checkRow () {
    var rows = tableRef_grid1514277480927.value.getTableData();
    for (var i = 0; i < rows.length; i++) {
        //初始化已维护岗位
        if (checkedRowNo.indexOf(rows[i].role_dep_no) >= 0) {
            var rowIndex = tableRef_grid1514277480927.value.getRowIndex(undefined);
            $('#grid1514277480927').datagrid('checkRow', rowIndex);
        }
        //初始化是否已维护岗位权限
        if (rows[i].flag > 0) {
            var rowIndex = tableRef_grid1514277480927.value.getRowIndex(undefined);
            tableRef_grid1514277480927.value.updateRow({ index: rowIndex, row: { user_role: '已维护', dep_role: '' } });
        }
    }
}
//获取岗位对应数据权限
function getDepRows () {
    var dep_role = window.frames[0].document.getElementById("dep_row").value;
    var dep_index = window.frames[0].document.getElementById("index").value;
    var dep_rows = tableRef_grid1514277480927.value.getTableData();
    var parseDepRole = JSON.parse(dep_role);
    var changeUserRole = '';
    for (var i = 0; i < parseDepRole.length; i++) {
        if (!isEmpty(parseDepRole[i].level_name)) {
            changeUserRole = 'Y';
            break;
        }
    }
    for (var i = 0; i < dep_rows.length; i++) {
        var index_ = tableRef_grid1514277480927.value.getRowIndex(undefined);
        if (dep_index == index_) {
            //$('#grid1514277480927').datagrid('checkRow',index_);
            if (dep_role != "") {
                if ('Y' == changeUserRole) {
                    tableRef_grid1514277480927.value.updateRow({ index: index_, row: { user_role: '已修改', dep_role: dep_role } });
                } else {
                    tableRef_grid1514277480927.value.updateRow({ index: index_, row: { dep_role: dep_role } });
                }
            } else {
                tableRef_grid1514277480927.value.updateRow({ index: index_, row: { user_role: '' } });
            }
        }
    }
}
function uncheckRow () {
    var dep_role = window.frames[0].document.getElementById("dep_row").value;
    var dep_index = window.frames[0].document.getElementById("index").value;
    var dep_rows = tableRef_grid1514277480927.value.getTableData();
    var rowVal = dep_rows[dep_index];
    var user_role = rowVal.user_role;
    tableRef_grid1514277480927.value.updateRow({ index: dep_index, row: { user_role: user_role } });
    //$('#grid1514277480927').datagrid('checkRow',dep_index);
}
//格式化数据权限列
function formstyle (value, row, index) {
    var dep_no_r = row.dep_no;
    var role_dep_no = row.role_dep_no;
    var dep_role_r = row.dep_role;
    var key = row.key;
    var plusButton = "<img src='" + "jsp语法格式化/common/resource/lib/themes/icons/edit_add.png'  style='float:right;cursor:pointer;width:15px' onclick=openWindow_z(" + index + ",'" + key + "'," + dep_no_r + "," + role_dep_no + "," + dep_role_r + ")>&nbsp;";
    if (value == undefined || value == null || value == "") {
        value = "";
        return plusButton;
    } else {
        return value + plusButton;
    }
}
/**
 * 打开窗口
 * @param url
 * @return
 */
function openWindow_z (index, key, dep_no, role_dep_no, dep_role_r) {
    var no = formData_form.value.no;
    var usertype_no = formData_form.value.usertype_no;
    var setrole_yn = formData_form.value.setrole_yn;
    var opts = $("#grid1514277480927").datagrid("options");
    var url = "/automake/system/user_manager/userSetDep.jsp?pageInterfaceNo=jsp语法格式化&index=" + index + "&setrole_yn=" + setrole_yn + "&usertype_no=" + usertype_no + "&dep_no=" + dep_no + "&role_dep_no=" + role_dep_no + "&no=" + no + "&dep_role=" + encodeURIComponent(JSON.stringify(dep_role_r)) + "&key=" + key + "&flag=modify";
    var type = opts.type;
    var title = opts.title;
    var width = opts.width * 0.8;
    var height = opts.height * 0.8;
    var gridid = opts.gridid;
    $("body").append("<div id='win'></div>");
    if (width == undefined || width == null || width == "") {
        width = $(window).width();
        height = $(window).height();
        width = width * 0.6;
        height = height * 0.6;
    }
    var config = {
        width: width,
        height: height,
        minimizable: false,
        href: basePath + url,
        inline: true,
        title: title,
        onResize: function (width, height) {
            $("#win_iframe").attr("height", height);
        },
        onClose: function () {
            if (gridid != "" && gridid != null) {
                gridSearch({
                    gridid: gridid
                });
            }
            $('#win').window("destroy");
        },
        modal: true
    };
    //if(type!=undefined && type=='iframe'){
    config.content = '<iframe scrolling="no" id="win_iframe" onload="LoadMask.remove();" frameborder="0"  src="' + config.href + '" height=' + height + ' style="width:100%;"></iframe>';
    config.href = null;
    //}
    LoadMask.mask("加载页面.....");
    $('#win').window(config).css("overflow", "hidden");
}
function queryDataRight (index) {
    //var dep_no_o = $("#dep_no").wrapper("getValue");
    var depTree = $('#user_dep_no').combotree('tree');
    var nodes = depTree.tree("getSelected");
    if (nodes != undefined) {
        var dep_no = nodes.dep_no;
    }
    currentIndex = index;
    var row = tableRef_grid1514277696180.value.getTableData()[index];
    var array = [];
    var level_info_no = row.level_info_no;
    var relationInfoNo = row.no;
    var modifyUserNo = formData_form.value.no;
    //if(levels[relationInfoNo]==undefined){
    $.ajax({
        url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserDataRightQueryController.do?level_info_no=' + level_info_no + '&relation_info_no=' + relationInfoNo + '&dep_no_o=' + dep_no + '&modifyUserNo=' + modifyUserNo,
        type: 'get',
        async: false,
        dataType: 'json',
        success: function (rs) {
            if (rs != null) {
                if (rs.length > 0) {
                    for (var i = 0; i < rs.length; i++) {
                        array.push({
                            item_no: rs[i].no,
                            item_name: rs[i].name
                        });
                    }
                }
            } else {
                array.push({
                    item_name: "操作权限不够,不能修改"
                });
                $("#grid1514277696180").datagrid('validateRow', currentIndex);
                $("#grid1514277696180").datagrid('endEdit', currentIndex);
            }
        }
    });
    levels[relationInfoNo] = array;
    //}
    array = levels[relationInfoNo];
    return array;
}
function LoadSuccess (row) {
    var flag = true;
    if (user_no == "jsp语法格式化") {
        showFlag_BEB2ABA4_E702_4338_AE3C_F54D3D18D6FF.value = false;
        $("#grid1514277696180").datagrid("hideColumn", "level_name");
    }
}
function check (rowIndex, rowData) {
    if (checkedRowNo.indexOf(rowData.role_dep_no) == -1) {
        checkedRowNo.push(rowData.role_dep_no);
    }
    if (checkedKey.indexOf(rowData.key) >= 0) {
        checkedKey.splice(checkedKey.indexOf(rowData.key), 1);
    }
}
function checkAll (rows) {
    for (var i = 0; i < rows.length; i++) {
        if (checkedRowNo.indexOf(rows[i].role_dep_no) == -1) {
            checkedRowNo.push(rows[i].role_dep_no);
        }
    }
}
function romeRowNo (rowIndex, rowData) {
    var key = rowData.key; // 获取当前行岗位的岗位编号
    var no = jsp语法格式化; // 获取当前修改的用户编号
    var depNo = rowData.dep_no; // 获取当前行岗位关联机构的no
    $.ajax({
        method: 'GET',
        dataType: 'json',
        data: {
            "no": no,
            "key": key,
            "depNo": depNo
        },
        url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/UserRoleCheckController.do',
        success: function (result) {
            if (result == "success") {
                if (checkedRowNo.indexOf(rowData.role_dep_no) >= 0) {
                    checkedRowNo.splice($.inArray(rowData.role_dep_no, checkedRowNo), 1);
                }
                if (checkedKey.indexOf(rowData.key) == -1) {
                    checkedKey.push(rowData.key);
                }
            } else if (result == "defeat") {
                alert("当前岗位有未完成业务，请完成");
                checkRow(rowIndex);
            } else {
                alert(result);
            }
        }
    });
}
function romeRowNoAll (rows) {
    for (var i = 0; i < rows.length; i++) {
        if (checkedRowNo.indexOf(rows[i].role_dep_no) >= 0) {
            checkedRowNo.splice($.inArray(rows[i].role_dep_no, checkedRowNo), 1);
        }
    }
}
//验证关闭的tab
async function validataTab ($tab) {
    var isValid = await formRef_form.value.validate();
    var vali = [];
    var tab = $tab.tabs('getSelected');
    var index = $tab.tabs('getTabIndex', tab);
    var panels = $(".tabs-panels .panel");
    var inputs;
    vali.push(index);
    if (isValid) {
        var options = $tab.tabs("tabs");
        for (var i = 0; i < options.length; i++) {
            if ($.inArray(i, vali) == -1) {
                inputs = $(panels[i]).find(".easyui-wrapper");
                for (var x = 0; x < inputs.length; x++) {
                    isValid = isValid && $(inputs[x]).wrapper("isValid");
                }
                if (!isValid) {
                    $tab.tabs("select", i);
                    return isValid;
                }
                vali.push(i);
            }
        }
    }
    return isValid;
}
function validateKey () {
    if (changeKeyFlag == 'N') {
        //增加前缀校验 update by yexinghai 20190829
        $.ajax({
            url: 'jsp语法格式化/im/dhc/sys/automake/system/user_manager/GetUserPrefixValController.do?',
            type: "POST",
            async: false,
            dataType: "json",
            success: function (result) {
                if (result.isNull == 'N') {
                    var length = result.val.length;
                    var oldKey = "jsp语法格式化";
                    var key = formData_form.value.user_key;
                    var key1 = formData_form.value.user_key;
                    console.log(key);
                    console.log(key1);
                    if (length > key.length) {
                        //前缀的长度大于编号长度
                        alert("用户编号前缀是:" + result.val + "，不符合要求");
                        validatePreFix = '1';
                    } else {
                        var prefixKey = key.substr(0, length);
                        if (prefixKey != result.val) {
                            alert("用户编号前缀是:" + result.val + "，不符合要求");
                            validatePreFix = '1';
                        }
                    }
                }
            }
        });
    }
    var depTree = $('#user_dep_no').combotree('tree');
    var nodes = depTree.tree("getSelected");
    if (!isEmpty(nodes)) {
        onChange();
    }
}
function validateKeyType (key) {
    var reg;
    if (!isEmpty(key)) {
        if (!isEmpty(validateType)) {
            if ("1" == validateType) {
                //数字
                reg = /^\s+$/;
                if (!reg.test(key)) {
                    alert("用户编号只支持数字", false);
                    validateKeyTypeFlag = '1';
                    return false;
                } else {
                    validateKeyTypeFlag = '';
                }
            } else if ("2" == validateType) {
                //字母
                reg = /^[a-zA-Z]+$/;
                if (!reg.test(key)) {
                    alert("用户编号只支持字母", false);
                    validateKeyTypeFlag = '1';
                    return false;
                } else {
                    validateKeyTypeFlag = '';
                }
            } else if ("3" == validateType) {
                //数字+字母
                reg = /^[0-9a-zA-Z]+$/;
                if (!reg.test(key)) {
                    alert("用户编号只支持数字字母组合", false);
                    validateKeyTypeFlag = '1';
                    return false;
                } else {
                    validateKeyTypeFlag = '';
                }
            } else if ("4" == validateType) {
                //数字+字母+特殊字符
                reg = /^[\da-zA-Z!！@#$%^&*(),，。、；;:：、’//`~{}【】\[\]|"“‘'<>《》=\+-_\——·]+$/;
                if (!reg.test(key)) {
                    alert("用户编号只支持数字字母特殊符号组合", false);
                    validateKeyTypeFlag = '1';
                    return false;
                } else {
                    validateKeyTypeFlag = '';
                }
            }
        } else {
            reg = /^[a-zA-Z0-9_]{1,}$/;
            if (!reg.test(key)) {
                alert("用户编号只支持数字字母下划线组合", false);
                validateKeyTypeFlag = '1';
                return false;
            } else {
                validateKeyTypeFlag = '';
            }
        }
    }
}
function onChange () {
    var oldDepNo = "jsp语法格式化";
    var oldKey = "jsp语法格式化";
    var cope_type = formData_form.value.cope_type;
    var setrole_yn = formData_form.value.setrole_yn;
    var Key = formData_form.value.user_key;
    var Name = formData_.value.name;
    var dep_no = formData_form.value.user_dep_no;
    var newKey = formData_form.value.user_key;
    var depTree = $('#user_dep_no').combotree('tree');
    var nodes = depTree.tree("getSelected");
    var dep_no = nodes.dep_no;
    if (!isEmpty(Key)) {
        validateKeyType(Key);
        //判断输入用户号是否合法
        $.ajax({
            url: 'jsp语法格式化/financemanage/validateModifyUserKey.do',
            type: "POST",
            data: {
                "key": Key,
                "dep_no": dep_no,
                "cope_type": cope_type,
                "oldDepNo": oldDepNo,
                "oldKey": oldKey,
                "newKey": newKey
            },
            async: false,
            success: function (rs) {
                rsFlag = rs;
                if (rs == '"0002"') {
                    formData_form.value.user_dep_no = "";
                    alert("用户编号重复，请重新选择所属机构或者修改用户编号");
                }
                if (rs == '"009"') {
                    console.log(lastLength);
                    alert("用户编号长度应该为" + lastLength + "!");
                }
                if (rs == '"0003"') {
                    $.messager.confirm('提示', '该用户号为已删除用户，是否进入删除用户查询页面？', function (r) {
                        if (r) {
                            window.parent.$("#sts").wrapper("setValue", "*"); //获取状态值
                            window.parent.document.getElementById("grid1440118835902").innerHTML = '<ul id="tt"></ul>';
                            window.parent.changeDepTree(); // 机构树查询
                            window.parent.validateDep_no(); //状态为删除的用户查询
                            window.parent.closeWindow();
                        } else {
                            formData_form.value.user_dep_no = "";
                        }
                    });
                }
            }
        });
    }
}
</script>
