//省市项目三级联动 var Adress = [], departPicker, departMent = []; // getPro(); var phone=/^\d{3,12}$/; var projectid=localStorage.getItem("projectid"); var ids= helper.request.queryString("id"); var floorid= helper.request.queryString("floorid"); var goods= helper.request.queryString("goods"); $(function(){ if(ids){ adressDetail();//获取详情 } if(floorid){ getQRfloor();//用扫码获取楼层id 获取地址详情 } getBuild(); }) //楼下拉 function getBuild() { $.ajax({ type: "get", url: huayi.config.callcenter_url + 'equipmentapi/api/equipment/getaddresstree', async: false, data: { projectid: projectid }, dataType: 'json', success: function(data) { var type_data = data.data; if(type_data != null && type_data.length > 0) { $(type_data).each(function(i, n) { var obj = {}; obj.value = n.id; obj.text = n.name; if(n.entityJson != null && n.entityJson.length > 0) { var children2 = []; $(n.entityJson).each(function(j, k) { var obj2 = {}; obj2.value = k.code; obj2.text = k.name+" "+k.departmentname; obj2.floorName = k.name; obj2.depname = k.departmentname; children2.push(obj2); }) obj.children = children2; } Adress.push(obj); }) } } }); } //科室下拉 function GetDepartment() { departMent = []; $.ajax({ type: "get", url: huayi.config.callcenter_url + 'configurationapi/api/Department/getlistdrop', // url: 'http://192.168.5.46:28000/configurationapi/api/Department/getlistdrop', async: false, data: { projectid: $('#proNameCode').val(), building: $('#buildCode').val(), floorid: $('#floorCode').val() }, dataType: 'json', success: function(data) { var result = data.data; // departMent = JSON.parse(JSON.stringify(defaultDatas).replace(/departmenname/g, "text")); // departMent = JSON.parse(JSON.stringify(defaultDatas).replace(/id/g, "value")); // departMent = JSON.parse(JSON.stringify(defaultDatas).replace(/\[\]/g, null)); if(result != null && result.length > 0) { departMent = filterTreeDatas(result); departPicker.setData(departMent); } else { departPicker.setData(departMent); } } }); } function filterTreeDatas(treeDatas) { var accessedRouters = []; var j = -1; for(var i in treeDatas) { j++; accessedRouters.push({ value: treeDatas[i].id, text: treeDatas[i].departmenname }); if(treeDatas[i].children) { // filterTreeDatas( // treeDatas[i].children // ); $.each(treeDatas[i].children, function(k, v) { accessedRouters.push({ value: v.id, text: v.departmenname }); if(v.children) { $.each(v.children, function(q, r) { accessedRouters.push({ value: r.id, text: r.departmenname }); }); } }); } } return accessedRouters; } //填充数据 (function($, doc) { $.init(); $.ready(function() { //位置 // var proPicker = new $.PopPicker(); // proPicker.setData(proData); // var showZhuTiPickerButton_ = doc.getElementById('showLocation'); // var zhuTiPicker_ = doc.getElementById('proNameText'); // showZhuTiPickerButton_.addEventListener('tap', function(event) { // proPicker.show(function(items) { // zhuTiPicker_.value = items[0].text; // doc.getElementById('proNameCode').value = items[0].value; // doc.getElementById('buildName').value = ""; // doc.getElementById('buildCode').value = ""; // doc.getElementById('floorCode').value = ""; //// getBuild(); // // if (Adress.length == 0) { // // doc.getElementById('buildName').setAttribute("placeholder", "暂无数据"); // // } else { // // doc.getElementById('buildName').setAttribute("placeholder", "请选择报修地点"); // // } // // //返回 false 可以阻止选择框的关闭 // //return false; // }); // }, false); //报修地点 楼 var blildPicker = new $.PopPicker({ layer: 2 }); blildPicker.setData(Adress); var ShowBuildPickerButton = doc.getElementById('showBuildPicker'); var BuildResult = doc.getElementById('buildName'); ShowBuildPickerButton.addEventListener('tap', function(event) { if(Adress.length > 0) { blildPicker.show(function(items) { BuildResult.value = (items[0].text ? items[0].text : "") + " " + (items[1].floorName ? items[1].floorName : ""); doc.getElementById('buildCode').value = items[0].value ? items[0].value : ""; doc.getElementById('floorCode').value = items[1].value ? items[1].value : ""; // doc.getElementById('departmentCode').value = ""; doc.getElementById('departmentVal').value =items[1].depname ? items[1].depname : ""; //返回 false 可以阻止选择框的关闭 //return false; // GetDepartment(); //科室 }); } }, false); //科室下拉 // departPicker = new $.PopPicker(); // var showDepartPickerButton_ = doc.getElementById('department'); // var departResult = doc.getElementById('departmentVal'); // showDepartPickerButton_.addEventListener('tap', function(event) { // if(departMent.length > 0) { // departPicker.show(function(items) { // departResult.value = items[0].text; // doc.getElementById('departmentCode').value = items[0].value ? items[0].value : ""; // //返回 false 可以阻止选择框的关闭 // //return false; // }); // } // // }, false); }) })(mui, document); //获取地址详情 function adressDetail(){ $.ajax({ type:"get", url:huayi.config.callcenter_url +"distributionapi/api/DistriAddress/getsingle", async:true, dataType:'json', data:{ id:ids }, success:function(result){ if(result.state.toLowerCase()=='success'){ $('#buildCode').val(result.data.buildingid), //楼 $('#buildName').val(result.data.buildingname+" "+result.data.floorname), //楼 文本 $('#floorCode').val(result.data.floorid); //楼层 $('#departmentVal').val(result.data.departmentname); //科室文本 // $('#departmentCode').val(result.data.departmentid); //科室id $("#contactName").val(result.data.fullname); $('#contactPhone').val(result.data.mobile); } } }); } //保存地址 function addSaveAdress(type){ var ajaxUrl; if(ids){ ajaxUrl="distributionapi/api/DistriAddress/update" }else{ ajaxUrl="distributionapi/api/DistriAddress/add" } $.ajax({ type:"post", url: huayi.config.callcenter_url + ajaxUrl, async:true, dataType:'json', beforeSend: function() { //触发ajax请求开始时执行 mui('#HY_add').button('loading'); // loadIndex = layer.load(); }, data:{ id:ids, addresstype:type,//0发货/1收货 projectid:projectid,//是 string 项目名称id buildingid: $('#buildCode').val(), //是 string 楼宇名称id floorid:$('#floorCode').val(), //是 string 层数id // departmentid:$('#departmentCode').val(),//否 string 科室id fullname:$('#contactName').val(), //否 string 姓名 mobile:$('#contactPhone').val() //否 string 电话 }, success:function(result){ if(result.state.toLowerCase()=='success'){ mui.alert('地址保存成功!'); mui('#HY_add').button('reset'); // $('#proNameText').val(''); //项目文本 // $('#proNameCode').val(''); //项目id $('#buildCode').val(''), //楼 $('#buildName').val(''), //楼 文本 $('#floorCode').val(''); //楼层 $('#departmentVal').val(''); //科室文本 // $('#departmentCode').val(''); //科室id $("#contactName").val(''); $('#contactPhone').val(''); window.location.href ='./GoodsDelivery.html?id='+ids+'&goods='+goods } } }); } // 用扫码获取楼层id 获取地址详情 function getQRfloor(){ $.ajax({ type: "get", url: huayi.config.callcenter_url + 'equipmentapi/api/Equipment/gettreeinfo', async: true, data: { floorid: floorid }, dataType: 'json', success: function (data) { if (data.state.toLowerCase() == "success") { $('#buildCode').val(data.data.bulidid), //楼 $('#buildName').val(data.data.bulidname+" "+data.data.floorname), //楼 文本 $('#floorCode').val(data.data.floorid); //楼层 $('#departmentVal').val(data.data.remark); //科室文本 } } }); }