character_content_view.js 28 KB

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