character_content_view.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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:160,dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center"},
  11. {headerName:"输出",headerWidth:80,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. me.workBook.options.allowUserDragDrop = false;
  18. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  19. me.workBook.options.allowCopyPasteExcelStyle = false;
  20. me.onContextmenuOpr();//右键菜单
  21. me.bindEvents(me.workBook);
  22. },
  23. bindEvents: function (workBook) {
  24. let sheet = workBook.getActiveSheet(), me = contentOprObj;
  25. const EVENTS = GC.Spread.Sheets.Events;
  26. workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
  27. sheet.bind(EVENTS.EditEnded, me.onEditEnded);
  28. sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
  29. sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
  30. },
  31. //将从清单库中添加的清单,把标准清单的工作内容转化成清单的工作内容
  32. buildJobContent: function (jobs) {
  33. let jobContent = [];
  34. for(let i = 0, len = jobs.length; i < len; i++){
  35. let newJob = {serialNo: i + 1, content: jobs[i].content, isChecked: true};//从清单库添加过来的默认输出
  36. jobContent.push(newJob);
  37. }
  38. return jobContent;
  39. },
  40. //显示在jobSpread的数据
  41. showContentData: function (sheet, setting, datas) {
  42. sheetCommonObj.showData(sheet, setting, datas);
  43. sheet.suspendPaint();
  44. sheet.suspendEvent();
  45. for(let i = 0, len = datas.length; i < len; i++){
  46. sheet.getCell(i, 0).locked(true);
  47. }
  48. sheet.resumePaint();
  49. sheet.suspendEvent();
  50. },
  51. //显示到清单工作内容列的数据
  52. getColData: function (jobsArr) {
  53. let me = contentOprObj;
  54. let rstStr = "", count = 0;
  55. for(let i = 0, len = jobsArr.length; i < len; i++){
  56. if(jobsArr[i].isChecked === true){
  57. count ++;
  58. /* if(count === 1){
  59. rstStr += "“";
  60. }
  61. else{
  62. rstStr += " ";
  63. }*/
  64. rstStr += count + ". " + jobsArr[i].content + "\n";
  65. }
  66. }
  67. if(rstStr.trim().length > 0){
  68. let reg = /\n+$/g;
  69. let newStr = rstStr.replace(reg, "");
  70. return newStr;
  71. }
  72. return null;
  73. },
  74. //新增行
  75. addRow: function (sheet) {
  76. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  77. checkBox.isThreeState = false;
  78. sheet.addRows(sheet.getRowCount(), 1);
  79. sheet.getCell(sheet.getRowCount() - 1, 1).cellType(checkBox);
  80. },
  81. upMove: function (cell) {
  82. let me = contentOprObj;
  83. let thisObj = me.currentCache[cell.row],
  84. preObj = me.currentCache[cell.row - 1],
  85. temp, contentTxt;
  86. temp = thisObj.serialNo;
  87. thisObj.serialNo = preObj.serialNo;
  88. preObj.serialNo = temp;
  89. me.sortCache(me.currentCache);
  90. me.save(function () {
  91. me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
  92. });
  93. },
  94. downMove: function (cell) {
  95. let me = contentOprObj;
  96. let thisObj = me.currentCache[cell.row],
  97. nextObj = me.currentCache[cell.row + 1],
  98. temp, contentTxt;
  99. temp = thisObj.serialNo;
  100. thisObj.serialNo = nextObj.serialNo;
  101. nextObj.serialNo = temp;
  102. me.sortCache(me.currentCache);
  103. me.save(function () {
  104. me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
  105. });
  106. },
  107. deleteContent: function (rowIdx) {
  108. let me = contentOprObj;
  109. me.currentCache.splice(rowIdx, 1);
  110. me.save();
  111. },
  112. //更新
  113. updateContent: function (job, newContent) {
  114. job.content = newContent;
  115. },
  116. //新增
  117. insertContent: function (content) {
  118. let me = contentOprObj;
  119. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  120. let newObj = {content: content, isCheceked: false, serialNo: preObj ? preObj.serialNo + 1 : 1};
  121. me.currentCache.push(newObj);
  122. },
  123. save: function (callback) {
  124. let selectedNode = projectObj.mainController.tree.selected;
  125. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  126. pageCCOprObj.setCharacterBySetting(contentOprObj, selectedNode, setting, callback);
  127. },
  128. onEditEnded: function (sender, args) {
  129. let me = contentOprObj;
  130. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  131. let contentTxt;
  132. if(args.editingText && args.editingText.toString().trim().length > 0){
  133. //更新
  134. if(args.row < me.currentCache.length ){
  135. me.updateContent(me.currentCache[args.row], args.editingText);
  136. }
  137. //新增
  138. else{
  139. me.insertContent(args.editingText);
  140. }
  141. //保存
  142. me.save();
  143. }
  144. else{
  145. //恢复
  146. args.sheet.setValue(args.row, args.col, me.currentCache.length > args.row ? me.currentCache[args.row].content + '' : '');
  147. }
  148. },
  149. //复选框控制输出
  150. onButtonClicked: function (sender, args) {
  151. let me = contentOprObj, contentTxt;
  152. if(args.sheet.isEditing()){
  153. args.sheet.endEdit(true);
  154. }
  155. let isChecked = args.sheet.getValue(args.row, args.col);
  156. if(me.currentCache.length > args.row){
  157. me.currentCache[args.row].isChecked = isChecked;
  158. me.save();
  159. }
  160. //else的情况就是新增
  161. else{
  162. //还没数据清空复选框
  163. args.sheet.setValue(args.row, args.col, 0);
  164. }
  165. },
  166. //复制粘贴
  167. onClipboardPasting: function (sender, args) {
  168. if(args.cellRange.colCount > 1 || args.cellRange.col !== 0){
  169. args.cancel = true;
  170. }
  171. },
  172. onClipboardPasted: function (sender, args) {
  173. let me = contentOprObj;
  174. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  175. for(let i = 0, len = items.length; i < len; i++){
  176. let rowIdx = args.cellRange.row + i;
  177. //更新
  178. if(rowIdx < me.currentCache.length){
  179. me.updateContent(me.currentCache[rowIdx], items[i].content);
  180. }
  181. //新增
  182. else{
  183. me.insertContent(items[i].content);
  184. }
  185. }
  186. me.save();
  187. },
  188. sortCache: function (cacheArr) {
  189. cacheArr.sort(function (a, b) {
  190. let rst = 0;
  191. if(a.serialNo > b.serialNo){
  192. rst = 1;
  193. }
  194. else if(a.serialNo < b.serialNo){
  195. rst = -1;
  196. }
  197. return rst;
  198. });
  199. },
  200. onContextmenuOpr: function () {//右键菜单
  201. let me = contentOprObj;
  202. $.contextMenu({
  203. selector: '#jobSpread',
  204. build: function($triggerElement, e){
  205. //控制允许右键菜单在哪个位置出现
  206. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  207. let sheet = me.workBook.getSheet(0);
  208. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  209. let insertDis = pageCCOprObj.isBillsType() ? false : true, delDis = false, upDis = false, downDis = false;
  210. if(typeof target.row !== 'undefined'){
  211. //控制按钮是否可用
  212. sheet.setActiveCell(target.row, target.col);
  213. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  214. delDis = true;
  215. downDis = true;
  216. upDis = true;
  217. }
  218. else{//有数据
  219. if(typeof target.col === 'undefined'){//定位不在表格内
  220. downDis = true;
  221. upDis = true;
  222. delDis = true;
  223. }
  224. else{//定位在表格内
  225. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  226. downDis = true;
  227. }
  228. if(target.row === 0){//定位在第一行,不可上移
  229. upDis = true;
  230. }
  231. }
  232. }
  233. }
  234. else{
  235. delDis = true;
  236. downDis = true;
  237. upDis = true;
  238. }
  239. return {
  240. callback: function(){},
  241. items: {
  242. "insert": {name: "添加", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  243. //插入空行
  244. me.addRow(sheet);
  245. }},
  246. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  247. me.deleteContent(target.row);
  248. }},
  249. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  250. me.upMove({row: target.row, col: target.col});
  251. }},
  252. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  253. me.downMove({row: target.row, col: target.col});
  254. }}
  255. }
  256. };
  257. }
  258. else{
  259. return false;
  260. }
  261. }
  262. });
  263. }
  264. };
  265. let characterOprObj = {
  266. workBook: null,
  267. currentCache: [],
  268. setting: {
  269. header: [
  270. {headerName:"项目特征",headerWidth:160,dataCode:"character", dataType: "String", hAlign: "left", vAlign: "center"},
  271. {headerName:"特征值",headerWidth:160,dataCode:"eigenvalue", dataType: "String", cellType: "comboBox", hAlign: "left", vAlign: "center"},
  272. {headerName:"输出",headerWidth:80,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
  273. ]
  274. },
  275. buildSheet: function(container) {
  276. let me = characterOprObj;
  277. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  278. me.workBook.options.allowUserDragDrop = false;
  279. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  280. me.workBook.options.allowCopyPasteExcelStyle = false;
  281. me.onContextmenuOpr();
  282. me.bindEvents(me.workBook);
  283. },
  284. bindEvents: function (workBook) {
  285. let sheet = workBook.getActiveSheet(), me = characterOprObj;
  286. const EVENTS = GC.Spread.Sheets.Events;
  287. workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
  288. sheet.bind(EVENTS.EditEnded, me.onEditEnded);
  289. sheet.bind(EVENTS.EditStarting, me.onEditStart);
  290. sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
  291. sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
  292. },
  293. //将从清单库中添加的清单,把标准清单的项目特征转化成清单的项目特征
  294. buildItemCharactet: function (items) {//从清单库过来的默认不输出
  295. let itemCharacter = [];
  296. for(let i = 0, len = items.length; i < len; i++){
  297. let newItem = {serialNo: i + 1, character: items[i].content, eigenvalue: [], isChecked: false};
  298. let eigenvalues = items[i].itemValue;
  299. for(let j = 0, len = eigenvalues.length; j < len; j++){
  300. let newValue = {value: eigenvalues[j].value, isSelected: false};
  301. newItem.eigenvalue.push(newValue);
  302. }
  303. itemCharacter.push(newItem);
  304. }
  305. return itemCharacter;
  306. },
  307. //显示在itemSpread的数据
  308. showCharacterData: function (sheet, setting, datas) {
  309. let me = characterOprObj;
  310. sheetCommonObj.showData(sheet, setting, datas);
  311. sheet.suspendPaint();
  312. sheet.suspendEvent();
  313. for(let i = 0, len = datas.length; i < len; i++){
  314. let comboObj = me.getComboBox(datas[i]);
  315. comboObj.combo.editable(false);//不可编辑
  316. sheet.getCell(i, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  317. sheet.getCell(i, 0).locked(true);
  318. }
  319. sheet.resumePaint();
  320. sheet.suspendEvent();
  321. },
  322. //获得项目特征特征值comboBox
  323. getComboBox: function (characterItem) {
  324. let rst = {};
  325. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  326. let comboItems = [], eigenvalues = characterItem.eigenvalue;
  327. for(let i = 0, len = eigenvalues.length; i < len; i++){
  328. comboItems.push(eigenvalues[i].value);
  329. if(eigenvalues[i].isSelected){
  330. rst.selectedValue = eigenvalues[i].value;
  331. }
  332. }
  333. combo.items(comboItems);
  334. rst.combo = combo;
  335. return rst;
  336. },
  337. //获得当前行选中的特征值
  338. getCurrentSelected: function (item) {
  339. let rst = null;
  340. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  341. if(item.eigenvalue[i].isSelected){
  342. rst = item.eigenvalue[i].value;
  343. break;
  344. }
  345. }
  346. return rst;
  347. },
  348. //显示到清单项目特征列的数据
  349. getColData: function (itemsArr) {
  350. let me = characterOprObj;
  351. let rstStr = "", count = 0;
  352. for(let i = 0, len = itemsArr.length; i < len; i++){
  353. if(itemsArr[i].isChecked === true){
  354. //获取选中的特征值
  355. let eigenvalueStr = "";
  356. let eigenvalue = itemsArr[i].eigenvalue;
  357. for(let j = 0, vLen = eigenvalue.length; j < vLen; j++){
  358. if(eigenvalue[j].isSelected){
  359. eigenvalueStr += eigenvalue[j].value;
  360. break;
  361. }
  362. }
  363. count ++;
  364. /*if(count === 1){
  365. rstStr += "“";
  366. }
  367. else{
  368. rstStr += " ";
  369. }*/
  370. rstStr += count + ". " + itemsArr[i].character + ": " + eigenvalueStr + "\n";
  371. }
  372. }
  373. if(rstStr.trim().length > 0){
  374. let reg = /\n+$/g;
  375. let newStr = rstStr.replace(reg, "");
  376. return newStr;
  377. }
  378. return null;
  379. },
  380. addRow: function (sheet) {
  381. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox(),
  382. combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  383. checkBox.isThreeState = false;
  384. combo.editable(true);
  385. let rowIdx = sheet.getRowCount();
  386. sheet.addRows(rowIdx, 1);
  387. sheet.getCell(rowIdx, 1).cellType(combo);
  388. sheet.getCell(rowIdx, 2).cellType(checkBox);
  389. },
  390. upMove: function (cell) {
  391. let me = characterOprObj;
  392. let thisObj = me.currentCache[cell.row],
  393. preObj = me.currentCache[cell.row - 1],
  394. temp;
  395. temp = thisObj.serialNo;
  396. thisObj.serialNo = preObj.serialNo;
  397. preObj.serialNo = temp;
  398. contentOprObj.sortCache(me.currentCache);
  399. me.save(function () {
  400. me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
  401. });
  402. },
  403. downMove: function (cell) {
  404. let me = characterOprObj;
  405. let thisObj = me.currentCache[cell.row],
  406. nextObj = me.currentCache[cell.row + 1],
  407. temp;
  408. temp = thisObj.serialNo;
  409. thisObj.serialNo = nextObj.serialNo;
  410. nextObj.serialNo = temp;
  411. contentOprObj.sortCache(me.currentCache);
  412. me.save(function () {
  413. me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
  414. });
  415. },
  416. deleteCharacter: function (rowIdx) {
  417. let me = characterOprObj;
  418. me.currentCache.splice(rowIdx, 1);
  419. me.save();
  420. },
  421. //取消选择的特征值
  422. unsetSelected: function (item) {
  423. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  424. if(item.eigenvalue[i].isSelected){
  425. item.eigenvalue[i].isSelected = false;
  426. }
  427. }
  428. },
  429. //设置选中的特征值
  430. setSelected: function (item, value) {
  431. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  432. if(item.eigenvalue[i].value === value){
  433. item.eigenvalue[i].isSelected = true;
  434. }
  435. }
  436. },
  437. //改变选择特征值
  438. changeSelected: function (item, value) {
  439. let me = characterOprObj;
  440. me.unsetSelected(item);
  441. me.setSelected(item, value);
  442. },
  443. insertValue: function (item, value) {
  444. let me = characterOprObj;
  445. me.unsetSelected(item);
  446. let newValue = {value: value, isSelected: true};
  447. item.eigenvalue.push(newValue);
  448. },
  449. updateCharacter: function (item, character, value) {
  450. let me = characterOprObj;
  451. if(character){
  452. item.character = character;
  453. }
  454. if(value){
  455. let isExist = false;
  456. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  457. if(item.eigenvalue[i].value === value){
  458. isExist = true;
  459. break;
  460. }
  461. }
  462. //不存在,新增进eigenvalue,自动打勾输出
  463. if(!isExist){
  464. //更新selected
  465. me.insertValue(item, value);
  466. item.isChecked = true;
  467. }
  468. //存在,选择特征值,自动打勾输出
  469. else{
  470. me.changeSelected(item, value);
  471. item.isChecked = true;
  472. }
  473. }
  474. },
  475. insertCharacter: function (character, value) {
  476. let me = characterOprObj;
  477. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  478. if(character && !value){
  479. let newCharacter = {character: character, eigenvalue: [], isChecked: false, serialNo: preObj ? preObj.serialNo + 1 : 1};
  480. me.currentCache.push(newCharacter);
  481. }
  482. else if(!character && value){
  483. let newValue = {value: value, isSelected: true};
  484. let newCharacter = {character: '', eigenvalue: [newValue], isChecked: false, serialNo: preObj? preObj.serialNo + 1 : 1};
  485. me.currentCache.push(newCharacter);
  486. }
  487. else if(character && value){//有了特征值自动打勾输出
  488. let newValue = {value: value, isSelected: true};
  489. let newCharacter = {character:character , eigenvalue: [newValue], isChecked: true, serialNo: preObj? preObj.serialNo + 1 : 1};
  490. me.currentCache.push(newCharacter);
  491. }
  492. },
  493. save: function (callback) {
  494. let selectedNode = projectObj.mainController.tree.selected;
  495. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  496. pageCCOprObj.setCharacterBySetting(characterOprObj, selectedNode, setting, callback);
  497. },
  498. onEditStart: function (sender, args) {
  499. let me = characterOprObj;
  500. if(args.col === 1){//改变选择的特征值
  501. me.currentSelectedValue = me.currentCache.length > args.row ? me.getCurrentSelected(me.currentCache[args.row]) : null;
  502. }
  503. },
  504. onEditEnded: function (sender, args) {
  505. let me = characterOprObj, characterTxt;
  506. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  507. if(args.editingText && args.editingText.toString().trim().length > 0){
  508. //更新
  509. if(args.row < me.currentCache.length){
  510. let thisCha = me.currentCache[args.row];
  511. if(args.col === 0){//特征
  512. me.updateCharacter(thisCha, args.editingText, null);
  513. }
  514. else if(args.col === 1){//特征值
  515. me.updateCharacter(thisCha, null, args.editingText);
  516. }
  517. }
  518. //新增
  519. else{
  520. if(args.col === 0){//特征
  521. me.insertCharacter(args.editingText, null);
  522. }
  523. else if(args.col === 1){//特征值
  524. me.insertCharacter(null, args.editingText);
  525. }
  526. }
  527. //保存
  528. me.save();
  529. }
  530. else{//恢复
  531. if(args.col === 0){
  532. args.sheet.setValue(args.row, args.col, me.currentCache.length > args.row ? me.currentCache[args.row].character + '' : '');
  533. }
  534. else if(args.col === 1){
  535. args.sheet.setValue(args.row, args.col, me.currentSelectedValue ? me.currentSelectedValue + '' : '');
  536. }
  537. }
  538. },
  539. onClipboardPasting: function (sender, args) {
  540. if(args.cellRange.col + args.colCount - 1 > 1){
  541. args.cancel = true;
  542. }
  543. },
  544. onClipboardPasted: function (sender, args) {
  545. let me = characterOprObj;
  546. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  547. for(let i = 0, len = items.length; i < len; i++){
  548. //更新
  549. let rowIdx = args.cellRange.row + i;
  550. if(me.currentCache.length > rowIdx){
  551. me.updateCharacter(me.currentCache[rowIdx], items[i].character, items[i].eigenvalue);
  552. }
  553. //新增
  554. else{
  555. me.insertCharacter(items[i].character, items[i].eigenvalue);
  556. }
  557. }
  558. me.save();
  559. },
  560. //复选框控制输出
  561. onButtonClicked: function (sender, args) {
  562. let me = characterOprObj, characterTxt;
  563. if(args.sheet.isEditing()){
  564. args.sheet.endEdit(true);
  565. }
  566. let isChecked = args.sheet.getValue(args.row, args.col);
  567. if(me.currentCache.length > args.row){
  568. me.currentCache[args.row].isChecked = isChecked;
  569. me.save();
  570. }
  571. //else的情况就是新增
  572. else{
  573. args.sheet.setValue(args.row, args.col, 0);
  574. }
  575. },
  576. onContextmenuOpr: function () {//右键菜单
  577. let me = characterOprObj;
  578. $.contextMenu({
  579. selector: '#itemSpread',
  580. build: function($triggerElement, e){
  581. //控制允许右键菜单在哪个位置出现
  582. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
  583. let sheet = me.workBook.getSheet(0);
  584. if(target.hitTestType === 3){//在表格内 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  585. let insertDis = pageCCOprObj.isBillsType() ? false : true, delDis = false, upDis = false, downDis = false;
  586. if(typeof target.row !== 'undefined'){
  587. //控制按钮是否可用
  588. sheet.setActiveCell(target.row, target.col);
  589. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  590. delDis = true;
  591. downDis = true;
  592. upDis = true;
  593. }
  594. else{//有数据
  595. if(typeof target.col === 'undefined'){//定位在表格外
  596. downDis = true;
  597. upDis = true;
  598. delDis = true;
  599. }
  600. else{
  601. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  602. downDis = true;
  603. }
  604. if(target.row === 0){//定位在第一行,不可上移
  605. upDis = true;
  606. }
  607. }
  608. }
  609. }
  610. else{
  611. delDis = true;
  612. downDis = true;
  613. upDis = true;
  614. }
  615. return {
  616. callback: function(){},
  617. items: {
  618. "insert": {name: "添加", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  619. me.addRow(sheet);
  620. }},
  621. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  622. me.deleteCharacter(target.row);
  623. }},
  624. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  625. me.upMove({row: target.row, col: target.col});
  626. }},
  627. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  628. me.downMove({row: target.row, col: target.col});
  629. }}
  630. }
  631. };
  632. }
  633. else{
  634. return false;
  635. }
  636. }
  637. });
  638. }
  639. };
  640. let pageCCOprObj = {
  641. currentFindSet: null,
  642. mainActiveCell: null,//mainSpread焦点单元格
  643. nameCache: '',
  644. //获得造价书当前焦点行的类型:清单、定额
  645. isBillsType: function () {
  646. let rst = false;
  647. let selectedNode = projectObj.mainController.tree.selected;
  648. if(selectedNode && selectedNode.sourceType === projectObj.project.Bills.getSourceType()){//为清单
  649. rst = true
  650. }
  651. return rst;
  652. },
  653. setItemContentNode: function (node, jobs, items, name = '') {
  654. let theCont = contentOprObj, theCha = characterOprObj,
  655. jobContent, itemCharacter, contentTxt, characterTxt;
  656. jobContent = theCont.buildJobContent(jobs);
  657. itemCharacter = theCha.buildItemCharactet(items);
  658. // contentTxt = theCont.getColData(jobContent);
  659. // characterTxt = theCha.getColData(itemCharacter);
  660. node.data.jobContent = jobContent;
  661. node.data.itemCharacter = itemCharacter;
  662. this.nameCache = name;
  663. // 根据规则设置对应特征、内容、名称格式
  664. const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
  665. const updateData = pageCCOprObj.getCharacterUpdateData(setting, node);
  666. node.data.jobContentText = updateData.jobContentText;
  667. node.data.itemCharacterText = updateData.itemCharacterText;
  668. node.data.name = updateData.name;
  669. },
  670. safeItemCharater: function (itemCharater) {
  671. return characterOprObj.buildItemCharactet(itemCharater);
  672. },
  673. //设置特征及内容currentCache
  674. setCacheAndShow: function (node) {
  675. let theCont = contentOprObj, theCha = characterOprObj;
  676. theCont.currentCache = node && typeof node.data.jobContent !== 'undefined' ? node.data.jobContent : [];
  677. theCha.currentCache = node && typeof node.data.itemCharacter !== 'undefined' ? node.data.itemCharacter : [];
  678. this.currentFindSet = node && typeof node.data.ID !== 'undefined' && typeof node.data.projectID ? {ID: node.data.ID, projectID: node.data.projectID} : null;
  679. this.showData(theCont.workBook.getSheet(0), theCont.setting, theCont.currentCache);
  680. this.showData(theCha.workBook.getSheet(0), theCha.setting, theCha.currentCache);
  681. },
  682. //contentSpread、itemSpread展示数据用
  683. showData: function(sheet, setting, data) {
  684. let me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  685. sheet.suspendPaint();
  686. sheet.suspendEvent();
  687. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  688. sheet.setRowCount(data.length);
  689. for (let col = 0; col < setting.header.length; col++) {
  690. var hAlign = "left", vAlign = "center";
  691. if (setting.header[col].hAlign) {
  692. hAlign = setting.header[col].hAlign;
  693. } else if (setting.header[col].dataType !== "String"){
  694. hAlign = "right";
  695. }
  696. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  697. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  698. if (setting.header[col].formatter) {
  699. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  700. }
  701. for (let row = 0; row < data.length; row++) {
  702. sheet.getCell(row, 0).locked(true);//locked
  703. let val = data[row][setting.header[col].dataCode];
  704. if(setting.header[col].cellType === "checkBox"){
  705. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  706. checkBox.isThreeState(false);
  707. sheet.getCell(row, col).cellType(checkBox).value(val);
  708. }
  709. else if(setting.header[col].cellType === 'comboBox'){
  710. let comboObj = characterOprObj.getComboBox(data[row]);
  711. comboObj.combo.editable(true);//可编辑
  712. sheet.getCell(row, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  713. }
  714. else{
  715. sheet.setValue(row, col, val, ch);
  716. }
  717. sheet.getCell(row, col).wordWrap(true);
  718. sheet.autoFitRow(row);
  719. }
  720. }
  721. sheet.resumeEvent();
  722. sheet.resumePaint();
  723. },
  724. clearData: function () {
  725. let theCon = contentOprObj, theCha = characterOprObj;
  726. theCon.workBook.getSheet(0).setRowCount(0);
  727. theCha.workBook.getSheet(0).setRowCount(0);
  728. sheetCommonObj.cleanSheet(theCon.workBook.getSheet(0), theCon.setting, -1);
  729. sheetCommonObj.cleanSheet(theCha.workBook.getSheet(0), theCha.setting, -1);
  730. projectObj.mainSpread.focus(true);
  731. },
  732. //更新特征及内容数据
  733. updateCharacterContent: function (findSet, updateObj, txtObj, oprObj, callback) {
  734. let me = pageCCOprObj, updateCol;
  735. if(txtObj){
  736. updateCol = txtObj.field === 'itemCharacterText' ? 4 : 5;//更新清单行特征列或内容列
  737. }
  738. else{
  739. updateCol = null;
  740. }
  741. let url = '/bills/updateCharacterContent';
  742. let postData = {
  743. findSet: findSet,
  744. updateObj: updateObj,
  745. txtObj: txtObj
  746. };
  747. CommonAjax.post(url, postData, function (rstData) {
  748. //更新节点数据
  749. if(updateCol){
  750. // 已当前选中行更新数据
  751. let selectedNode = projectObj.mainController.tree.selected;
  752. selectedNode.data[updateObj.field] = updateObj.updateArr;
  753. selectedNode.data[txtObj.field] = txtObj.text;
  754. me.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  755. let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
  756. projectObj.mainSpread.getActiveSheet().setValue(activeCell.row, updateCol, txtObj.text + ''); //刷新输出显示
  757. projectObj.mainSpread.getActiveSheet().autoFitRow(activeCell.row);
  758. if(callback){
  759. callback();
  760. }
  761. }
  762. });
  763. },
  764. /**
  765. * 更新bill数据
  766. *
  767. * @param {Object} findSet - 更新条件
  768. * @param {Object} updateData - 更新数据
  769. * @param {Function} callback - 回调函数
  770. * @return {void}
  771. */
  772. updateBill: function(findSet, updateData, callback) {
  773. if (!updateData instanceof Array || updateData.length <= 0) {
  774. return;
  775. }
  776. let url = '/bills/updateBill';
  777. let postData = { findSet, updateData };
  778. CommonAjax.post(url, postData, function (response) {
  779. callback(response);
  780. });
  781. },
  782. /**
  783. * 刷新节点数据
  784. *
  785. * @param {Object} node - 节点数据
  786. * @param {Object} refreshData - 刷新的数据
  787. * @return {void}
  788. */
  789. refreshView: function(node, refreshData) {
  790. // 更新清单行特征列或内容列
  791. let updateCol = [
  792. { name: 'itemCharacterText', col: 4 },
  793. { name: 'jobContentText', col: 5 },
  794. { name: 'name', col: 2 }
  795. ];
  796. if (updateCol === '') {
  797. return;
  798. }
  799. const row = node.serialNo();
  800. // 刷新输出显示
  801. for (const tmp of updateCol) {
  802. // 没有默认的数据则跳过刷新
  803. if (refreshData[tmp.name] === undefined) {
  804. continue;
  805. }
  806. projectObj.mainSpread.getActiveSheet().setValue(row, tmp.col, refreshData[tmp.name] + '');
  807. }
  808. projectObj.mainSpread.getActiveSheet().autoFitRow(row);
  809. },
  810. /**
  811. * 根据配置设置清单项目特征
  812. *
  813. * @param {Object} node - 选中的node节点
  814. * @param {Object} setting - 设置
  815. * @return {void}
  816. */
  817. setCharacterBySetting: function(oprObj, node, setting, callback) {
  818. let self = this;
  819. // 保存的条件数据
  820. const findSet = { ID: node.data.ID, projectID: node.data.projectID };
  821. const updateData = this.getCharacterUpdateData(setting, node);
  822. let saveObj = [];
  823. for (const index in updateData) {
  824. saveObj.push({field: index, value: updateData[index]});
  825. }
  826. saveObj.push({field: 'addRule', value: setting});
  827. // 更新到数据库
  828. pageCCOprObj.updateBill(findSet, saveObj, function(response) {
  829. self.refreshView(node, updateData);
  830. // 更新项目属性的配置
  831. projectObj.project.property.addRule = setting;
  832. // 更新节点数据
  833. node.data.name = updateData.name;
  834. node.data.itemCharacterText = updateData.itemCharacterText;
  835. node.data.jobContentText = updateData.jobContentText;
  836. pageCCOprObj.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  837. if(callback){
  838. callback();
  839. }
  840. });
  841. },
  842. /**
  843. * 格式化序号格式
  844. *
  845. * @param {Number} type - 格式化的类型
  846. * @param {String} serialNo - 待格式化的序号
  847. * @return {String} - 返回格式化后的字符
  848. */
  849. formatSerialNumber: function(type, serialNo) {
  850. const letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  851. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  852. switch (type) {
  853. case '1':
  854. // 数字
  855. serialNo = serialNo + '. ';
  856. break;
  857. case '2':
  858. // 英文字母(小写)
  859. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1] + '. ' : '';
  860. break;
  861. case '3':
  862. // 英文字母(大写)
  863. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1].toUpperCase() + '. ' : '';
  864. break;
  865. default:
  866. serialNo = '';
  867. break;
  868. }
  869. return serialNo;
  870. },
  871. /**
  872. * 查找选中的树节点中定额子目数据
  873. *
  874. * @param {Object} selectNode - 选中的节点
  875. * @param {Object} setting - 设置
  876. * @return {Array} - 返回定额子目数组
  877. */
  878. getRationChapter: function(selectNode, setting) {
  879. let result = [];
  880. if (selectNode.children === undefined || selectNode.children.length <= 0) {
  881. return result;
  882. }
  883. // 查找对应的定额数据
  884. let count = 1;
  885. for (const tmp of selectNode.children) {
  886. if (tmp.sourceType !== 'ration') {
  887. continue;
  888. }
  889. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  890. setting.childDisplayFormat === "1" ? result.push(tmp.data.code + ':' + tmp.data.name) : result.push(serialNo + tmp.data.name);
  891. count++;
  892. }
  893. return result;
  894. },
  895. /**
  896. * 获取默认数据
  897. *
  898. * @param {Object} node - 节点数据
  899. * @param {Object} setting - 设置
  900. * @return {Object}
  901. */
  902. getDataBySetting: function(node, setting) {
  903. let result = {};
  904. try {
  905. if (node.data === undefined) {
  906. throw '数据错误';
  907. }
  908. const itemCharacter = node.data.itemCharacter;
  909. const itemJob = node.data.jobContent;
  910. if (itemCharacter === undefined || itemCharacter.length <= 0 || itemJob === undefined || itemJob.length <= 0) {
  911. throw '内部数据错误';
  912. }
  913. // 默认名称
  914. result['name'] = this.nameCache;
  915. // 特征
  916. let characterArray = [];
  917. let count = 1;
  918. for (const tmp of itemCharacter) {
  919. if (tmp.eigenvalue === undefined || tmp.eigenvalue.length <= 0 || !tmp.isChecked) {
  920. continue;
  921. }
  922. // 获取选中的特征值
  923. let selectedEigen = '';
  924. for (const eigen of tmp.eigenvalue) {
  925. if (eigen.isSelected) {
  926. selectedEigen = eigen.value;
  927. }
  928. }
  929. // 匹配设置的序号格式
  930. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  931. let characterString = '';
  932. // 特征生成方式
  933. switch (setting.characterFormat) {
  934. case '1':
  935. // 特征值
  936. characterString = serialNo + selectedEigen;
  937. break;
  938. case '2':
  939. // 特征:特征值
  940. characterString = serialNo + tmp.character + ': ' + selectedEigen;
  941. break;
  942. }
  943. characterArray.push(characterString);
  944. count++;
  945. }
  946. result['character'] = characterArray;
  947. // 内容部分
  948. let jobArray = [];
  949. count = 1;
  950. for (const tmp of itemJob) {
  951. if (!tmp.isChecked) {
  952. continue;
  953. }
  954. // 匹配设置的序号格式
  955. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  956. jobArray.push(serialNo + tmp.content);
  957. count++;
  958. }
  959. result['content'] = jobArray;
  960. } catch (error) {
  961. console.log(error);
  962. result = {};
  963. }
  964. return result;
  965. },
  966. /**
  967. * 获取特征内容名称更新的数据
  968. *
  969. * @param {Object} setting - 设置
  970. * @param {Object} node - 节点数据
  971. * @return {Object} - 返回更新的数据
  972. */
  973. getCharacterUpdateData: function(setting, node) {
  974. // 获取原名称
  975. const name = node.data.name.split("\n");
  976. this.nameCache = name[0] !== undefined ? name[0] : "";
  977. let updateData = {
  978. itemCharacterText: '',
  979. jobContentText: '',
  980. name: this.nameCache,
  981. };
  982. let contentArray = [];
  983. // 获取当前设置数据
  984. const currentData = this.getDataBySetting(node, setting);
  985. // 组合数据
  986. let content = '';
  987. switch (setting.addContent) {
  988. case "1":
  989. // 项目特征+工作内容
  990. contentArray.push('[项目特征]');
  991. contentArray.push.apply(contentArray, currentData.character);
  992. contentArray.push('[工作内容]');
  993. contentArray.push.apply(contentArray, currentData.content);
  994. break;
  995. case "2":
  996. // 工作内容+项目特征
  997. contentArray.push('[工作内容]');
  998. contentArray.push.apply(contentArray, currentData.content);
  999. contentArray.push('[项目特征]');
  1000. contentArray.push.apply(contentArray, currentData.character);
  1001. break;
  1002. case "3":
  1003. // 项目特征
  1004. contentArray.push.apply(contentArray, currentData.character);
  1005. break;
  1006. case "4":
  1007. // 工作内容
  1008. contentArray.push.apply(contentArray, currentData.content);
  1009. break;
  1010. case "5":
  1011. // 定额子目
  1012. const rationChapter = this.getRationChapter(node, setting);
  1013. contentArray.push.apply(contentArray, rationChapter);
  1014. break;
  1015. case "":
  1016. // 无
  1017. break;
  1018. }
  1019. // 显示格式
  1020. switch (setting.displayFormat) {
  1021. case "1":
  1022. // 换行分隔
  1023. content = contentArray.join("\n");
  1024. currentData.character = currentData.character.join("\n");
  1025. currentData.content = currentData.content.join("\n");
  1026. break;
  1027. case "2":
  1028. // 逗号分隔
  1029. content = contentArray.join(',');
  1030. currentData.character = currentData.character.join(",");
  1031. currentData.content = currentData.content.join(",");
  1032. break;
  1033. case "3":
  1034. // 括号分隔
  1035. content = '(' + contentArray.join(',') + ')';
  1036. break;
  1037. }
  1038. // 添加到对应位置
  1039. switch (setting.position) {
  1040. case "1":
  1041. // 添加到项目特征列
  1042. updateData.itemCharacterText = content;
  1043. break;
  1044. case "2":
  1045. // 添加到清单名称列
  1046. content = this.nameCache + "\n" + content;
  1047. updateData.name = content;
  1048. break;
  1049. case "3":
  1050. // 添加到工作内容列
  1051. updateData.jobContentText = content;
  1052. break;
  1053. case "4":
  1054. updateData = {
  1055. itemCharacterText: currentData.character,
  1056. jobContentText: currentData.content,
  1057. name: currentData.name,
  1058. };
  1059. break;
  1060. }
  1061. return updateData;
  1062. },
  1063. }