|
@@ -0,0 +1,479 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="zh-CN">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport"
|
|
|
+ content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
|
|
|
+ <meta name="apple-mobile-web-app-capable" content="yes">
|
|
|
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
+ <title>选择角色</title>
|
|
|
+ <script src="../../js/rem.js?v=c9079f88b2"></script>
|
|
|
+ <link rel="stylesheet" href="../../css/base.css?v=881ec9966d">
|
|
|
+ <link rel="stylesheet" href="../../iconfont/iconfont.css">
|
|
|
+ <link rel="stylesheet" href=//cdn-common.jianyu360.com/cdn/lib/weui/2.0.1/weui.min.css></link>
|
|
|
+ <link rel="stylesheet" href="../../css/public.css?v=4954190af4">
|
|
|
+ <link rel="stylesheet" href="../../css/choose_branch.css?v=6b2d00324a">
|
|
|
+ <style>
|
|
|
+ .checkbox,.checkbox:checked{width: 0.4rem!important;height: 0.4rem!important;}
|
|
|
+ .checkbox:disabled{background-color: #eee;}
|
|
|
+ </style>
|
|
|
+<script src="/common-module/public/head.js"></script>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <div class="j-container choose-branch">
|
|
|
+ <div class="j-header app-header" style="display: none">
|
|
|
+ <span class="header-left iconfont icon-fanhui"></span>
|
|
|
+ <span class="header-title">选择角色</span>
|
|
|
+ <span class="header-right add-branch-handle"></span>
|
|
|
+ </div>
|
|
|
+ <!-- <div class="wx-action-header" style="display: none">
|
|
|
+ <span></span>
|
|
|
+ <span class="action-button add-branch-handle">新增部门</span>
|
|
|
+ </div> -->
|
|
|
+ <div class="j-body">
|
|
|
+ <div class="j-title" style="white-space:nowrap;overflow-y: scroll;">
|
|
|
+ <span class="prev-name"></span>
|
|
|
+ <span class="prev-children-name"></span>
|
|
|
+ <span class="selected-name"></span>
|
|
|
+ </div>
|
|
|
+ <div class="j-cells branch-cell">
|
|
|
+ <script type="text/html" id="branch">
|
|
|
+ {{each data value i}}
|
|
|
+ <a class="j-cell">
|
|
|
+ <div class="j-cell_left">
|
|
|
+ {{if value.isDisabled == true}}
|
|
|
+ <input id="{{value.id}}" type="radio" disabled="{{value.isDisabled}}" data-count="{{value.dept_count}}" data-name="{{value.name}}" value="{{value.id}}" class="checkbox" name="branch">
|
|
|
+ {{else}}
|
|
|
+ <input id="{{value.id}}" type="radio" data-count="{{value.dept_count}}" data-name="{{value.name}}" value="{{value.id}}" class="checkbox" name="branch">
|
|
|
+ {{/if}}
|
|
|
+ </div>
|
|
|
+ <div class="j-cell_right choose-children-branch" data-count="{{value.dept_count}}" data-name="{{value.name}}" data-id="{{value.id}}">
|
|
|
+ <div class="j-cell_rl"><label for="{{value.id}}">{{value.name}}</label></div>
|
|
|
+ <div class="j-cell_rr">
|
|
|
+ {{if value.dept_count > 0}}
|
|
|
+ <i class="iconfont icon-arrow"></i>
|
|
|
+ {{/if}}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </a>
|
|
|
+ {{/each}}
|
|
|
+ </script>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="j-footer">
|
|
|
+ <div class="j-button-group">
|
|
|
+ <button class="j-button-confirm" id="enterChoose" disabled>确定</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="js_dialog add-branch-dialog">
|
|
|
+ <div class="weui-mask"></div>
|
|
|
+ <div class="weui-dialog">
|
|
|
+ <div class="weui-dialog__hd"><strong>新增部门</strong></div>
|
|
|
+ <div class="weui-dialog__bd">
|
|
|
+ <input class="branch-input" type="text" placeholder="请填写部门名称">
|
|
|
+ </div>
|
|
|
+ <div class="weui-dialog__ft">
|
|
|
+ <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_default cancel_btn">取消</a>
|
|
|
+ <button class="weui-dialog__btn weui-dialog__btn_primary confirm_btn" disabled>确定</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <script src=//cdn-common.jianyu360.com/cdn/lib/jquery/3.6.0/jquery.min.js></script>
|
|
|
+ <script src="../../js/weui.min.js?v=e983e1bcc0"></script>
|
|
|
+ <script src=//cdn-common.jianyu360.com/cdn/lib/art-template/4.13.2/template-web.min.js></script>
|
|
|
+ <script src="../../js/common.js?v=621f02e007"></script>
|
|
|
+ <script src="/jyapp/js/common.js?v=921e02f006"></script>
|
|
|
+ <script>
|
|
|
+ $(function(){
|
|
|
+ var did = vTools.getParam('did');//接收移动过来的部门id
|
|
|
+ var uid = vTools.getParam('uid');//接收移动过来的人员id
|
|
|
+ var pid = vTools.getParam('id');
|
|
|
+ console.log(did,uid,pid,vTools.getParam('id'));
|
|
|
+ var chooseBranch = {
|
|
|
+ branchName:[],//面包屑数组{name:'',id:''}
|
|
|
+ init:function(){
|
|
|
+ this.getPrevBranchName();
|
|
|
+ this.getBranch();
|
|
|
+ this.isSelected();
|
|
|
+ this.getChildrenBranch();
|
|
|
+ this.addBranchHandle();
|
|
|
+ this.cancelHandle();
|
|
|
+ this.checkInput();
|
|
|
+ this.confirmHandle();
|
|
|
+ this.enterChoose();
|
|
|
+ this.returnParent();
|
|
|
+ this.getBreadChildren();
|
|
|
+ },
|
|
|
+ // 获取到公司名称(仅为展示)
|
|
|
+ getPrevBranchName:function(){
|
|
|
+ var that = this;
|
|
|
+ vTools.ajax({
|
|
|
+ url: '/department/detail',
|
|
|
+ type: 'POST',
|
|
|
+ contentType:'application/x-www-form-urlencoded',
|
|
|
+ data: {
|
|
|
+ "id": vTools.getParam('id') || sessionStorage.getItem('initId')
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ $('.j-title .prev-name').html(res.data.name);
|
|
|
+ $('.j-title .prev-name').attr('data-id',res.data.pid);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取到公司下的部门
|
|
|
+ getBranch:function(){
|
|
|
+ var that = this;
|
|
|
+ var res = {
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": "",
|
|
|
+ "data": [
|
|
|
+ {
|
|
|
+ "dept_count": 0,
|
|
|
+ "id": 2,
|
|
|
+ "name": "资讯分配"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "dept_count": 0,
|
|
|
+ "id": 3,
|
|
|
+ "name": "资讯分配+销售"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "dept_count": 0,
|
|
|
+ "id": 1,
|
|
|
+ "name": "员工"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ var comHTML = template('branch', res);
|
|
|
+ $('.branch-cell').html(comHTML);
|
|
|
+ // vTools.ajax({
|
|
|
+ // url: '/department/childrens',
|
|
|
+ // type: 'POST',
|
|
|
+ // contentType:'application/x-www-form-urlencoded',
|
|
|
+ // data: {
|
|
|
+ // "id": vTools.getParam('id') || sessionStorage.getItem('initId')
|
|
|
+ // },
|
|
|
+ // success: function(res) {
|
|
|
+ // console.log(res,"获取到公司下的部门")
|
|
|
+ // res.data.forEach(function(v){
|
|
|
+ // did.split(',').forEach(function(s){
|
|
|
+ // if(v.id == s){
|
|
|
+ // v.isDisabled = true;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // if(pid == v.id){
|
|
|
+ // v.isDisabled = true;
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // 通过点击部门查找下一级部门
|
|
|
+ getChildrenBranch:function(){
|
|
|
+ var that = this;
|
|
|
+ $('.branch-cell').on('click','.choose-children-branch',function (e) {
|
|
|
+ var id = e.currentTarget.dataset.id;
|
|
|
+ var name = e.currentTarget.dataset.name;
|
|
|
+ var count = e.currentTarget.dataset.count;
|
|
|
+ var isDisabled = $(this).siblings().find('input').prop("disabled")
|
|
|
+ $('.last-child').remove();
|
|
|
+ if(!isDisabled){
|
|
|
+ if(count > 0){
|
|
|
+ $('.selected-name').html('');
|
|
|
+ // that.branchName = [];
|
|
|
+ // 有子部门时添加到数组里面
|
|
|
+ that.branchName.push({
|
|
|
+ id:id,
|
|
|
+ name:name,
|
|
|
+ })
|
|
|
+ console.log(that.branchName)
|
|
|
+ that.changeBread();
|
|
|
+ that.getBreadChildren();
|
|
|
+ vTools.ajax({
|
|
|
+ url: '/department/childrens',
|
|
|
+ type: 'POST',
|
|
|
+ contentType:'application/x-www-form-urlencoded',
|
|
|
+ data: {
|
|
|
+ "id":id
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ // console.log(res)
|
|
|
+ res.data.forEach(function(v){
|
|
|
+ did.split(',').forEach(function(s){
|
|
|
+ if(v.id == s){
|
|
|
+ v.isDisabled = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if(pid == v.id){
|
|
|
+ v.isDisabled = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ var comHTML = template('branch', res);
|
|
|
+ $('.branch-cell').html(comHTML);
|
|
|
+ $("#enterChoose").attr('disabled',true)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 循环渲染面包屑函数
|
|
|
+ changeBread:function(){
|
|
|
+ // 数组去重
|
|
|
+ var temp = {};
|
|
|
+ this.branchName = this.branchName.reduce(function(prev, curv) {
|
|
|
+ if (temp[curv.id]) {
|
|
|
+ }else {
|
|
|
+ temp[curv.id] = true;
|
|
|
+ prev.push(curv);
|
|
|
+ }
|
|
|
+ return prev
|
|
|
+ }, []);
|
|
|
+ var html = '';
|
|
|
+ for(var i =0;i<this.branchName.length;i++){
|
|
|
+ html += "<em class='child' data-id=" + this.branchName[i].id +">" + ">" + this.branchName[i].name + "</em>"
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.prev-children-name').html(html);
|
|
|
+ },
|
|
|
+ // 点击面包屑导航返回上一级(再次查询子部门)
|
|
|
+ getBreadChildren:function(){
|
|
|
+ var that = this;
|
|
|
+ $(document).on('click','.child',function(e) {
|
|
|
+ var index = $(this).index();//获取点击面包屑导航的下标
|
|
|
+ var id = e.currentTarget.dataset.id;
|
|
|
+ // console.log(index,id)
|
|
|
+ if(index != -1){
|
|
|
+ that.branchName.splice(index+1,that.branchName.length)
|
|
|
+ console.log(that.branchName,"删除后的数组")
|
|
|
+ $('.selected-name').html('');//清除最后checkbox选中的部门
|
|
|
+ that.changeBread();
|
|
|
+ }
|
|
|
+ vTools.ajax({
|
|
|
+ url: '/department/childrens',
|
|
|
+ type: 'POST',
|
|
|
+ contentType:'application/x-www-form-urlencoded',
|
|
|
+ data: {
|
|
|
+ "id":id
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ // console.log(res)
|
|
|
+ res.data.forEach(function(v){
|
|
|
+ did.split(',').forEach(function(s){
|
|
|
+ if(v.id == s){
|
|
|
+ v.isDisabled = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if(pid == v.id){
|
|
|
+ v.isDisabled = true;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ var comHTML = template('branch', res);
|
|
|
+ $('.branch-cell').html(comHTML);
|
|
|
+ $("#enterChoose").attr('disabled',true)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // checkbox选中校验
|
|
|
+ isSelected:function(){
|
|
|
+ var that = this;
|
|
|
+ $('.j-body').on('change','.checkbox',function(){
|
|
|
+ if($('.checkbox:checked').length > 0){
|
|
|
+ $("#enterChoose").removeAttr('disabled')
|
|
|
+ }else{
|
|
|
+ $("#enterChoose").attr('disabled',true)
|
|
|
+ }
|
|
|
+
|
|
|
+ $('.checkbox:checked').each(function(){
|
|
|
+ // if($(this).attr('data-count') == 0){
|
|
|
+ // $('.selected-name').html('>' + $(this).attr('data-name'))
|
|
|
+ // }else{
|
|
|
+ // $('.selected-name').html('');
|
|
|
+ // }
|
|
|
+ $this = $(this);
|
|
|
+ $('.selected-name').html('>' + $(this).attr('data-name'))
|
|
|
+ $('.selected-name').attr('data-id',$(this).val())
|
|
|
+ that.branchName.forEach(function(v){
|
|
|
+ // console.log(v,$(this).attr('data-name'))
|
|
|
+ if(v.name == $this.attr('data-name')){
|
|
|
+ $('.selected-name').html('');
|
|
|
+ $('.selected-name').removeAttr('data-id')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 点击面包屑上的公司名称,清除面包屑导航,重新渲染公司下的部门
|
|
|
+ returnParent:function(){
|
|
|
+ var that = this;
|
|
|
+ $('.prev-name').on('click',function () {
|
|
|
+ $("#enterChoose").attr('disabled',true);
|
|
|
+ $('.selected-name').html('');//清除最后checkbox选中的部门
|
|
|
+ that.getBranch();
|
|
|
+ that.branchName = [];//点公司名称 清空面包屑导航数组
|
|
|
+ $('.prev-children-name').html('')
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 显示新增部门弹框
|
|
|
+ addBranchHandle:function(){
|
|
|
+ $('.add-branch-handle').on('click',function(){
|
|
|
+ $('.add-branch-dialog').fadeIn(200)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 隐藏新增部门弹框
|
|
|
+ cancelHandle:function(){
|
|
|
+ $('.cancel_btn').on('click',function(){
|
|
|
+ $('.add-branch-dialog').fadeOut(200);
|
|
|
+ console.log($('.child:last-child').attr('data-id'))
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 输入框验证
|
|
|
+ checkInput:function(){
|
|
|
+ if ($('.branch-input').val().trim() != '' ) {
|
|
|
+ $('.confirm_btn').removeAttr('disabled')
|
|
|
+ } else{
|
|
|
+ $('.confirm_btn').attr('disabled',true)
|
|
|
+ }
|
|
|
+ $('.branch-input').on('input',function(e){
|
|
|
+ var val = $(this).val().trim();
|
|
|
+ var input = e.target;
|
|
|
+ var value = input.value
|
|
|
+ var split = value.split('');
|
|
|
+ var map = split.map(function(s, i) {
|
|
|
+ return (value.charCodeAt(i) >= 0 && value.charCodeAt(i) <= 128) ? 1 : 2;
|
|
|
+ });
|
|
|
+ var n = 0;
|
|
|
+ $this = $(this);
|
|
|
+ var charLength = map.length > 0 && map.reduce(function(accumulator, currentValue, index) {
|
|
|
+ var count = accumulator + currentValue;
|
|
|
+ if (count === 40) {
|
|
|
+ n = index;
|
|
|
+ }
|
|
|
+ if (count > 40) {
|
|
|
+ $this.val(split.slice(0, n+1).join(''))
|
|
|
+ }
|
|
|
+ return count
|
|
|
+ });
|
|
|
+ if(val == ''){
|
|
|
+ $('.confirm_btn').attr('disabled',true)
|
|
|
+ }else{
|
|
|
+ $('.confirm_btn').removeAttr('disabled')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 弹框新增部门输入确认
|
|
|
+ confirmHandle:function(){
|
|
|
+ var that = this;
|
|
|
+ $('.confirm_btn').on('click',function(){
|
|
|
+ var val = $('.branch-input').val().trim();
|
|
|
+ console.log(val)
|
|
|
+ vTools.ajax({
|
|
|
+ url: '/department/add',
|
|
|
+ type: 'POST',
|
|
|
+ contentType:'application/x-www-form-urlencoded',
|
|
|
+ data: {
|
|
|
+ "name": val,
|
|
|
+ "pid": $('.checkbox:checked').val() || $('.child:last-child').attr('data-id') || vTools.getParam('id') || sessionStorage.getItem('initId'),
|
|
|
+ "aid": ''
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res)
|
|
|
+ if(res.data.status == 1){
|
|
|
+ $('.add-branch-dialog').fadeOut(200);
|
|
|
+ $('.branch-input').val('');
|
|
|
+ weui.toast('添加成功', {
|
|
|
+ duration: 1500,
|
|
|
+ className: 'j-toast',
|
|
|
+ callback: function(){
|
|
|
+ that.getBranch();
|
|
|
+ $("#enterChoose").attr('disabled',true);
|
|
|
+ $('.prev-children-name').html('');
|
|
|
+ $('.selected-name').html('')
|
|
|
+ }
|
|
|
+ });
|
|
|
+ that.isSelected();
|
|
|
+ }else if(res.data.status == -1){
|
|
|
+ weui.toast('部门已存在', {
|
|
|
+ duration: 1500,
|
|
|
+ className: 'j-toast',
|
|
|
+ callback: function(){
|
|
|
+ console.log('close')
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ weui.toast('添加失败', {
|
|
|
+ duration: 1500,
|
|
|
+ className: 'j-toast',
|
|
|
+ callback: function(){ console.log('close') }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 选择确认
|
|
|
+ enterChoose:function(){
|
|
|
+ $('#enterChoose').on('click',function(){
|
|
|
+ var pageName = document.referrer;//获取上个页面的页面地址
|
|
|
+ // 判断由哪个页面进来,从人员管理页面批量管理移动过来,则执行移动部门及人员服务请求
|
|
|
+ if(pageName.indexOf('people_management_branch') != -1 || pageName.indexOf('people_management') != -1){
|
|
|
+ vTools.ajax({
|
|
|
+ url: '/framework/move',
|
|
|
+ type: 'POST',
|
|
|
+ contentType:'application/x-www-form-urlencoded',
|
|
|
+ data: {
|
|
|
+ "pid": $('.checkbox:checked').val(),//移动至哪个部门的id
|
|
|
+ "did": did,//移动的部门
|
|
|
+ "uid": uid //移动的成员
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ console.log(res)
|
|
|
+ if(res.data.status == 1){
|
|
|
+ weui.toast('移动成功', {
|
|
|
+ duration: 1500,
|
|
|
+ className: 'j-toast',
|
|
|
+ callback: function(){
|
|
|
+ window.history.go(-1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ weui.toast('移动失败', {
|
|
|
+ duration: 1500,
|
|
|
+ className: 'j-toast',
|
|
|
+ callback: function(){
|
|
|
+ // window.history.go(-1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{ //从其他页面进来,执行返回上一页并利用sessionStorage实现回显
|
|
|
+ console.log($('.checkbox:checked').val())
|
|
|
+ var id = $('.checkbox:checked').val();
|
|
|
+ var name =$('.checkbox:checked').attr('data-name');
|
|
|
+ const params = {
|
|
|
+ roleName: name,
|
|
|
+ roleID: id
|
|
|
+ }
|
|
|
+ sessionStorage.setItem('roleInfo', JSON.stringify(params))
|
|
|
+ window.history.go(-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ chooseBranch.init();
|
|
|
+ })
|
|
|
+ </script>
|
|
|
+<script src="/common-module/public/fotter.js"></script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|