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