character_content_view.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /**
  2. * Created by Zhong on 2017/8/31.
  3. * 特征及内容
  4. */
  5. //todo:清单库相关联的操作
  6. let contentOprObj = {
  7. workBook: null,
  8. currentCache: [],//按照serialNo排序
  9. setting: {
  10. header: [
  11. {headerName:"工作内容",headerWidth:160,dataCode:"content", dataType: "String", hAlign: "center", vAlign: "center"},
  12. {headerName:"输出",headerWidth:80,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
  13. ]
  14. },
  15. buildSheet: function(container) {
  16. let me = contentOprObj;
  17. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  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. //显示在jobSpread的数据
  32. showContentData: function (sheet, setting, datas) {
  33. sheetCommonObj.showData(sheet, setting, datas);
  34. sheet.suspendPaint();
  35. sheet.suspendEvent();
  36. for(let i = 0, len = datas.length; i < len; i++){
  37. sheet.getCell(i, 0).locked(true);
  38. }
  39. sheet.resumePaint();
  40. sheet.suspendEvent();
  41. },
  42. //显示到清单工作内容列的数据
  43. getColData: function (jobsArr) {
  44. let me = contentOprObj;
  45. let rstStr = "", count = 0;
  46. for(let i = 0, len = jobsArr.length; i < len; i++){
  47. if(jobsArr[i].isChecked === true){
  48. count ++;
  49. if(count === 1){
  50. rstStr += "“";
  51. }
  52. else{
  53. rstStr += " ";
  54. }
  55. rstStr += count + " " + jobsArr[i].content + "\n";
  56. }
  57. }
  58. if(rstStr.trim().length > 0){
  59. let reg = /\n+$/g;
  60. let newStr = rstStr.replace(reg, "”");
  61. return newStr;
  62. }
  63. return null;
  64. },
  65. //新增行
  66. addRow: function (sheet) {
  67. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  68. checkBox.isThreeState = false;
  69. sheet.addRows(sheet.getRowCount(), 1);
  70. sheet.getCell(sheet.getRowCount() - 1, 1).cellType(checkBox);
  71. },
  72. upMove: function (rowIdx) {
  73. let me = contentOprObj;
  74. let thisObj = me.currentCache[rowIdx],
  75. preObj = me.currentCache[rowIdx - 1],
  76. temp, contentTxt;
  77. temp = thisObj.serialNo;
  78. thisObj.serialNo = preObj.serialNo;
  79. preObj.serialNo = temp;
  80. me.sortCache(me.currentCache);
  81. me.save();
  82. },
  83. downMove: function (rowIdx) {
  84. let me = contentOprObj;
  85. let thisObj = me.currentCache[rowIdx],
  86. nextObj = me.currentCache[rowIdx + 1],
  87. temp, contentTxt;
  88. temp = thisObj.serialNo;
  89. thisObj.serialNo = nextObj.serialNo;
  90. nextObj.serialNo = temp;
  91. me.sortCache(me.currentCache);
  92. me.save();
  93. },
  94. deleteContent: function (rowIdx) {
  95. let me = contentOprObj;
  96. me.currentCache.splice(rowIdx, 1);
  97. me.save();
  98. },
  99. //更新
  100. updateContent: function (job, newContent) {
  101. job.content = newContent;
  102. },
  103. //新增
  104. insertContent: function (content) {
  105. let me = contentOprObj;
  106. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  107. let newObj = {content: content, isCheceked: false, serialNo: preObj ? preObj.serialNo + 1 : 1};
  108. me.currentCache.push(newObj);
  109. },
  110. save: function () {
  111. let me = contentOprObj;
  112. let contentTxt = me.getColData(me.currentCache);
  113. let txtObj = {field: 'jobContentText', text: contentTxt ? contentTxt : ''};
  114. pageCCOprObj.updateCharacterContent(pageCCOprObj.currentFindSet, {field: 'jobContent', updateArr: me.currentCache}, txtObj, contentOprObj);
  115. },
  116. onEditEnded: function (sender, args) {
  117. let me = contentOprObj;
  118. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  119. let contentTxt;
  120. if(args.editingText && args.editingText.toString().trim().length > 0){
  121. //更新
  122. if(args.row < me.currentCache.length ){
  123. me.updateContent(me.currentCache[args.row], args.editingText);
  124. }
  125. //新增
  126. else{
  127. me.insertContent(args.editingText);
  128. }
  129. //保存
  130. me.save();
  131. }
  132. else{
  133. //恢复
  134. args.sheet.setValue(args.row, args.col, me.currentCache.length > args.row ? me.currentCache[args.row].content + '' : '');
  135. }
  136. },
  137. //复选框控制输出
  138. onButtonClicked: function (sender, args) {
  139. let me = contentOprObj, contentTxt;
  140. if(args.sheet.isEditing()){
  141. args.sheet.endEdit(true);
  142. }
  143. let isChecked = args.sheet.getValue(args.row, args.col);
  144. if(me.currentCache.length > args.row){
  145. me.currentCache[args.row].isChecked = isChecked;
  146. me.save();
  147. }
  148. //else的情况就是新增
  149. else{
  150. //还没数据清空复选框
  151. args.sheet.setValue(args.row, args.col, 0);
  152. }
  153. },
  154. //复制粘贴
  155. onClipboardPasting: function (sender, args) {
  156. if(args.cellRange.colCount > 1 || args.cellRange.col !== 0){
  157. args.cancel = true;
  158. }
  159. },
  160. onClipboardPasted: function (sender, args) {
  161. let me = contentOprObj;
  162. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  163. for(let i = 0, len = items.length; i < len; i++){
  164. let rowIdx = args.cellRange.row + i;
  165. //更新
  166. if(rowIdx < me.currentCache.length){
  167. me.updateContent(me.currentCache[rowIdx], items[i].content);
  168. }
  169. //新增
  170. else{
  171. me.insertContent(items[i].content);
  172. }
  173. }
  174. me.save();
  175. },
  176. sortCache: function (cacheArr) {
  177. cacheArr.sort(function (a, b) {
  178. let rst = 0;
  179. if(a.serialNo > b.serialNo){
  180. rst = 1;
  181. }
  182. else if(a.serialNo < b.serialNo){
  183. rst = -1;
  184. }
  185. return rst;
  186. });
  187. },
  188. onContextmenuOpr: function () {//右键菜单
  189. let me = contentOprObj;
  190. $.contextMenu({
  191. selector: '#jobSpread',
  192. build: function($triggerElement, e){
  193. //控制允许右键菜单在哪个位置出现
  194. let clientX = e.originalEvent.clientX,
  195. clientY = e.originalEvent.clientY;
  196. let sheet = me.workBook.getSheet(0);
  197. let offset = $("#jobSpread").offset(),
  198. x = clientX - offset.left,
  199. y = clientY - offset.top;
  200. let target = sheet.hitTest(x, y);
  201. if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  202. let insertDis = false, delDis = false, upDis = false, downDis = false;
  203. if(typeof target.row !== 'undefined'){
  204. //控制按钮是否可用
  205. sheet.setActiveCell(target.row, target.col);
  206. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  207. delDis = true;
  208. downDis = true;
  209. upDis = true;
  210. }
  211. else{//有数据
  212. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  213. downDis = true;
  214. }
  215. if(target.row === 0){//定位在第一行,不可上移
  216. upDis = true;
  217. }
  218. }
  219. }
  220. else{
  221. delDis = true;
  222. downDis = true;
  223. upDis = true;
  224. }
  225. return {
  226. callback: function(){},
  227. items: {
  228. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  229. //插入空行
  230. me.addRow(sheet);
  231. }},
  232. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  233. me.deleteContent(target.row);
  234. }},
  235. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  236. me.upMove(target.row);
  237. }},
  238. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  239. me.downMove(target.row);
  240. }}
  241. }
  242. };
  243. }
  244. else{
  245. return false;
  246. }
  247. }
  248. });
  249. }
  250. };
  251. let characterOprObj = {
  252. workBook: null,
  253. currentCache: [],
  254. setting: {
  255. header: [
  256. {headerName:"项目特征",headerWidth:160,dataCode:"character", dataType: "String", hAlign: "center", vAlign: "center"},
  257. {headerName:"特征值",headerWidth:160,dataCode:"eigenvalue", dataType: "String", cellType: "comboBox", hAlign: "center", vAlign: "center"},
  258. {headerName:"输出",headerWidth:80,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
  259. ]
  260. },
  261. buildSheet: function(container) {
  262. let me = characterOprObj;
  263. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
  264. me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  265. me.workBook.options.allowCopyPasteExcelStyle = false;
  266. me.onContextmenuOpr();
  267. me.bindEvents(me.workBook);
  268. },
  269. bindEvents: function (workBook) {
  270. let sheet = workBook.getActiveSheet(), me = characterOprObj;
  271. const EVENTS = GC.Spread.Sheets.Events;
  272. workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
  273. sheet.bind(EVENTS.EditEnded, me.onEditEnded);
  274. sheet.bind(EVENTS.EditStarting, me.onEditStart);
  275. sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
  276. sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
  277. },
  278. //显示在itemSpread的数据
  279. showCharacterData: function (sheet, setting, datas) {
  280. let me = characterOprObj;
  281. sheetCommonObj.showData(sheet, setting, datas);
  282. sheet.suspendPaint();
  283. sheet.suspendEvent();
  284. for(let i = 0, len = datas.length; i < len; i++){
  285. let comboObj = me.getComboBox(datas[i]);
  286. comboObj.combo.editable(false);//不可编辑
  287. sheet.getCell(i, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  288. sheet.getCell(i, 0).locked(true);
  289. }
  290. sheet.resumePaint();
  291. sheet.suspendEvent();
  292. },
  293. //获得项目特征特征值comboBox
  294. getComboBox: function (characterItem) {
  295. let rst = {};
  296. let combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  297. let comboItems = [], eigenvalues = characterItem.eigenvalue;
  298. for(let i = 0, len = eigenvalues.length; i < len; i++){
  299. comboItems.push(eigenvalues[i].value);
  300. if(eigenvalues[i].isSelected){
  301. rst.selectedValue = eigenvalues[i].value;
  302. }
  303. }
  304. combo.items(comboItems);
  305. rst.combo = combo;
  306. return rst;
  307. },
  308. //获得当前行选中的特征值
  309. getCurrentSelected: function (item) {
  310. let rst = null;
  311. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  312. if(item.eigenvalue[i].isSelected){
  313. rst = item.eigenvalue[i].value;
  314. break;
  315. }
  316. }
  317. return rst;
  318. },
  319. //显示到清单项目特征列的数据
  320. getColData: function (itemsArr) {
  321. let me = characterOprObj;
  322. let rstStr = "", count = 0;
  323. for(let i = 0, len = itemsArr.length; i < len; i++){
  324. if(itemsArr[i].isChecked === true){
  325. //获取选中的特征值
  326. let eigenvalueStr = "";
  327. let eigenvalue = itemsArr[i].eigenvalue;
  328. for(let j = 0, vLen = eigenvalue.length; j < vLen; j++){
  329. if(eigenvalue[j].isSelected){
  330. eigenvalueStr += eigenvalue[j].value;
  331. break;
  332. }
  333. }
  334. count ++;
  335. if(count === 1){
  336. rstStr += "“";
  337. }
  338. else{
  339. rstStr += " ";
  340. }
  341. rstStr += count + " " + itemsArr[i].character + ": " + eigenvalueStr + "\n";
  342. }
  343. }
  344. if(rstStr.trim().length > 0){
  345. let reg = /\n+$/g;
  346. let newStr = rstStr.replace(reg, "”");
  347. return newStr;
  348. }
  349. return null;
  350. },
  351. addRow: function (sheet) {
  352. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox(),
  353. combo = new GC.Spread.Sheets.CellTypes.ComboBox();
  354. checkBox.isThreeState = false;
  355. combo.editable(true);
  356. let rowIdx = sheet.getRowCount();
  357. sheet.addRows(rowIdx, 1);
  358. sheet.getCell(rowIdx, 1).cellType(combo);
  359. sheet.getCell(rowIdx, 2).cellType(checkBox);
  360. },
  361. upMove: function (rowIdx) {
  362. let me = characterOprObj;
  363. let thisObj = me.currentCache[rowIdx],
  364. preObj = me.currentCache[rowIdx - 1],
  365. temp;
  366. temp = thisObj.serialNo;
  367. thisObj.serialNo = preObj.serialNo;
  368. preObj.serialNo = temp;
  369. contentOprObj.sortCache(me.currentCache);
  370. me.save();
  371. },
  372. downMove: function (rowIdx) {
  373. let me = characterOprObj;
  374. let thisObj = me.currentCache[rowIdx],
  375. nextObj = me.currentCache[rowIdx + 1],
  376. temp;
  377. temp = thisObj.serialNo;
  378. thisObj.serialNo = nextObj.serialNo;
  379. nextObj.serialNo = temp;
  380. contentOprObj.sortCache(me.currentCache);
  381. me.save();
  382. },
  383. deleteCharacter: function (rowIdx) {
  384. let me = characterOprObj;
  385. me.currentCache.splice(rowIdx, 1);
  386. me.save();
  387. },
  388. //取消选择的特征值
  389. unsetSelected: function (item) {
  390. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  391. if(item.eigenvalue[i].isSelected){
  392. item.eigenvalue[i].isSelected = false;
  393. }
  394. }
  395. },
  396. //设置选中的特征值
  397. setSelected: function (item, value) {
  398. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  399. if(item.eigenvalue[i].value === value){
  400. item.eigenvalue[i].isSelected = true;
  401. }
  402. }
  403. },
  404. //改变选择特征值
  405. changeSelected: function (item, value) {
  406. let me = characterOprObj;
  407. me.unsetSelected(item);
  408. me.setSelected(item, value);
  409. },
  410. insertValue: function (item, value) {
  411. let me = characterOprObj;
  412. me.unsetSelected(item);
  413. let newValue = {value: value, isSelected: true};
  414. item.eigenvalue.push(newValue);
  415. },
  416. updateCharacter: function (item, character, value) {
  417. let me = characterOprObj;
  418. if(character){
  419. item.character = character;
  420. }
  421. if(value){
  422. let isExist = false;
  423. for(let i = 0, len = item.eigenvalue.length; i < len; i++){
  424. if(item.eigenvalue[i].value === value){
  425. isExist = true;
  426. break;
  427. }
  428. }
  429. //不存在,新增进eigenvalue
  430. if(!isExist){
  431. //更新selected
  432. me.insertValue(item, value);
  433. }
  434. //存在,选择特征值
  435. else{
  436. me.changeSelected(item, value);
  437. }
  438. }
  439. },
  440. insertCharacter: function (character, value) {
  441. let me = characterOprObj;
  442. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  443. if(character && !value){
  444. let newCharacter = {character: character, eigenvalue: [], isChecked: false, serialNo: preObj ? preObj.serialNo + 1 : 1};
  445. me.currentCache.push(newCharacter);
  446. }
  447. else if(!character && value){
  448. let newValue = {value: value, isSelected: true};
  449. let newCharacter = {character: '', eigenvalue: [newValue], isChecked: false, serialNo: preObj? preObj.serialNo + 1 : 1};
  450. me.currentCache.push(newCharacter);
  451. }
  452. else if(character && value){
  453. let newValue = {value: value, isSelected: true};
  454. let newCharacter = {character:character , eigenvalue: [newValue], isChecked: false, serialNo: preObj? preObj.serialNo + 1 : 1};
  455. me.currentCache.push(newCharacter);
  456. }
  457. },
  458. save: function () {
  459. let me = characterOprObj;
  460. let characterTxt = me.getColData(me.currentCache);
  461. let txtObj = {field: 'itemCharacterText', text: characterTxt ? characterTxt : ''};
  462. pageCCOprObj.updateCharacterContent(pageCCOprObj.currentFindSet, {field: 'itemCharacter', updateArr: me.currentCache}, txtObj, characterOprObj);
  463. },
  464. onEditStart: function (sender, args) {
  465. let me = characterOprObj;
  466. if(args.col === 1){//改变选择的特征值
  467. me.currentSelectedValue = me.currentCache.length > args.row ? me.getCurrentSelected(me.currentCache[args.row]) : null;
  468. }
  469. },
  470. onEditEnded: function (sender, args) {
  471. let me = characterOprObj, characterTxt;
  472. let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
  473. if(args.editingText && args.editingText.toString().trim().length > 0){
  474. //更新
  475. if(args.row < me.currentCache.length){
  476. let thisCha = me.currentCache[args.row];
  477. if(args.col === 0){//特征
  478. me.updateCharacter(thisCha, args.editingText, null);
  479. }
  480. else if(args.col === 1){//特征值
  481. me.updateCharacter(thisCha, null, args.editingText);
  482. }
  483. }
  484. //新增
  485. else{
  486. if(args.col === 0){//特征
  487. me.insertCharacter(args.editingText, null);
  488. }
  489. else if(args.col === 1){//特征值
  490. me.insertCharacter(null, args.editingText);
  491. }
  492. }
  493. //保存
  494. me.save();
  495. }
  496. else{//恢复
  497. if(args.col === 0){
  498. args.sheet.setValue(args.row, args.col, me.currentCache.length > args.row ? me.currentCache[args.row].character + '' : '');
  499. }
  500. else if(args.col === 1){
  501. args.sheet.setValue(args.row, args.col, me.currentSelectedValue ? me.currentSelectedValue + '' : '');
  502. }
  503. }
  504. },
  505. onClipboardPasting: function (sender, args) {
  506. if(args.cellRange.col + args.colCount - 1 > 1){
  507. args.cancel = true;
  508. }
  509. },
  510. onClipboardPasted: function (sender, args) {
  511. let me = characterOprObj;
  512. let items = sheetCommonObj.analyzePasteData(me.setting, args);
  513. for(let i = 0, len = items.length; i < len; i++){
  514. //更新
  515. let rowIdx = args.cellRange.row + i;
  516. if(me.currentCache.length > rowIdx){
  517. me.updateCharacter(me.currentCache[rowIdx], items[i].character, items[i].eigenvalue);
  518. }
  519. //新增
  520. else{
  521. me.insertCharacter(items[i].character, items[i].eigenvalue);
  522. }
  523. }
  524. me.save();
  525. },
  526. //复选框控制输出
  527. onButtonClicked: function (sender, args) {
  528. let me = characterOprObj, characterTxt;
  529. if(args.sheet.isEditing()){
  530. args.sheet.endEdit(true);
  531. }
  532. let isChecked = args.sheet.getValue(args.row, args.col);
  533. if(me.currentCache.length > args.row){
  534. me.refreshColData = true;
  535. me.currentCache[args.row].isChecked = isChecked;
  536. me.save();
  537. }
  538. //else的情况就是新增
  539. else{
  540. args.sheet.setValue(args.row, args.col, 0);
  541. }
  542. },
  543. onContextmenuOpr: function () {//右键菜单
  544. let me = characterOprObj;
  545. $.contextMenu({
  546. selector: '#itemSpread',
  547. build: function($triggerElement, e){
  548. //控制允许右键菜单在哪个位置出现
  549. let clientX = e.originalEvent.clientX,
  550. clientY = e.originalEvent.clientY;
  551. let sheet = me.workBook.getSheet(0);
  552. let offset = $("#itemSpread").offset(),
  553. x = clientX - offset.left,
  554. y = clientY - offset.top;
  555. let target = sheet.hitTest(x, y);
  556. if(target.hitTestType === 3){//在表格内 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  557. let insertDis = false, delDis = false, upDis = false, downDis = false;
  558. if(typeof target.row !== 'undefined'){
  559. //控制按钮是否可用
  560. sheet.setActiveCell(target.row, target.col);
  561. if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
  562. delDis = true;
  563. downDis = true;
  564. upDis = true;
  565. }
  566. else{//有数据
  567. if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
  568. downDis = true;
  569. }
  570. if(target.row === 0){//定位在第一行,不可上移
  571. upDis = true;
  572. }
  573. }
  574. }
  575. else{
  576. delDis = true;
  577. downDis = true;
  578. upDis = true;
  579. }
  580. return {
  581. callback: function(){},
  582. items: {
  583. "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
  584. me.addRow(sheet);
  585. }},
  586. "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
  587. me.deleteCharacter(target.row);
  588. }},
  589. "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
  590. me.upMove(target.row);
  591. }},
  592. "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
  593. me.downMove(target.row);
  594. }}
  595. }
  596. };
  597. }
  598. else{
  599. return false;
  600. }
  601. }
  602. });
  603. }
  604. };
  605. let pageCCOprObj = {
  606. currentFindSet: null,
  607. mainActiveCell: null,//mainSpread焦点单元格
  608. //设置特征及内容currentCache
  609. setCacheAndShow: function (node) {
  610. let theCont = contentOprObj, theCha = characterOprObj;
  611. theCont.currentCache = node && typeof node.data.jobContent !== 'undefined' ? node.data.jobContent : [];
  612. theCha.currentCache = node && typeof node.data.itemCharacter !== 'undefined' ? node.data.itemCharacter : [];
  613. this.currentFindSet = node && typeof node.data.ID !== 'undefined' && typeof node.data.projectID ? {ID: node.data.ID, projectID: node.data.projectID} : null;
  614. this.showData(theCont.workBook.getSheet(0), theCont.setting, theCont.currentCache);
  615. this.showData(theCha.workBook.getSheet(0), theCha.setting, theCha.currentCache);
  616. },
  617. //contentSpread、itemSpread展示数据用
  618. showData: function(sheet, setting, data) {
  619. let me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
  620. sheet.suspendPaint();
  621. sheet.suspendEvent();
  622. sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  623. sheet.setRowCount(data.length);
  624. for (let col = 0; col < setting.header.length; col++) {
  625. var hAlign = "left", vAlign = "center";
  626. if (setting.header[col].hAlign) {
  627. hAlign = setting.header[col].hAlign;
  628. } else if (setting.header[col].dataType !== "String"){
  629. hAlign = "right";
  630. }
  631. vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
  632. sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
  633. if (setting.header[col].formatter) {
  634. sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
  635. }
  636. for (let row = 0; row < data.length; row++) {
  637. sheet.getCell(row, 0).locked(true);//locked
  638. let val = data[row][setting.header[col].dataCode];
  639. if(setting.header[col].cellType === "checkBox"){
  640. let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
  641. checkBox.isThreeState(false);
  642. sheet.getCell(row, col).cellType(checkBox).value(val);
  643. }
  644. else if(setting.header[col].cellType === 'comboBox'){
  645. let comboObj = characterOprObj.getComboBox(data[row]);
  646. comboObj.combo.editable(true);//不可编辑
  647. sheet.getCell(row, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
  648. }
  649. else{
  650. sheet.setValue(row, col, val, ch);
  651. }
  652. }
  653. }
  654. sheet.resumeEvent();
  655. sheet.resumePaint();
  656. },
  657. clearData: function () {
  658. let theCon = contentOprObj, theCha = characterOprObj;
  659. sheetCommonObj.cleanSheet(theCon.workBook.getSheet(0), theCon.setting, -1);
  660. sheetCommonObj.cleanSheet(theCha.workBook.getSheet(0), theCha.setting, -1);
  661. },
  662. //更新特征及内容数据
  663. updateCharacterContent: function (findSet, updateObj, txtObj, oprObj) {
  664. let me = pageCCOprObj, updateCol;
  665. if(txtObj){
  666. updateCol = txtObj.field === 'itemCharacterText' ? 4 : 5;//更新清单行特征列或内容列
  667. }
  668. else{
  669. updateCol = null;
  670. }
  671. $.ajax({
  672. type: 'post',
  673. url: '/bills/updateCharacterContent',
  674. dataType: 'json',
  675. data: {findSet: JSON.stringify(findSet), updateObj: JSON.stringify(updateObj), txtObj: JSON.stringify(txtObj)},
  676. success: function (result) {
  677. if(!result.error){
  678. //更新节点数据
  679. let selectedNode = projectObj.mainController.tree.selected;
  680. selectedNode.data[updateObj.field] = updateObj.updateArr;
  681. selectedNode.data[txtObj.field] = txtObj.text;
  682. me.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
  683. if(updateCol){
  684. projectObj.mainSpread.getActiveSheet().setValue(me.mainActiveCell.row, updateCol, txtObj.text + ''); //刷新输出显示
  685. }
  686. }
  687. }
  688. });
  689. }
  690. }