/**
|
* date:
|
* author: neeler
|
*/
|
|
//test data start
|
// var data_doDel = Mock.mock('/enterprise/position/delItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
// var data_doSave = Mock.mock('/enterprise/position/saveItem.htm', {code: 0, errmsg: '此岗位正在使用中不能删除!'})
|
// var data_doBind = Mock.mock('/basicconfig/mapmaterial/bind.htm', {code: 0, })
|
// var data_doUnbind = Mock.mock('/basicconfig/mapmaterial/unbind.htm', {code: 0, })
|
//test data end
|
|
var TYPE = [{key: '全部', value: 0}, {key: '已映射', value: 1}, {key: '未映射', value: 2}]
|
|
var Obj = {
|
// sysDepartNo: '',
|
sysCompanyNo: '',
|
sysname: '',
|
companyNo: '',
|
cname: ''
|
}
|
|
window.I = {
|
PZ: 30,
|
keyword: $('#keyword'),
|
searchBtn: $('#searchBtn'),
|
newObj: $('#newObj')
|
}
|
|
var ViewModel = function() {
|
var self = this;
|
self.tList = ko.observableArray(TYPE);
|
self.skeyword = ko.observable();
|
self.ckeyword = ko.observable();
|
self.type = ko.observable();
|
self.list = ko.observableArray();
|
|
self.del = function(item) {
|
doDel(item);
|
}
|
self.unbind = function(item) {
|
doUnbind(item);
|
}
|
self.bind = function(item) {
|
ksdoBind(item);
|
if (item.cnorms() != '' && item.cnorms() != undefined) {
|
ksdoBind(item);
|
}
|
}
|
}
|
|
$(function () {
|
window.vm = new ViewModel();
|
ko.applyBindings(vm);
|
doSearch();
|
pageInit();
|
});
|
|
function pageInit() {
|
I.newObj.click(function (e) {
|
e.preventDefault();
|
vm.list.push(ko.mapping.fromJS(Obj));
|
refreshTypeahead();
|
});
|
I.searchBtn.click(function(event) {
|
doSearch();
|
});
|
I.keyword.on(ISIE ? 'keydown' : 'keyup', function (event) {
|
if (event.keyCode == 13) {
|
doSearch();
|
}
|
});
|
}
|
|
function doSearch() {
|
getList(vm.skeyword(), vm.ckeyword(), vm.type(), 0, I.PZ, 1);
|
}
|
|
function getList(skeyword, ckeyword, type, page, pagesize, pages) {
|
$.post('/basicconfig/mapmaterial/getList.htm', {
|
skeyword: skeyword,
|
ckeyword: ckeyword,
|
type: type,
|
page: page,
|
pagesize: pagesize,
|
pages: pages
|
}, function(data, textStatus, xhr) {
|
vm.list.removeAll();
|
if (data.code >= 1) {
|
// parent.showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
|
if (data.code == 0) {
|
if (isList(data.items)) {
|
$.each(data.items, function(index, val) {
|
val.cname = ko.observable(val.cname);
|
val.cnorms = ko.observable(val.cnorms);
|
val.cMaterielNo = ko.observable(val.cMaterielNo);
|
val.cunitname = ko.observable(val.cunitname);
|
val.num = ko.observable(val.cnum);
|
vm.list.push(val);
|
});
|
refreshTypeahead();
|
}
|
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){
|
getList(skeyword, ckeyword, type, num - 1, pagesize, 0);
|
});
|
}
|
}
|
return;
|
}
|
}, 'json');
|
}
|
|
function valid() {
|
return true;
|
}
|
|
function doSave() {
|
}
|
|
function doDel(item) {
|
var obj = ko.mapping.toJS(item);
|
console.log(obj);return;
|
$.post("/basicinfo/mapCompany/doDel.htm", {sysCompanyNo: obj.sysCompanyNo},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
//showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
vm.list.remove(item);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function validMsg(msg) {
|
$("#modalContent").html(msg);
|
$("#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" );
|
// doDel(item);
|
// }
|
// }
|
// ,
|
{
|
html: "<i class='ace-icon fa fa-times bigger-110'></i> 确定",
|
"class" : "btn btn-minier",
|
click: function() {
|
$( this ).dialog( "close" );
|
}
|
}
|
]
|
});
|
}
|
|
function refreshTypeahead() {
|
$('.mtableTypeahead').typeahead('destroy');
|
$('.mtableTypeahead').unbind('typeahead:select');
|
// $('.mtableTypeahead').unbind('typeahead:change');
|
var reception = new Bloodhound({
|
datumTokenizer: Bloodhound.tokenizers.whitespace,
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
remote: {
|
url: '/basicconfig/mapmaterial/typeahead.htm?query=%QUERY',
|
wildcard: '%QUERY'
|
}
|
});
|
|
$('.mtableTypeahead').typeahead(null, {
|
display: 'cname',
|
limit: 15,
|
source: reception,
|
templates: {
|
header: '<div id="bx"><span class="bh">编号</span><span class="mc">名称</span><span class="gg">规格</span><span class="dw">单位</span></div>',
|
suggestion: function(data) {
|
return '<div><span class="bh">' + data.cMaterielNo + '</span><span class="mc">' + data.cname + '</span><span class="gg">' + data.cnorms + '</span><span class="dw">' + data.cunitname + '</span></div>';
|
},
|
}
|
});
|
|
$('.mtableTypeahead').bind('typeahead:select', function(ev, suggestion) {
|
var index = $('.mtableTypeahead.tt-input').index($(this));
|
// index = Math.floor(index / 2);
|
// console.log(index);
|
doBind(index, suggestion);
|
// vm.list()[index].cname(suggestion.name);
|
// vm.list()[index].companyNo(suggestion.companyNo);
|
// $(this).data('_mlname', suggestion.name);
|
});
|
}
|
|
function ksdoBind(item) {
|
// console.log(item);
|
$.post("/basicconfig/mapmaterial/bind.htm", {
|
id: item.id,
|
erpID: item.erpid,
|
cname: item.cname(),
|
cnorms: item.cnorms(),
|
cMaterielNo: item.cMaterielNo(),
|
cnum: item.num()
|
},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
//showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
console.log('映射成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doBind(index, obj) {
|
var id = vm.list()[index].id;
|
var erpID = obj.id;
|
$.post("/basicconfig/mapmaterial/bind.htm", {
|
id: id,
|
erpID: obj.erpid,
|
cname: obj.cname,
|
cnorms: obj.cnorms,
|
cMaterielNo: obj.cMaterielNo,
|
num: vm.list()[index].num()
|
},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
//showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
console.log('映射成功!');
|
vm.list()[index].erpid = erpID;
|
vm.list()[index].cname(obj.cname);
|
vm.list()[index].cnorms(obj.cnorms);
|
vm.list()[index].cMaterielNo(obj.cMaterielNo);
|
vm.list()[index].cunitname(obj.cunitname);
|
return;
|
}
|
},
|
"json"
|
);
|
}
|
|
function doUnbind(item) {
|
var id = item.id;
|
var erpID = item.erpID;
|
$.post("/basicconfig/mapmaterial/unbind.htm", {
|
id: id,
|
erpID: erpID
|
},
|
function (data, textStatus, jqXHR) {
|
if (data.code >= 1) {
|
//showErrmsg(data.errmsg);
|
swal({title:'',text:data.errmsg,type:'error',confirmButtonText:'确定'});
|
return;
|
}
|
if (data.code == 0) {
|
item.cname('');
|
item.cnorms('');
|
item.cMaterielNo('');
|
item.cunitname('');
|
item.num('');
|
console.log('解除成功!');
|
return;
|
}
|
},
|
"json"
|
);
|
}
|