window.onload = function () {
initHierarchyParentType ()
document.getElementById('formUpdate').onclick = function () {
toSubmit()
}
// document.getElementById('addColumn').onclick = function () {
// addColumn()
// }
// document.getElementById('disableData').onclick = function () {
// toDisableData()
// }
document.getElementById('disabletab').onclick = function () {
toDisabletab()
}
document.getElementById('test').onclick = function () {
toTest()
}
};
// 自定义层级结构
function initHierarchyParentType() {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 0, tabStripPosition: GC.Spread.Sheets.TabStripPosition.top });
var dataManager = spread.dataManager();
// 初始化数据
icostData.forEach((item, index) => {
initTableData(spread, dataManager, item, index)
})
}
function initTableData(spread, dataManager, item, index) {
var taskTable = dataManager.addTable("Tasks", {
data: item.list,
schema: {
hierarchy: {
type: 'Custom',
column: 'accountCode',
parse: function (options) {
// parse the primary key "1.1.1" to "1.1"
// the returned value will be treated as parentId
let seg = options.data.accountCode.split('.');
return seg.slice(0, seg.length - 1).join('.')
},
unparse: function (options) {
let parentIds, currentIndex = options.index, parentData = options.parentData, parentKey = parentData && parentData.WBSNumber;
if (parentKey) {
let sp = parentKey.split('.');
parentIds = sp;
} else {
parentIds = [];
}
parentIds.push(currentIndex + 1);
return parentIds.join('.');
},
summaryFields: { // 层级数据合计
'allAmount':'=SUM(CHILDREN(1,"allAmount"))'
}
},
columns: {
accountCode: { dataName: 'accountCode', isPrimaryKey: true,allowSort: false, allowFilterByValue: false, allowFilterByList : false, readonly: true }, // using primary key to indicate the hierarchy id optionally
accountName: { dataName: 'accountName',allowSort: false, allowFilterByValue: false, allowFilterByList : false, readonly: true },
factorName: { dataName: 'factorName',allowSort: false, allowFilterByValue: false, allowFilterByList : false, readonly: true, value:''},
engQty: { dataName: 'engQty',allowSort: false, allowFilterByValue: false, allowFilterByList : false },
engQtyUnit: { dataName: 'engQtyUnit',allowSort: false, allowFilterByValue: false, allowFilterByList : false, readonly: true },
priceFormula: { dataName: 'priceFormula', allowSort: false, allowFilterByValue: false, allowFilterByList: false },
priceChangeFactor: { dataName: 'priceChangeFactor', allowSort: false, allowFilterByValue: false, allowFilterByList: false, dataType: 'number',
type: 'Select',
style: {
cellType: {
type: 'combobox',
editorValueType: 'value',
items: [
{ text: '1', value: 1 },
{ text: '0.03', value: 0.03 },
{ text: '0.05', value: 0.05 }
]
}
},
},
finalPrice: { dataName: 'finalPrice', allowSort: false, allowFilterByValue: false, allowFilterByList: false, dataType: "formula",
value: "IF(AND([@priceFormula] > 0, [@priceChangeFactor] > 0), [@priceFormula] * [@priceChangeFactor], 0) "
},
priceUnit: { dataName: 'priceUnit', allowSort: false, allowFilterByValue: false, allowFilterByList: false, readonly: true },
acctdAmount: { dataName: 'acctdAmount', allowSort: false, allowFilterByValue: false, allowFilterByList: false },
taxRate: { dataName: 'taxRate', allowSort: false, allowFilterByValue: false, allowFilterByList: false },
vatAmount: { dataName: 'vatAmount', allowSort: false, allowFilterByValue: false, allowFilterByList: false, readonly: true },
allAmount: {
dataName: 'allAmount', allowSort: false, allowFilterByValue: false, allowFilterByList: false, dataType: "Number",
trigger: {
when: "onNewAndUpdate", // 在创建后应用公式 when: "onNewAndUpdate",// 在更新时应用公式
formula: "=[@engQty] * [@finalPrice]", // 触发公式设置当前的时间
fields: "engQty,finalPrice,priceChangeFactor" // 在新建时,不需要指定受影响字段
},
// value: "[@engQty] * [@finalPrice]"
},
}
}
});
var sheet = spread.addSheetTab(index, item.dantiName, GC.Spread.Sheets.SheetType.tableSheet);
// sheet.setDefaultRowHeight(40, GC.Spread.Sheets.SheetArea.colHeader);
sheet.options.allowAddNew = true;
taskTable.fetch().then(r => {
var myView = taskTable.addView("myView", [
{ value: "accountCode", caption:'对应科目代码', width: 200, outlineColumn: true },
{ value: "accountName", caption:'科目', width: 200 },
{ value: "factorName", caption:'成本影响因素', width: 200},
{ value: "engQty", caption:'数值', width: 100 }, // style: { formatter: '0.00%' }
{ value: "engQtyUnit", caption:'单位', width: 80 },
{ value: "priceFormula", caption: '原始指标', width: 100 },
{ value: "priceChangeFactor", caption: '调整系数', width: 100 },
{ value: "finalPrice", caption: '数值', width: 200 },
{ value: "priceUnit", caption: '单位', width: 80 },
{ value: "acctdAmount", caption: '不含增值税总价(万元)', width: 200 },
{ value: "taxRate", caption: '增值税率', width: 100 },
{ value: "vatAmount", caption: '增值税总额(万元)', width: 200 },
{ value: "allAmount", caption: '含增值税总价(万元)', width: 200 },
]);
spread.suspendPaint();
sheet.setDataView(myView);
spread.resumePaint();
})
}
// 提交数据
function toSubmit() {
let spread = GC.Spread.Sheets.findControl(document.getElementById("ss"));
let sheet = spread.getActiveSheetTab();
// let sheet = spread.getSheetTab()
// console.log(sheet.getDataView()) // 获取数据源
// 获取数据源
sheet.getDataView().fetch().then(data=>{
console.log(data)
})
}
|