Nessuna descrizione

addEquipmentRepair.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //省市联动
  2. function getProvinceCity(ele1, isasync) {
  3. if (isasync != false) {
  4. isasync = true;
  5. }
  6. $.ajaxSettings.async = isasync;
  7. ele1.empty();
  8. ele1.append('<option selected="selected" value="">请选择省</option>');
  9. $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/equipment/getfivetree", function(data) {
  10. if (data.state.toLowerCase() == "success") {
  11. var province = data.data;
  12. var citys = []; //市
  13. var projects = []; //项目
  14. var builds = []; //楼
  15. var floors = []; //楼层
  16. $(data.data).each(function(i, n) {
  17. $("<option value='" + n.code + "' selected='selected'>" + n.name + "</option>").appendTo(ele1);
  18. ele1.selectpicker('refresh');
  19. if (n.entityJson != null && n.entityJson.length != 0) {
  20. citys.push(n.entityJson);
  21. for (var c = 0; c < citys.length; c++) {
  22. $(citys[c]).each(function(j, v) {
  23. if (v.parentcode > 0) {
  24. $("<option value='" + v.code + "' selected='selected'>" + v.name + "</option>").appendTo("#city");
  25. $("#city").selectpicker('refresh');
  26. if (v.entityJson != null && v.entityJson.length > 0) {
  27. projects.push(v.entityJson);
  28. }
  29. }
  30. });
  31. }
  32. for (var j = 0; j < projects.length; j++) {
  33. $(projects[j]).each(function(i, n) {
  34. if (n.parentcode > 0) {
  35. $('#protype_addText').val(n.protypename);
  36. $('#protype_addNode').val(n.protypeid);
  37. $("<option value='" + n.code + "' selected='selected'>" + n.name + "</option>").appendTo("#proname");
  38. $("#proname").selectpicker('refresh');
  39. if (n.entityJson != null && n.entityJson.length > 0) {
  40. builds.push(n.entityJson);
  41. }
  42. }
  43. });
  44. }
  45. for (var g = 0; g < builds.length; g++) {
  46. $(builds[g]).each(function(q, p) {
  47. if (p.parentcode) {
  48. $("<option value='" + p.code + "'>" + p.name + "</option>").appendTo("#build");
  49. $("#build").selectpicker('refresh');
  50. if (p.entityJson != null && p.entityJson.length > 0) {
  51. floors.push(p.entityJson);
  52. }
  53. }
  54. });
  55. }
  56. for (var k = 0; k < floors.length; k++) {
  57. $(floors[k]).each(function(y, z) {
  58. if (z.parentcode) {
  59. $("<option value='" + z.code + "'>" + z.name + "</option>").appendTo("#floor");
  60. $("#floor").selectpicker('refresh');
  61. }
  62. });
  63. }
  64. }
  65. })
  66. //市级信息
  67. $("#province").change(function() {
  68. $("#city").empty();
  69. projects = [];
  70. for (var i = 0; i < citys.length; i++) {
  71. $(citys[i]).each(function(j, v) {
  72. if (v.parentcode > 0) {
  73. if ($("#province").val() == v.parentcode) {
  74. $("<option value='" + v.code + "'>" + v.name + "</option>").appendTo("#city");
  75. if (v.entityJson != null && v.entityJson.length > 0) {
  76. projects.push(v.entityJson);
  77. }
  78. }
  79. }
  80. });
  81. }
  82. $("#city").selectpicker('refresh');
  83. if ($("#province").val() == '') {
  84. $("#city").append('<option selected="selected" value="">请选择所在市</option>');
  85. }
  86. if ($("#city").val() == null) {
  87. $("#city").append('<option selected="selected" value="">暂无数据</option>');
  88. }
  89. $("#city").trigger('change');
  90. })
  91. //项目信息
  92. $("#city").change(function() {
  93. $("#proname").empty();
  94. builds = [];
  95. $('#protype_addText').val('');
  96. $('#protype_addNode').val('');
  97. for (var j = 0; j < projects.length; j++) {
  98. $(projects[j]).each(function(i, n) {
  99. if (n.parentcode > 0) {
  100. if ($("#city").val() == n.parentcode) {
  101. $('#protype_addText').val(n.protypename);
  102. $('#protype_addNode').val(n.protypeid);
  103. $("<option value='" + n.code + "'>" + n.name + "</option>").appendTo("#proname");
  104. if (n.entityJson != null && n.entityJson.length > 0) {
  105. builds.push(n.entityJson);
  106. }
  107. }
  108. }
  109. });
  110. }
  111. $("#proname").selectpicker('refresh');
  112. if ($("#city").val() == '') {
  113. $("#proname").append('<option selected="selected" value="">请选择项目</option>');
  114. }
  115. if ($("#proname").val() == null || $("#proname").val() == '') {
  116. $("#proname").append('<option selected="selected" value="">暂无数据</option>');
  117. }
  118. $("#proname").trigger('change');
  119. })
  120. //楼信息
  121. $("#proname").change(function() {
  122. $("#build").empty();
  123. floors = [];
  124. $('<option selected="selected" value="">请选择楼</option>').appendTo("#build");
  125. for (var g = 0; g < builds.length; g++) {
  126. $(builds[g]).each(function(q, p) {
  127. if (p.parentcode) {
  128. if ($("#proname").val() == p.parentcode) {
  129. $("<option value='" + p.code + "'>" + p.name + "</option>").appendTo("#build");
  130. if (p.entityJson != null && p.entityJson.length > 0) {
  131. floors.push(p.entityJson);
  132. }
  133. }
  134. }
  135. });
  136. }
  137. $("#build").selectpicker('refresh');
  138. if ($("#proname").val() == '') {
  139. $("#build").append('<option selected="selected" value="">请选择科室</option>');
  140. }
  141. // if ($("#build").val() == null || $("#build").val() == '') {
  142. if ($("#build").val() == null) {
  143. $("#build").append('<option selected="selected" value="">暂无数据</option>');
  144. }
  145. $("#build").trigger('change');
  146. })
  147. //楼层信息
  148. $("#build").change(function() {
  149. $("#floor").html('');
  150. $("#floor").append('<option selected="selected" value="">请选择科室</option>');
  151. for (var k = 0; k < floors.length; k++) {
  152. $(floors[k]).each(function(y, z) {
  153. if (z.parentcode) {
  154. if ($("#build").val() == z.parentcode) {
  155. $("<option value='" + z.code + "'>" + z.name + "</option>").appendTo("#floor");
  156. }
  157. }
  158. });
  159. }
  160. $("#floor").selectpicker('refresh');
  161. if ($("#build").val() == '') {
  162. $("#floor").append('<option selected="selected" value="">请选择楼层</option>');
  163. }
  164. // if ($("#floor").val() == null || $("#floor").val() == '') {
  165. if ($("#floor").val() == null) {
  166. $("#floor").append('<option selected="selected" value="">暂无数据</option>');
  167. }
  168. // $("#floor").trigger('change');
  169. })
  170. //
  171. // $("#floor").change(function() {
  172. // })
  173. }
  174. if (!isasync) {
  175. $.ajaxSettings.async = true;
  176. }
  177. })
  178. }
  179. //菜单下拉
  180. function getMenuLists() {
  181. $.getJSON(huayi.config.callcenter_url + '/equipmentapi/api/WoRepairBase/getwxwpstimetree', {
  182. }, function(result) {
  183. if(result.state.toLowerCase() == "success") {
  184. var defaultDatas = getTreeData(result.data)
  185. console.log(defaultDatas)
  186. var $sTree = $('#menusTreeView').treeview({
  187. color: "#428bca",
  188. expandIcon: 'glyphicon glyphicon-chevron-right',
  189. collapseIcon: 'glyphicon glyphicon-chevron-down',
  190. nodeIcon: 'fa fa-folder-o',
  191. //selectedIcon: "glyphicon glyphicon-stop",
  192. //icon: "glyphicon glyphicon-stop",
  193. //emptyIcon: 'glyphicon',
  194. //showCheckbox: true,
  195. selectable: true,
  196. state: {
  197. selected: true
  198. },
  199. data: defaultDatas,
  200. onNodeSelected: function(event, node) {
  201. $sTree.treeview('clearSearch');
  202. console.log(event, node)
  203. $('#menus').val(node.text);
  204. $('#menusName').val(node.name);
  205. $('#menus').attr('data-id', node.id);
  206. $('#menusTreeView').removeClass('show').addClass('hidden');
  207. },
  208. onNodeUnselected: function(event, node) {
  209. $('#menus').val('顶级分类');
  210. $('#menus').attr('data-id', '000000000000000000000000');
  211. }
  212. });
  213. $('#menusTreeView').treeview('collapseAll', {
  214. silent: true
  215. });
  216. var findSNodes = function() {
  217. return $sTree.treeview('search', [$('#menus').val(), {
  218. ignoreCase: false,
  219. exactMatch: false
  220. }]);
  221. };
  222. $('#menus').on('keyup', function(e) {
  223. var selectableNodes = findSNodes();
  224. // var m = $('#menusTreeView').treeview('getParent', selectableNodes);
  225. // $('#menusTreeView').treeview('selectNode', [ m, { silent: true } ]);
  226. });
  227. }
  228. })
  229. }
  230. function getTreeData (data) {
  231. var newData=[]
  232. data.forEach(function (ele) {
  233. newData.push({
  234. id: ele.id,
  235. parentid: ele.pid,
  236. // text: ele.wxcenter +'-'+ ele.name,
  237. name: ele.name,
  238. text: ele.wxcenter,
  239. children: (ele.child && ele.child.length > 0) ? getTreeData(ele.child) : []
  240. })
  241. })
  242. return newData
  243. }