|
@@ -118,11 +118,16 @@ const PRICE_BOOK = (() => {
|
|
|
const changedCells = [{ row: info.row }];
|
|
|
handleEdit(changedCells);
|
|
|
});
|
|
|
- sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
|
|
|
- const row = info.newSelections && info.newSelections[0] ? info.newSelections[0].row : 0;
|
|
|
+
|
|
|
+ const handleSelectionChange = (row) => {
|
|
|
// 显示关键字数据
|
|
|
const keywordList = cache[row] && cache[row].keywordList || [];
|
|
|
KEYWORD_BOOK.showKeywordData(keywordList);
|
|
|
+ }
|
|
|
+
|
|
|
+ sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
|
|
|
+ const row = info.newSelections && info.newSelections[0] ? info.newSelections[0].row : 0;
|
|
|
+ handleSelectionChange(row);
|
|
|
});
|
|
|
sheet.bind(GC.Spread.Sheets.Events.RangeChanged, function (e, info) {
|
|
|
const changedRows = [];
|
|
@@ -169,10 +174,97 @@ const PRICE_BOOK = (() => {
|
|
|
showData(sheet, cache, setting.header);
|
|
|
}
|
|
|
|
|
|
+ const getKey = (item) => {
|
|
|
+ return `${item.code || ''}@${item.name || ''}@${item.specs || ''}@${item.unit || ''}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量修改
|
|
|
+ const batchEdit = async () => {
|
|
|
+ try {
|
|
|
+ $.bootstrapLoading.start();
|
|
|
+ const row = sheet.getActiveRowIndex();
|
|
|
+ const col = sheet.getActiveColumnIndex();
|
|
|
+ const colHeader = setting.header[col];
|
|
|
+ const priceItem = cache[row];
|
|
|
+ if (!priceItem || !colHeader) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const prop = colHeader.dataCode;
|
|
|
+ const val = $('#edit-text').val();
|
|
|
+ if (['noTaxPrice', 'taxPrice'].includes(prop) && (!val || isNaN(val))) {
|
|
|
+ throw new Error('请输入数值');
|
|
|
+ }
|
|
|
+ await ajaxPost('/priceInfo/batchUpdate', { priceItem, prop, val });
|
|
|
+ const key = getKey(priceItem);
|
|
|
+ cache.forEach(item => {
|
|
|
+ if (key === getKey(item)) {
|
|
|
+ item[prop] = val;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ showData(sheet, cache, setting.header, 5);
|
|
|
+ $('#batch-edit').modal('hide');
|
|
|
+ } catch (error) {
|
|
|
+ alert(error.message);
|
|
|
+ }
|
|
|
+ $.bootstrapLoading.end();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 右键功能
|
|
|
+ function buildContextMenu() {
|
|
|
+ $.contextMenu({
|
|
|
+ selector: '#price-spread',
|
|
|
+ build: function ($triggerElement, e) {
|
|
|
+ // 控制允许右键菜单在哪个位置出现
|
|
|
+ const offset = $('#price-spread').offset();
|
|
|
+ const x = e.pageX - offset.left;
|
|
|
+ const y = e.pageY - offset.top;
|
|
|
+ const target = sheet.hitTest(x, y);
|
|
|
+ if (target.hitTestType === 3) { // 在表格内
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ if (sel && sel.rowCount === 1 && typeof target.row !== 'undefined') {
|
|
|
+ const orgRow = sheet.getActiveRowIndex();
|
|
|
+ sheet.setActiveCell(target.row, target.col);
|
|
|
+ if (orgRow !== target.row) {
|
|
|
+ handleSelectionChange(target.row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ items: {
|
|
|
+ batchUpdate: {
|
|
|
+ name: '批量修改',
|
|
|
+ icon: "fa-edit",
|
|
|
+ disabled: function () {
|
|
|
+ return locked || !cache[target.row];
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ const colHeader = setting.header[target.col];
|
|
|
+ const item = cache[target.row];
|
|
|
+ if (item) {
|
|
|
+ const info = `材料:${item.code || ''} ${item.name || ''} ${item.specs || ''} ${item.unit}`;
|
|
|
+ $('#edit-item').text(info);
|
|
|
+ $('#edit-label').text(colHeader.headerName);
|
|
|
+ $('#edit-text').attr('placeholder', `请输入${colHeader.headerName}`);
|
|
|
+ $('#edit-text').val(item[colHeader.dataCode] || '');
|
|
|
+ $('#batch-edit').modal('show');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ buildContextMenu();
|
|
|
+
|
|
|
return {
|
|
|
clear,
|
|
|
initData,
|
|
|
showRepeatData,
|
|
|
+ batchEdit,
|
|
|
}
|
|
|
})();
|
|
|
|
|
@@ -181,4 +273,13 @@ $(document).ready(() => {
|
|
|
$('#check-repeat').click(() => {
|
|
|
PRICE_BOOK.showRepeatData();
|
|
|
});
|
|
|
+
|
|
|
+ // 批量修改
|
|
|
+ $('#batch-edit-confirm').click(() => {
|
|
|
+ PRICE_BOOK.batchEdit();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#batch-edit').on('shown.bs.modal', function () {
|
|
|
+ $('#edit-text').focus();
|
|
|
+ });
|
|
|
});
|