| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- /**
- * 添加或修改科室
- * */
- $(function() {
- //项目名称
- autosize($('textarea'));
- init();
- });
- function init() {
- initDept();
- var isEdit = helper.request.queryString("isEdit");
- var mid = helper.request.queryString("mid");
- var txt = helper.request.queryString("txt");
- txt = decodeURIComponent(txt);
- var pid = helper.request.queryString("pid");
- var pTxt = helper.request.queryString("pTxt");
- pTxt = decodeURIComponent(pTxt);
- //项目名称 科室下拉数据
- helper.getDropList.getProlistDrop($('#pro_title'))
- .then(function() {
- $('#pro_title').on('change', function() {
- $('#build').selectpicker('destroy');
- $('#floor').selectpicker('destroy');
- $('#menusTreeView').empty();
- helper.getDropList.getBuildlistDrop($('#build'), $(this).val())
- });
- $('#build').on('change', function() {
- $('#floor').selectpicker('destroy');
- $('#menusTreeView').empty();
- helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
- });
- })
- .then(function() {
- if (isEdit) {
- //修改
- if (pid == null || pid == "undefined") {
- $('#menus').val("顶级分类");
- $('#menus').attr('data-id', null);
- } else {
- $('#menus').val(pTxt);
- $('#menus').attr('data-id', pid);
- }
- getMenusInfo();
- $('#save_btns').on('click', saveAccount);
- } else {
- //添加
- if (mid == "undefined") {
- $('#menus').val("顶级分类");
- $('#menus').attr('data-id', null);
- } else {
- $('#menus').val(txt);
- $('#menus').attr('data-id', mid);
- }
- getMenuLists({});
- $('#save_btns').on('click', saveAccount);
- }
- });
- }
- //初始化科室下拉
- function initDept() {
- $('#menus').on('focus click', function() {
- $('#menusTreeView').removeClass('hidden').addClass('show');
- });
- $('#menus').on('keyup', function() {
- if ($(this).val() == '') {
- $('menusTreeView').treeview('uncheckAll', {
- silent: true
- });
- $(this).attr('data-id', null);
- }
- });
- $('#menus + .caret').on('click', function() {
- $('#menusTreeView').removeClass('hidden').addClass('show');
- });
- $('#menusTreeView').mouseleave(function() {
- $(this).removeClass('show').addClass('hidden');
- });
- }
- //获取科室信息
- function getMenusInfo() {
- var mid = helper.request.queryString("mid");
- $.getJSON(huayi.config.callcenter_url + "configurationapi/api/Department/getdetailes", {
- id: mid,
- }, function(data) {
- if (data.state == "success") {
- var res = data.data;
- $('#pro_title').selectpicker('val', res.projectid);
- helper.getDropList.getBuildlistDrop($('#build'), res.projectid)
- .then(function(){
- $('#build').selectpicker('val', res.building);
- });
- helper.getDropList.getFloorlistDrop($('#floor'), res.building)
- .then(function(){
- $('#floor').selectpicker('val', res.floorid);
- });
- getMenuLists({
- projectid: res.projectid, // 否 string 项目id
- building: res.building, // 否 string 楼栋id
- floorid: res.floorid, // 否 string 楼层id
- });
-
- $('#departmenname').val(res.departmenname);
- $('#sortnum').val(res.sortnum);
- $('#telephone').val(res.telephone);
- $('#mobile').val(res.mobile);
- $('#elsephone').val(res.elsephone);
- $('#email').val(res.email);
- $('#remark').val(res.remark);
- }
- });
- }
- //保存科室信息
- function saveAccount() {
- var wURL;
- var mid = helper.request.queryString("mid");
- var isEdit = helper.request.queryString("isEdit");
- if (isEdit) {
- wURL = "configurationapi/api/Department/update";
- } else {
- mid = null;
- wURL = "configurationapi/api/Department/add";
- }
- if (!$.trim($('#pro_title').val())) {
- layer.confirm('项目名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
-
- if (!$.trim($('#departmenname').val())) {
- layer.confirm('科室名称不允许为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
- layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if ($.trim($('#telephone').val())) {
- if (!regexs.fax.test($.trim($('#telephone').val()))) {
- layer.confirm('请输入正确的固话号码!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
- if ($.trim($('#mobile').val())) {
- if (!regexs.phone.test($.trim($('#mobile').val()))) {
- layer.confirm('请输入正确的手机号码!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
- if ($.trim($('#email').val())) {
- if (!regexs.email.test($.trim($('#email').val()))) {
- layer.confirm('请输入正确的邮箱!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
- $.post(huayi.config.callcenter_url + wURL, {
- id: mid, // 是 string id
- parentid: $('#menus').attr('data-id'), // 当前选择节点ID父级ID,无父级ID为null string 父级id
- projectid: $('#pro_title').val(), // string 项目名称id
- building: $('#build').val(), // string 楼id
- floorid: $('#floor').val(), // string 楼层名称id
- departmenname: $('#departmenname').val(), // string 科室名称
- sortnum: $('#sortnum').val(), // string 排序
- remark: helper.filter.delHtmlTag($('#remark').val()), // string 备注
- telephone: $('#telephone').val(), // string 固定电话
- mobile: $('#mobile').val(), // string 手机号
- elsephone: $('#elsephone').val(), // string 备用电话
- email: $('#email').val(), // string 邮箱
- }, function(data) {
- var data = JSON.parse(data);
- if (data.state == "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$("#gridList").resetSelection();
- parent.$("#gridList").trigger("reloadGrid");
- parent.layer.msg("保存成功");
- }
- });
- }
- //科室下拉
- function getMenuLists(option) {
- var pid = helper.request.queryString("pid");
- $.getJSON(huayi.config.callcenter_url + 'configurationapi/api/Department/getlistdrop', option, function(result) {
- if (result.state.toLowerCase() == "success") {
- var defaultDatas = result.data;
- defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/departmenname/g, "text"));
- defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/\[\]/g, null));
- var $sTree = $('#menusTreeView').treeview({
- color: "#428bca",
- expandIcon: 'glyphicon glyphicon-chevron-right',
- collapseIcon: 'glyphicon glyphicon-chevron-down',
- nodeIcon: 'fa fa-folder-o',
- //selectedIcon: "glyphicon glyphicon-stop",
- //icon: "glyphicon glyphicon-stop",
- //emptyIcon: 'glyphicon',
- //showCheckbox: true,
- selectable: true,
- state: {
- selected: true
- },
- data: defaultDatas,
- onNodeSelected: function(event, node) {
- $sTree.treeview('clearSearch');
- $('#menus').val(node.text);
- $('#menus').attr('data-id', node.id);
- $('#menusTreeView').removeClass('show').addClass('hidden');
- },
- onNodeUnselected: function(event, node) {
- $('#menus').val('顶级分类');
- $('#menus').attr('data-id', null);
- }
- });
- $('#menusTreeView').treeview('collapseAll', {
- silent: true
- });
- var findSNodes = function() {
- return $sTree.treeview('search', [$('#menus').val(), {
- ignoreCase: false,
- exactMatch: false
- }]);
- };
- $('#menus').on('keyup', function(e) {
- var selectableNodes = findSNodes();
- });
- }
- })
- }
|