Нет описания

addOrEditDept.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**
  2. * 添加或修改科室
  3. * */
  4. $(function() {
  5. //项目名称
  6. autosize($('textarea'));
  7. init();
  8. });
  9. function init() {
  10. initDept();
  11. var isEdit = helper.request.queryString("isEdit");
  12. var mid = helper.request.queryString("mid");
  13. var txt = helper.request.queryString("txt");
  14. txt = decodeURIComponent(txt);
  15. var pid = helper.request.queryString("pid");
  16. var pTxt = helper.request.queryString("pTxt");
  17. pTxt = decodeURIComponent(pTxt);
  18. //项目名称 科室下拉数据
  19. helper.getDropList.getProlistDrop($('#pro_title'))
  20. .then(function() {
  21. $('#pro_title').on('change', function() {
  22. $('#build').selectpicker('destroy');
  23. $('#floor').selectpicker('destroy');
  24. $('#menusTreeView').empty();
  25. helper.getDropList.getBuildlistDrop($('#build'), $(this).val())
  26. });
  27. $('#build').on('change', function() {
  28. $('#floor').selectpicker('destroy');
  29. $('#menusTreeView').empty();
  30. helper.getDropList.getFloorlistDrop($('#floor'), $(this).val());
  31. });
  32. })
  33. .then(function() {
  34. if (isEdit) {
  35. //修改
  36. if (pid == null || pid == "undefined") {
  37. $('#menus').val("顶级分类");
  38. $('#menus').attr('data-id', null);
  39. } else {
  40. $('#menus').val(pTxt);
  41. $('#menus').attr('data-id', pid);
  42. }
  43. getMenusInfo();
  44. $('#save_btns').on('click', saveAccount);
  45. } else {
  46. //添加
  47. if (mid == "undefined") {
  48. $('#menus').val("顶级分类");
  49. $('#menus').attr('data-id', null);
  50. } else {
  51. $('#menus').val(txt);
  52. $('#menus').attr('data-id', mid);
  53. }
  54. getMenuLists({});
  55. $('#save_btns').on('click', saveAccount);
  56. }
  57. });
  58. }
  59. //初始化科室下拉
  60. function initDept() {
  61. $('#menus').on('focus click', function() {
  62. $('#menusTreeView').removeClass('hidden').addClass('show');
  63. });
  64. $('#menus').on('keyup', function() {
  65. if ($(this).val() == '') {
  66. $('menusTreeView').treeview('uncheckAll', {
  67. silent: true
  68. });
  69. $(this).attr('data-id', null);
  70. }
  71. });
  72. $('#menus + .caret').on('click', function() {
  73. $('#menusTreeView').removeClass('hidden').addClass('show');
  74. });
  75. $('#menusTreeView').mouseleave(function() {
  76. $(this).removeClass('show').addClass('hidden');
  77. });
  78. }
  79. //获取科室信息
  80. function getMenusInfo() {
  81. var mid = helper.request.queryString("mid");
  82. $.getJSON(huayi.config.callcenter_url + "configurationapi/api/Department/getdetailes", {
  83. id: mid,
  84. }, function(data) {
  85. if (data.state == "success") {
  86. var res = data.data;
  87. $('#pro_title').selectpicker('val', res.projectid);
  88. helper.getDropList.getBuildlistDrop($('#build'), res.projectid)
  89. .then(function(){
  90. $('#build').selectpicker('val', res.building);
  91. });
  92. helper.getDropList.getFloorlistDrop($('#floor'), res.building)
  93. .then(function(){
  94. $('#floor').selectpicker('val', res.floorid);
  95. });
  96. getMenuLists({
  97. projectid: res.projectid, // 否 string 项目id
  98. building: res.building, // 否 string 楼栋id
  99. floorid: res.floorid, // 否 string 楼层id
  100. });
  101. $('#departmenname').val(res.departmenname);
  102. $('#sortnum').val(res.sortnum);
  103. $('#telephone').val(res.telephone);
  104. $('#mobile').val(res.mobile);
  105. $('#elsephone').val(res.elsephone);
  106. $('#email').val(res.email);
  107. $('#remark').val(res.remark);
  108. }
  109. });
  110. }
  111. //保存科室信息
  112. function saveAccount() {
  113. var wURL;
  114. var mid = helper.request.queryString("mid");
  115. var isEdit = helper.request.queryString("isEdit");
  116. if (isEdit) {
  117. wURL = "configurationapi/api/Department/update";
  118. } else {
  119. mid = null;
  120. wURL = "configurationapi/api/Department/add";
  121. }
  122. if (!$.trim($('#pro_title').val())) {
  123. layer.confirm('项目名称不允许为空!', {
  124. icon: 2,
  125. btn: ['确定'] //按钮
  126. });
  127. return;
  128. }
  129. if (!$.trim($('#departmenname').val())) {
  130. layer.confirm('科室名称不允许为空!', {
  131. icon: 2,
  132. btn: ['确定'] //按钮
  133. });
  134. return;
  135. }
  136. if (!regexs.integerReg.test($.trim($('#sortnum').val()))) {
  137. layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
  138. icon: 2,
  139. btn: ['确定'] //按钮
  140. });
  141. return;
  142. }
  143. if ($.trim($('#telephone').val())) {
  144. if (!regexs.fax.test($.trim($('#telephone').val()))) {
  145. layer.confirm('请输入正确的固话号码!', {
  146. icon: 2,
  147. btn: ['确定']
  148. });
  149. return;
  150. }
  151. }
  152. if ($.trim($('#mobile').val())) {
  153. if (!regexs.phone.test($.trim($('#mobile').val()))) {
  154. layer.confirm('请输入正确的手机号码!', {
  155. icon: 2,
  156. btn: ['确定']
  157. });
  158. return;
  159. }
  160. }
  161. if ($.trim($('#email').val())) {
  162. if (!regexs.email.test($.trim($('#email').val()))) {
  163. layer.confirm('请输入正确的邮箱!', {
  164. icon: 2,
  165. btn: ['确定']
  166. });
  167. return;
  168. }
  169. }
  170. $.post(huayi.config.callcenter_url + wURL, {
  171. id: mid, // 是 string id
  172. parentid: $('#menus').attr('data-id'), // 当前选择节点ID父级ID,无父级ID为null string 父级id
  173. projectid: $('#pro_title').val(), // string 项目名称id
  174. building: $('#build').val(), // string 楼id
  175. floorid: $('#floor').val(), // string 楼层名称id
  176. departmenname: $('#departmenname').val(), // string 科室名称
  177. sortnum: $('#sortnum').val(), // string 排序
  178. remark: helper.filter.delHtmlTag($('#remark').val()), // string 备注
  179. telephone: $('#telephone').val(), // string 固定电话
  180. mobile: $('#mobile').val(), // string 手机号
  181. elsephone: $('#elsephone').val(), // string 备用电话
  182. email: $('#email').val(), // string 邮箱
  183. }, function(data) {
  184. var data = JSON.parse(data);
  185. if (data.state == "success") {
  186. var index = parent.layer.getFrameIndex(window.name);
  187. parent.layer.close(index);
  188. parent.$("#gridList").resetSelection();
  189. parent.$("#gridList").trigger("reloadGrid");
  190. parent.layer.msg("保存成功");
  191. }
  192. });
  193. }
  194. //科室下拉
  195. function getMenuLists(option) {
  196. var pid = helper.request.queryString("pid");
  197. $.getJSON(huayi.config.callcenter_url + 'configurationapi/api/Department/getlistdrop', option, function(result) {
  198. if (result.state.toLowerCase() == "success") {
  199. var defaultDatas = result.data;
  200. defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/departmenname/g, "text"));
  201. defaultDatas = JSON.parse(JSON.stringify(defaultDatas).replace(/\[\]/g, null));
  202. var $sTree = $('#menusTreeView').treeview({
  203. color: "#428bca",
  204. expandIcon: 'glyphicon glyphicon-chevron-right',
  205. collapseIcon: 'glyphicon glyphicon-chevron-down',
  206. nodeIcon: 'fa fa-folder-o',
  207. //selectedIcon: "glyphicon glyphicon-stop",
  208. //icon: "glyphicon glyphicon-stop",
  209. //emptyIcon: 'glyphicon',
  210. //showCheckbox: true,
  211. selectable: true,
  212. state: {
  213. selected: true
  214. },
  215. data: defaultDatas,
  216. onNodeSelected: function(event, node) {
  217. $sTree.treeview('clearSearch');
  218. $('#menus').val(node.text);
  219. $('#menus').attr('data-id', node.id);
  220. $('#menusTreeView').removeClass('show').addClass('hidden');
  221. },
  222. onNodeUnselected: function(event, node) {
  223. $('#menus').val('顶级分类');
  224. $('#menus').attr('data-id', null);
  225. }
  226. });
  227. $('#menusTreeView').treeview('collapseAll', {
  228. silent: true
  229. });
  230. var findSNodes = function() {
  231. return $sTree.treeview('search', [$('#menus').val(), {
  232. ignoreCase: false,
  233. exactMatch: false
  234. }]);
  235. };
  236. $('#menus').on('keyup', function(e) {
  237. var selectableNodes = findSNodes();
  238. });
  239. }
  240. })
  241. }