Authored by kuangjiahua

直通车优化

... ... @@ -24,7 +24,7 @@
<a id="all-btn" href="javascript:;" class="btn btn-info">全部</a>
</div>
<div class="panel-col">
<a id="batchUnChoose-btn" href="javascript:;" class="btn btn-success" hidden>取消选中</a>
<a id="batchUnChoose-btn" href="javascript:;" class="btn btn-danger" hidden>取消选中</a>
<a id="batchChoose-btn" href="javascript:;" class="btn btn-success" hidden>选中</a>
</div>
</div>
... ...
... ... @@ -2,14 +2,22 @@
var $ = require('jquery'),
common = require('../../../common/common');
//存储批量选中的sourceId
//存储批量选中的直通车Id
window.batchChooseSourceIds = [];
//存储批量选中的直通车名称
window.batchChooseSourceNames = [];
//存储批量取消选中的sourceId
//存储批量取消选中的直通车Id
window.batchUnChooseSourceIds = [];
//存储批量取消选中的直通车名称
window.batchUnChooseSourceNames = [];
//标签
window.status=0;
$("#batchChoose-btn").show();
$("#batchUnChoose-btn").hide();
var pageUnSourceIds = [];
var pageUnChooseSourceIds = [];
var pageChooseSourceIds = [];
var pageSourceIds=[];
var EMUN = {
status: {
... ... @@ -18,26 +26,14 @@ var EMUN = {
}
}
//筛选
$(document).on('click', '#filter-btn', function () {
var state = $('.state-select').find('.current').find('input').val();
if(state == 1){
sc.reload(1);
}else{
g.reload(1);
}
});
var pageChooseSourceIds = [];
var g = new common.grid({
el: "#basicTable",
parms: function() {
return {
state: 0,
sourceName: common.util.__input("sourceName"),
categoryId: getCategoryId()
categoryId: getCategoryId(),
}
},
columns: [
... ... @@ -50,14 +46,14 @@ var g = new common.grid({
return htmlContent;
}
if(batchChooseSourceIds.length == 0 ){
htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' class='g_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
}else{
$.each(batchChooseSourceIds,function(n,value) {
if(item.sourceId == value){
htmlContent = "<input type='checkbox' checked='checked' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' checked='checked' class='g_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
return false
}else{
htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' class='g_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
}
})
}
... ... @@ -69,7 +65,7 @@ var g = new common.grid({
name: 'sourceId',
render: function (item) {
if(item.state != 1) {
pageChooseSourceIds.push(item.sourceId);
pageSourceIds.push(item.sourceId);
}
return item.sourceId;
}
... ... @@ -98,53 +94,22 @@ var g = new common.grid({
}
}],
selectedCallback:function(item){
if($.inArray(item.sourceId, batchChooseSourceIds) === -1 ){
batchChooseSourceIds.push(item.sourceId);
batchChooseSourceNames.push(item.sourceName);
}
},
unselectedCallback:function(item){
var _index = $.inArray(item.sourceId, batchChooseSourceIds);
if( _index !== -1 ){
batchChooseSourceIds.splice(_index,1);
batchChooseSourceNames.splice(_index, 1);
}
},
complete:function(){
$.each(pageChooseSourceIds, function (i, pageItem) {
if($.inArray(pageItem, batchChooseSourceIds) == -1 ) {
$(".wqt_all").prop("checked", false);
return false;
}
$(".wqt_all").prop("checked", true);
});
pageChooseSourceIds = [];
pageChooseSourceIds = pageSourceIds;
var allChecked = isAllChecked(pageChooseSourceIds, batchChooseSourceIds);
$(".wqt_all").prop("checked", allChecked);
pageSourceIds = [];
}
});
g.init('/categorySource/queryCategorySourceList');
$("#batchChoose-btn").show();
$("#batchUnChoose-btn").hide();
//全部
$(document).on('click', '#all-btn', function () {
var state = $('.state-select').find('.current').find('input').val();
$('#sourceName').val('');
if(state == 1){
sc.reload(1);
}else{
g.reload(1);
}
});
var pageUnChooseSourceIds = [];
var sc = new common.grid({
el: "#basicTable",
parms: function() {
return {
state: 1,
sourceName: common.util.__input("sourceName"),
categoryId: getCategoryId()
categoryId: getCategoryId(),
}
},
columns: [
... ... @@ -154,14 +119,14 @@ var sc = new common.grid({
render: function (item) {
var htmlContent = "";
if(batchUnChooseSourceIds.length === 0 ){
htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' class='sc_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
}else{
$.each(batchUnChooseSourceIds,function(n,value) {
if(item.sourceId == value){
htmlContent = "<input type='checkbox' checked='checked' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' checked='checked' class=sc_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
return false
}else{
htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
htmlContent = "<input type='checkbox' class='sc_checkbox' _id='"+item.sourceId+"' _sourceName='"+item.sourceName+"' data-index='"+item.__index+"'>";
}
})
}
... ... @@ -171,7 +136,7 @@ var sc = new common.grid({
display: '资源位直通车id',
name: 'sourceId',
render: function (item) {
pageUnChooseSourceIds.push(item.sourceId);
pageUnSourceIds.push(item.sourceId);
return item.sourceId;
}
},
... ... @@ -194,47 +159,85 @@ var sc = new common.grid({
return '<a class="btn btn-xs btn-warning close-btn" data-title="' + item.sourceName + '" _id="' + item.sourceId + '" href="javascript:;">取消选中</a>';
}
}],
selectedCallback:function(item){
if($.inArray(item.sourceId, batchUnChooseSourceIds) === -1 ){
batchUnChooseSourceIds.push(item.sourceId);
batchUnChooseSourceNames.push(item.sourceName);
}
},
unselectedCallback:function(item){
var _index = $.inArray(item.sourceId, batchUnChooseSourceIds);
if(_index !== -1 ){
batchUnChooseSourceIds.splice(_index,1);
batchUnChooseSourceNames.splice(_index, 1);
}
},
complete:function(){
$.each(pageUnChooseSourceIds, function (i, pageItem) {
if($.inArray(pageItem, batchUnChooseSourceIds) == -1 ) {
$(".wqt_all").prop("checked", false);
return false;
}
$(".wqt_all").prop("checked", true);
});
pageUnChooseSourceIds = [];
pageUnChooseSourceIds = pageUnSourceIds;
var allChecked = isAllChecked(pageUnChooseSourceIds, batchUnChooseSourceIds);
$(".wqt_all").prop("checked", allChecked);
pageUnSourceIds = [];
}
});
g.init('/categorySource/queryCategorySourceList');
//筛选
$(document).on('click', '#filter-btn', function () {
var state = $('.state-select').find('.current').find('input').val();
if(state == 1){
batchUnChooseSourceIds=[];
batchUnChooseSourceNames=[];
sc.reload(1);
}else{
batchChooseSourceIds=[];
batchChooseSourceIds=[];
g.reload(1);
}
});
//全部
$(document).on('click', '#all-btn', function () {
var state = $('.state-select').find('.current').find('input').val();
$('#sourceName').val('');
if(state == 1){
sc.reload(1);
}else{
g.reload(1);
}
});
$(document).on('change', '.wqt_all', function () {
var selected = $(this).prop("checked");
if(status == 0){
$(".g_checkbox").each(function() {
$(this).prop("checked",selected);
gCheckBox($(this));
});
}else{
$(".sc_checkbox").each(function() {
$(this).prop("checked",selected);
scCheckBox($(this));
});
}
});
$(document).on('change', '.g_checkbox', function () {
gCheckBox($(this));
});
$(document).on('change', '.sc_checkbox', function () {
scCheckBox($(this));
});
$('input[name="state"]').on('change', function() {
$(this).parent().addClass('current').siblings().removeClass('current');
var state = $('.state-select').find('.current').find('input').val();
$('#sourceName').val('');
batchUnChooseSourceIds = [];
batchUnChooseSourceNames = [];
batchChooseSourceIds = [];
batchChooseSourceNames = [];
if(state == 0){
batchChooseSourceIds = [];
batchChooseSourceNames = [];
$("#batchChoose-btn").show();
$("#batchUnChoose-btn").hide();
g.init('/categorySource/queryCategorySourceList');
status = 0;
}else if(state == 1){
batchUnChooseSourceIds = [];
batchUnChooseSourceNames = [];
$("#batchChoose-btn").hide();
$("#batchUnChoose-btn").show();
sc.init('/categorySource/queryCategorySourceList');
status = 1;
}
});
... ... @@ -369,7 +372,6 @@ $(document).on('click', '.remove-btn', function() {
function getCategoryId() {
var categoryId = $('#categoryId').val();
categoryId = categoryId ? categoryId : getCategoryIdFromUrl();
if(categoryId) {
return categoryId;
} else {
... ... @@ -377,6 +379,64 @@ function getCategoryId() {
return "";
}
}
function push(id,name,idArr,nameArr){
var chooseId = parseInt(id);
if($.inArray(chooseId, idArr) === -1 ){
idArr.push(chooseId);
nameArr.push(name);
}
}
function splice(id,idArr,nameArr){
var chooseId = parseInt(id);
var _index = $.inArray(chooseId, idArr);
if( _index !== -1 ){
idArr.splice(_index,1);
nameArr.splice(_index, 1);
}
}
function isAllChecked(pageIds, chooseIds){
var allChecked = true;
if(chooseIds.length == 0 ){
allChecked = false;
}else {
$.each(pageIds, function (i, id) {
if ($.inArray(id, chooseIds) == -1) {
allChecked = false;
return false;
}
});
}
return allChecked;
}
function gCheckBox(item){
var checked = item.prop("checked");
var id = item.attr('_id');
var allChecked = false;
if(checked){
var sourceName = item.attr('_sourceName');
push(id,sourceName,batchChooseSourceIds,batchChooseSourceNames);
allChecked = isAllChecked(pageChooseSourceIds, batchChooseSourceIds);
}else{
splice(id,batchChooseSourceIds,batchChooseSourceNames);
}
$(".wqt_all").prop("checked", allChecked);
}
function scCheckBox(item){
var checked = item.prop("checked");
var id = item.attr('_id');
var allChecked = false;
if(checked){
var sourceName = item.attr('_sourceName');
push(id,sourceName,batchUnChooseSourceIds,batchUnChooseSourceNames);
allChecked = isAllChecked(pageUnChooseSourceIds, batchUnChooseSourceIds);
}else{
splice(id,batchUnChooseSourceIds,batchUnChooseSourceNames);
}
$(".wqt_all").prop("checked", allChecked);
}
function getCategoryIdFromUrl() {
// sale/category/resource/1#page=1
... ...