|
@@ -0,0 +1,252 @@
|
|
|
+/**
|
|
|
+ * Created by Mai on 2017/8/22.
|
|
|
+ */
|
|
|
+
|
|
|
+let TEMPLATE_BILLS_SETTING = {
|
|
|
+ "emptyRows":1,
|
|
|
+ "headRows":1,
|
|
|
+ "headRowHeight":[35],
|
|
|
+ "treeCol": 0,
|
|
|
+ "cols":[{
|
|
|
+ "width":200,
|
|
|
+ "readOnly":null,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["编号"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"code",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":3,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ "width":300,
|
|
|
+ "readOnly":null,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["名称"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"name",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":3,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ "width":50,
|
|
|
+ "readOnly":null,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["单位"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"unit",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":1,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ "width":50,
|
|
|
+ "readOnly":true,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["ID"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"ID",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":1,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ "width":50,
|
|
|
+ "readOnly":true,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["ParentID"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"ParentID",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":1,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ "width":50,
|
|
|
+ "readOnly":true,
|
|
|
+ "head":{
|
|
|
+ "titleNames":["NextSiblingID"],
|
|
|
+ "spanCols":[1],
|
|
|
+ "spanRows":[1],
|
|
|
+ "vAlign":[1],
|
|
|
+ "hAlign":[1],
|
|
|
+ "font":["Arial"]
|
|
|
+ },
|
|
|
+ "data":{
|
|
|
+ "field":"NextSiblingID",
|
|
|
+ "vAlign":0,
|
|
|
+ "hAlign":1,
|
|
|
+ "font":"Arail"
|
|
|
+ }
|
|
|
+ }]
|
|
|
+};
|
|
|
+
|
|
|
+$(document).ready(function () {
|
|
|
+ let RefreshBaseActn = function (tree) {
|
|
|
+ let showButton = function (show, btn) {
|
|
|
+ if (show) {
|
|
|
+ btn.show();
|
|
|
+ } else {
|
|
|
+ btn.hide();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ showButton(tree.selected && tree.selected.canUpLevel(), $('#upLevel'));
|
|
|
+ showButton(tree.selected && tree.selected.canDownLevel(), $('#downLevel'));
|
|
|
+ showButton(tree.selected && tree.selected.canUpMove(), $('#upMove'));
|
|
|
+ showButton(tree.selected && tree.selected.canDownMove(), $('#downMove'));
|
|
|
+ showButton(tree.selected ? true : false, $('#delete'));
|
|
|
+ }
|
|
|
+ let RefreshBillsData = function (datas) {
|
|
|
+ datas.forEach(function (data) {
|
|
|
+ let node = tree.findNode(data.data.ID);
|
|
|
+ if (node) {
|
|
|
+ $.extend(true, node.data, data.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ let tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
|
|
|
+ let billsSpread = TREE_SHEET_HELPER.createNewSpread($('#billsSpread')[0]);
|
|
|
+ let controller = TREE_SHEET_CONTROLLER.createNew(tree, billsSpread.getActiveSheet(), TEMPLATE_BILLS_SETTING);
|
|
|
+
|
|
|
+ controller.bind('refreshBaseActn', RefreshBaseActn);
|
|
|
+
|
|
|
+ billsSpread.bind(GC.Spread.Sheets.Events.EditEnded, function (sender, info) {
|
|
|
+ var node = controller.tree.items[info.row];
|
|
|
+ var fieldName = controller.setting.cols[info.col].data.field;
|
|
|
+ var data = {type: 'update', data: {ID: node.getID()}};
|
|
|
+ data.data[fieldName] = info.editingText;
|
|
|
+ var updateData = [data];
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ node.data[fieldName] = info.editingText;
|
|
|
+ controller.refreshTreeNode([node], false);
|
|
|
+ }, function () {
|
|
|
+ controller.refreshTreeNode([node], false);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ billsSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, function (e, info) {
|
|
|
+ console.log("ClipboardPasted");
|
|
|
+ var node, iRow, iCol, curRow, curCol, datas = [], data, fieldName, updateData;
|
|
|
+ for (iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
|
|
|
+ curRow = info.cellRange.row + iRow;
|
|
|
+ node = controller.tree.items[curRow];
|
|
|
+ if (node) {
|
|
|
+ data = {type: 'update', data: {ID: node.getID()}};
|
|
|
+ for (iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ curCol = info.cellRange.col + iCol;
|
|
|
+ fieldName = controller.setting.cols[curCol].data.field;
|
|
|
+ data.data[fieldName] = info.sheet.getText(curRow, curCol);
|
|
|
+ }
|
|
|
+ datas.push(data);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ CommonAjax.post(updateUrl, datas, function (data) {
|
|
|
+ RefreshBillsData(data);
|
|
|
+ controller.showTreeData();
|
|
|
+ }, function () {
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ tree.loadDatas(JSON.parse(billsTemplateData));
|
|
|
+ controller.showTreeData();
|
|
|
+ RefreshBaseActn(tree);
|
|
|
+
|
|
|
+ $('#insert').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = controller.tree.getInsertData(selected.getParentID(), selected.getNextSiblingID());
|
|
|
+ } else {
|
|
|
+ updateData = controller.tree.getInsertData();
|
|
|
+ }
|
|
|
+ if (updateData.updateData.length > 0) {
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.insert();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ alert('新增节点失败, 请重试.');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#delete').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = controller.tree.getDeleteData(selected);
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.delete();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#upLevel').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = selected.getUpLevelData();
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.upLevel();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#downLevel').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = selected.getDownLevelData();
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.downLevel();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#upMove').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = selected.getUpMoveData();
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.upMove();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ $('#downMove').click(function () {
|
|
|
+ var selected = controller.tree.selected, updateData;
|
|
|
+ if (selected) {
|
|
|
+ updateData = selected.getDownMoveData();
|
|
|
+ CommonAjax.post(updateUrl, updateData, function (data) {
|
|
|
+ controller.downMove();
|
|
|
+ controller.showTreeData();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+});
|