| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- //省市联动
- function getProvinceCity(ele1, isasync) {
- if (isasync != false) {
- isasync = true;
- }
- $.ajaxSettings.async = isasync;
- ele1.empty();
- ele1.append('<option selected="selected" value="">请选择省</option>');
- $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/equipment/getfivetree", function(data) {
- if (data.state.toLowerCase() == "success") {
- var province = data.data;
- var citys = []; //市
- var projects = []; //项目
- var builds = []; //楼
- var floors = []; //楼层
- $(data.data).each(function(i, n) {
- $("<option value='" + n.code + "' selected='selected'>" + n.name + "</option>").appendTo(ele1);
- ele1.selectpicker('refresh');
- if (n.entityJson != null && n.entityJson.length != 0) {
- citys.push(n.entityJson);
- for (var c = 0; c < citys.length; c++) {
- $(citys[c]).each(function(j, v) {
- if (v.parentcode > 0) {
- $("<option value='" + v.code + "' selected='selected'>" + v.name + "</option>").appendTo("#city");
- $("#city").selectpicker('refresh');
- if (v.entityJson != null && v.entityJson.length > 0) {
- projects.push(v.entityJson);
- }
- }
- });
- }
- for (var j = 0; j < projects.length; j++) {
- $(projects[j]).each(function(i, n) {
- if (n.parentcode > 0) {
- $('#protype_addText').val(n.protypename);
- $('#protype_addNode').val(n.protypeid);
- $("<option value='" + n.code + "' selected='selected'>" + n.name + "</option>").appendTo("#proname");
- $("#proname").selectpicker('refresh');
- if (n.entityJson != null && n.entityJson.length > 0) {
- builds.push(n.entityJson);
- }
- }
- });
- }
- for (var g = 0; g < builds.length; g++) {
- $(builds[g]).each(function(q, p) {
- if (p.parentcode) {
- $("<option value='" + p.code + "'>" + p.name + "</option>").appendTo("#build");
- $("#build").selectpicker('refresh');
- if (p.entityJson != null && p.entityJson.length > 0) {
- floors.push(p.entityJson);
- }
- }
- });
- }
- for (var k = 0; k < floors.length; k++) {
- $(floors[k]).each(function(y, z) {
- if (z.parentcode) {
- $("<option value='" + z.code + "'>" + z.name + "</option>").appendTo("#floor");
- $("#floor").selectpicker('refresh');
- }
- });
- }
- }
- })
- //市级信息
- $("#province").change(function() {
- $("#city").empty();
- projects = [];
- for (var i = 0; i < citys.length; i++) {
- $(citys[i]).each(function(j, v) {
- if (v.parentcode > 0) {
- if ($("#province").val() == v.parentcode) {
- $("<option value='" + v.code + "'>" + v.name + "</option>").appendTo("#city");
- if (v.entityJson != null && v.entityJson.length > 0) {
- projects.push(v.entityJson);
- }
- }
- }
- });
- }
- $("#city").selectpicker('refresh');
- if ($("#province").val() == '') {
- $("#city").append('<option selected="selected" value="">请选择所在市</option>');
- }
- if ($("#city").val() == null) {
- $("#city").append('<option selected="selected" value="">暂无数据</option>');
- }
- $("#city").trigger('change');
- })
- //项目信息
- $("#city").change(function() {
- $("#proname").empty();
- builds = [];
- $('#protype_addText').val('');
- $('#protype_addNode').val('');
- for (var j = 0; j < projects.length; j++) {
- $(projects[j]).each(function(i, n) {
- if (n.parentcode > 0) {
- if ($("#city").val() == n.parentcode) {
- $('#protype_addText').val(n.protypename);
- $('#protype_addNode').val(n.protypeid);
- $("<option value='" + n.code + "'>" + n.name + "</option>").appendTo("#proname");
- if (n.entityJson != null && n.entityJson.length > 0) {
- builds.push(n.entityJson);
- }
- }
- }
- });
- }
- $("#proname").selectpicker('refresh');
- if ($("#city").val() == '') {
- $("#proname").append('<option selected="selected" value="">请选择项目</option>');
- }
- if ($("#proname").val() == null || $("#proname").val() == '') {
- $("#proname").append('<option selected="selected" value="">暂无数据</option>');
- }
- $("#proname").trigger('change');
- })
- //楼信息
- $("#proname").change(function() {
- $("#build").empty();
- floors = [];
- $('<option selected="selected" value="">请选择楼</option>').appendTo("#build");
- for (var g = 0; g < builds.length; g++) {
- $(builds[g]).each(function(q, p) {
- if (p.parentcode) {
- if ($("#proname").val() == p.parentcode) {
- $("<option value='" + p.code + "'>" + p.name + "</option>").appendTo("#build");
- if (p.entityJson != null && p.entityJson.length > 0) {
- floors.push(p.entityJson);
- }
- }
- }
- });
- }
- $("#build").selectpicker('refresh');
- if ($("#proname").val() == '') {
- $("#build").append('<option selected="selected" value="">请选择科室</option>');
- }
- // if ($("#build").val() == null || $("#build").val() == '') {
- if ($("#build").val() == null) {
- $("#build").append('<option selected="selected" value="">暂无数据</option>');
- }
- $("#build").trigger('change');
- })
- //楼层信息
- $("#build").change(function() {
- $("#floor").html('');
- $("#floor").append('<option selected="selected" value="">请选择科室</option>');
- for (var k = 0; k < floors.length; k++) {
- $(floors[k]).each(function(y, z) {
- if (z.parentcode) {
- if ($("#build").val() == z.parentcode) {
- $("<option value='" + z.code + "'>" + z.name + "</option>").appendTo("#floor");
- }
- }
- });
- }
- $("#floor").selectpicker('refresh');
- if ($("#build").val() == '') {
- $("#floor").append('<option selected="selected" value="">请选择楼层</option>');
- }
- // if ($("#floor").val() == null || $("#floor").val() == '') {
- if ($("#floor").val() == null) {
- $("#floor").append('<option selected="selected" value="">暂无数据</option>');
- }
- // $("#floor").trigger('change');
- })
- //
- // $("#floor").change(function() {
-
- // })
- }
- if (!isasync) {
- $.ajaxSettings.async = true;
- }
- })
- }
- //菜单下拉
- function getMenuLists() {
- $.getJSON(huayi.config.callcenter_url + '/equipmentapi/api/WoRepairBase/getwxwpstimetree', {
- }, function(result) {
- if(result.state.toLowerCase() == "success") {
- var defaultDatas = getTreeData(result.data)
- console.log(defaultDatas)
- 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');
- console.log(event, node)
- $('#menus').val(node.text);
- $('#menusName').val(node.name);
- $('#menus').attr('data-id', node.id);
- $('#menusTreeView').removeClass('show').addClass('hidden');
- },
- onNodeUnselected: function(event, node) {
- $('#menus').val('顶级分类');
- $('#menus').attr('data-id', '000000000000000000000000');
- }
- });
- $('#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();
- // var m = $('#menusTreeView').treeview('getParent', selectableNodes);
- // $('#menusTreeView').treeview('selectNode', [ m, { silent: true } ]);
- });
- }
- })
- }
- function getTreeData (data) {
- var newData=[]
- data.forEach(function (ele) {
- newData.push({
- id: ele.id,
- parentid: ele.pid,
- // text: ele.wxcenter +'-'+ ele.name,
- name: ele.name,
- text: ele.wxcenter,
- children: (ele.child && ele.child.length > 0) ? getTreeData(ele.child) : []
- })
- })
- return newData
- }
|