character_content_view.js 43 KB

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