|
@@ -217,20 +217,32 @@ $(document).ready(() => {
|
|
|
class Bonus {
|
|
|
constructor () {
|
|
|
this.data = [];
|
|
|
+ this.displayData = [];
|
|
|
+ this._curOnlyKey = 'se_bonus_' + window.location.pathname.split('/')[2];
|
|
|
+ const cache = getLocalCache(this._curOnlyKey);
|
|
|
+ this._curOnly = cache && cache === 'true' ? true : false;
|
|
|
}
|
|
|
resortData() {
|
|
|
this.data.sort(function (a, b) {
|
|
|
return a.sorder !== b.sorder ? a.sorder - b.sorder : a.order - b.order;
|
|
|
});
|
|
|
}
|
|
|
+ refreshDisplay() {
|
|
|
+ this.displayData.length = 0;
|
|
|
+ for (const d of this.data) {
|
|
|
+ if (!this._curOnly || d.sid === stageId) this.displayData.push(d);
|
|
|
+ }
|
|
|
+ }
|
|
|
loadDatas(datas) {
|
|
|
this.data = datas;
|
|
|
this.resortData();
|
|
|
+ this.refreshDisplay();
|
|
|
}
|
|
|
loadUpdateData(updateData) {
|
|
|
if (updateData.add) {
|
|
|
for (const a of updateData.add) {
|
|
|
this.data.push(a);
|
|
|
+ this.displayData.push(a);
|
|
|
}
|
|
|
}
|
|
|
if (updateData.update) {
|
|
@@ -242,6 +254,7 @@ $(document).ready(() => {
|
|
|
_.assign(d, u);
|
|
|
} else {
|
|
|
this.data.push(d);
|
|
|
+ this.displayData.push(d);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -249,6 +262,9 @@ $(document).ready(() => {
|
|
|
_.remove(this.data, function (d) {
|
|
|
return updateData.del.indexOf(d.id) >= 0;
|
|
|
});
|
|
|
+ _.remove(this.displayData, function (d) {
|
|
|
+ return updateData.del.indexOf(d.id) >= 0;
|
|
|
+ });
|
|
|
}
|
|
|
this.resortData();
|
|
|
}
|
|
@@ -271,30 +287,58 @@ $(document).ready(() => {
|
|
|
return cur.indexOf(bonusData) === cur.length - 1;
|
|
|
}
|
|
|
sum () {
|
|
|
- const result = {
|
|
|
- tp: 0,
|
|
|
- };
|
|
|
- for (const d of this.data) {
|
|
|
- result.tp = ZhCalc.add(result.tp, d.tp);
|
|
|
+ const result = [];
|
|
|
+ const sum = { name: '合计', positive_tp: 0, negative_tp: 0 };
|
|
|
+ for (const d of this.displayData) {
|
|
|
+ if (d.b_type) {
|
|
|
+ let type = result.find(x => { return d.b_type === x.name; });
|
|
|
+ if (!type) {
|
|
|
+ type = { name: d.b_type, positive_tp: 0, negative_tp: 0 };
|
|
|
+ result.push(type);
|
|
|
+ }
|
|
|
+ if (d.tp >= 0) {
|
|
|
+ type.positive_tp = ZhCalc.add(type.positive_tp, d.tp);
|
|
|
+ } else {
|
|
|
+ type.negative_tp = ZhCalc.add(type.negative_tp, d.tp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (d.tp >= 0) {
|
|
|
+ sum.positive_tp = ZhCalc.add(sum.positive_tp, d.tp);
|
|
|
+ } else {
|
|
|
+ sum.negative_tp = ZhCalc.add(sum.negative_tp, d.tp);
|
|
|
+ }
|
|
|
}
|
|
|
+ result.push(sum);
|
|
|
+ result.forEach(x => { x.tp = ZhCalc.add(x.positive_tp, x.negative_tp); });
|
|
|
return result;
|
|
|
}
|
|
|
+ set curOnly(b) {
|
|
|
+ this._curOnly = b;
|
|
|
+ setLocalCache(this._curOnlyKey, this._curOnly);
|
|
|
+ this.refreshDisplay();
|
|
|
+ }
|
|
|
+ get curOnly() {
|
|
|
+ return this._curOnly;
|
|
|
+ }
|
|
|
}
|
|
|
const bonusObj = new Bonus();
|
|
|
const refreshSum = function () {
|
|
|
const sum = bonusObj.sum();
|
|
|
const html = [];
|
|
|
- const getTrHtml = function (name, value) {
|
|
|
- return '<tr><td>' + name + '</td><td class="text-right">' + (!checkZero(value) ? value : '') + ' </td></tr>';
|
|
|
+ const getTrHtml = function (s) {
|
|
|
+ return `<tr><td>${s.name}</td><td class="text-right">${s.positive_tp || ''}</td><td class="text-right">${s.negative_tp || ''}</td><td class="text-right">${s.tp || ''}</td></tr>`;
|
|
|
};
|
|
|
- html.push(getTrHtml('金额', sum.tp));
|
|
|
+ for (const s of sum) {
|
|
|
+ html.push(getTrHtml(s));
|
|
|
+ }
|
|
|
$('#sum').html(html.join(' '));
|
|
|
};
|
|
|
|
|
|
postData(window.location.pathname + '/load', null, function (result) {
|
|
|
bonusObj.loadDatas(result);
|
|
|
- SpreadJsObj.loadSheetData(bonusSheet, SpreadJsObj.DataType.Data, bonusObj.data);
|
|
|
+ SpreadJsObj.loadSheetData(bonusSheet, SpreadJsObj.DataType.Data, bonusObj.displayData);
|
|
|
refreshSum();
|
|
|
+ $('#cur-only')[0].checked = bonusObj.curOnly;
|
|
|
});
|
|
|
|
|
|
if (!readOnly) {
|
|
@@ -590,4 +634,9 @@ $(document).ready(() => {
|
|
|
});
|
|
|
$('#upload-file').change(fileObj.uploadFile);
|
|
|
$('body').on('click', '.delete-att', fileObj.deleteFile);
|
|
|
+ $('#cur-only').change(function (){
|
|
|
+ bonusObj.curOnly = this.checked;
|
|
|
+ SpreadJsObj.reLoadSheetData(bonusSheet);
|
|
|
+ refreshSum();
|
|
|
+ })
|
|
|
});
|