character_content_view.js 44 KB

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