| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 | 
							- /**
 
-  * Created by Mai on 2017/8/22.
 
-  */
 
- let TEMPLATE_BILLS_SETTING = {
 
-     "emptyRows":1,
 
-     "headRows":1,
 
-     "headRowHeight":[35],
 
-     "treeCol": 1,
 
-     "cols":[{
 
-         "width":80,
 
-         "readOnly":false,
 
-         "head":{
 
-             "titleNames":["类别"],
 
-             "spanCols":[1],
 
-             "spanRows":[1],
 
-             "vAlign":[1],
 
-             "hAlign":[1],
 
-             "font":["Arial"]
 
-         },
 
-         "data":{
 
-             "field":"type",
 
-             "vAlign":0,
 
-             "hAlign":1,
 
-             "font":"Arail",
 
-         }
 
-     }, {
 
-         "width":200,
 
-         "readOnly":false,
 
-         "head":{
 
-             "titleNames":["编号"],
 
-             "spanCols":[1],
 
-             "spanRows":[1],
 
-             "vAlign":[1],
 
-             "hAlign":[1],
 
-             "font":["Arial"]
 
-         },
 
-         "data":{
 
-             "field":"code",
 
-             "vAlign":0,
 
-             "hAlign":3,
 
-             "font":"Arail"
 
-         }
 
-     }, {
 
-         "width":300,
 
-         "readOnly":false,
 
-         "head":{
 
-             "titleNames":["名称"],
 
-             "spanCols":[1],
 
-             "spanRows":[1],
 
-             "vAlign":[1],
 
-             "hAlign":[1],
 
-             "font":["Arial"]
 
-         },
 
-         "data":{
 
-             "field":"name",
 
-             "vAlign":0,
 
-             "hAlign":3,
 
-             "font":"Arail"
 
-         }
 
-     }, {
 
-         "width":50,
 
-         "readOnly":false,
 
-         "head":{
 
-             "titleNames":["单位"],
 
-             "spanCols":[1],
 
-             "spanRows":[1],
 
-             "vAlign":[1],
 
-             "hAlign":[1],
 
-             "font":["Arial"]
 
-         },
 
-         "data":{
 
-             "field":"unit",
 
-             "vAlign":0,
 
-             "hAlign":1,
 
-             "font":"Arail"
 
-         }
 
-     }, {
 
-         "width":200,
 
-         "readOnly":false,
 
-         "head":{
 
-             "titleNames":["清单固定类别"],
 
-             "spanCols":[1],
 
-             "spanRows":[1],
 
-             "vAlign":[1],
 
-             "hAlign":[1],
 
-             "font":["Arial"]
 
-         },
 
-         "data":{
 
-             "field":"flagsIndex.fixed.flag",
 
-             "vAlign":0,
 
-             "hAlign":3,
 
-             "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 getNameValueComboCellType = function (datas) {
 
-         let comboItems = [];
 
-         for (let data of datas) {
 
-             comboItems.push({text: data.name, value: data.value});
 
-         }
 
-         let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
 
-         combo.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value)
 
-             .items(comboItems);
 
-         return combo;
 
-     }
 
-     let getFixedFlagCellType = function () {
 
-         let billsFixedFlagData = JSON.parse(billsFixedFlagList);
 
-         return getNameValueComboCellType(billsFixedFlagData);
 
-     };
 
-     let getTypeFlagCellType = function () {
 
-         let billsTypeFlagData = JSON.parse(billsTypeFlagList);
 
-         return getNameValueComboCellType(billsTypeFlagData);
 
-     };
 
-     let setFee = function (data, fullField, value) {
 
-         let fields = fullField.split('.'), valueField = data;
 
-         for (let i in fields) {
 
-             if (valueField[fields[i]]) {
 
-                 if (i == fields.length - 1) {
 
-                     valueField[fields[i]] = value;
 
-                 } else {
 
-                     valueField = valueField[fields[i]];
 
-                 }
 
-             } else {
 
-                 if (i == fields.length - 1) {
 
-                     valueField[fields[i]] = value;
 
-                 } else {
 
-                     valueField[fields[i]] = {};
 
-                 };
 
-                 valueField = valueField[fields[i]];
 
-             }
 
-         }
 
-     }
 
-     billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
 
-     let templateData = JSON.parse(billsTemplateData);
 
-     for (let data of templateData) {
 
-         if (data.flags) {
 
-             data.flagsIndex = {};
 
-             for (let flag of data.flags) {
 
-                 data.flagsIndex[flag.fieldName] = flag;
 
-             }
 
-         }
 
-     }
 
-     for (col of TEMPLATE_BILLS_SETTING.cols) {
 
-         if (col.data.field === 'type' && TEMPLATE_BILLS_SETTING.cols.indexOf(col) !== TEMPLATE_BILLS_SETTING.treeCol) {
 
-             col.data.cellType = getTypeFlagCellType();
 
-         } else if (col.data.field === 'flagsIndex.fixed.flag' && TEMPLATE_BILLS_SETTING.cols.indexOf(col) !== TEMPLATE_BILLS_SETTING.treeCol) {
 
-             col.data.cellType = getFixedFlagCellType();
 
-         }
 
-     }
 
-     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()}};
 
-        if (/flagsIndex/.test(fieldName)) {
 
-             data.data.flags = [];
 
-             let flagField = fieldName.split('.');
 
-             data.data.flags.push({fieldName: flagField[1], flag: info.editingText});
 
-         } else {
 
-             setFee(data.data, fieldName, info.editingText);
 
-         }
 
-         var updateData = [data];
 
-         CommonAjax.post(updateUrl, updateData, function (data) {
 
-             setFee(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;
 
-                     if (/flagsIndex/.test(fieldName)) {
 
-                         data.data.flags = [];
 
-                         let flagField = fieldName.split('.');
 
-                         data.data.flags.push({fieldName: flagField[1],flag: info.sheet.getText(curRow, curCol)});
 
-                     } else {
 
-                         setFee(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(templateData);
 
-     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.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();
 
-             });
 
-         }
 
-     });
 
- });
 
 
  |