character_content_view.js 44 KB

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