character_content_view.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. /**
  2. * Created by Zhong on 2017/8/31.
  3. * 特征及内容
  4. */
  5. let contentOprObj = {
  6. workBook: null,
  7. currentCache: [],//按照serialNo排序
  8. setting: {
  9. header: [
  10. {headerName:"工作内容", headerWidth: 360, rateWidth:0.93, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center"},
  11. {headerName:"输出", headerWidth: 40, rateWidth: null, dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
  12. ]
  13. },
  14. buildSheet: function(container) {
  15. let me = contentOprObj;
  16. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  17. //获取工作内容列比例
  18. let workBookWidth = pageCCOprObj.getWorkBookWidth();
  19. me.setRateWith(workBookWidth);
  20. sheetCommonObj.setColumnWidthByRate(workBookWidth, me.workBook, me.setting.header);
  21. me.workBook.options.allowUserDragDrop = false;
  22. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  23. me.workBook.options.allowCopyPasteExcelStyle = false;
  24. if(!projectReadOnly){
  25. me.onContextmenuOpr();//右键菜单
  26. }
  27. me.bindEvents(me.workBook);
  28. },
  29. setRateWith: function (workBookWidth) {
  30. let me = this;
  31. let otherWidthRate = me.setting.header[1]['headerWidth'] / workBookWidth;
  32. let contentWidthRate = 1 - otherWidthRate;
  33. me.setting.header[0]['rateWidth'] = contentWidthRate;
  34. },
  35. bindEvents: function (workBook) {
  36. let sheet = workBook.getActiveSheet(), me = contentOprObj;
  37. const EVENTS = GC.Spread.Sheets.Events;
  38. workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
  39. sheet.bind(EVENTS.EditStarting, me.onEditStart);
  40. sheet.bind(EVENTS.ValueChanged, me.onValueChanged);
  41. sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
  42. sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
  43. sheet.bind(EVENTS.SelectionChanged, me.onSelectionChanged);
  44. workBook.bind(EVENTS.RangeChanged, me.onRangeChanged);
  45. me.bindTools();
  46. },
  47. bindTools: function () {
  48. let me = contentOprObj;
  49. let sheet = me.workBook.getActiveSheet();
  50. $('#jobAdd').click(function () {
  51. me.insertContent(sheet, me.currentCache.length, '');
  52. me.workBook.focus();
  53. });
  54. $('#jobInsert').click(function(){
  55. me.insertContent(sheet, sheet.getActiveRowIndex(), '');
  56. me.workBook.focus();
  57. });
  58. $('#jobDel').click(function(){
  59. me.deleteContent(sheet.getActiveRowIndex());
  60. me.workBook.focus();
  61. });
  62. $('#jobUp').click(function(){
  63. me.upMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
  64. me.workBook.focus();
  65. });
  66. $('#jobDown').click(function(){
  67. me.downMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
  68. me.workBook.focus();
  69. });
  70. },
  71. //将从清单库中添加的清单,把标准清单的工作内容转化成清单的工作内容
  72. buildJobContent: function (jobs) {
  73. let jobContent = [];
  74. for(let i = 0, len = jobs.length; i < len; i++){
  75. let newJob = {serialNo: i + 1, content: jobs[i].content, isChecked: true};//从清单库添加过来的默认输出
  76. jobContent.push(newJob);
  77. }
  78. return jobContent;
  79. },
  80. //显示在jobSpread的数据
  81. showContentData: function (sheet, setting, datas) {
  82. sheetCommonObj.showData(sheet, setting, datas);
  83. sheet.suspendPaint();
  84. sheet.suspendEvent();
  85. for(let i = 0, len = datas.length; i < len; i++){
  86. sheet.getCell(i, 0).locked(true);
  87. }
  88. sheet.resumePaint();
  89. sheet.suspendEvent();
  90. },
  91. //显示到清单工作内容列的数据
  92. getColData: function (jobsArr) {
  93. let me = contentOprObj;
  94. let rstStr = "", count = 0;
  95. for(let i = 0, len = jobsArr.length; i < len; i++){
  96. if(jobsArr[i].isChecked === true){
  97. count ++;
  98. /* if(count === 1){
  99. rstStr += "“";
  100. }
  101. else{
  102. rstStr += " ";
  103. }*/
  104. rstStr += count + ". " + jobsArr[i].content + "\n";
  105. }
  106. }
  107. if(rstStr.trim().length > 0){
  108. let reg = /\n+$/g;
  109. let newStr = rstStr.replace(reg, "");
  110. return newStr;
  111. }
  112. return null;
  113. },
  114. //新增行
  115. addRow: function (idx, sheet) {
  116. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  117. checkBox.isThreeState = false;
  118. sheet.addRows(idx, 1);
  119. sheet.getCell(idx - 1, 1).cellType(checkBox);
  120. },
  121. upMove: function (cell) {
  122. let me = contentOprObj;
  123. let thisObj = me.currentCache[cell.row],
  124. preObj = me.currentCache[cell.row - 1],
  125. temp, contentTxt;
  126. temp = thisObj.serialNo;
  127. thisObj.serialNo = preObj.serialNo;
  128. preObj.serialNo = temp;
  129. me.sortCache(me.currentCache);
  130. me.save(function () {
  131. me.workBook.focus();
  132. me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
  133. me.initSelection(cell.row - 1);
  134. });
  135. },
  136. downMove: function (cell) {
  137. let me = contentOprObj;
  138. let thisObj = me.currentCache[cell.row],
  139. nextObj = me.currentCache[cell.row + 1],
  140. temp, contentTxt;
  141. temp = thisObj.serialNo;
  142. thisObj.serialNo = nextObj.serialNo;
  143. nextObj.serialNo = temp;
  144. me.sortCache(me.currentCache);
  145. me.save(function () {
  146. me.workBook.focus();
  147. me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
  148. me.initSelection(cell.row + 1);
  149. });
  150. },
  151. deleteContent: function (rowIdx) {
  152. let me = contentOprObj;
  153. me.currentCache.splice(rowIdx, 1);
  154. me.save();
  155. me.workBook.focus();
  156. },
  157. //更新
  158. updateContent: function (job, newContent, save = true) {
  159. let me = contentOprObj;
  160. job.content = newContent;
  161. if(save){
  162. me.save();
  163. }
  164. },
  165. //新增
  166. insertContent: function (sheet, idx, content) {
  167. let me = contentOprObj;
  168. me.addRow(idx, sheet);
  169. let newObj = {content: content, isChecked: true};
  170. me.currentCache.splice(idx, 0, newObj);
  171. //重新排序赋值
  172. pageCCOprObj.resortNo(me.currentCache);
  173. me.save();
  174. me.workBook.focus();
  175. },
  176. save: function (callback) {
  177. let selectedNode = projectObj.mainController.tree.selected;
  178. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  179. pageCCOprObj.setCharacterBySetting(selectedNode, setting, callback, contentOprObj);
  180. },
  181. onEditStart(sender, args){
  182. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  183. args.cancel = true;
  184. return;
  185. }
  186. },
  187. onValueChanged: function (sender, args) {
  188. let me = contentOprObj;
  189. if(me.setting.header[args.col].dataCode === 'isChecked'){
  190. return;
  191. }
  192. args.newValue = args.newValue ? args.newValue : '';
  193. //更新
  194. if(args.row < me.currentCache.length){
  195. let job = me.currentCache[args.row];
  196. me.updateContent(job, args.newValue);
  197. }
  198. },
  199. //复选框控制输出
  200. onButtonClicked: function (sender, args) {
  201. let me = contentOprObj, contentTxt;
  202. if(args.sheet.isEditing()){
  203. args.sheet.endEdit(true);
  204. }
  205. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  206. args.sheet.setValue(args.row, args.col, 0);
  207. return;
  208. }
  209. let isChecked = args.sheet.getValue(args.row, args.col);
  210. if(me.currentCache.length > args.row){
  211. me.currentCache[args.row].isChecked = isChecked;
  212. me.save();
  213. }
  214. //else的情况就是新增
  215. else{
  216. //还没数据清空复选框
  217. args.sheet.setValue(args.row, args.col, 0);
  218. }
  219. },
  220. onRangeChanged: function (sender, args) {
  221. let me = contentOprObj;
  222. let rangeCell = isDef(args.changedCells[0]) ? args.changedCells[0] : null;
  223. if(!rangeCell){
  224. return;
  225. }
  226. let rangeData = isDef(me.currentCache[rangeCell.row]) ? me.currentCache[rangeCell.row] : null;
  227. if(!rangeData){
  228. return;
  229. }
  230. if(rangeCell.col === 0){//工作内容
  231. me.updateContent(rangeData, '');
  232. }
  233. else if(rangeCell.col === 1){//输出
  234. rangeData.isChecked = false;
  235. me.save();
  236. }
  237. },
  238. //复制粘贴
  239. onClipboardPasting: function (sender, args) {
  240. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  241. args.cancel = true;
  242. return;
  243. }
  244. if(args.cellRange.colCount > 1 || args.cellRange.col !== 0){
  245. args.cancel = true;
  246. }
  247. },
  248. onClipboardPasted: function (sender, args) {
  249. let me = contentOprObj;
  250. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  251. let toSave = false;
  252. for(let i = 0, len = items.length; i < len; i++){
  253. let rowIdx = args.cellRange.row + i;
  254. //更新
  255. if(rowIdx < me.currentCache.length){
  256. toSave = true;
  257. me.updateContent(me.currentCache[rowIdx], items[i].content, false);
  258. }
  259. }
  260. if(toSave){
  261. me.save();
  262. }
  263. },
  264. onSelectionChanged: function (sender, args) {
  265. let me = contentOprObj;
  266. if(args.newSelections && args.newSelections.length > 0){
  267. me.initSelection(args.newSelections[0].row);
  268. }
  269. },
  270. initSelection: function (row) {
  271. let me = contentOprObj;
  272. let disObj = {jobAdd: false, jobInsert: true, jobDel: true, jobUp: true, jobDown: true};
  273. disObj.jobAdd = !pageCCOprObj.canAddType();
  274. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  275. disObj.jobAdd = true;
  276. disObj.jobInsert = true;
  277. disObj.jobDel = true;
  278. disObj.jobUp = true;
  279. disObj.jobDown = true;
  280. }
  281. else{
  282. if(row !== -1){
  283. //在表内
  284. if(row < me.currentCache.length){
  285. disObj.jobDel = false;
  286. disObj.jobInsert = false;
  287. if(row !== 0){
  288. disObj.jobUp = false;
  289. }
  290. if(row !== me.currentCache.length - 1){
  291. disObj.jobDown = false;
  292. }
  293. }
  294. }
  295. }
  296. me.refreshTools(disObj);
  297. },
  298. //刷新工具条
  299. refreshTools: function (disObj) {
  300. for(let o in disObj){
  301. let jqSel = $(`#${o}`);
  302. jqSel.removeClass('disabled');
  303. if(disObj[o]){
  304. jqSel.addClass('disabled');
  305. }
  306. }
  307. },
  308. sortCache: function (cacheArr) {
  309. cacheArr.sort(function (a, b) {
  310. let rst = 0;
  311. if(a.serialNo > b.serialNo){
  312. rst = 1;
  313. }
  314. else if(a.serialNo < b.serialNo){
  315. rst = -1;
  316. }
  317. return rst;
  318. });
  319. },
  320. onContextmenuOpr: function () {//右键菜单
  321. let me = contentOprObj;
  322. $.contextMenu({
  323. selector: '#jobSpread',
  324. build: function($triggerElement, e){
  325. //控制允许右键菜单在哪个位置出现
  326. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  327. let sheet = me.workBook.getSheet(0);
  328. let addDis = pageCCOprObj.canAddType() ? false : true, insertDis = false, delDis = false, upDis = false, downDis = false;
  329. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  330. //清单锁定,不可用
  331. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  332. addDis = true;
  333. insertDis = true;
  334. delDis = true;
  335. upDis = true;
  336. downDis = true;
  337. }
  338. else{
  339. if(typeof target.row !== 'undefined'){
  340. //控制按钮是否可用
  341. sheet.setActiveCell(target.row, target.col);
  342. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  343. insertDis = true;
  344. delDis = true;
  345. downDis = true;
  346. upDis = true;
  347. }
  348. else{//有数据
  349. if(typeof target.col === 'undefined'){//定位不在表格内
  350. insertDis = true;
  351. downDis = true;
  352. upDis = true;
  353. delDis = true;
  354. }
  355. else{//定位在表格内
  356. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  357. downDis = true;
  358. }
  359. if(target.row === 0){//定位在第一行,不可上移
  360. upDis = true;
  361. }
  362. }
  363. }
  364. }
  365. else{
  366. insertDis = true;
  367. delDis = true;
  368. downDis = true;
  369. upDis = true;
  370. }
  371. }
  372. me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
  373. return {
  374. callback: function(){},
  375. items: {
  376. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  377. me.insertContent(sheet, sheet.getActiveRowIndex(), '');
  378. }},
  379. "add": {name: "添加", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
  380. me.insertContent(sheet, me.currentCache.length, '');
  381. }},
  382. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  383. me.deleteContent(target.row);
  384. }},
  385. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  386. me.upMove({row: target.row, col: target.col});
  387. }},
  388. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  389. me.downMove({row: target.row, col: target.col});
  390. }}
  391. }
  392. };
  393. }
  394. else{
  395. me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
  396. return false;
  397. }
  398. }
  399. });
  400. }
  401. };
  402. let characterOprObj = {
  403. workBook: null,
  404. currentCache: [],
  405. setting: {
  406. header: [
  407. {headerName:"项目特征",headerWidth:120, rateWidth:0.9, dataCode:"character", dataType: "String", hAlign: "left", vAlign: "center"},
  408. {headerName:"特征值",headerWidth:160,dataCode:"eigenvalue", dataType: "String", cellType: "comboBox", hAlign: "left", vAlign: "center"},
  409. {headerName:"输出",headerWidth:40,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
  410. ]
  411. },
  412. buildSheet: function(container) {
  413. let me = characterOprObj;
  414. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  415. //获取项目特征列比例
  416. let workBookWidth = pageCCOprObj.getWorkBookWidth();
  417. me.setRateWith(workBookWidth);
  418. sheetCommonObj.setColumnWidthByRate(workBookWidth, me.workBook, me.setting.header);
  419. me.workBook.options.allowUserDragDrop = false;
  420. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  421. me.workBook.options.allowCopyPasteExcelStyle = false;
  422. if(!projectReadOnly){
  423. me.onContextmenuOpr();
  424. }
  425. me.bindEvents(me.workBook);
  426. },
  427. setRateWith: function (workBookWidth) {
  428. let me = this;
  429. let otherWidthRate = (me.setting.header[1]['headerWidth'] + me.setting.header[2]['headerWidth']) / workBookWidth;
  430. let contentWidthRate = 1 - otherWidthRate;
  431. me.setting.header[0]['rateWidth'] = contentWidthRate;
  432. },
  433. bindEvents: function (workBook) {
  434. let sheet = workBook.getActiveSheet(), me = characterOprObj;
  435. const EVENTS = GC.Spread.Sheets.Events;
  436. workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
  437. sheet.bind(EVENTS.EnterCell, me.onEnterCell);
  438. sheet.bind(EVENTS.ValueChanged, me.onValueChanged);
  439. sheet.bind(EVENTS.EditStarting, me.onEditStart);
  440. sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
  441. sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
  442. sheet.bind(EVENTS.SelectionChanged, me.onSelectionChanged);
  443. workBook.bind(EVENTS.RangeChanged, me.onRangeChanged);
  444. me.bindTools();
  445. },
  446. bindTools: function () {
  447. let me = characterOprObj;
  448. let sheet = me.workBook.getActiveSheet();
  449. $('#itemAdd').click(function () {
  450. me.insertCharacter(sheet, me.currentCache.length, '');
  451. me.workBook.focus();
  452. });
  453. $('#itemInsert').click(function(){
  454. me.insertCharacter(sheet, sheet.getActiveRowIndex(), '');
  455. me.workBook.focus();
  456. });
  457. $('#itemDel').click(function(){
  458. me.deleteCharacter(sheet.getActiveRowIndex());
  459. me.workBook.focus();
  460. });
  461. $('#itemUp').click(function(){
  462. me.upMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
  463. me.workBook.focus();
  464. });
  465. $('#itemDown').click(function(){
  466. me.downMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
  467. me.workBook.focus();
  468. });
  469. },
  470. //将从清单库中添加的清单,把标准清单的项目特征转化成清单的项目特征
  471. buildItemCharactet: function (items) {//从清单库过来的默认不输出
  472. let itemCharacter = [];
  473. for(let i = 0, len = items.length; i < len; i++){
  474. let newItem = {serialNo: i + 1, character: items[i].content, eigenvalue: [], isChecked: false};
  475. let eigenvalues = items[i].itemValue;
  476. for(let j = 0, len = eigenvalues.length; j < len; j++){
  477. let newValue = {value: eigenvalues[j].value, isSelected: false};
  478. newItem.eigenvalue.push(newValue);
  479. }
  480. itemCharacter.push(newItem);
  481. }
  482. return itemCharacter;
  483. },
  484. //显示在itemSpread的数据
  485. showCharacterData: function (sheet, setting, datas) {
  486. let me = characterOprObj;
  487. sheetCommonObj.showData(sheet, setting, datas);
  488. sheet.suspendPaint();
  489. sheet.suspendEvent();
  490. for(let i = 0, len = datas.length; i < len; i++){
  491. let comboObj = me.getComboBox(datas[i]);
  492. comboObj.combo.editable(false);//不可编辑
  493. sheet.getCell(i, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  494. sheet.getCell(i, 0).locked(true);
  495. }
  496. sheet.resumePaint();
  497. sheet.suspendEvent();
  498. },
  499. //获得项目特征特征值comboBox
  500. getComboBox: function (characterItem) {
  501. let rst = {};
  502. let combo = sheetCommonObj.getDynamicCombo();
  503. let comboItems = [], eigenvalues = characterItem.eigenvalue;
  504. for(let i = 0, len = eigenvalues.length; i < len; i++){
  505. comboItems.push(eigenvalues[i].value);
  506. if(eigenvalues[i].isSelected){
  507. rst.selectedValue = eigenvalues[i].value;
  508. }
  509. }
  510. combo.items(comboItems);
  511. rst.combo = combo;
  512. return rst;
  513. },
  514. //获得当前行选中的特征值
  515. getCurrentSelected: function (item) {
  516. let rst = null;
  517. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  518. if(item.eigenvalue[i].isSelected){
  519. rst = item.eigenvalue[i].value;
  520. break;
  521. }
  522. }
  523. return rst;
  524. },
  525. //显示到清单项目特征列的数据
  526. getColData: function (itemsArr) {
  527. let me = characterOprObj;
  528. let rstStr = "", count = 0;
  529. for(let i = 0, len = itemsArr.length; i < len; i++){
  530. if(itemsArr[i].isChecked === true){
  531. //获取选中的特征值
  532. let eigenvalueStr = "";
  533. let eigenvalue = itemsArr[i].eigenvalue;
  534. for(let j = 0, vLen = eigenvalue.length; j < vLen; j++){
  535. if(eigenvalue[j].isSelected){
  536. eigenvalueStr += eigenvalue[j].value;
  537. break;
  538. }
  539. }
  540. count ++;
  541. /*if(count === 1){
  542. rstStr += "“";
  543. }
  544. else{
  545. rstStr += " ";
  546. }*/
  547. rstStr += count + ". " + itemsArr[i].character + ": " + eigenvalueStr + "\n";
  548. }
  549. }
  550. if(rstStr.trim().length > 0){
  551. let reg = /\n+$/g;
  552. let newStr = rstStr.replace(reg, "");
  553. return newStr;
  554. }
  555. return null;
  556. },
  557. addRow: function (idx, sheet) {
  558. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox(),
  559. combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  560. checkBox.isThreeState = false;
  561. combo.editable(true);
  562. sheet.addRows(idx, 1);
  563. sheet.getCell(idx, 1).cellType(combo);
  564. sheet.getCell(idx, 2).cellType(checkBox);
  565. },
  566. upMove: function (cell) {
  567. let me = characterOprObj;
  568. let thisObj = me.currentCache[cell.row],
  569. preObj = me.currentCache[cell.row - 1],
  570. temp;
  571. temp = thisObj.serialNo;
  572. thisObj.serialNo = preObj.serialNo;
  573. preObj.serialNo = temp;
  574. contentOprObj.sortCache(me.currentCache);
  575. me.save(function () {
  576. me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
  577. me.workBook.focus();
  578. me.initSelection(cell.row - 1);
  579. });
  580. },
  581. downMove: function (cell) {
  582. let me = characterOprObj;
  583. let thisObj = me.currentCache[cell.row],
  584. nextObj = me.currentCache[cell.row + 1],
  585. temp;
  586. temp = thisObj.serialNo;
  587. thisObj.serialNo = nextObj.serialNo;
  588. nextObj.serialNo = temp;
  589. contentOprObj.sortCache(me.currentCache);
  590. me.save(function () {
  591. me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
  592. me.workBook.focus();
  593. me.initSelection(cell.row + 1);
  594. });
  595. },
  596. deleteCharacter: function (rowIdx) {
  597. let me = characterOprObj;
  598. me.currentCache.splice(rowIdx, 1);
  599. me.save();
  600. me.workBook.focus();
  601. },
  602. //取消选择的特征值
  603. unsetSelected: function (item) {
  604. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  605. if(item.eigenvalue[i].isSelected){
  606. item.eigenvalue[i].isSelected = false;
  607. }
  608. }
  609. },
  610. //设置选中的特征值
  611. setSelected: function (item, value) {
  612. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  613. if(item.eigenvalue[i].value === value){
  614. item.eigenvalue[i].isSelected = true;
  615. }
  616. }
  617. },
  618. //改变选择特征值
  619. changeSelected: function (item, value) {
  620. let me = characterOprObj;
  621. me.unsetSelected(item);
  622. me.setSelected(item, value);
  623. },
  624. insertValue: function (item, value) {
  625. let me = characterOprObj;
  626. me.unsetSelected(item);
  627. let newValue = {value: value, isSelected: true};
  628. item.eigenvalue.push(newValue);
  629. },
  630. updateCharacter: function (item, character, value, save = true) {
  631. let me = characterOprObj;
  632. if(character !== undefined && character !== null){
  633. item.character = character;
  634. }
  635. if(value !== undefined && value !== null){
  636. if(value !== ''){
  637. let isExist = false;
  638. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  639. if(item.eigenvalue[i].value === value){
  640. isExist = true;
  641. break;
  642. }
  643. }
  644. //不存在,新增进eigenvalue,自动打勾输出
  645. if(!isExist){
  646. //更新selected
  647. me.insertValue(item, value);
  648. item.isChecked = true;
  649. }
  650. //存在,选择特征值,自动打勾输出
  651. else{
  652. me.changeSelected(item, value);
  653. item.isChecked = true;
  654. }
  655. }
  656. else {
  657. me.unsetSelected(item);
  658. }
  659. }
  660. if(save){
  661. me.save();
  662. }
  663. },
  664. insertCharacter: function (sheet, idx, character) {
  665. let me = characterOprObj;
  666. me.addRow(idx, sheet);
  667. let newObj = {character: character, eigenvalue: [], isChecked: false};
  668. me.currentCache.splice(idx, 0, newObj);
  669. pageCCOprObj.resortNo(me.currentCache);
  670. me.save();
  671. me.workBook.focus();
  672. },
  673. save: function (callback) {
  674. let selectedNode = projectObj.mainController.tree.selected;
  675. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  676. pageCCOprObj.setCharacterBySetting(selectedNode, setting, callback, characterOprObj);
  677. },
  678. onEditStart: function (sender, args) {
  679. let me = characterOprObj;
  680. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  681. args.cancel = true;
  682. return;
  683. }
  684. if(args.col === 1){//改变选择的特征值
  685. me.currentSelectedValue = me.currentCache.length > args.row ? me.getCurrentSelected(me.currentCache[args.row]) : null;
  686. }
  687. },
  688. onEnterCell: function (sender, args) {
  689. args.sheet.repaint();
  690. },
  691. onValueChanged: function (sender, args) {
  692. let me = characterOprObj;
  693. args.newValue = args.newValue ? args.newValue : '';
  694. //更新
  695. if(args.row < me.currentCache.length){
  696. let thisCha = me.currentCache[args.row];
  697. if(args.col === 0){//特征
  698. me.updateCharacter(thisCha, args.newValue, null);
  699. }
  700. else if(args.col === 1){//特征值
  701. me.updateCharacter(thisCha, null, args.newValue);
  702. }
  703. }
  704. },
  705. onClipboardPasting: function (sender, args) {
  706. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  707. args.cancel = true;
  708. }
  709. if(args.cellRange.col + args.colCount - 1 > 1){
  710. args.cancel = true;
  711. }
  712. },
  713. onClipboardPasted: function (sender, args) {
  714. let me = characterOprObj;
  715. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  716. let toSave = false;
  717. for(let i = 0, len = items.length; i < len; i++){
  718. //更新
  719. let rowIdx = args.cellRange.row + i;
  720. if(me.currentCache.length > rowIdx){
  721. toSave = true;
  722. me.updateCharacter(me.currentCache[rowIdx], items[i].character, items[i].eigenvalue, false);
  723. }
  724. }
  725. if(toSave){
  726. me.save();
  727. }
  728. },
  729. onRangeChanged: function (sender, args) {
  730. let me = characterOprObj;
  731. let rangeCell = isDef(args.changedCells[0]) ? args.changedCells[0] : null;
  732. if(!rangeCell){
  733. return;
  734. }
  735. let rangeData = isDef(me.currentCache[rangeCell.row]) ? me.currentCache[rangeCell.row] : null;
  736. if(!rangeData){
  737. return;
  738. }
  739. if(rangeCell.col === 0){//特征
  740. me.updateCharacter(rangeData, '', null);
  741. }
  742. else if(rangeCell.col === 1){//特征值
  743. me.updateCharacter(rangeData, null, '');
  744. }
  745. else if(rangeCell.col === 2){
  746. rangeData.isChecked = false;
  747. me.save();
  748. }
  749. /*if(rangeCell.col === 1){//特征值
  750. rangeData.isChecked = false;
  751. for(let value of rangeData.eigenvalue){
  752. value.isSelected = false;
  753. }
  754. }*/
  755. //me.save();
  756. },
  757. //复选框控制输出
  758. onButtonClicked: function (sender, args) {
  759. let me = characterOprObj, characterTxt;
  760. if(args.sheet.isEditing()){
  761. args.sheet.endEdit(true);
  762. }
  763. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  764. args.sheet.setValue(args.row, args.col, 0);
  765. return;
  766. }
  767. let isChecked = args.sheet.getValue(args.row, args.col);
  768. if(me.currentCache.length > args.row){
  769. me.currentCache[args.row].isChecked = isChecked;
  770. me.save();
  771. }
  772. //else的情况就是新增
  773. else{
  774. args.sheet.setValue(args.row, args.col, 0);
  775. }
  776. },
  777. onSelectionChanged: function (sender, args) {
  778. let me = characterOprObj;
  779. if(args.newSelections && args.newSelections.length > 0){
  780. me.initSelection(args.newSelections[0].row);
  781. }
  782. },
  783. initSelection: function (row) {
  784. let me = characterOprObj;
  785. let disObj = {itemAdd: false, itemInsert: true, itemDel: true, itemUp: true, itemDown: true};
  786. disObj.itemAdd = !pageCCOprObj.canAddType();
  787. //清单锁定,不可用
  788. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  789. disObj.itemAdd = true;
  790. disObj.itemInsert = true;
  791. disObj.itemDel = true;
  792. disObj.itemUp = true;
  793. disObj.itemDown = true;
  794. }
  795. else{
  796. if(row !== -1){
  797. //在表内
  798. if(row < me.currentCache.length){
  799. disObj.itemDel = false;
  800. disObj.itemInsert = false;
  801. if(row !== 0){
  802. disObj.itemUp = false;
  803. }
  804. if(row !== me.currentCache.length - 1){
  805. disObj.itemDown = false;
  806. }
  807. }
  808. }
  809. }
  810. me.refreshTools(disObj);
  811. },
  812. //刷新工具条
  813. refreshTools: function (disObj) {
  814. for(let o in disObj){
  815. let jqSel = $(`#${o}`);
  816. jqSel.removeClass('disabled');
  817. if(disObj[o]){
  818. jqSel.addClass('disabled');
  819. }
  820. }
  821. },
  822. onContextmenuOpr: function () {//右键菜单
  823. let me = characterOprObj;
  824. $.contextMenu({
  825. selector: '#itemSpread',
  826. build: function($triggerElement, e){
  827. //控制允许右键菜单在哪个位置出现
  828. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  829. let sheet = me.workBook.getSheet(0);
  830. let addDis = pageCCOprObj.canAddType() ? false : true, insertDis = false, delDis = false, upDis = false, downDis = false;
  831. if(target.hitTestType === 3){//在表格内 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  832. //清单锁定,则不可用
  833. if(projectInfoObj.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  834. addDis = true;
  835. insertDis = true;
  836. delDis = true;
  837. upDis = true;
  838. downDis = true;
  839. }
  840. else{
  841. if(typeof target.row !== 'undefined'){
  842. //控制按钮是否可用
  843. sheet.setActiveCell(target.row, target.col);
  844. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  845. insertDis = true;
  846. delDis = true;
  847. downDis = true;
  848. upDis = true;
  849. }
  850. else{//有数据
  851. if(typeof target.col === 'undefined'){//定位在表格外
  852. insertDis = true;
  853. downDis = true;
  854. upDis = true;
  855. delDis = true;
  856. }
  857. else{
  858. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  859. downDis = true;
  860. }
  861. if(target.row === 0){//定位在第一行,不可上移
  862. upDis = true;
  863. }
  864. }
  865. }
  866. }
  867. else{
  868. insertDis = true;
  869. delDis = true;
  870. downDis = true;
  871. upDis = true;
  872. }
  873. }
  874. me.refreshTools({itemAdd: addDis, itemInsert: insertDis, itemDel: delDis, itemUp: upDis, itemDown: downDis});
  875. return {
  876. callback: function(){},
  877. items: {
  878. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  879. me.insertCharacter(sheet, sheet.getActiveRowIndex(), '');
  880. }},
  881. "add": {name: "添加", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
  882. me.insertCharacter(sheet, me.currentCache.length, '');
  883. }},
  884. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  885. me.deleteCharacter(target.row);
  886. }},
  887. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  888. me.upMove({row: target.row, col: target.col});
  889. }},
  890. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  891. me.downMove({row: target.row, col: target.col});
  892. }}
  893. }
  894. };
  895. }
  896. else{
  897. me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
  898. return false;
  899. }
  900. }
  901. });
  902. }
  903. };
  904. let pageCCOprObj = {
  905. currentFindSet: null,
  906. mainActiveCell: null,//mainSpread焦点单元格
  907. nameCache: '',
  908. //重新赋serialNo
  909. resortNo: function (items) {
  910. let count = 1;
  911. for(let item of items){
  912. item.serialNo = count++;
  913. }
  914. },
  915. //可以添加的类型:分项、补项、清单
  916. canAddType: function () {
  917. let rst = false;
  918. let selectedNode = projectObj.mainController.tree.selected;
  919. if(selectedNode && selectedNode.sourceType === projectObj.project.Bills.getSourceType() &&
  920. (selectedNode.data.type === billType.FX || selectedNode.data.type === billType.BX || selectedNode.data.type === billType.BILL)){//为清单
  921. rst = true
  922. }
  923. return rst;
  924. },
  925. setItemContentNode: function (node, jobs, items, name = '') {
  926. let theCont = contentOprObj, theCha = characterOprObj,
  927. jobContent, itemCharacter, contentTxt, characterTxt;
  928. jobContent = theCont.buildJobContent(jobs);
  929. itemCharacter = theCha.buildItemCharactet(items);
  930. // contentTxt = theCont.getColData(jobContent);
  931. // characterTxt = theCha.getColData(itemCharacter);
  932. node.data.jobContent = jobContent;
  933. node.data.itemCharacter = itemCharacter;
  934. this.nameCache = name;
  935. // 根据规则设置对应特征、内容、名称格式
  936. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  937. const updateData = pageCCOprObj.getCharacterUpdateData(setting, node);
  938. node.data.jobContentText = updateData.jobContentText;
  939. node.data.itemCharacterText = updateData.itemCharacterText;
  940. node.data.name = updateData.name;
  941. },
  942. safeItemCharater: function (itemCharater) {
  943. return characterOprObj.buildItemCharactet(itemCharater);
  944. },
  945. //设置特征及内容currentCache
  946. setCacheAndShow: function (node) {
  947. if(!projectReadOnly){
  948. this.refreshRuleTools(projectObj.project.isBillsLocked());
  949. }
  950. if(node && node.sourceType === projectObj.project.Bills.getSourceType()){
  951. let theCont = contentOprObj, theCha = characterOprObj;
  952. node.data.jobContent = node && typeof node.data.jobContent !== 'undefined' ? node.data.jobContent : [];
  953. node.data.itemCharacter = node && typeof node.data.itemCharacter !== 'undefined' ? node.data.itemCharacter : [];
  954. theCont.currentCache = node.data.jobContent;
  955. theCha.currentCache = node.data.itemCharacter;
  956. this.currentFindSet = node && typeof node.data.ID !== 'undefined' && typeof node.data.projectID ? {ID: node.data.ID, projectID: node.data.projectID} : null;
  957. this.showData(theCont.workBook.getSheet(0), theCont.setting, theCont.currentCache);
  958. this.showData(theCha.workBook.getSheet(0), theCha.setting, theCha.currentCache);
  959. }
  960. else{
  961. this.clearData();
  962. }
  963. },
  964. //contentSpread、itemSpread展示数据用
  965. showData: function(sheet, setting, data) {
  966. let me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  967. sheet.suspendPaint();
  968. sheet.suspendEvent();
  969. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  970. sheet.setRowCount(data.length);
  971. for (let col = 0; col < setting.header.length; col++) {
  972. var hAlign = "left", vAlign = "center";
  973. if (setting.header[col].hAlign) {
  974. hAlign = setting.header[col].hAlign;
  975. } else if (setting.header[col].dataType !== "String"){
  976. hAlign = "right";
  977. }
  978. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  979. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  980. if (setting.header[col].formatter) {
  981. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  982. }
  983. for (let row = 0; row < data.length; row++) {
  984. sheet.getCell(row, 0).locked(true);//locked
  985. let val = data[row][setting.header[col].dataCode];
  986. if(setting.header[col].cellType === "checkBox"){
  987. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  988. checkBox.isThreeState(false);
  989. sheet.getCell(row, col).cellType(checkBox).value(val);
  990. }
  991. else if(setting.header[col].cellType === 'comboBox'){
  992. let comboObj = characterOprObj.getComboBox(data[row]);
  993. comboObj.combo.editable(true);//可编辑
  994. sheet.getCell(row, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  995. }
  996. else{
  997. sheet.setValue(row, col, val, ch);
  998. }
  999. sheet.getCell(row, col).wordWrap(true);
  1000. sheet.autoFitRow(row);
  1001. }
  1002. }
  1003. contentOprObj.initSelection(contentOprObj.workBook.getSheet(0).getActiveRowIndex());
  1004. characterOprObj.initSelection(characterOprObj.workBook.getSheet(0).getActiveRowIndex());
  1005. sheet.resumeEvent();
  1006. sheet.resumePaint();
  1007. },
  1008. clearData: function () {
  1009. let theCon = contentOprObj, theCha = characterOprObj;
  1010. theCon.workBook.getSheet(0).setRowCount(0);
  1011. theCon.refreshTools({jobAdd: true, jobInsert: true, jobDel: true, jobUp: true, jobDown: true});
  1012. theCha.workBook.getSheet(0).setRowCount(0);
  1013. theCha.refreshTools({itemAdd: true, itemInsert: true, itemDel: true, itemUp: true, itemDown: true});
  1014. sheetCommonObj.cleanSheet(theCon.workBook.getSheet(0), theCon.setting, -1);
  1015. sheetCommonObj.cleanSheet(theCha.workBook.getSheet(0), theCha.setting, -1);
  1016. projectObj.mainSpread.focus(true);
  1017. },
  1018. //锁定/解锁清单后添加规则的改变
  1019. refreshRuleTools: function (lockBills) {
  1020. $('#use-to-current').removeClass('disabled');
  1021. $('#use-to-all').removeClass('disabled');
  1022. if(lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
  1023. $('#use-to-current').addClass('disabled');
  1024. $('#use-to-all').addClass('disabled');
  1025. }
  1026. },
  1027. //更新特征及内容数据
  1028. updateCharacterContent: function (findSet, updateObj, txtObj, oprObj, callback) {
  1029. let me = pageCCOprObj, updateCol;
  1030. if(txtObj){
  1031. updateCol = txtObj.field === 'itemCharacterText' ? 4 : 5;//更新清单行特征列或内容列
  1032. }
  1033. else{
  1034. updateCol = null;
  1035. }
  1036. let url = '/bills/updateCharacterContent';
  1037. let postData = {
  1038. findSet: findSet,
  1039. updateObj: updateObj,
  1040. txtObj: txtObj
  1041. };
  1042. CommonAjax.post(url, postData, function (rstData) {
  1043. //更新节点数据
  1044. if(updateCol){
  1045. // 已当前选中行更新数据
  1046. let selectedNode = projectObj.mainController.tree.selected;
  1047. selectedNode.data[updateObj.field] = updateObj.updateArr;
  1048. selectedNode.data[txtObj.field] = txtObj.text;
  1049. me.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  1050. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  1051. projectObj.mainSpread.getActiveSheet().setValue(activeCell.row, updateCol, txtObj.text + ''); //刷新输出显示
  1052. projectObj.mainSpread.getActiveSheet().autoFitRow(activeCell.row);
  1053. if(callback){
  1054. callback();
  1055. }
  1056. }
  1057. });
  1058. },
  1059. /**
  1060. * 更新bill数据
  1061. *
  1062. * @param {Object} findSet - 更新条件
  1063. * @param {Object} updateData - 更新数据
  1064. * @param {Function} callback - 回调函数
  1065. * @return {void}
  1066. */
  1067. updateBill: function(findSet, updateData, callback) {
  1068. if (!updateData instanceof Array || updateData.length <= 0) {
  1069. return;
  1070. }
  1071. let url = '/bills/updateBill';
  1072. let postData = { findSet, updateData };
  1073. CommonAjax.post(url, postData, function (response) {
  1074. callback(response);
  1075. });
  1076. },
  1077. /**
  1078. * 刷新节点数据
  1079. *
  1080. * @param {Object} node - 节点数据
  1081. * @param {Object} refreshData - 刷新的数据
  1082. * @return {void}
  1083. */
  1084. refreshView: function(node, refreshData) {
  1085. // 更新清单行特征列或内容列
  1086. let updateCol = [
  1087. { name: 'itemCharacterText', col: colSettingObj.getColByField('itemCharacterText')},
  1088. { name: 'jobContentText', col: colSettingObj.getColByField('jobContentText')},
  1089. { name: 'name', col: colSettingObj.getColByField('name')}
  1090. ];
  1091. if (updateCol === '') {
  1092. return;
  1093. }
  1094. const row = node.serialNo();
  1095. // 刷新输出显示
  1096. for (const tmp of updateCol) {
  1097. // 没有默认的数据则跳过刷新
  1098. if (refreshData[tmp.name] === undefined) {
  1099. continue;
  1100. }
  1101. projectObj.mainSpread.getActiveSheet().setValue(row, tmp.col, refreshData[tmp.name] + '');
  1102. }
  1103. projectObj.mainSpread.getActiveSheet().autoFitRow(row);
  1104. },
  1105. /**
  1106. * 根据配置设置清单项目特征
  1107. *
  1108. * @param {Object} node - 选中的node节点
  1109. * @param {Object} setting - 设置
  1110. * @return {void}
  1111. */
  1112. setCharacterBySetting: function(node, setting, callback = null, oprObj = null, usedToAll = null) {
  1113. if(!node || node.sourceType !== projectObj.project.Bills.getSourceType()){
  1114. return;
  1115. }
  1116. let self = this;
  1117. // 保存的条件数据
  1118. const findSet = { ID: node.data.ID, projectID: node.data.projectID };
  1119. const updateData = this.getCharacterUpdateData(setting, node);
  1120. let saveObj = [];
  1121. for (const index in updateData) {
  1122. saveObj.push({field: index, value: updateData[index]});
  1123. }
  1124. //saveObj.push({field: 'addRule', value: setting});
  1125. saveObj.push({field: 'jobContent', value: node.data.jobContent});
  1126. saveObj.push({field: 'itemCharacter', value: node.data.itemCharacter});
  1127. if(usedToAll){
  1128. //应用到所有清单、过滤,只更新会发生变化的清单
  1129. let orgName = isDef(node.data.name) ? node.data.name : '';
  1130. let orgItemCharacterText = isDef(node.data.itemCharacterText) ? node.data.itemCharacterText : '';
  1131. let orgJobContentText = isDef(node.data.jobContentText) ? node.data.jobContentText : '';
  1132. if(orgName == updateData.name && orgItemCharacterText == updateData.itemCharacterText && orgJobContentText == updateData.jobContentText){
  1133. return;
  1134. }
  1135. }
  1136. // 更新到数据库
  1137. pageCCOprObj.updateBill(findSet, saveObj, function(response) {
  1138. self.refreshView(node, updateData);
  1139. // 更新项目属性的配置
  1140. //projectObj.project.property.addRule = setting;
  1141. // 更新节点数据
  1142. node.data.name = updateData.name;
  1143. node.data.itemCharacterText = updateData.itemCharacterText;
  1144. node.data.jobContentText = updateData.jobContentText;
  1145. if (oprObj) {
  1146. pageCCOprObj.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  1147. }
  1148. if(callback){
  1149. callback();
  1150. }
  1151. });
  1152. },
  1153. /**
  1154. * 格式化序号格式
  1155. *
  1156. * @param {Number} type - 格式化的类型
  1157. * @param {String} serialNo - 待格式化的序号
  1158. * @return {String} - 返回格式化后的字符
  1159. */
  1160. formatSerialNumber: function(type, serialNo) {
  1161. const letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  1162. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  1163. switch (type) {
  1164. case '1':
  1165. // 数字
  1166. serialNo = serialNo + '. ';
  1167. break;
  1168. case '2':
  1169. // 英文字母(小写)
  1170. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1] + '. ' : '';
  1171. break;
  1172. case '3':
  1173. // 英文字母(大写)
  1174. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1].toUpperCase() + '. ' : '';
  1175. break;
  1176. default:
  1177. serialNo = '';
  1178. break;
  1179. }
  1180. return serialNo;
  1181. },
  1182. /**
  1183. * 查找选中的树节点中定额子目数据
  1184. *
  1185. * @param {Object} selectNode - 选中的节点
  1186. * @param {Object} setting - 设置
  1187. * @return {Array} - 返回定额子目数组
  1188. */
  1189. getRationChapter: function(selectNode, setting) {
  1190. let result = [];
  1191. if (selectNode.children === undefined || selectNode.children.length <= 0) {
  1192. return result;
  1193. }
  1194. // 查找对应的定额数据
  1195. let count = 1;
  1196. for (const tmp of selectNode.children) {
  1197. if (tmp.sourceType !== 'ration') {
  1198. continue;
  1199. }
  1200. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  1201. if(setting.childDisplayFormat === '1'){
  1202. }
  1203. let code = isDef(tmp.data.code) ? tmp.data.code : '';
  1204. let name = isDef(tmp.data.name) ? tmp.data.name : '';
  1205. setting.childDisplayFormat === "1" ? result.push(code + ':' + name) : result.push(serialNo + name);
  1206. count++;
  1207. }
  1208. return result;
  1209. },
  1210. /**
  1211. * 获取默认数据
  1212. *
  1213. * @param {Object} node - 节点数据
  1214. * @param {Object} setting - 设置
  1215. * @return {Object}
  1216. */
  1217. getDataBySetting: function(node, setting) {
  1218. let result = {};
  1219. try {
  1220. if (node.data === undefined) {
  1221. throw '数据错误';
  1222. }
  1223. const itemCharacter = node.data.itemCharacter;
  1224. const itemJob = node.data.jobContent;
  1225. /* if (itemCharacter === undefined || itemCharacter.length <= 0 || itemJob === undefined || itemJob.length <= 0) {
  1226. throw '内部数据错误';
  1227. }*/
  1228. if (itemCharacter === undefined || itemJob === undefined) {
  1229. throw '内部数据错误';
  1230. }
  1231. // 默认名称
  1232. result['name'] = this.nameCache;
  1233. // 特征
  1234. let characterArray = [];
  1235. let count = 1;
  1236. for (const tmp of itemCharacter) {
  1237. if (!tmp.isChecked) {
  1238. continue;
  1239. }
  1240. if(tmp.eigenvalue === undefined || tmp.eigenvalue.length <= 0){
  1241. tmp.eigenvalue = [];
  1242. }
  1243. // 获取选中的特征值
  1244. let selectedEigen = '';
  1245. for (const eigen of tmp.eigenvalue) {
  1246. if (eigen.isSelected) {
  1247. selectedEigen = eigen.value;
  1248. }
  1249. }
  1250. // 匹配设置的序号格式
  1251. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  1252. let characterString = '';
  1253. // 特征生成方式
  1254. switch (setting.characterFormat) {
  1255. case '1':
  1256. // 特征值
  1257. characterString = serialNo + selectedEigen;
  1258. break;
  1259. case '2':
  1260. // 特征:特征值
  1261. characterString = serialNo + tmp.character + ': ' + selectedEigen;
  1262. break;
  1263. }
  1264. characterArray.push(characterString);
  1265. count++;
  1266. }
  1267. result['character'] = characterArray;
  1268. // 内容部分
  1269. let jobArray = [];
  1270. count = 1;
  1271. for (const tmp of itemJob) {
  1272. if (!tmp.isChecked) {
  1273. continue;
  1274. }
  1275. // 匹配设置的序号格式
  1276. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  1277. jobArray.push(serialNo + tmp.content);
  1278. count++;
  1279. }
  1280. result['content'] = jobArray;
  1281. } catch (error) {
  1282. console.log(error);
  1283. result = {};
  1284. }
  1285. return result;
  1286. },
  1287. /**
  1288. * 获取特征内容名称更新的数据
  1289. *
  1290. * @param {Object} setting - 设置
  1291. * @param {Object} node - 节点数据
  1292. * @return {Object} - 返回更新的数据
  1293. */
  1294. getCharacterUpdateData: function(setting, node) {
  1295. let updateData = {
  1296. itemCharacterText: '',
  1297. jobContentText: '',
  1298. name: node.data.name ? node.data.name : '',
  1299. };
  1300. /* let updateData = {
  1301. itemCharacterText: '',
  1302. jobContentText: '',
  1303. name: '',
  1304. };*/
  1305. if(!node.data.itemCharacter){
  1306. node.data.itemCharacter = [];
  1307. }
  1308. if(!node.data.jobContent){
  1309. node.data.jobContent = [];
  1310. }
  1311. if(setting.addContent !== '5'){
  1312. if (node.data.name === undefined || (node.data.itemCharacter.length <= 0 && node.data.jobContent.length <= 0)) {
  1313. return updateData;
  1314. }
  1315. }
  1316. // 获取原名称
  1317. const name = isDef(node.data.name) ? node.data.name.split("\n") : '';
  1318. this.nameCache = name[0] !== undefined ? name[0] : "";
  1319. updateData.name = this.nameCache;
  1320. let contentArray = [];
  1321. // 获取当前设置数据
  1322. const currentData = this.getDataBySetting(node, setting);
  1323. // 组合数据
  1324. let content = '';
  1325. switch (setting.addContent) {
  1326. case "1":
  1327. // 项目特征+工作内容
  1328. contentArray.push('[项目特征]');
  1329. contentArray.push.apply(contentArray, currentData.character);
  1330. contentArray.push('[工作内容]');
  1331. contentArray.push.apply(contentArray, currentData.content);
  1332. break;
  1333. case "2":
  1334. // 工作内容+项目特征
  1335. contentArray.push('[工作内容]');
  1336. contentArray.push.apply(contentArray, currentData.content);
  1337. contentArray.push('[项目特征]');
  1338. contentArray.push.apply(contentArray, currentData.character);
  1339. break;
  1340. case "3":
  1341. // 项目特征
  1342. contentArray.push.apply(contentArray, currentData.character);
  1343. break;
  1344. case "4":
  1345. // 工作内容
  1346. contentArray.push.apply(contentArray, currentData.content);
  1347. break;
  1348. case "5":
  1349. // 定额子目
  1350. const rationChapter = this.getRationChapter(node, setting);
  1351. contentArray.push.apply(contentArray, rationChapter);
  1352. break;
  1353. case "":
  1354. // 无
  1355. break;
  1356. }
  1357. // 显示格式
  1358. switch (setting.displayFormat) {
  1359. case "1":
  1360. // 换行分隔
  1361. content = contentArray.join("\n");
  1362. currentData.character = currentData.character.join("\n");
  1363. currentData.content = currentData.content.join("\n");
  1364. break;
  1365. case "2":
  1366. // 逗号分隔
  1367. content = contentArray.join(',');
  1368. currentData.character = currentData.character.join(",");
  1369. currentData.content = currentData.content.join(",");
  1370. break;
  1371. case "3":
  1372. // 括号分隔
  1373. content = '(' + contentArray.join(',') + ')';
  1374. break;
  1375. }
  1376. // 添加到对应位置
  1377. switch (setting.position) {
  1378. case "1":
  1379. // 添加到项目特征列
  1380. updateData.itemCharacterText = content;
  1381. break;
  1382. case "2":
  1383. // 添加到清单名称列
  1384. content = content !== '' ? this.nameCache + "\n" + content : this.nameCache;
  1385. updateData.name = content;
  1386. break;
  1387. case "3":
  1388. // 添加到工作内容列
  1389. updateData.jobContentText = content;
  1390. break;
  1391. case "4":
  1392. updateData = {
  1393. itemCharacterText: currentData.character,
  1394. jobContentText: currentData.content,
  1395. name: currentData.name,
  1396. };
  1397. break;
  1398. }
  1399. return updateData;
  1400. },
  1401. //获取特征及内容工作簿宽度
  1402. getWorkBookWidth: function () {
  1403. return ($(window).width() - $('.main-nav').width()) / 3 - 50;
  1404. }
  1405. }
  1406. $(window).resize(function () {
  1407. let workBookWidth = pageCCOprObj.getWorkBookWidth();
  1408. contentOprObj.setRateWith(workBookWidth);
  1409. sheetCommonObj.setColumnWidthByRate(workBookWidth, contentOprObj.workBook, contentOprObj.setting.header);
  1410. characterOprObj.setRateWith(workBookWidth);
  1411. sheetCommonObj.setColumnWidthByRate(workBookWidth, characterOprObj.workBook, characterOprObj.setting.header);
  1412. });