character_content_view.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  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(selectedNode, setting, callback, contentOprObj);
  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(selectedNode, setting, callback, characterOprObj);
  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(node, setting, callback = null, oprObj = null) {
  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. if (oprObj) {
  837. pageCCOprObj.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  838. }
  839. if(callback){
  840. callback();
  841. }
  842. });
  843. },
  844. /**
  845. * 格式化序号格式
  846. *
  847. * @param {Number} type - 格式化的类型
  848. * @param {String} serialNo - 待格式化的序号
  849. * @return {String} - 返回格式化后的字符
  850. */
  851. formatSerialNumber: function(type, serialNo) {
  852. const letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
  853. 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  854. switch (type) {
  855. case '1':
  856. // 数字
  857. serialNo = serialNo + '. ';
  858. break;
  859. case '2':
  860. // 英文字母(小写)
  861. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1] + '. ' : '';
  862. break;
  863. case '3':
  864. // 英文字母(大写)
  865. serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1].toUpperCase() + '. ' : '';
  866. break;
  867. default:
  868. serialNo = '';
  869. break;
  870. }
  871. return serialNo;
  872. },
  873. /**
  874. * 查找选中的树节点中定额子目数据
  875. *
  876. * @param {Object} selectNode - 选中的节点
  877. * @param {Object} setting - 设置
  878. * @return {Array} - 返回定额子目数组
  879. */
  880. getRationChapter: function(selectNode, setting) {
  881. let result = [];
  882. if (selectNode.children === undefined || selectNode.children.length <= 0) {
  883. return result;
  884. }
  885. // 查找对应的定额数据
  886. let count = 1;
  887. for (const tmp of selectNode.children) {
  888. if (tmp.sourceType !== 'ration') {
  889. continue;
  890. }
  891. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  892. setting.childDisplayFormat === "1" ? result.push(tmp.data.code + ':' + tmp.data.name) : result.push(serialNo + tmp.data.name);
  893. count++;
  894. }
  895. return result;
  896. },
  897. /**
  898. * 获取默认数据
  899. *
  900. * @param {Object} node - 节点数据
  901. * @param {Object} setting - 设置
  902. * @return {Object}
  903. */
  904. getDataBySetting: function(node, setting) {
  905. let result = {};
  906. try {
  907. if (node.data === undefined) {
  908. throw '数据错误';
  909. }
  910. const itemCharacter = node.data.itemCharacter;
  911. const itemJob = node.data.jobContent;
  912. if (itemCharacter === undefined || itemCharacter.length <= 0 || itemJob === undefined || itemJob.length <= 0) {
  913. throw '内部数据错误';
  914. }
  915. // 默认名称
  916. result['name'] = this.nameCache;
  917. // 特征
  918. let characterArray = [];
  919. let count = 1;
  920. for (const tmp of itemCharacter) {
  921. if (tmp.eigenvalue === undefined || tmp.eigenvalue.length <= 0 || !tmp.isChecked) {
  922. continue;
  923. }
  924. // 获取选中的特征值
  925. let selectedEigen = '';
  926. for (const eigen of tmp.eigenvalue) {
  927. if (eigen.isSelected) {
  928. selectedEigen = eigen.value;
  929. }
  930. }
  931. // 匹配设置的序号格式
  932. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  933. let characterString = '';
  934. // 特征生成方式
  935. switch (setting.characterFormat) {
  936. case '1':
  937. // 特征值
  938. characterString = serialNo + selectedEigen;
  939. break;
  940. case '2':
  941. // 特征:特征值
  942. characterString = serialNo + tmp.character + ': ' + selectedEigen;
  943. break;
  944. }
  945. characterArray.push(characterString);
  946. count++;
  947. }
  948. result['character'] = characterArray;
  949. // 内容部分
  950. let jobArray = [];
  951. count = 1;
  952. for (const tmp of itemJob) {
  953. if (!tmp.isChecked) {
  954. continue;
  955. }
  956. // 匹配设置的序号格式
  957. const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
  958. jobArray.push(serialNo + tmp.content);
  959. count++;
  960. }
  961. result['content'] = jobArray;
  962. } catch (error) {
  963. console.log(error);
  964. result = {};
  965. }
  966. return result;
  967. },
  968. /**
  969. * 获取特征内容名称更新的数据
  970. *
  971. * @param {Object} setting - 设置
  972. * @param {Object} node - 节点数据
  973. * @return {Object} - 返回更新的数据
  974. */
  975. getCharacterUpdateData: function(setting, node) {
  976. // 获取原名称
  977. const name = node.data.name.split("\n");
  978. this.nameCache = name[0] !== undefined ? name[0] : "";
  979. let updateData = {
  980. itemCharacterText: '',
  981. jobContentText: '',
  982. name: this.nameCache,
  983. };
  984. let contentArray = [];
  985. // 获取当前设置数据
  986. const currentData = this.getDataBySetting(node, setting);
  987. // 组合数据
  988. let content = '';
  989. switch (setting.addContent) {
  990. case "1":
  991. // 项目特征+工作内容
  992. contentArray.push('[项目特征]');
  993. contentArray.push.apply(contentArray, currentData.character);
  994. contentArray.push('[工作内容]');
  995. contentArray.push.apply(contentArray, currentData.content);
  996. break;
  997. case "2":
  998. // 工作内容+项目特征
  999. contentArray.push('[工作内容]');
  1000. contentArray.push.apply(contentArray, currentData.content);
  1001. contentArray.push('[项目特征]');
  1002. contentArray.push.apply(contentArray, currentData.character);
  1003. break;
  1004. case "3":
  1005. // 项目特征
  1006. contentArray.push.apply(contentArray, currentData.character);
  1007. break;
  1008. case "4":
  1009. // 工作内容
  1010. contentArray.push.apply(contentArray, currentData.content);
  1011. break;
  1012. case "5":
  1013. // 定额子目
  1014. const rationChapter = this.getRationChapter(node, setting);
  1015. contentArray.push.apply(contentArray, rationChapter);
  1016. break;
  1017. case "":
  1018. // 无
  1019. break;
  1020. }
  1021. // 显示格式
  1022. switch (setting.displayFormat) {
  1023. case "1":
  1024. // 换行分隔
  1025. content = contentArray.join("\n");
  1026. currentData.character = currentData.character.join("\n");
  1027. currentData.content = currentData.content.join("\n");
  1028. break;
  1029. case "2":
  1030. // 逗号分隔
  1031. content = contentArray.join(',');
  1032. currentData.character = currentData.character.join(",");
  1033. currentData.content = currentData.content.join(",");
  1034. break;
  1035. case "3":
  1036. // 括号分隔
  1037. content = '(' + contentArray.join(',') + ')';
  1038. break;
  1039. }
  1040. // 添加到对应位置
  1041. switch (setting.position) {
  1042. case "1":
  1043. // 添加到项目特征列
  1044. updateData.itemCharacterText = content;
  1045. break;
  1046. case "2":
  1047. // 添加到清单名称列
  1048. content = this.nameCache + "\n" + content;
  1049. updateData.name = content;
  1050. break;
  1051. case "3":
  1052. // 添加到工作内容列
  1053. updateData.jobContentText = content;
  1054. break;
  1055. case "4":
  1056. updateData = {
  1057. itemCharacterText: currentData.character,
  1058. jobContentText: currentData.content,
  1059. name: currentData.name,
  1060. };
  1061. break;
  1062. }
  1063. return updateData;
  1064. },
  1065. }