/**
|
* date:
|
* author: neeler
|
*/
|
|
// test data start
|
// var data_getList = Mock.mock('/area/getList.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null,
|
// "list":[
|
// {"name":"河南省","bianhao":"01","xsbianhao":"01","mx":false,'jishu':1},
|
// {"name":"河南省郑州市","bianhao":"0101","xsbianhao":"01","mx":true,'jishu':2},
|
// {"name":"河南省洛阳市","bianhao":"0102","xsbianhao":"02","mx":false,'jishu':2},
|
// {"name":"河南省洛阳市偃师市","bianhao":"010201","xsbianhao":"01","mx":true,'jishu':3},
|
// {"name":"山东省","bianhao":"02","xsbianhao":"02","mx":false,'jishu':1}
|
// ],"hint":null,"errmsg":null,"code":0})
|
// var data_gecmtList = Mock.mock('/area/getallCMlist.htm', {"rowCount":0,"pagesize":0,"pages":0,"page":0,"items":null,
|
// "list":[
|
// {"name":"郑州鑫玉升运输有限公司","companyNo":"001"},
|
// {"name":"河南天海物流有限公司","companyNo":"002"},
|
// {"name":"洛阳市汇宇汽车运输有限公司","companyNo":"003"},
|
// {"name":"河南龙威货运有限公司","companyNo":"004"},
|
// {"name":"王学寨","companyNo":"005"}
|
// ],"hint":null,"errmsg":null,"code":0})
|
// var date_getsecmlist = Mock.mock('/area/getcmList.htm', {code: 0, item: '001,003' })
|
// var data_delItem = Mock.mock('/area/delItem.htm', {code: 0, errmsg: '删除失败!'})
|
// var data_saveItem = Mock.mock('/area/saveItem.htm', {code: 0, errmsg: '保存成功!'})
|
|
window.I = {
|
PZ: 25,
|
Page:0,
|
Pages:1,
|
addSibling: $('#addSibling'),
|
addChild: $('#addChild'),
|
search: $('#search'),
|
save: $('#save'),
|
DB_ep: {},
|
GLXJ:$('#GLXJ'),
|
CC_ep:{}
|
}
|
|
function EnterpriseObj() {
|
return {
|
name: '',
|
bianhao: '',//编号
|
jishu:'',//级数
|
code: '',//显示的编号
|
pbianhao:'',//父节点
|
isadd:false//是否是新增
|
}
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
//待编辑对象
|
self.o = ko.observable(ko.mapping.fromJS(EnterpriseObj()));
|
//是否可以删除
|
// self.canDelete = ko.observable(false);
|
//是否可以添加子节点
|
// self.canAddChild = ko.observable(false);
|
// 是否修改下级
|
self.canGLXJ=ko.observable(false);
|
//删除操作
|
// self.del = function() {
|
// delConfirm();
|
// }
|
//已选择的物流公司
|
self.selectedList=ko.observableArray();
|
//全部的物流公司
|
self.allCMlist=ko.observableArray();
|
//业务单元编号
|
self.ywdyNoVal=ko.observable('103');
|
self.ywdychange=function(){
|
getselectedCMlist(I.selectedId);
|
}
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
getList(I.search.val(),I.Page,I.PZ,I.Pages);
|
pageInit();
|
getallCMlist();
|
});
|
|
function pageInit() {
|
I.save.click(function(event) {
|
saveItem();
|
});
|
// I.addSibling.click(function(event) {
|
// var o = EnterpriseObj();
|
// o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu;
|
// o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao.substring(0,I.DB_ep[I.selectedId].bianhao.length-2);
|
// vm.o(ko.mapping.fromJS(o));
|
// vm.selectedList([]);
|
// $('#dp').val('').trigger("chosen:updated");
|
// I.GLXJ.attr("checked",false);
|
// vm.canGLXJ(false);
|
// });
|
// I.addChild.click(function(event) {
|
// var o = EnterpriseObj();
|
// o.jishu = I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].jishu;
|
// o.jishu+=1;
|
// o.pbianhao=I.DB_ep[I.selectedId] && I.DB_ep[I.selectedId].bianhao;
|
// vm.o(ko.mapping.fromJS(o));
|
// vm.selectedList([]);
|
// $('#dp').val('').trigger("chosen:updated");
|
// I.GLXJ.attr("checked",false);
|
// vm.canGLXJ(false);
|
// });
|
I.search.keyup(function(event) {
|
// var to = false;
|
// if(to) {
|
// clearTimeout(to);
|
// }
|
// to = setTimeout(function () {
|
// var v = I.search.val();
|
// $('#jstree_Enterprise').jstree(true).search(v);
|
// }, 250);
|
if(event.keyCode ==13){
|
getList(I.search.val(),0,I.PZ,1);
|
}
|
});
|
I.GLXJ.change(function(event){
|
if(I.GLXJ.prop("checked")){
|
I.GLXJ.attr("checked",true);
|
}else{
|
I.GLXJ.attr("checked",false);
|
}
|
});
|
}
|
|
function getList(keyword, page, pagesize, pages) {
|
$.post('/area/getList.htm', {
|
search: keyword,
|
page: page,
|
pagesize: 0,
|
pages: 0
|
}, function(data, textStatus, xhr) {
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
I.CC_ep={};
|
if (!!$('#jstree_Enterprise').jstree(true)) {
|
$('#jstree_Enterprise').jstree(true).refresh();
|
}
|
if (isList(data.list)) {
|
$.jstree.destroy();
|
// vm.canAddChild(true);
|
var Arr = [];
|
var level = 0;
|
$.each(data.list, function(index, val) {
|
//顶级
|
val.jishu=1;
|
if(I.CC_ep[val.code.substring(0,2)]!=null && I.CC_ep[val.code.substring(0,2)]!=''){
|
jishu=2;
|
}else{
|
I.CC_ep[val.code.substring(0,2)]=val.code;
|
jishu=1;
|
}
|
val.jishu=jishu;
|
I.DB_ep[val.code] = val;
|
if(val.fd_companyS==null){
|
val.fd_companyS=[];
|
}
|
if (jishu==1) {
|
Arr.push({
|
text: val.code + ' ' + val.name,
|
id: val.code,
|
companyS:val.fd_companyS,
|
children: [],
|
state: index === 0 ? {selected: true} : ''
|
});
|
} else {
|
var j = 2;
|
var children = Arr[Arr.length - 1].children;
|
while (j < val.jishu) {
|
children = children[children.length - 1].children;
|
j++;
|
}
|
children.push({
|
text: val.code + ' ' + val.name,
|
id: val.code,
|
companyS:val.fd_companyS,
|
children: []
|
})
|
}
|
});
|
$('#jstree_Enterprise')
|
.jstree({
|
core: {
|
check_callback : true,
|
data: Arr,
|
themes: {
|
// stripes: true
|
}
|
},
|
types: {
|
"default" : {
|
"icon" : false // 删除默认图标
|
},
|
},
|
plugins : [
|
'search',
|
'types',
|
'themes'
|
]
|
})
|
.on("changed.jstree", function (e, data) {
|
if(data.selected.length) {
|
var selected = data.instance.get_node(data.selected[0]);
|
var id = selected.id;
|
I.selectedId = id;
|
clearValid();
|
vm.selectedList.removeAll();
|
if(isList(selected.original.companyS)){
|
$.each(selected.original.companyS, function(index, val) {
|
vm.selectedList.push(val.companyNo);
|
});
|
}else{
|
vm.selectedList([]);
|
}
|
$('#dp').val(vm.selectedList()).trigger("chosen:updated");
|
vm.o(ko.mapping.fromJS(I.DB_ep[id]));
|
// vm.canDelete(!selected.children.length);
|
if(vm.o().jishu()==1){
|
vm.canGLXJ(true);
|
}else{
|
vm.canGLXJ(false);
|
}
|
getselectedCMlist(id);
|
I.GLXJ.attr("checked",false);
|
}
|
})
|
.on("ready.jstree", function(e, data) {
|
data.instance.open_all(-1);
|
$('.page-content').height($('#jstree_Enterprise').height()+50);
|
})
|
.on("after_open.jstree",function(e, data){
|
$('.page-content').height($('#jstree_Enterprise').height()+50);
|
})
|
.on("after_close.jstree",function(e, data){
|
$('.page-content').height($('#jstree_Enterprise').height()+50);
|
})
|
}
|
|
if (!!pages) {
|
pages = data.pages;
|
$('#pagdiv').unbind('page').empty();
|
if (pages > 1) {
|
$('#pagdiv').bootpag({total: pages, maxVisible: 10, page: page + 1}).on('page',function(event,num){
|
I.Page=num-1;
|
I.Pages=0;
|
getList(keyword,num - 1, pagesize, 0);
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
//获取全部的物流公司
|
function getallCMlist() {
|
$.post("/area/getallCMlist.htm",
|
function (data, textStatus, jqXHR) {
|
vm.allCMlist.removeAll();
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (isList(data.list)) {
|
$.each(data.list, function(index, val) {
|
vm.allCMlist.push(val);
|
});
|
$('.chosen-select').chosen({search_contains: true});
|
}
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
//获取已选择的物流公司
|
function getselectedCMlist(bianhao) {
|
$.post('/area/getcmList.htm', {bianhao:bianhao,ywdyNo:vm.ywdyNoVal()}, function(data, textStatus, xhr) {
|
vm.selectedList.removeAll();
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
if (data.item) {
|
vm.selectedList(data.item.split(','));
|
} else {
|
vm.selectedList([]);
|
}
|
$('#dp').val(vm.selectedList()).trigger("chosen:updated");
|
return;
|
}
|
}, 'json');
|
}
|
|
// function delItem() {
|
// var id = I.selectedId;
|
// if (!id && !!I.AjaxDelItem) return;
|
// I.AjaxDelItem = true;
|
// $.post('/area/delItem.htm', {bianhao: id}, function(data, textStatus, xhr) {
|
// I.AjaxDelItem = false;
|
// if (data.code >= 1) {
|
// swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
// return;
|
// }
|
// if (data.code == 0) {
|
// var ref = $('#jstree_Enterprise').jstree(true),
|
// sel = ref.get_selected();
|
// if(!sel.length) { return false; }
|
// ref.select_node(ref.get_prev_dom(sel));
|
// ref.delete_node(sel);
|
// }
|
// }, 'json');
|
// }
|
|
function saveItem() {
|
if (!I.AjaxSaveItem && valid()) {
|
I.AjaxSaveItem = true;
|
var o = ko.mapping.toJS(vm.o());
|
// if(o.bianhao==null||o.bianhao==''){
|
// if(o.pbianhao==''&&o.jishu!=1){
|
// swal({title:'',text:'数据错误,请刷新页面重新操作!',type:'error',confirmButtonText:'确定'});
|
// return
|
// }
|
// if(o.pbianhao==''){
|
// o.bianhao=o.xsbianhao;
|
// }else{
|
// o.bianhao=o.pbianhao+o.xsbianhao;
|
// }
|
// }
|
o.companyNos='';
|
if(!!vm.selectedList()){
|
for(var i=0;i<vm.selectedList().length;i++){
|
if(o.companyNos==''){
|
o.companyNos=vm.selectedList()[i];
|
}else{
|
o.companyNos=o.companyNos+','+vm.selectedList()[i];
|
}
|
}
|
}
|
o.GLXJ=I.GLXJ.prop("checked");
|
o.ywdyNo=vm.ywdyNoVal();
|
$.post('/area/saveItem.htm', o, function(data, textStatus, xhr) {
|
I.AjaxSaveItem = false;
|
if (data.code >= 1) {
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
parent.showErrmsg('保存成功!');
|
getList(I.search.val(),I.Page,I.PZ,I.Pages);
|
return;
|
}
|
}, 'json');
|
}
|
}
|
|
function valid(){
|
var isValid = false;
|
var iF = $('#form');
|
iF.validate({
|
rules: {
|
'xsbianhao': {
|
required: true,
|
rangelength:[2,2],
|
},
|
'name': {
|
required: true
|
}
|
},
|
messages: {
|
'xsbianhao': {
|
required: '编号不能为空!',
|
rangelength:'编号必须是两位数字',
|
},
|
'name': {
|
required: '名称不能为空!'
|
}
|
},
|
errorPlacement: function (err, element) {
|
var p = element.parents('.col-sm-9').eq(0);
|
var d = p.children('.text-error').eq(0);
|
d.css('color', '#D9534F');
|
err.appendTo(d);
|
}
|
})
|
isValid = iF.valid();
|
return isValid;
|
}
|
|
function clearValid() {
|
$('input[type="text"]').removeClass('error');
|
$('span.text-error').text('');
|
}
|
|
// function delConfirm() {
|
// $("#modalContent").html('确定要删除【' + I.DB_ep[I.selectedId].name + '】吗?');
|
// $("#dialog-confirm").removeClass('hide').dialog({
|
// resizable: false,
|
// width: '320',
|
// modal: true,
|
// title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i>确认信息</h4></div>",
|
// title_html: true,
|
// position: { my: "center", at: "center", of: window },
|
// buttons: [
|
// {
|
// html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> 确定",
|
// "class" : "btn btn-danger btn-minier",
|
// click: function() {
|
// $( this ).dialog( "close" );
|
// delItem();
|
// }
|
// }
|
// ,
|
// {
|
// html: "<i class='ace-icon fa fa-times bigger-110'></i> 取消",
|
// "class" : "btn btn-minier",
|
// click: function() {
|
// $( this ).dialog( "close" );
|
// }
|
// }
|
// ]
|
// });
|
// }
|
|
|
// function getChooseWLGS( ){
|
|
// }
|