'use strict';
/**
* cs_errorList:错误列表
* 使用范围:
* 台账分解(原报)、台账修订(原报)、计量台账(所有角色)
*
* posSearch & billsSearch:台账搜索相关
* 使用范围:
* 0号台账:台账分解、台账审批、台账修订、部位台账;
* 期计量:计量台账、部位台账
*
* 所有工具均基于spreadjs,请放在gc.spread.sheets.all.10.0.1.min.js/spreadjs_zh.js之后
*
* @author Mai
* @date
* @version
*/
const showSideTools = function (show) {
const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
if (show) {
right.show();
autoFlashHeight();
/**
* right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
* 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
* 故需要通过最终的parent.width再计算一次left.width
*
* Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
* A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
*
*/
//left.css('width', parent.width() - right.outerWidth());
//left.css('width', parent.width() - right.outerWidth());
const percent = 100 - right.outerWidth() /parent.width() * 100;
left.css('width', percent + '%');
} else {
left.width(parent.width());
right.hide();
}
};
const showSelectTab = function(select, spread, afterShow) {
const tab = $(select), tabPanel = $(tab.attr('content'));
$('a', '.side-menu').removeClass('active');
tab.addClass('active');
$('.tab-content .tab-pane').removeClass('active');
tabPanel.addClass('active');
showSideTools(true);
spread && spread.refresh();
if (afterShow) afterShow();
};
(function($){
/**
* 错误列表
* @param setting
* {
* tabSelector: 'a[content=#error-list]',
* selector: '#error-list',
* relaSpread: ledgerSpread,
* storeKey: 'ledger-error-' + tenderId,
* }
* @returns {{spread: *}}
*/
$.cs_errorList = function (setting) {
if (!setting.spreadSetting) {
setting.spreadSetting = {
cols: [
{title: '行号', field: 'serialNo', width: 50, formatter: '@'},
{
title: '错误类型', field: 'errorType', width: 60, formatter: '@',
getValue: function (x) {
switch (x.errorType) {
case 'qty': return '数量';
case 'tp': return '金额';
case 'over': return '超计';
case 'sibling': return '项目节清单同层';
case 'same_code': return '重复项目节编号';
case 's2b_over_gxby': return '违规计量(工序报验)';
case 's2b_over_dagl': return '违规计量(档案管理)';
case 's2b_lost_gxby': return '遗漏计量(工序报验)';
case 's2b_lost_dagl': return '遗漏计量(档案管理)';
default: return '';
}
}
},
{title: '清单编号', field: 'b_code', width: 135, formatter: '@'},
{title: '清单名称', field: 'name', width: 215, formatter: '@'},
],
emptyRows: 0,
headRows: 1,
headRowHeight: [32],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
selectedBackColor: '#fffacd',
readOnly: true,
};
}
const clearErrorData = function () {
if (setting.storeKey) removeLocalCache(setting.storeKey);
};
const autoShowHistory = function (show) {
if (setting.storeKey) {
setLocalCache(setting.storeKey + '-showHis', show.toString());
}
};
if (setting.selector && setting.relaSpread) {
const resultId = setting.id + '-spread';
const obj = $(setting.selector);
obj.html(
'
');
tagHtml.push('');
return tagHtml.join('');
};
const searchTagsAndShow = function () {
const keyword = $('#bills-tag-keyword').val();
const filterClass = $('#bills-tag-filter')[0].classList;
const tagClass = filterClass.length > 2 ? filterClass[2] : null;
const ci = tagClass ? classIndexes.find(x => {return x.tagClass === tagClass}) : null;
curShow = billsTags.filter(x => {
if (ci && ci.color !== x.color) return false;
if (!keyword) return true;
if (x.node.code && x.node.code.indexOf(keyword) >= 0) return true;
if (x.node.b_code && x.node.b_code.indexOf(keyword) >= 0) return true;
if (x.node.name && x.node.name.indexOf(keyword) >= 0) return true;
return false;
});
reloadViewTags();
};
const refreshTagView = function (tag) {
const obj = $('#bills-tag-' + tag.id);
if (obj && obj.length > 0) {
obj.html(getTagDisplayHtml(tag));
}
};
const refreshBillsTagView = function (bills) {
const bi = billsIndexes[bills.id] || [];
for (const tag of bi) {
refreshTagView(tag);
}
};
const reviewTag = function (tag, isTop = false) {
const obj = $('#bills-tag-' + tag.id);
if (obj && obj.length > 0) {
obj.html(getTagDisplayHtml(tag));
} else {
const objHtml = [];
objHtml.push(`
`);
objHtml.push(getTagDisplayHtml(tag));
objHtml.push('
');
if (isTop) {
$('#bills-tag-list').prepend(objHtml.join(''));
} else {
$('#bills-tag-list').append(objHtml.join(''));
}
}
tag.display = true;
};
const loadViewTags = function () {
let showCount = 0;
for (const t of curShow) {
if (showCount >= pageLength) continue;
if (t.display) continue;
reviewTag(t);
showCount++;
}
};
const reloadViewTags = function () {
clearViewTags();
$("#bills-tag-lis").scrollTop(0);
loadViewTags();
};
const _addToBillsIndex = function(data, isTop = false) {
let bi = billsIndexes[data.lid];
if (!bi) {
bi = [];
billsIndexes[data.lid] = bi;
}
isTop ? bi.unshift(data) : bi.push(data);
};
const loadDatas = function (datas) {
billsTags = [];
billsIndexes = {};
for (const d of datas) {
billsTags.push(d);
_addToBillsIndex(d);
}
curShow = billsTags;
reloadViewTags();
};
const updateDatas = function (data) {
const refresh = {};
if (data.add) {
billsTags.push(data.add);
_addToBillsIndex(data.add, true);
refresh.add = data.add;
}
if (data.del) {
const delTag = billsTags.find(x => {return x.id === data.del});
billsTags.splice(billsTags.indexOf(delTag), 1);
if (delTag.node) {
const bi = billsIndexes[delTag.node.id];
bi.splice(bi.indexOf(delTag), 1);
}
refresh.del = delTag;
}
if (data.update) {
const updateTag = billsTags.find(x => {return x.id === data.update.id});
for (const prop in data.update) {
updateTag[prop] = data.update[prop];
}
refresh.update = updateTag;
}
return refresh;
};
const updateDatasAndShow = function (data) {
const relaBills = [];
const refresh = updateDatas(data);
if (refresh.add) {
reviewTag(refresh.add, true);
relaBills.push(refresh.add.node);
}
if (refresh.del) {
$('#bills-tag-' + refresh.del.id).remove();
relaBills.push(refresh.del.node);
}
if (refresh.update) {
refreshTagView(refresh.update);
relaBills.push(refresh.update.node);
}
return relaBills;
};
const show = function () {
showSelectTab(setting.selector, null, setting.afterShow);
};
const getBillsTagsColor = function (id) {
const billsTags = billsIndexes[id] || [];
return billsTags.length > 0 ? billsTags.map(x => {return x.color}) : undefined;
};
const getBillsTagsInfo = function (id) {
const billsTags = billsIndexes[id] || [];
return billsTags.length > 0 ? billsTags.map(x => {
const tagClass = classIndexes.find(tc => {return tc.color === x.color}) || {};
return {color: x.color, comment: x.comment, tagClass: tagClass.tagClass};
}) : undefined;
};
$('body').on('click', '[name=bills-tag-locate]', function () {
const lid = parseInt(this.getAttribute('lid'));
SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), lid);
setting.afterLocated && setting.afterLocated();
});
$('body').on('click', '[name=bills-tag-edit]', function () {
const tagId = this.getAttribute('tag-id');
const tag = billsTags.find(x => {return x.id == tagId});
if (tag) {
const obj = $('#bills-tag-' + tag.id);
$('[name=tag-view]', obj).hide();
obj.append(getTagEditHtml(tag));
}
});
$('body').on('click', '#tag-edit-cancel', function () {
const obj = $('[name=tag-edit]').parent();
$('[name=tag-edit]').remove();
$('[name=tag-view]', obj).show();
});
$('body').on('click', '#tag-del', function () {
const obj = $('[name=tag-edit]').parent();
postData(setting.updateUrl, {del: parseInt(obj.attr('tag-id'))}, function (result) {
if (!result.del) return;
const bills = updateDatasAndShow(result);
setting.afterModify && setting.afterModify(bills);
});
});
$('body').on('click', '#tag-edit-ok', function () {
const obj = $('[name=tag-edit]').parent();
const data = {
id: parseInt(obj.attr('tag-id')),
share: $('#tag-share')[0].checked,
comment: $('#tag-comment').val(),
color: $('#tag-change-color').attr('tag-color'),
};
postData(setting.updateUrl, {update: data}, function (result) {
if (!result.update) return;
const bills = updateDatasAndShow(result);
setting.afterModify && setting.afterModify(bills);
});
});
$('body').on('click', '[name=tag-color]', function () {
const tagClass = this.classList[1];
const ci = classIndexes.find(tc => {return tc.tagClass === tagClass});
const tcc = $('#tag-change-color');
tcc.attr('tag-color', ci.color);
tcc.find('i').attr('class', 'fa fa-tag ' + tagClass);
});
$('body').on('click', '[tagType]', function () {
const tagClass = this.getAttribute('tagType');
if (tagClass === 'all') {
$('#bills-tag-filter').attr('class', 'fa fa-list-ol');
} else {
$('#bills-tag-filter').attr('class', 'fa fa-tag ' + tagClass);
}
searchTagsAndShow();
});
// 防抖
function debounce(fun, delay) {
let timer = null;
return function () {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(fun, delay);
}
}
$('#bills-tag-list').bind('scroll', debounce(function (e) {
const obj = $('#bills-tag-list');
var sum = obj[0].scrollHeight;
if (sum <= obj.scrollTop() + obj.height()) {
loadViewTags();
}
}, 300));
$('#bills-tag-clear').bind('click', () => {
if (!$('#bills-tag-keyword').val()) return;
$('#bills-tag-keyword').val('');
searchTagsAndShow();
});
$('#bills-tag-search').bind('click', () => {searchTagsAndShow();});
$('#bills-tag-keyword').bind('keydown', e => {if (e.keyCode === 13) searchTagsAndShow();});
return { loadDatas, updateDatasAndShow, show, getBillsTagsColor, getBillsTagsInfo, refreshBillsTagView, }
};
$.sumLoadMiss = function (setting) {
if (!setting.spreadSetting) {
setting.spreadSetting = {
cols: [
{ title: '清单编号', field: 'b_code', width: 80, formatter: '@' },
{ title: '清单名称', field: 'name', width: 120, formatter: '@' },
{ title: '单位', field: 'unit', width: 50, formatter: '@' },
{ title: '数量', field: 'qty', width: 60 },
{
title: '类型', field: 'type', width: 100, getValue: function (x) {
switch (x.type) {
case 'less': return '数量变少';
case 'miss': return '找不到清单';
case 'qc': return '变更';
case 'miss-qc': return '变更(找不到清单)';
default: return '';
}
}
}
],
emptyRows: 0,
headRows: 1,
headRowHeight: [32],
defaultRowHeight: 21,
headerFont: '12px 微软雅黑',
font: '12px 微软雅黑',
selectedBackColor: '#fffacd',
readOnly: true,
};
}
const clearMissData = function () {
if (setting.storeKey) removeLocalCache(setting.storeKey);
};
const autoShowHistory = function (show) {
if (setting.storeKey) {
setLocalCache(setting.storeKey + '-showHis', show.toString());
}
};
if (setting.selector && setting.relaSpread) {
const resultId = setting.id + '-spread';
const obj = $(setting.selector);
obj.html(
'
\n' +
'
'
);
autoFlashHeight();
const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
const sheet = spread.getActiveSheet();
SpreadJsObj.initSheet(sheet, setting.spreadSetting);
spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
if (!setting.relaSpread) return;
const sheet = info.sheet;
const data = sheet.zh_data;
if (!data) { return }
const curBills = data[info.row];
if (!curBills) { return }
if (curBills.ledger_id) {
SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
if (setting.afterLocated) {
setting.afterLocated();
}
} else {
toastr.warning('找不到该清单');
}
});
const loadMissData = function (data, his = false) {
const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
if (!sourceTree) return;
for (const d of data) {
d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
}
data.sort(function (a, b) {
return a.serialNo - b.serialNo;
});
SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
if (!his && setting.storeKey) {
setLocalCache(setting.storeKey, JSON.stringify(data));
}
$(setting.tabSelector).show();
};
const showMissList = function () {
const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
$('a', '.side-menu').removeClass('active');
tab.addClass('active');
$('.tab-content .tab-pane').removeClass('active');
tabPanel.addClass('active');
showSideTools(true);
spread.refresh();
if (setting.afterShow) setting.afterShow();
};
const loadHisMissData = function () {
if (setting.storeKey) {
const storeStr = getLocalCache(setting.storeKey);
const storeData = storeStr ? JSON.parse(storeStr) : [];
if (storeData.length > 0) {
loadMissData(storeData, true);
const showHis = getLocalCache(setting.storeKey + '-showHis');
if (showHis === 'true') {
showMissList();
removeLocalCache(setting.storeKey + '-showHis');
}
}
}
};
return {
spread: spread,
loadMissData: loadMissData,
clearMissData: clearMissData,
loadHisMissData: loadHisMissData,
show: showMissList,
autoShowHistory: autoShowHistory,
};
} else {
const loadMissData = function (data) {
if (setting.storeKey) {
setLocalCache(setting.storeKey, JSON.stringify(data));
}
};
return {
loadErrorData: loadMissData,
clearErrorData: clearMissData,
autoShowHistory: autoShowHistory,
};
}
};
})(jQuery);