define(function (require) { return function (context) { var $grid1, $grid2, $dlg, $form; var tabIndex = 0, tabSelect = 1; var search = [{ queryProperties: '' }, { queryProperties: '' }]; // 输入搜索文本后点击回车按钮查询列表 function enterQueryGrid1(e) { if (e.keyCode === 13) { var tmp = $(this).val(); $form.formSet({queryProperties: tmp}); queryGrid1(); queryGrid2(); } } //左侧列表 function queryGrid1() { $grid1.jqGrid("clearGridData"); var obj = $form.formGet(); obj.roleId = context.roleId; $grid1.reload({ url: api('/hr/userRole/querySys'), mtype: 'POST', queryParams: obj }); if ($grid2 != undefined) { $grid2.jqGrid("clearGridData"); } } //右侧列表 function queryGrid2() { $grid2.jqGrid("clearGridData"); var obj = $form.formGet(); obj.roleId = context.roleId; $grid2.reload({ url: api('/sys/sysRole/querySysRoleNot'), mtype: 'POST', queryParams: obj }); } return { xtype: 'dialog', dialogId: 'dialogHrUserRole', title: '分配角色人员', width: '100%', height: '100%', onOpen: function () { $dlg = $(this); if (context.isEdit) { } }, north: { height: 90, split: true, border: false, items: [ { xtype: 'toolbar', title: '', items: [ { text: '查询', iconCls: 'fa fa-search', onClick: function () { if (tabIndex == 0) { queryGrid1(); } else if (tabIndex == 1) { queryGrid2(); } } }, { text: '重置', iconCls: 'fa fa-refresh', onClick: function () { $form.formClear(); if (tabIndex == 0) { queryGrid1(); } else if (tabIndex == 1) { queryGrid2(); } } }, { text: '关闭', iconCls: 'fa fa-times-circle', onClick: function () { $dlg.window('close'); } } ] }, { xtype: 'form', onRender: function () { $form = $(this); }, items: [[ {name: 'roleId', label: '当前角色 》', labelWidth: 'auto', value: context.roleName, readonly: true}, { xtype: 'textbox', label: '检索条件', name: 'queryProperties', prompt: '姓名/用户名/手机号/部门', labelWidth: 'auto', events: {keydown: enterQueryGrid1} }, { xtype: 'yvselect', label: '是否分配角色', name: 'hasRole', labelWidth: 'auto', width: 220, data: [{"id": '', "text": '全部'}, {"id": '0', "text": '未分配'}, {"id": '1', "text": '已分配'}], value: '', onChange: function () { if (tabIndex == 0) { queryGrid1(); } else if (tabIndex == 1) { queryGrid2(); } } }, ]] } ] }, center: { items: { xtype: 'tabs', onRender: function () { var $tabs = $(this); $tabs.tabs('select', tabSelect); }, //切换tabs事件 onSelect: function (title, index) { //得到第几个grid被选中 var obj = $form.formGet(); search[0].queryProperties = obj.queryProperties; search[1].queryProperties = obj.queryProperties; var _data = search[index]; $form.formSet({ queryProperties: _data.queryProperties }); tabIndex = index; }, items: [ { title: '已选择', lazy: true, items: { onRender: function () { $grid1 = $(this); queryGrid1(); //初始化数据 }, xtype: 'grid', pagination: true, toolbar: { xtype: 'toolbar', title: '已选择的人员', items: [ { text: '移除人员', iconCls: 'fa fa-times', onClick: function () { var row = $grid1.rowData(); if (!row) { $.yvan.msg('请先选择一行数据'); return; } if (row.hurId == undefined || row.hurId == null) { $.yvan.msg('请先选择一行数据'); return; } $.yvan.confirm('确定移除 [' + row.name + ']吗?', { yes: function () { $.yvan.ajax({ url: api('/hr/userRole/delete'), method: 'post', data: { hurId: row.hurId, roleName: context.roleName, userId:row.userId, roleId:row.roleId, }, success: function () { $.yvan.msg('操作成功'); $grid1.reload(); if ($grid2 != undefined && $grid2 != null) { $grid2.reload(); } context.confirm(); } }); } }); } } ] }, columns: [[ {field: 'hurId', title: '选择', hidden: true}, {field: 'sysId', title: '用户ID', hidden: true}, {field: 'userId', title: '用户ID', hidden: true}, {field: 'roleId', title: '用户ID', hidden: true}, {field: 'name', title: '姓名'}, {field: 'gender', title: '性别', align: 'center', formatter: $.fn.fmatter.genderSrc}, {field: 'account', title: '用户名'}, {field: 'mobile', title: '手机号'}, {field: 'deptName', title: '所属部门'}, {field: 'roleName', title: '拥有角色'}, {field: 'timeCreate', title: '加入时间', align: 'center', formatter: 'ts'}, ]], } }, { title: '待选择', lazy: true, items: { onRender: function () { $grid2 = $(this); queryGrid2(); //初始化数据 }, xtype: 'grid', toolbar: { xtype: 'toolbar', title: '待选择的人员', items: [ { text: '新增人员', iconCls: 'fa fa-plus-circle', onClick: function () { var row = $grid2.rowData(); if (!row) { $.yvan.msg('请先选择一行数据'); return; } if (row.userId == undefined || row.userId == null) { $.yvan.msg('请先选择一行数据'); return; } var obj = $form.formGet(); if (obj.farmId == "" || obj.farmId == 0) { $.yvan.msg('请先选择加入的库区'); return; } $.yvan.ajax({ url: api('/hr/userRole/insert'), method: 'post', data: { userId: row.userId, roleId: context.roleId, sysId: obj.sysId, name:row.name, roleName:row.roleNames, mobile:row.mobile, deptNames:row.deptNames, jobcard:row.jobcard, gender:row.gender, xtRoleName:context.roleName, }, success: function () { $.yvan.msg('操作成功'); $grid1.reload(); $grid2.reload(); context.confirm(); } }); } } ] }, columns: [[ {field: 'userId', title: '用户ID', hidden: true}, {field: 'name', title: '姓名'}, {field: 'gender', title: '性别', align: 'center', formatter: $.fn.fmatter.genderSrc}, {field: 'gender', title: '性别', hidden: true}, {field: 'account', title: '用户名'}, {field: 'mobile', title: '手机号'}, {field: 'deptNames', title: '所属部门'}, {field: 'roleNames', title: '拥有角色'}, {field: 'jobcard', title: '职工号', hidden: true}, {field: 'userCreate', title: '新增人', hidden: true}, {field: 'timeCreate', title: '新增时间', hidden: true}, ]] } } ] } } }; }; } );