std_billsGuidance_lib.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/11
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. const libSel = $('#stdBillsGuidanceLibSelect');
  11. const bills = {
  12. dom: $('#billsGuidance_bills'),
  13. workBook: null,
  14. cache: [],
  15. tree: null,
  16. controller: null,
  17. treeSetting: {
  18. treeCol: 0,
  19. emptyRows: 0,
  20. headRows: 1,
  21. headRowHeight: [40],
  22. defaultRowHeight: 21,
  23. cols: [{
  24. width: 200,
  25. readOnly: true,
  26. head: {
  27. titleNames: ["项目编码"],
  28. spanCols: [1],
  29. spanRows: [1],
  30. vAlign: [1],
  31. hAlign: [1],
  32. font: ["Arial"]
  33. },
  34. data: {
  35. field: "code",
  36. vAlign: 1,
  37. hAlign: 0,
  38. font: "Arial"
  39. }
  40. }, {
  41. width: 200,
  42. readOnly: true,
  43. head: {
  44. titleNames: ["项目名称"],
  45. spanCols: [1],
  46. spanRows: [1],
  47. vAlign: [1],
  48. hAlign: [1],
  49. font: ["Arial"]
  50. },
  51. data: {
  52. field: "name",
  53. vAlign: 1,
  54. hAlign: 0,
  55. font: "Arial"
  56. }
  57. }]
  58. },
  59. headers: [
  60. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  61. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  62. ],
  63. events: {
  64. SelectionChanging: function (sender, info) {
  65. billsInitSel(info.newSelections[0].row);
  66. }
  67. }
  68. };
  69. //项目指引类型
  70. const itemType = {
  71. job: 0,
  72. ration: 1
  73. };
  74. const guideItem = {
  75. dom: $('#billsGuidance_items'),
  76. workBook: null,
  77. tree: null,
  78. controller: null,
  79. treeSetting: {
  80. treeCol: 0,
  81. emptyRows: 0,
  82. headRows: 1,
  83. headRowHeight: [40],
  84. defaultRowHeight: 21,
  85. cols: [{
  86. width: 300,
  87. readOnly: false,
  88. head: {
  89. titleNames: ["项目指引"],
  90. spanCols: [1],
  91. spanRows: [1],
  92. vAlign: [1],
  93. hAlign: [1],
  94. font: ["Arial"]
  95. },
  96. data: {
  97. field: "name",
  98. vAlign: 1,
  99. hAlign: 0,
  100. font: "Arial"
  101. }
  102. },
  103. {
  104. width: 50,
  105. readOnly: false,
  106. head: {
  107. titleNames: ["选择"],
  108. spanCols: [1],
  109. spanRows: [1],
  110. vAlign: [1],
  111. hAlign: [1],
  112. font: ["Arial"]
  113. },
  114. data: {
  115. field: "select",
  116. vAlign: 1,
  117. hAlign: 1,
  118. font: "Arial"
  119. }
  120. }
  121. ]
  122. },
  123. headers: [
  124. {name: '项目指引', dataCode: 'name', width: 300, vAlign: 'center', hAlign: 'left', formatter: '@'},
  125. {name: '选择', dataCode: 'name', width: 50, vAlign: 'center', hAlign: 'center', formatter: '@'},
  126. ],
  127. events: {
  128. EditStarting: function (sender, args) {
  129. if(guideItem.headers[args.col]['dataCode'] === 'name'){
  130. args.cancel = true;
  131. }
  132. },
  133. ButtonClicked: function (sender, args) {
  134. if(args.sheet.isEditing()){
  135. args.sheet.endEdit(true);
  136. }
  137. },
  138. }
  139. };
  140. const options = {
  141. workBook: {
  142. tabStripVisible: false,
  143. allowContextMenu: false,
  144. allowCopyPasteExcelStyle : false,
  145. allowExtendPasteRange: false,
  146. allowUserDragDrop : false,
  147. allowUserDragFill: false,
  148. scrollbarMaxAlign : true
  149. },
  150. sheet: {
  151. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  152. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  153. }
  154. };
  155. //渲染时方法,停止渲染
  156. //@param {Object}sheet {Function}func @return {void}
  157. function renderSheetFunc(sheet, func){
  158. sheet.suspendEvent();
  159. sheet.suspendPaint();
  160. if(func){
  161. func();
  162. }
  163. sheet.resumeEvent();
  164. sheet.resumePaint();
  165. }
  166. //设置表选项
  167. //@param {Object}workBook {Object}opts @return {void}
  168. function setOptions (workBook, opts) {
  169. for(let opt in opts.workBook){
  170. workBook.options[opt] = opts.workBook[opt];
  171. }
  172. for(let opt in opts.sheet){
  173. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  174. }
  175. }
  176. //建表头
  177. //@param {Object}sheet {Array}headers @return {void}
  178. function buildHeader(sheet, headers) {
  179. let fuc = function () {
  180. sheet.setColumnCount(headers.length);
  181. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  182. for(let i = 0, len = headers.length; i < len; i++){
  183. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  184. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  185. if(headers[i].formatter){
  186. sheet.setFormatter(-1, i, headers[i].formatter);
  187. }
  188. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  189. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  190. }
  191. };
  192. renderSheetFunc(sheet, fuc);
  193. }
  194. //表监听事件
  195. //@param {Object}workBook @return {void}
  196. function bindEvent(workBook, events) {
  197. if(Object.keys(events).length === 0){
  198. return;
  199. }
  200. const Events = GC.Spread.Sheets.Events;
  201. let sheet = workBook.getActiveSheet();
  202. for(let event in events){
  203. workBook.bind(Events[event], events[event]);
  204. }
  205. }
  206. //建表
  207. //@param {Object}module @return {void}
  208. function buildSheet(module) {
  209. if(!module.workBook){
  210. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  211. let sheet = module.workBook.getActiveSheet();
  212. if(module === bills){
  213. //默认初始可控制焦点在清单表中
  214. module.workBook.focus();
  215. sheet.options.isProtected = true;
  216. }
  217. if(module === guideItem){
  218. sheet.options.isProtected = true;
  219. sheet.getRange(-1, 1, -1, 1).locked(false);
  220. sheet.getRange(-1, 0, -1, 1).locked(true);
  221. }
  222. setOptions(module.workBook, options);
  223. buildHeader(module.workBook.getActiveSheet(), module.headers);
  224. bindEvent(module.workBook, module.events);
  225. }
  226. }
  227. //清空表数据
  228. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  229. function cleanData(sheet, headers, rowCount){
  230. renderSheetFunc(sheet, function () {
  231. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  232. if (rowCount > 0) {
  233. sheet.setRowCount(rowCount);
  234. }
  235. });
  236. }
  237. //初始化各工作表
  238. //@param {Array}modules @return {void}
  239. function initWorkBooks(modules){
  240. for(let module of modules){
  241. buildSheet(module);
  242. }
  243. }
  244. //初始化并输出树
  245. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  246. function initTree(module, sheet, treeSetting, datas){
  247. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  248. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  249. module.tree.loadDatas(datas);
  250. module.controller.showTreeData();
  251. }
  252. //项目指引表焦点控制
  253. //@param {Number}row @return {void}
  254. function guideItemInitSel(row){
  255. let billsNode = bills.tree.selected;
  256. let node = null;
  257. if(billsNode && billsNode.guidance.tree){
  258. node = billsNode.guidance.tree.items[row];
  259. if(node){
  260. billsNode.guidance.tree.selected = node;
  261. }
  262. }
  263. }
  264. //根据项目指引的类型设置单元格类型,定额类型的项目指引为复选框
  265. //@param {Array}nodes @return {void}
  266. function setItemCellType(nodes){
  267. //设置单元格类型
  268. const base = new GC.Spread.Sheets.CellTypes.Base();
  269. const checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  270. const sheet = guideItem.workBook.getActiveSheet();
  271. renderSheetFunc(sheet, function(){
  272. for(let node of nodes){
  273. sheet.setCellType(node.serialNo(), 1, node.data.type === itemType.ration ? checkBox : base);
  274. }
  275. });
  276. }
  277. //清单表焦点控制
  278. //@param {Number}row @return {void}
  279. function billsInitSel(row){
  280. let guideSheet = guideItem.workBook.getActiveSheet();
  281. cleanData(guideSheet, guideItem.headers, -1);
  282. let node = bills.tree.items[row];
  283. if(!node){
  284. return;
  285. }
  286. bills.tree.selected = node;
  287. if(!node.guidance.tree){
  288. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: libSel.val(), billsID: node.getID()}, function (rstData) {
  289. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  290. setItemCellType(node.guidance.tree.items);
  291. //项目指引初始焦点
  292. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  293. });
  294. }
  295. else{
  296. node.guidance.controller.showTreeData();
  297. setItemCellType(node.guidance.tree.items);
  298. //项目指引初始焦点
  299. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  300. }
  301. }
  302. //初始选择清单指引库
  303. //@param {Number}libID @return {void}
  304. function libInitSel(libID){
  305. //获取清单
  306. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function(rstData){
  307. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, rstData.bills);
  308. //每一棵项目指引树挂在清单节点上
  309. for(let node of bills.tree.items){
  310. node.guidance = {tree: null, controller: null};
  311. }
  312. //默认初始节点
  313. billsInitSel(0);
  314. });
  315. }
  316. //初始化清单指引库
  317. //@param {Array}libDats @return {void}
  318. function initLibs(libDatas){
  319. libSel.empty();
  320. for(let libData of libDatas){
  321. let opt = `<option value="${libData.id}">${libData.name}</option>`;
  322. libSel.append(opt);
  323. }
  324. //初始默认选择
  325. libInitSel(libSel.select().val());
  326. }
  327. //初始化视图
  328. //@param {void} @return {void}
  329. function initViews(){
  330. let modules = [bills, guideItem];
  331. initWorkBooks(modules);
  332. }
  333. //各按钮监听事件
  334. //@return {void}
  335. function bindBtn(){
  336. //打开清单指引库
  337. $('#stdBillsGuidanceTab').click(function () {
  338. if(libSel.children().length === 0){
  339. initLibs(projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib);
  340. }
  341. });
  342. //更改清单指引库
  343. $('#stdBillsGuidanceLibSelect').change(function () {
  344. libInitSel($(this).select().val());
  345. });
  346. //插入定额
  347. $('#guidanceInsertRation').click(function () {
  348. });
  349. //插入清单
  350. $('#guidanceInsertBills').click(function () {
  351. });
  352. }
  353. //刷新表
  354. //@return {void}
  355. function refreshWorkBook(){
  356. if(bills.workBook){
  357. bills.workBook.refresh();
  358. }
  359. if(guideItem.workBook){
  360. guideItem.workBook.refresh();
  361. }
  362. }
  363. return {initViews, bindBtn, refreshWorkBook};
  364. })();
  365. $(document).ready(function(){
  366. billsGuidance.initViews();
  367. billsGuidance.bindBtn();
  368. });