billsGuidance.js 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/6/1
  7. * @version
  8. */
  9. const billsGuidance = (function () {
  10. function _isDef(v) {
  11. return typeof v !== 'undefined' && v !== null;
  12. }
  13. function sortByCode(arr) {
  14. function recurCompare(a, b, index){
  15. if (a[index] && !b[index]) {
  16. return 1;
  17. } else if (!a[index] && b[index]) {
  18. return -1;
  19. } else if (a[index] && b[index]) {
  20. let aV = a[index],
  21. bV = b[index];
  22. if (!isNaN(aV) && !isNaN(bV)) {
  23. aV = parseFloat(a[index]);
  24. bV = parseFloat(b[index]);
  25. }
  26. if (aV > bV) {
  27. return 1;
  28. } else if (aV < bV) {
  29. return -1;
  30. } else {
  31. return recurCompare(a, b, index + 1);
  32. }
  33. }
  34. return 0;
  35. }
  36. arr.sort(function (a, b) {
  37. if (!_isDef(a.code) || !_isDef(b.code)) {
  38. return 0;
  39. }
  40. let aArr = a.code.split('-'),
  41. bArr = b.code.split('-');
  42. return recurCompare(aArr, bArr, 0);
  43. });
  44. }
  45. let curCompilationID = '';
  46. const locked = lockUtil.getLocked();
  47. let moduleName = 'stdBillsGuidance';
  48. //上下拖动的拖动条高度
  49. const verticalResize = 10;
  50. //自执行函数全局变量定义
  51. const libID = getQueryString('libID');
  52. //总工作内容数据
  53. let stdBillsJobData = [];
  54. //总项目特征数据
  55. let stdBillsFeatureData = [];
  56. const bills = {
  57. dom: $('#billsSpread'),
  58. workBook: null,
  59. cache: [],
  60. tree: null,
  61. controller: null,
  62. treeSetting: {
  63. treeCol: 0,
  64. emptyRows: 0,
  65. headRows: 1,
  66. headRowHeight: [40],
  67. defaultRowHeight: 21,
  68. cols: [{
  69. width: 200,
  70. readOnly: true,
  71. showHint: true,
  72. head: {
  73. titleNames: ["项目编码"],
  74. spanCols: [1],
  75. spanRows: [1],
  76. vAlign: [1],
  77. hAlign: [1],
  78. font: ["Arial"]
  79. },
  80. data: {
  81. field: "code",
  82. vAlign: 1,
  83. hAlign: 0,
  84. font: "Arial"
  85. }
  86. }, {
  87. width: 200,
  88. readOnly: true,
  89. head: {
  90. titleNames: ["项目名称"],
  91. spanCols: [1],
  92. spanRows: [1],
  93. vAlign: [1],
  94. hAlign: [1],
  95. font: ["Arial"]
  96. },
  97. data: {
  98. field: "name",
  99. vAlign: 1,
  100. hAlign: 0,
  101. font: "Arial"
  102. }
  103. }]
  104. },
  105. headers: [
  106. {name: '项目编码', dataCode: 'code', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'},
  107. {name: '项目名称', dataCode: 'name', width: 200, vAlign: 'center', hAlign: 'left', formatter: '@'}
  108. ],
  109. events: {
  110. SelectionChanged: function (sender, info) {
  111. billsInitSel(info.newSelections[0].row, info.oldSelections[0]);
  112. }
  113. }
  114. };
  115. const selectedBgColor = '#DFE8F9';
  116. const searchBgColor = 'lemonChiffon';
  117. //项目指引类型
  118. const itemType = {
  119. job: 0,
  120. ration: 1
  121. };
  122. //项目指引复制整块localStorage key
  123. const itemCopyBlockKey = 'guideItemCopyBlock';
  124. const updateType = {
  125. create: 'create',
  126. update: 'update',
  127. del: 'delete'
  128. };
  129. //项目指引节点状态:展开全部、收起定额
  130. const itemExpandState = {
  131. expand: 1,
  132. contract: 0
  133. };
  134. //项目指引当前节点展开收缩状态,默认展开全部
  135. let curExpandState = 1;
  136. const guideItem = {
  137. dom: $('#guideItemSpread'),
  138. workBook: null,
  139. tree: null,
  140. controller: null,
  141. treeSetting: {
  142. treeCol: 0,
  143. emptyRows: 0,
  144. headRows: 1,
  145. headRowHeight: [40],
  146. defaultRowHeight: 21,
  147. cols: [{
  148. width: 400,
  149. readOnly: locked,
  150. head: {
  151. titleNames: ["项目指引"],
  152. spanCols: [1],
  153. spanRows: [1],
  154. vAlign: [1],
  155. hAlign: [1],
  156. font: ["Arial"]
  157. },
  158. data: {
  159. field: "name",
  160. vAlign: 1,
  161. hAlign: 0,
  162. font: "Arial",
  163. formatter: "@"
  164. }
  165. },
  166. {
  167. width: 50,
  168. readOnly: locked,
  169. head: {
  170. titleNames: ["单位"],
  171. spanCols: [1],
  172. spanRows: [1],
  173. vAlign: [1],
  174. hAlign: [1],
  175. font: ["Arial"]
  176. },
  177. data: {
  178. field: "unit",
  179. vAlign: 1,
  180. hAlign: 1,
  181. font: "Arial",
  182. formatter: "@"
  183. }
  184. },
  185. {
  186. width: 40,
  187. readOnly: true,
  188. head: {
  189. titleNames: ["输出特征"],
  190. spanCols: [1],
  191. spanRows: [1],
  192. vAlign: [1],
  193. hAlign: [1],
  194. font: ["Arial"]
  195. },
  196. data: {
  197. field: "outputItemCharacter",
  198. vAlign: 1,
  199. hAlign: 1,
  200. font: "Arial"
  201. }
  202. },
  203. {
  204. width: 40,
  205. readOnly: true,
  206. head: {
  207. titleNames: ["必填"],
  208. spanCols: [1],
  209. spanRows: [1],
  210. vAlign: [1],
  211. hAlign: [1],
  212. font: ["Arial"]
  213. },
  214. data: {
  215. field: "required",
  216. vAlign: 1,
  217. hAlign: 1,
  218. font: "Arial"
  219. }
  220. },
  221. {
  222. width: 40,
  223. readOnly: true,
  224. head: {
  225. titleNames: ["材料"],
  226. spanCols: [1],
  227. spanRows: [1],
  228. vAlign: [1],
  229. hAlign: [1],
  230. font: ["Arial"]
  231. },
  232. data: {
  233. field: "isMaterial",
  234. vAlign: 1,
  235. hAlign: 1,
  236. font: "Arial"
  237. }
  238. }
  239. ]
  240. },
  241. headers: [
  242. {name: '项目指引', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  243. {name: '单位', dataCode: 'unit', width: 50, vAlign: 'center', hAlign: 'center', formatter: '@'},
  244. {name: '输出特征', dataCode: 'outputItemCharacter', width: 40, vAlign: 'center', hAlign: 'center'},
  245. {name: '必填', dataCode: 'required', width: 40, vAlign: 'center', hAlign: 'center'},
  246. {name: '材料', dataCode: 'isMaterial', width: 40, vAlign: 'center', hAlign: 'center'},
  247. ],
  248. events: {
  249. SelectionChanged: function (sender, info) {
  250. guideItemInitSel(info.newSelections[0].row)
  251. },
  252. EditEnded: function (sender, args) {
  253. edit(args.sheet, [{row: args.row, col: args.col}]);
  254. },
  255. ButtonClicked: function (sender, args) {
  256. edit(args.sheet, [{row: args.row, col: args.col}]);
  257. },
  258. RangeChanged: function (sender, args) {
  259. edit(args.sheet, args.changedCells);
  260. },
  261. CellDoubleClick: function(sender, args) {
  262. locateAtRation(args.row);
  263. }
  264. }
  265. };
  266. //定额章节树
  267. const section = {
  268. dom: $('#sectionSpread'),
  269. workBook: null,
  270. cache: [],
  271. tree: null,
  272. controller: null,
  273. treeSetting: {
  274. treeCol: 0,
  275. emptyRows: 0,
  276. headRows: 1,
  277. headRowHeight: [40],
  278. defaultRowHeight: 21,
  279. cols: [{
  280. width: 400,
  281. readOnly: true,
  282. head: {
  283. titleNames: ["名称"],
  284. spanCols: [1],
  285. spanRows: [1],
  286. vAlign: [1],
  287. hAlign: [1],
  288. font: ["Arial"]
  289. },
  290. data: {
  291. field: "name",
  292. vAlign: 1,
  293. hAlign: 0,
  294. font: "Arial"
  295. }
  296. }]
  297. },
  298. headers: [
  299. {name: '名称', dataCode: 'name', width: 400, vAlign: 'center', hAlign: 'left', formatter: '@'},
  300. ],
  301. events: {
  302. SelectionChanged: function (sender, info) {
  303. sectionInitSel(info.newSelections[0].row)
  304. }
  305. }
  306. };
  307. const ration = {
  308. dom: $('#rationSpread'),
  309. workBook: null,
  310. datas: [],//所有的数据,搜索定额时,从所有数据中筛选
  311. cache: [],//显示在表格上的数据,添加定额可以有效根据行识别定额
  312. headers: [
  313. {name: '选择', dataCode: 'select', width: 50, vAlign: 'center', hAlign: 'center'},
  314. {name: '编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  315. {name: '名称', dataCode: 'name', width: 250, vAlign: 'center', hAlign: 'left', formatter: '@'},
  316. {name: '单位', dataCode: 'unit', width: 100, vAlign: 'center', hAlign: 'left', formatter: '@'}
  317. ],
  318. events: {
  319. ButtonClicked: function (sender, args) {
  320. if(args.sheet.isEditing()){
  321. args.sheet.endEdit(true);
  322. }
  323. },
  324. CellDoubleClick: function (sender, args) {
  325. if(ration.headers[args.col].dataCode === 'name'){
  326. let insertDatas = getInsertRations([args.row]);
  327. if(insertDatas.length > 0){
  328. insert(insertDatas, false);
  329. }
  330. }
  331. }
  332. }
  333. };
  334. const options = {
  335. workBook: {
  336. tabStripVisible: false,
  337. allowContextMenu: false,
  338. allowCopyPasteExcelStyle : false,
  339. allowExtendPasteRange: false,
  340. allowUserDragDrop : false,
  341. allowUserDragFill: false,
  342. scrollbarMaxAlign : true
  343. },
  344. sheet: {
  345. protectionOptions: {allowResizeRows: true, allowResizeColumns: true},
  346. clipBoardOptions: GC.Spread.Sheets.ClipboardPasteOptions.values
  347. }
  348. };
  349. /* 清单材料表 */
  350. const billMaterial = {
  351. dom: $('#bill-material-spread'),
  352. workBook: null,
  353. cache: [],
  354. headers: [
  355. {name: '材料编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
  356. {name: '材料名称', dataCode: 'name', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'},
  357. {name: '规格', dataCode: 'specs', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'}
  358. ],
  359. events: {
  360. EditEnded: function (sender, args) {
  361. editMaterials(args.sheet, [{row: args.row, col: args.col}]);
  362. },
  363. RangeChanged: function (sender, args) {
  364. editMaterials(args.sheet, args.changedCells);
  365. },
  366. }
  367. }
  368. // 显示清单材料数据
  369. function showBillMaterialData(sheet, headers, datas, emptyRow = 0){
  370. let fuc = function () {
  371. const rowCount = datas.length + emptyRow;
  372. sheet.setRowCount(rowCount);
  373. for(let col = 0, cLen = headers.length; col < cLen; col++){
  374. for(let row = 0; row < rowCount; row++){
  375. if (datas[row]) {
  376. sheet.setValue(row, col, datas[row][headers[col]['dataCode']] || '');
  377. } else {
  378. sheet.setValue(row, col, '');
  379. }
  380. }
  381. }
  382. };
  383. renderSheetFunc(sheet, fuc);
  384. }
  385. // 获取清单材料数据
  386. async function getBillMaterials() {
  387. if (!bills.tree.selected) {
  388. return;
  389. }
  390. billMaterial.cache = [];
  391. try {
  392. $.bootstrapLoading.start();
  393. billMaterial.cache = await ajaxPost('/billsGuidance/api/getBillMaterials', { libID, billID: bills.tree.selected.data.ID });
  394. sortByCode(billMaterial.cache);
  395. } catch (error) {
  396. $('#alert-info').text(error.message);
  397. $('#alert').modal('show');
  398. } finally {
  399. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  400. $.bootstrapLoading.end();
  401. }
  402. }
  403. function getText(sheet, row, col) {
  404. let text = sheet.getValue(row, col);
  405. text = text ? text.toString().trim() : '';
  406. return text;
  407. }
  408. // 编辑材料表
  409. async function editMaterials(sheet, cells){
  410. let isChanged = false;
  411. for(let cell of cells){
  412. const itemCode = billMaterial.cache[cell.row] && billMaterial.cache[cell.row].code || '';
  413. if (itemCode !== getText(sheet, cell.row, 0)) {
  414. isChanged = true;
  415. }
  416. }
  417. if (!isChanged) {
  418. return;
  419. }
  420. let gljCodes = new Set();
  421. const count = sheet.getRowCount();
  422. for (let row = 0; row < count; row++) {
  423. const code = getText(sheet, row, 0);
  424. if (code) {
  425. gljCodes.add(code);
  426. }
  427. }
  428. // 提交数据
  429. try {
  430. $.bootstrapLoading.start();
  431. billMaterial.cache = await ajaxPost('/billsGuidance/api/editBillMaterials', { libID, billID: bills.tree.selected.data.ID, gljCodes: [...gljCodes], compilationID: curCompilationID }, undefined, true);
  432. sortByCode(billMaterial.cache);
  433. } catch (error) {
  434. $('#alert-info').html(error);
  435. $('#alert').modal('show');
  436. } finally {
  437. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  438. $.bootstrapLoading.end();
  439. }
  440. }
  441. // 是否为工序行
  442. function isProcessNode(node) {
  443. return node && node.depth() % 2 === 0 && _isDef(node.data.type) && node.data.type === itemType.job
  444. }
  445. //渲染时方法,停止渲染
  446. //@param {Object}sheet {Function}func @return {void}
  447. function renderSheetFunc(sheet, func){
  448. sheet.suspendEvent();
  449. sheet.suspendPaint();
  450. if(func){
  451. func();
  452. }
  453. sheet.resumeEvent();
  454. sheet.resumePaint();
  455. }
  456. //设置表选项
  457. //@param {Object}workBook {Object}opts @return {void}
  458. function setOptions (workBook, opts) {
  459. for(let opt in opts.workBook){
  460. workBook.options[opt] = opts.workBook[opt];
  461. }
  462. for(let opt in opts.sheet){
  463. workBook.getActiveSheet().options[opt] = opts.sheet[opt];
  464. }
  465. }
  466. //建表头
  467. //@param {Object}sheet {Array}headers @return {void}
  468. function buildHeader(sheet, headers) {
  469. let fuc = function () {
  470. sheet.setColumnCount(headers.length);
  471. sheet.setRowHeight(0, 40, GC.Spread.Sheets.SheetArea.colHeader);
  472. for(let i = 0, len = headers.length; i < len; i++){
  473. sheet.setValue(0, i, headers[i].name, GC.Spread.Sheets.SheetArea.colHeader);
  474. sheet.setColumnWidth(i, headers[i].width, GC.Spread.Sheets.SheetArea.colHeader);
  475. sheet.getCell(0, i, GC.Spread.Sheets.SheetArea.colHeader).wordWrap(true);
  476. if(headers[i].formatter){
  477. sheet.setFormatter(-1, i, headers[i].formatter);
  478. }
  479. sheet.getRange(-1, i, -1, 1).hAlign(GC.Spread.Sheets.HorizontalAlign[headers[i]['hAlign']]);
  480. sheet.getRange(-1, i, -1, 1).vAlign(GC.Spread.Sheets.VerticalAlign[headers[i]['vAlign']]);
  481. }
  482. };
  483. renderSheetFunc(sheet, fuc);
  484. }
  485. //表监听事件
  486. //@param {Object}workBook @return {void}
  487. function bindEvent(workBook, events) {
  488. if(Object.keys(events).length === 0){
  489. return;
  490. }
  491. const Events = GC.Spread.Sheets.Events;
  492. for(let event in events){
  493. workBook.bind(Events[event], events[event]);
  494. }
  495. }
  496. //建表
  497. //@param {Object}module @return {void}
  498. function buildSheet(module) {
  499. if(!module.workBook){
  500. module.workBook = new GC.Spread.Sheets.Workbook(module.dom[0], {sheetCount: 1});
  501. let sheet = module.workBook.getActiveSheet();
  502. if(module === bills){
  503. sheet.name('stdBillsGuidance_bills');
  504. //默认初始可控制焦点在清单表中
  505. module.workBook.focus();
  506. sheet.options.isProtected = true;
  507. }
  508. else if(module === ration){
  509. sheet.options.isProtected = true;
  510. sheet.getRange(-1, 0, -1, 1).locked(locked);
  511. sheet.getRange(-1, 1, -1, -1).locked(true);
  512. }
  513. else if(module === guideItem){
  514. sheetCommonObj.bindEscKey(module.workBook, [{sheet: sheet, editStarting: null, editEnded: module.events.EditEnded}]);
  515. }
  516. else if (module === billMaterial) {
  517. sheet.options.isProtected = true;
  518. sheet.getRange(-1, 0, -1, 1).locked(locked);
  519. sheet.getRange(-1, 1, -1, -1).locked(true);
  520. sheet.getRange(-1, 2, -1, -1).locked(true);
  521. }
  522. setOptions(module.workBook, options);
  523. buildHeader(module.workBook.getActiveSheet(), module.headers);
  524. bindEvent(module.workBook, module.events);
  525. }
  526. lockUtil.lockSpreads([module.workBook], locked);
  527. if (locked) {
  528. // 锁定表格后双击事件失效了,但是需要双击定位,因此重新绑定双击
  529. if (module === guideItem) {
  530. module.workBook.bind('CellDoubleClick', module.events.CellDoubleClick);
  531. }
  532. }
  533. }
  534. //清空表数据
  535. //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
  536. function cleanData(sheet, headers, rowCount){
  537. renderSheetFunc(sheet, function () {
  538. sheet.clear(-1, 0, -1, headers.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  539. if (rowCount >= 0) {
  540. sheet.setRowCount(rowCount);
  541. }
  542. });
  543. }
  544. //根据清单获取项目指引
  545. //@param {String}guidanceLibID {Number}billsID {Function}callback @return {void}
  546. function getItemsByBills(guidanceLibID, billsID, callback){
  547. CommonAjax.post('/billsGuidance/api/getItemsByBills', {guidanceLibID: guidanceLibID, billsID: billsID}, function (rstData) {
  548. if(callback){
  549. callback(rstData);
  550. }
  551. });
  552. }
  553. //清单表焦点控制
  554. //@param {Number}row @return {void}
  555. function billsInitSel(row, oldSel){
  556. let guideSheet = guideItem.workBook.getActiveSheet();
  557. cleanData(guideSheet, guideItem.headers, -1);
  558. let node = bills.tree.items[row];
  559. if(!node){
  560. return;
  561. }
  562. const billSheet = bills.workBook.getActiveSheet();
  563. setBgColor(billSheet, row, selectedBgColor);
  564. if (oldSel && row !== oldSel.row) {
  565. const orgNode = bills.tree.items[oldSel.row]
  566. setBgColor(billSheet, oldSel.row, orgNode && orgNode.isSearch ? searchBgColor : 'white');
  567. }
  568. bills.tree.selected = node;
  569. //显示备注
  570. $('.main-side-bottom').find('textarea').val(node.data.comment ? node.data.comment : '');
  571. if(!node.guidance.tree){
  572. getItemsByBills(libID, node.data.ID, function (rstData) {
  573. initTree(node.guidance, guideSheet, guideItem.treeSetting, rstData);
  574. setNodesExpandState(node.guidance.tree.items, curExpandState);
  575. setProcessNodes(guideSheet, node.guidance.tree.items);
  576. renderSheetFunc(guideSheet, function () {
  577. TREE_SHEET_HELPER.refreshNodesVisible(node.guidance.tree.roots, guideSheet, true);
  578. });
  579. //设置底色
  580. setNodesColor(guideSheet, node.guidance.tree.items);
  581. //项目指引初始焦点
  582. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  583. });
  584. } else{
  585. setNodesExpandState(node.guidance.tree.items, curExpandState);
  586. node.guidance.controller.showTreeData();
  587. setProcessNodes(guideSheet, node.guidance.tree.items);
  588. //设置底色
  589. setNodesColor(guideSheet, node.guidance.tree.items);
  590. //项目指引初始焦点
  591. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  592. }
  593. }
  594. function showCheckBox(sheet, nodes) {
  595. // const checkBoxType = locked ? sheetCommonObj.getReadOnlyCheckBox() : sheetCommonObj.getCheckBox();
  596. const checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  597. const baseType = new GC.Spread.Sheets.CellTypes.Base();
  598. renderSheetFunc(sheet, function () {
  599. nodes.forEach(node => {
  600. const row = node.serialNo();
  601. if (isProcessNode(node)) {
  602. sheet.setCellType(row, 2, checkBoxType);
  603. sheet.setCellType(row, 3, checkBoxType);
  604. sheet.setCellType(row, 4, checkBoxType);
  605. sheet.setValue(row, 2, node.data.outputItemCharacter || false);
  606. sheet.setValue(row, 3, node.data.required || false);
  607. sheet.setValue(row, 4, node.data.isMaterial || false);
  608. } else {
  609. sheet.setCellType(row, 2, baseType);
  610. sheet.setCellType(row, 3, baseType);
  611. sheet.setCellType(row, 4, baseType);
  612. sheet.setValue(row, 2, '');
  613. sheet.setValue(row, 3, '');
  614. sheet.setValue(row, 4, '');
  615. }
  616. })
  617. });
  618. }
  619. function setReadOnly(sheet, nodes) {
  620. if (locked) {
  621. return;
  622. }
  623. // 单位,可输入单位文本。仅特征/工序行可输入
  624. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  625. renderSheetFunc(sheet, function () {
  626. nodes.forEach(node => {
  627. const row = node.serialNo();
  628. sheet.getCell(row, unitCol).locked(!isProcessNode(node));
  629. });
  630. });
  631. }
  632. // 设置选项行相关
  633. function setProcessNodes(sheet, nodes) {
  634. showCheckBox(sheet, nodes);
  635. setReadOnly(sheet, nodes);
  636. }
  637. //设置项目节点展开收起状态:展开全部、收起定额
  638. //@param {Array}nodes(当前清单下的所有项目指引节点) {Number}expandState(展开全部1或收起定额0).
  639. function setNodesExpandState(nodes, expandState) {
  640. if(expandState === itemExpandState.contract) {
  641. //找出所有定额的父节点
  642. let rations = _.filter(nodes, function (node) {
  643. return node.data.type === itemType.ration;
  644. });
  645. let rationParentIDs = [];
  646. for(let ration of rations){
  647. if(ration.data.ParentID != -1){
  648. rationParentIDs.push(ration.data.ParentID);
  649. }
  650. }
  651. rationParentIDs = Array.from(new Set(rationParentIDs));
  652. let rationParentNodes = _.filter(nodes, function (node) {
  653. return rationParentIDs.includes(node.data.ID);
  654. });
  655. //收起定额
  656. for(let node of rationParentNodes){
  657. node.setExpanded(false);
  658. }
  659. } else {
  660. for(let node of nodes){
  661. node.setExpanded(true);
  662. }
  663. }
  664. }
  665. // 设置行底色
  666. function setBgColor(sheet, row, color) {
  667. const style = new GC.Spread.Sheets.Style();
  668. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  669. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  670. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  671. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  672. style.backColor = color;
  673. sheet.setStyle(row, -1, style);
  674. }
  675. //根据奇偶层级设置节点底色,奇数层为蓝色(树节点深度为偶数)
  676. //@param {Object}sheet {Array}nodes @return {void}
  677. function setNodesColor(sheet, nodes) {
  678. renderSheetFunc(sheet, function () {
  679. for(let node of nodes){
  680. const color = isProcessNode(node) ? selectedBgColor : 'White';
  681. setBgColor(sheet, node.serialNo(), color);
  682. }
  683. });
  684. }
  685. //选中的节点是否全是同层节点
  686. //@param {Object}sheet {Array}items @return {Boolean}
  687. function itemsSameDepth(sheet, items) {
  688. let sels = sheet.getSelections();
  689. if(sels.length === 0 || items.length === 0){
  690. return false;
  691. }
  692. let depths = [];
  693. for(let i = 0; i < sels[0].rowCount; i++){
  694. let row = sels[0].row + i;
  695. let node = items[row];
  696. if(node){
  697. depths.push(node.depth());
  698. }
  699. }
  700. }
  701. //节点子项是否全是工作内容
  702. //@param {Object}node @return {Boolean}
  703. function allJobChildren(node){
  704. for(let c of node.children){
  705. if(c.data.type === itemType.ration){
  706. return false;
  707. }
  708. }
  709. return true;
  710. }
  711. //节点子项是否全是定额
  712. //@param {Object}node @return {Boolean}
  713. function allRationChildren(node){
  714. for(let c of node.children){
  715. if(c.data.type === itemType.job){
  716. return false;
  717. }
  718. }
  719. return true;
  720. }
  721. //刷新按钮有效性
  722. //@param {Object}node @return {void}
  723. function refreshBtn(node){
  724. if (locked) {
  725. return;
  726. }
  727. //全部设为无效
  728. $('.tools-btn').children().addClass('disabled');
  729. $('#insertRation').addClass('disabled');
  730. $('#insertAll').addClass('disabled');
  731. $('.main-bottom-content').find('textarea').attr('readonly', true);
  732. //插入
  733. if(bills.tree.selected && bills.tree.selected.guidance.tree){
  734. $('#insert').removeClass('disabled');
  735. if(node && node.data.type === itemType.ration){
  736. $('#insert').addClass('disabled');
  737. }
  738. }
  739. //删除
  740. if(node){
  741. $('#del').removeClass('disabled');
  742. }
  743. if(node && node.data.type === itemType.job){
  744. //升级
  745. if(node.parent){
  746. $('#upLevel').removeClass('disabled');
  747. if(node.nextSibling && node.children.length > 0 && !allJobChildren(node)){
  748. $('#upLevel').addClass('disabled');
  749. }
  750. }
  751. //降级
  752. if(node.preSibling){
  753. $('#downLevel').removeClass('disabled');
  754. if(node.preSibling.children.length > 0 && !allJobChildren(node.preSibling)){
  755. $('#downLevel').addClass('disabled');
  756. }
  757. }
  758. }
  759. //上移
  760. if(node && node.preSibling){
  761. $('#upMove').removeClass('disabled')
  762. }
  763. //下移
  764. if(node && node.nextSibling){
  765. $('#downMove').removeClass('disabled');
  766. }
  767. //收起定额、展开全部
  768. $('#expandContract').removeClass('disabled');
  769. //插入定额
  770. if(node && (node.children.length === 0 || allRationChildren(node))){
  771. $('#insertRation').removeClass('disabled');
  772. $('#insertAll').removeClass('disabled');
  773. }
  774. //备注,奇数节点可用
  775. if(isProcessNode(node)){
  776. $('.main-bottom-content').find('textarea').attr('readonly', false);
  777. }
  778. }
  779. //项目指引表焦点控制
  780. //@param {Number}row @return {void}
  781. function guideItemInitSel(row){
  782. let billsNode = bills.tree.selected;
  783. let node = null;
  784. if(billsNode && billsNode.guidance.tree){
  785. node = billsNode.guidance.tree.items[row];
  786. if(node){
  787. billsNode.guidance.tree.selected = node;
  788. //显示备注
  789. $('.main-bottom-content').find('textarea').val(node.data.comment ? node.data.comment : '');
  790. }
  791. }
  792. refreshBtn(node);
  793. }
  794. //初始化当前库名
  795. //@param {String} @return {void}
  796. function initLibName(libName) {
  797. $('#libName')[0].outerHTML = $('#libName')[0].outerHTML.replace("XXX清单指引", libName);
  798. }
  799. //初始化各工作表
  800. //@param {Array}modules @return {void}
  801. function initWorkBooks(modules){
  802. for(let module of modules){
  803. buildSheet(module);
  804. }
  805. }
  806. function tipDivCheck(){
  807. setTimeout(function () {
  808. let tips = $('#autoTip');
  809. if(ration.tipDiv == 'show'){
  810. return;
  811. } else if(ration.tipDiv == 'hide'&&tips){
  812. tips.hide();
  813. ration._toolTipElement = null;
  814. }
  815. },600)
  816. }
  817. //获取悬浮提示单元格
  818. //@param {Object}sheet @return {Object}
  819. function getTipCellType(sheet) {
  820. let setting = {};
  821. let TipCellType = function () {};
  822. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
  823. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  824. return {
  825. x: x,
  826. y: y,
  827. row: context.row,
  828. col: context.col,
  829. cellStyle: cellStyle,
  830. cellRect: cellRect,
  831. sheet: context.sheet,
  832. sheetArea: context.sheetArea
  833. };
  834. };
  835. TipCellType.prototype.processMouseEnter = function (hitinfo) {
  836. let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
  837. let tag = hitinfo.sheet.getTag(hitinfo.row, hitinfo.col);
  838. if(tag !== undefined && tag){
  839. text = tag;
  840. }
  841. if(sheet && sheet.getParent().qo){
  842. setting.pos = SheetDataHelper.getObjPos(sheet.getParent().qo);
  843. }
  844. let delayTimes = 500; //延时时间
  845. let now_timeStamp = +new Date();
  846. this.tipTimeStamp = now_timeStamp;
  847. let me = this;
  848. setTimeout(function () {
  849. if(now_timeStamp - me.tipTimeStamp == 0){//鼠标停下的时候才显示
  850. if (setting.pos && text && text !== '') {
  851. //固定不显示的div,存储文本获取固定div宽度,toolTipElement由于显示和隐藏,获取宽度不正确
  852. if(!me._fixedTipElement){
  853. let div = $('#fixedTip1')[0];
  854. if (!div) {
  855. div = document.createElement("div");
  856. $(div).css("padding", 5)
  857. .attr("id", 'fixedTip');
  858. $(div).hide();
  859. document.body.insertBefore(div, null);
  860. }
  861. me._fixedTipElement = div;
  862. }
  863. $(me._fixedTipElement).width('');
  864. $(me._fixedTipElement).html(text);
  865. if (!me._toolTipElement) {
  866. let div = $('#autoTip1')[0];
  867. if (!div) {
  868. div = document.createElement("div");
  869. $(div).css("position", "absolute")
  870. .css("border", "1px #C0C0C0 solid")
  871. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  872. .css("font", "0.9rem Calibri")
  873. .css("background", "white")
  874. .css("padding", 5)
  875. .attr("id", 'autoTip1');
  876. $(div).hide();
  877. document.body.insertBefore(div, null);
  878. }
  879. me._toolTipElement = div;
  880. $(me._toolTipElement).width('');
  881. //实时读取位置信息
  882. if(hitinfo.sheet && hitinfo.sheet.getParent().qo){
  883. setting.pos = SheetDataHelper.getObjPos(hitinfo.sheet.getParent().qo);
  884. }
  885. $(me._toolTipElement).html(text);
  886. //定额库定额特殊处理
  887. if($(hitinfo.sheet.getParent().qo).attr('id') === 'rationSpread'){
  888. let divWidth = $(me._fixedTipElement).width(),
  889. divHeight = $(me._fixedTipElement).height();
  890. if(divWidth > 600){
  891. divWidth = 590;
  892. $(me._toolTipElement).width(divWidth);
  893. }
  894. let top = setting.pos.y + hitinfo.y - divHeight < 0 ? 0 : setting.pos.y + hitinfo.cellRect.y - divHeight;
  895. $(me._toolTipElement).css("top", top).css("left", setting.pos.x - divWidth);
  896. }
  897. else{
  898. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  899. }
  900. //名称
  901. if(hitinfo.col === 2){
  902. let acStyle = hitinfo.sheet.getActualStyle(hitinfo.row, hitinfo.col),
  903. zoom = hitinfo.sheet.zoom();
  904. let value = hitinfo.sheet.getValue(hitinfo.row, hitinfo.col);
  905. let textLength = me.getAutoFitWidth(value, text, acStyle, zoom, {sheet: hitinfo.sheet, row: hitinfo.row, col: hitinfo.col, sheetArea: GC.Spread.Sheets.SheetArea.viewport});
  906. let cellWidth = hitinfo.sheet.getCell(-1, hitinfo.col).width();
  907. if(textLength > cellWidth){
  908. $(me._toolTipElement).css("top", setting.pos.y + hitinfo.y +15).css("left", setting.pos.x + hitinfo.x + 15);
  909. $(me._toolTipElement).show("fast");
  910. ration.tipDiv = 'show';//做个标记
  911. }
  912. }
  913. else {
  914. $(me._toolTipElement).show("fast");
  915. ration.tipDiv = 'show';//做个标记
  916. }
  917. }
  918. }
  919. }
  920. },delayTimes);
  921. };
  922. TipCellType.prototype.processMouseLeave = function (hininfo) {
  923. this.tipTimeStamp = +new Date();
  924. ration.tipDiv = 'hide';
  925. if (this._toolTipElement) {
  926. $(this._toolTipElement).hide();
  927. this._toolTipElement = null;
  928. }
  929. tipDivCheck();//延时检查:当tips正在show的时候,就调用了hide方法,会导致tips一直存在,所以设置一个超时处理
  930. }
  931. return new TipCellType();
  932. }
  933. //输出表数据(定额表)
  934. //@param {Object}sheet {Array}headers {Array}datas @return {void}
  935. function showData(sheet, headers, datas){
  936. let fuc = function () {
  937. sheet.setRowCount(datas.length);
  938. //复选框
  939. let checkBoxType = new GC.Spread.Sheets.CellTypes.CheckBox();
  940. let tipCellType = getTipCellType(sheet);
  941. sheet.setCellType(-1, 0, checkBoxType);
  942. for(let col = 0, cLen = headers.length; col < cLen; col++){
  943. for(let row = 0, rLen = datas.length; row < rLen; row++){
  944. sheet.setValue(row, col, datas[row][headers[col]['dataCode']]);
  945. if(col === 1){
  946. sheet.setTag(row, col, datas[row]['hint']);
  947. }
  948. }
  949. }
  950. sheet.setCellType(-1, 1, tipCellType);
  951. sheet.setCellType(-1, 2, tipCellType);
  952. };
  953. renderSheetFunc(sheet, fuc);
  954. }
  955. //根据定额章节树ID获取定额(从数据缓存中获取,定额数据一开始一次性拉取)
  956. //@param {Number}sectionId {Array}rations @return {Array}
  957. function getRationsBySectionId(sectionId, rations) {
  958. if(!sectionId || !rations){
  959. return [];
  960. }
  961. return _.filter(rations, {sectionId});
  962. }
  963. //定额章节树焦点控制
  964. //@param {Number}row @return {void}
  965. function sectionInitSel(row) {
  966. let rationSheet = ration.workBook.getActiveSheet();
  967. let sectionNode = section.tree ? section.tree.items[row] : null;
  968. if(sectionNode && sectionNode.children.length === 0){
  969. let sectionRations = getRationsBySectionId(sectionNode.data.ID, ration.datas);
  970. ration.cache = sectionRations;
  971. showData(rationSheet, ration.headers, sectionRations);
  972. }
  973. else {
  974. cleanData(rationSheet, ration.headers, 0);
  975. }
  976. }
  977. //初始化定额条目
  978. //@param {Number}rationLibId @return {void}
  979. function initRationItems(rationLibId, successCb){
  980. $.bootstrapLoading.start();
  981. //获取定额章节树
  982. let sectionSheet = section.workBook.getActiveSheet();
  983. CommonAjax.post('/rationRepository/api/getRationTree', {rationLibId: rationLibId}, function (sectionDatas) {
  984. //获取所有定额数据
  985. let reqEntity = {rationLibId: rationLibId, showHint: true, returnFields: '-_id code ID sectionId name unit basePrice rationGljList jobContent annotation'};
  986. CommonAjax.post('/rationRepository/api/getRationItemsByLib', reqEntity, function (rstData) {
  987. section.cache = sectionDatas;
  988. initTree(section, section.workBook.getActiveSheet(), section.treeSetting, sectionDatas);
  989. //初始焦点在第一行(切换库)
  990. sectionSheet.setActiveCell(0, 0);
  991. sortByCode(rstData);
  992. /* rstData.sort(function (a, b) {
  993. let rst = 0;
  994. if(a.code > b.code){
  995. rst = 1;
  996. }
  997. else if(a.code < b.code){
  998. rst = -1;
  999. }
  1000. return rst;
  1001. }); */
  1002. ration.datas = rstData;
  1003. sectionInitSel(0);
  1004. $.bootstrapLoading.end();
  1005. if (successCb) {
  1006. successCb();
  1007. }
  1008. }, function () {
  1009. $.bootstrapLoading.end();
  1010. });
  1011. }, function () {
  1012. $.bootstrapLoading.end();
  1013. });
  1014. }
  1015. // 可用的定额库ID
  1016. const rationLibIDs = [];
  1017. //初始化定额库选择
  1018. //@param {String}compilationId @return {void}
  1019. function initRationLibs(compilationId){
  1020. CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
  1021. $('#rationLibSel').empty();
  1022. for(let rationLib of rstData){
  1023. rationLibIDs.push(+rationLib.ID);
  1024. let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
  1025. $('#rationLibSel').append(opt);
  1026. }
  1027. //初始选择
  1028. initRationItems(parseInt($('#rationLibSel').select().val()));
  1029. $('#rationLibSel').change(function () {
  1030. let rationLibId = parseInt($(this).select().val());
  1031. initRationItems(rationLibId);
  1032. })
  1033. });
  1034. }
  1035. // 变更定额库
  1036. function changeRationLib(libID, successCb) {
  1037. $('#rationLibSel').val(libID);
  1038. initRationItems(libID, successCb);
  1039. }
  1040. // 设置清单名称文本色
  1041. function setBillsForeColor(billsNodes) {
  1042. const sheet = bills.workBook.getActiveSheet();
  1043. renderSheetFunc(sheet, function () {
  1044. for(let bills of billsNodes){
  1045. const row = bills.serialNo();
  1046. sheet.setStyle(row, 1, { foreColor: bills.data.hasGuide ? 'darkgreen' : 'black' });
  1047. }
  1048. });
  1049. }
  1050. //清单设置悬浮提示信息
  1051. //@param {Array}billsNodes(清单节点) {Array}jobs(总的工作内容数据) {Array}items(总的项目特征数据)
  1052. function setBillsHint(billsNodes, jobs, items) {
  1053. let jobsMapping = {},
  1054. itemsMapping = {};
  1055. for(let job of jobs){
  1056. jobsMapping[job.id] = job;
  1057. }
  1058. for(let item of items){
  1059. itemsMapping[item.id] = item;
  1060. }
  1061. let tagInfo = [];
  1062. for(let billsNode of billsNodes){
  1063. let hintArr = [];
  1064. let billsItems = billsNode.data.items;
  1065. if(billsItems.length > 0){
  1066. //项目特征
  1067. hintArr.push('项目特征:');
  1068. }
  1069. let itemCount = 1,
  1070. jobCount = 1;
  1071. for(let billsItem of billsItems){
  1072. let itemData = itemsMapping[billsItem.id];
  1073. if(itemData){
  1074. //特征值
  1075. let eigens = [];
  1076. for(let eigen of itemData.itemValue){
  1077. eigens.push(eigen.value);
  1078. }
  1079. eigens = eigens.join(';');
  1080. hintArr.push(`${itemCount}.${itemData.content}${eigens === '' ? '' : ': ' + eigens}`);
  1081. itemCount ++;
  1082. }
  1083. }
  1084. //工作内容
  1085. let billsJobs = billsNode.data.jobs;
  1086. if(billsJobs.length > 0){
  1087. hintArr.push('工作内容:');
  1088. }
  1089. for(let billsJob of billsJobs){
  1090. let jobData = jobsMapping[billsJob.id];
  1091. if(jobData){
  1092. hintArr.push(`${jobCount}.${jobData.content}`);
  1093. jobCount ++;
  1094. }
  1095. }
  1096. /*if(billsNode.data.ruleText && billsNode.data.ruleText !== ''){
  1097. hintArr.push('工程量计算规则:');
  1098. hintArr.push(billsNode.data.ruleText);
  1099. }
  1100. if(billsNode.data.recharge && billsNode.data.recharge !== ''){
  1101. hintArr.push('补注:');
  1102. hintArr.push(billsNode.data.recharge);
  1103. }*/
  1104. if(hintArr.length > 0){
  1105. tagInfo.push({row: billsNode.serialNo(), value: hintArr.join('\n')});
  1106. }
  1107. }
  1108. let sheet = bills.workBook.getActiveSheet();
  1109. renderSheetFunc(sheet, function () {
  1110. for(let tagI of tagInfo){
  1111. sheet.setTag(tagI.row, 0, tagI.value);
  1112. }
  1113. });
  1114. }
  1115. //初始化清单的工作内容和项目特征
  1116. //@param {Number}billsLibId {Function}callback @return {void}
  1117. function initJobAndCharacter(billsLibId, callback){
  1118. CommonAjax.post('/stdBillsEditor/getJobContent', {billsLibId: billsLibId}, function (datas) {
  1119. stdBillsJobData = datas;
  1120. CommonAjax.post('/stdBillsEditor/getItemCharacter', {billsLibId: billsLibId}, function (datas) {
  1121. stdBillsFeatureData = datas;
  1122. if(callback){
  1123. callback();
  1124. }
  1125. });
  1126. });
  1127. }
  1128. let billsLibId = 0;
  1129. //获取指引库信息及关联的清单
  1130. //@param {Number}libID {Function}callback @return {Object}
  1131. function getLibWithBills(libID, callback){
  1132. CommonAjax.post('/billsGuidance/api/getLibWithBills', {libID: libID}, function (rstData) {
  1133. billsLibId = rstData.guidanceLib.billsLibId;
  1134. initRationLibs(rstData.guidanceLib.compilationId);
  1135. curCompilationID = rstData.guidanceLib.compilationId;
  1136. bills.cache = rstData.bills;
  1137. initLibName(rstData.guidanceLib.name);
  1138. /*initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1139. //每一棵项目指引树挂在清单节点上
  1140. for(let node of bills.tree.items){
  1141. node.guidance = {tree: null, controller: null};
  1142. }
  1143. //默认初始节点
  1144. billsInitSel(0);
  1145. if(callback){
  1146. callback(rstData);
  1147. }*/
  1148. let initDataCallback = function () {
  1149. initTree(bills, bills.workBook.getActiveSheet(), bills.treeSetting, bills.cache);
  1150. //每一棵项目指引树挂在清单节点上
  1151. for(let node of bills.tree.items){
  1152. node.guidance = {tree: null, controller: null};
  1153. }
  1154. //默认初始节点
  1155. billsInitSel(0);
  1156. if(callback){
  1157. callback(rstData);
  1158. }
  1159. };
  1160. initJobAndCharacter(rstData.guidanceLib.billsLibId, initDataCallback);
  1161. }, function (msg) {
  1162. window.location.href = '/billsGuidance/main';
  1163. });
  1164. }
  1165. //初始化并输出树
  1166. //@param {Object}module {Object}sheet {Object}treeSetting {Array}datas
  1167. function initTree(module, sheet, treeSetting, datas){
  1168. module.tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
  1169. module.controller = TREE_SHEET_CONTROLLER.createNew(module.tree, sheet, treeSetting);
  1170. module.tree.loadDatas(datas);
  1171. if(module === bills){
  1172. module.tree.roots.forEach(root => {
  1173. root.setExpanded(false);
  1174. })
  1175. }
  1176. module.controller.showTreeData();
  1177. if(module === bills){
  1178. setBillsHint(bills.tree.items, stdBillsJobData, stdBillsFeatureData);
  1179. setBillsForeColor(bills.tree.items);
  1180. }
  1181. }
  1182. //更新清单备注
  1183. function updateBillsComment(updateData, callback, errCB) {
  1184. CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
  1185. if (callback) {
  1186. callback();
  1187. }
  1188. }, function () {
  1189. if(errCB) {
  1190. errCB();
  1191. }
  1192. });
  1193. }
  1194. //更新项目指引
  1195. //@param {Array}updateDatas {Function}callback @return {void}
  1196. function updateGuideItems(updateDatas, callback, errCB){
  1197. CommonAjax.post('/billsGuidance/api/updateItems', {updateDatas: updateDatas}, function (rstData) {
  1198. if(callback){
  1199. callback(rstData);
  1200. }
  1201. }, function () {
  1202. if(errCB) {
  1203. errCB();
  1204. }
  1205. $.bootstrapLoading.end();
  1206. });
  1207. }
  1208. //编辑后自动去除换行符回车符
  1209. const deESC = /[\n]/g;
  1210. //项目指引编辑
  1211. //@param {Object}sheet {Array}cells
  1212. function edit(sheet, cells){
  1213. let updateDatas = [];
  1214. //同步节点数据
  1215. let syncDatas = [];
  1216. for(let cell of cells){
  1217. const field = guideItem.headers[cell.col].dataCode;
  1218. let node = bills.tree.selected.guidance.tree.items[cell.row];
  1219. if (field === 'name' || field === 'unit') {
  1220. let text = sheet.getValue(cell.row, cell.col);
  1221. text = text ? text.toString() : '';
  1222. text = text.replace(deESC, '');
  1223. sheet.setValue(cell.row, cell.col, text);
  1224. if(node.data[field] != text){
  1225. syncDatas.push({node: node, text: text, field, cell});
  1226. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: text}});
  1227. }
  1228. } else if (field === 'outputItemCharacter' || field === 'required' || field === 'isMaterial') {
  1229. const val = !sheet.getValue(cell.row, cell.col);
  1230. sheet.setValue(cell.row, cell.col, val);
  1231. syncDatas.push({node: node, text: val, field, cell });
  1232. updateDatas.push({updateType: updateType.update, findData: {ID: node.getID()}, updateData: {[field]: val}});
  1233. }
  1234. }
  1235. if(updateDatas.length > 0){
  1236. updateGuideItems(updateDatas, function () {
  1237. for(let syncData of syncDatas){
  1238. syncData.node.data[syncData.field] = syncData.text;
  1239. }
  1240. }, function () {
  1241. //失败恢复
  1242. renderSheetFunc(sheet, function () {
  1243. for(let syncData of syncDatas){
  1244. sheet.setValue(syncData.node.serialNo(), syncData.cell.col, syncData.node.data[syncData.field] ? syncData.node.data[syncData.field] : '');
  1245. }
  1246. });
  1247. });
  1248. }
  1249. }
  1250. //项目指引插入,支持一次插入多条数据
  1251. //@param {Array}datas {Boolean}tobeChild(插入成为子项) {Function}callback @return {void}
  1252. function insert(datas, tobeChild, callback = null){
  1253. $.bootstrapLoading.start();
  1254. let sheet = guideItem.workBook.getActiveSheet();
  1255. let controller = bills.tree.selected.guidance.controller;
  1256. let selected = bills.tree.selected.guidance.tree.selected;
  1257. let updateDatas = [];
  1258. //建立数组下标索引
  1259. let newDataIndex = {};
  1260. for(let i = 0; i < datas.length; i++){
  1261. let newNodeData = {
  1262. libID: libID, ID: uuid.v1(), ParentID: selected ? selected.getParentID() : -1, NextSiblingID: selected ? selected.getNextSiblingID() : -1,
  1263. billsID: bills.tree.selected.getID()
  1264. };
  1265. //定额类型插入当前工作内容焦点行,
  1266. if(selected && ((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1267. newNodeData.ParentID = selected.getID();
  1268. newNodeData.NextSiblingID = -1;
  1269. }
  1270. Object.assign(newNodeData, datas[i]);
  1271. newDataIndex[i] = newNodeData;
  1272. }
  1273. for(let i = 0; i < datas.length; i++){
  1274. //第一个节点
  1275. if(i === 0){
  1276. //非插入成子节点,更新选中节点NestSiblingID
  1277. if(selected && !((selected.data.type === itemType.job && datas[i].type === itemType.ration) || tobeChild)){
  1278. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: newDataIndex[i].ID}});
  1279. }
  1280. }
  1281. //非最后一个节点
  1282. if(i !== datas.length - 1){
  1283. newDataIndex[i].NextSiblingID = newDataIndex[i + 1].ID;
  1284. }
  1285. updateDatas.push({updateType: updateType.create, updateData: newDataIndex[i]});
  1286. }
  1287. updateGuideItems(updateDatas, function () {
  1288. for(let updateData of updateDatas){
  1289. if(updateData.updateType === updateType.create){
  1290. let newNode = controller.insertByIDS(updateData.updateData.ID, updateData.updateData.ParentID, updateData.updateData.NextSiblingID);
  1291. //同步data
  1292. Object.assign(newNode.data, updateData.updateData);
  1293. const row = newNode.serialNo();
  1294. sheet.setValue(row, 0, newNode.data.name);
  1295. if (newNode.data.outputItemCharacter !== undefined) {
  1296. sheet.setValue(row, 2, newNode.data.outputItemCharacter);
  1297. }
  1298. setProcessNodes(sheet, [newNode]);
  1299. refreshBtn(newNode);
  1300. }
  1301. }
  1302. if (!bills.tree.selected.data.hasGuide && bills.tree.selected.guidance.tree.items.length) {
  1303. bills.tree.selected.data.hasGuide = true;
  1304. setBillsForeColor([bills.tree.selected]);
  1305. }
  1306. if(callback){
  1307. callback();
  1308. }
  1309. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1310. guideItem.workBook.focus(true);
  1311. $.bootstrapLoading.end();
  1312. });
  1313. }
  1314. // 删除定额(嵌套删除自身及后代定额)
  1315. function delRations() {
  1316. const selected = bills.tree.selected.guidance.tree.selected;
  1317. if (!selected) {
  1318. return;
  1319. }
  1320. if (selected.data.type === itemType.ration) {
  1321. del({ row: selected.serialNo(), col: 0, rowCount: 1, colCount: 1 });
  1322. return;
  1323. }
  1324. const rations = selected.getPosterity().filter(item => item.data.type === itemType.ration);
  1325. if (!rations.length) {
  1326. return;
  1327. }
  1328. const updateDatas = rations.map(item => ({ updateType: updateType.del, findData: { ID: item.data.ID } }));
  1329. const rationIDs = rations.map(r => r.data.ID);
  1330. $.bootstrapLoading.start();
  1331. updateGuideItems(updateDatas, function () {
  1332. const guideSheet = guideItem.workBook.getSheet(0);
  1333. const treeNodes = bills.tree.selected.guidance.tree.items.filter(item => !rationIDs.includes(item.data.ID));
  1334. const state = bills.tree.selected.guidance.tree.getExpState(treeNodes);
  1335. const treeData = treeNodes.map(item => item.data);
  1336. initTree(bills.tree.selected.guidance, guideSheet, guideItem.treeSetting, treeData);
  1337. bills.tree.selected.guidance.tree.setExpandedByState(bills.tree.selected.guidance.tree.items, state);
  1338. renderSheetFunc(guideSheet, function () {
  1339. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.selected.guidance.tree.roots, guideSheet, true);
  1340. });
  1341. //设置底色
  1342. setNodesColor(guideSheet, bills.tree.selected.guidance.tree.items);
  1343. //项目指引初始焦点
  1344. guideItemInitSel(guideSheet.getActiveRowIndex() ? guideSheet.getActiveRowIndex() : 0);
  1345. $.bootstrapLoading.end();
  1346. guideItem.workBook.focus(true)
  1347. });
  1348. }
  1349. //项目指引删除操作
  1350. //@return {void}
  1351. function del(selArea = null){
  1352. $.bootstrapLoading.start();
  1353. let controller = bills.tree.selected.guidance.controller;
  1354. let selNodes = [];
  1355. let sheet = guideItem.workBook.getSheet(0);
  1356. let sel = selArea ? selArea : sheet.getSelections()[0];
  1357. if(sel){
  1358. sel.row = sel.row === -1 ? 0 : sel.row;
  1359. for(let i = 0; i < sel.rowCount; i++){
  1360. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1361. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1362. }
  1363. }
  1364. }
  1365. //选中的块节点
  1366. let blockNodes = getBlockNodes(selNodes);
  1367. let updateDatas = [];
  1368. function getDelDatas(nodes){
  1369. for (let node of nodes) {
  1370. updateDatas.push({updateType: updateType.del, findData: {ID: node.getID()}});
  1371. if (node.children.length > 0) {
  1372. getDelDatas(node.children);
  1373. }
  1374. }
  1375. }
  1376. getDelDatas(blockNodes);
  1377. //更新相关的前节点
  1378. for (let node of blockNodes) {
  1379. if (node.preSibling && !blockNodes.includes(node.preSibling)) {
  1380. let next = node;
  1381. while (next.nextSibling && blockNodes.includes(next.nextSibling)) {
  1382. next = next.nextSibling;
  1383. }
  1384. updateDatas.push({updateType: updateType.update, findData: {ID: node.preSibling.getID()}, updateData: {NextSiblingID: next.getNextSiblingID()}});
  1385. }
  1386. }
  1387. updateGuideItems(updateDatas, function () {
  1388. console.log(blockNodes);
  1389. controller.m_delete(blockNodes);
  1390. guideItemInitSel(sheet.getActiveRowIndex());
  1391. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1392. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1393. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1394. if (bills.tree.selected.data.hasGuide && !bills.tree.selected.guidance.tree.items.length) {
  1395. bills.tree.selected.data.hasGuide = false;
  1396. setBillsForeColor([bills.tree.selected]);
  1397. }
  1398. $.bootstrapLoading.end();
  1399. guideItem.workBook.focus(true)
  1400. });
  1401. }
  1402. //项目指引升级
  1403. //@return {void}
  1404. function upLevel(){
  1405. $.bootstrapLoading.start();
  1406. let controller = bills.tree.selected.guidance.controller;
  1407. let selected = bills.tree.selected.guidance.tree.selected;
  1408. let updateDatas = [];
  1409. //更新父节点
  1410. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getParentID()}, updateData: {NextSiblingID: selected.getID()}});
  1411. //更新选中节点
  1412. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()},
  1413. updateData: {ParentID: selected.parent.getParentID(), NextSiblingID: selected.parent.getNextSiblingID(), unit: ''}});
  1414. if(selected.nextSibling && selected.children.length > 0){
  1415. //更新选中节点最末子节点
  1416. let lastChild = selected.children[selected.children.length - 1];
  1417. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: -1}});
  1418. }
  1419. //选中节点的所有后兄弟节点成为选中节点的子项
  1420. let selectedNextIDs = [];
  1421. let sNext = selected.nextSibling;
  1422. while(sNext){
  1423. selectedNextIDs.push(sNext.getID());
  1424. sNext = sNext.nextSibling;
  1425. }
  1426. for(let sID of selectedNextIDs){
  1427. updateDatas.push({updateType: updateType.update, findData: {ID: sID}, updateData: {ParentID: selected.getID()}});
  1428. }
  1429. updateGuideItems(updateDatas, function () {
  1430. controller.upLevel();
  1431. const sheet = guideItem.workBook.getActiveSheet();
  1432. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1433. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1434. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1435. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1436. sheet.setValue(selected.serialNo(), unitCol, '');
  1437. $.bootstrapLoading.end();
  1438. guideItem.workBook.focus(true)//31574
  1439. });
  1440. }
  1441. //项目指引降级
  1442. //@return {void}
  1443. function downLevel(){
  1444. $.bootstrapLoading.start();
  1445. let controller = bills.tree.selected.guidance.controller;
  1446. let selected = bills.tree.selected.guidance.tree.selected;
  1447. let updateDatas = [];
  1448. //更新前兄弟节点
  1449. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1450. //更新前兄弟节点最末子节点
  1451. if(selected.preSibling.children.length > 0){
  1452. let lastChild = selected.preSibling.children[selected.preSibling.children.length - 1];
  1453. updateDatas.push({updateType: updateType.update, findData: {ID: lastChild.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1454. }
  1455. //更新选中节点
  1456. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {ParentID: selected.preSibling.getID(), NextSiblingID: -1, unit: ''}});
  1457. updateGuideItems(updateDatas, function () {
  1458. controller.downLevel();
  1459. const sheet = guideItem.workBook.getActiveSheet();
  1460. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1461. setNodesColor(sheet, bills.tree.selected.guidance.tree.items);
  1462. setProcessNodes(sheet, bills.tree.selected.guidance.tree.items);
  1463. const unitCol = guideItem.headers.findIndex(item => item.dataCode === 'unit');
  1464. sheet.setValue(selected.serialNo(), unitCol, '');
  1465. $.bootstrapLoading.end();
  1466. guideItem.workBook.focus(true)
  1467. });
  1468. }
  1469. //项目指引上移
  1470. //@return {void}
  1471. function upMove(){
  1472. $.bootstrapLoading.start();
  1473. let controller = bills.tree.selected.guidance.controller;
  1474. let selected = bills.tree.selected.guidance.tree.selected;
  1475. let updateDatas = [];
  1476. //更新前节点
  1477. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1478. //更新前前节点
  1479. if(selected.preSibling.preSibling){
  1480. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.preSibling.getID()}, updateData: {NextSiblingID: selected.getID()}});
  1481. }
  1482. //更新选中节点
  1483. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.preSibling.getID()}});
  1484. updateGuideItems(updateDatas, function () {
  1485. controller.upMove();
  1486. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1487. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1488. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1489. $.bootstrapLoading.end();
  1490. guideItem.workBook.focus(true)
  1491. });
  1492. }
  1493. //项目指引下移
  1494. //@return {void}
  1495. function downMove(){
  1496. $.bootstrapLoading.start();
  1497. let controller = bills.tree.selected.guidance.controller;
  1498. let selected = bills.tree.selected.guidance.tree.selected;
  1499. let updateDatas = [];
  1500. //更新下节点
  1501. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getNextSiblingID()}, updateData: {NextSiblingID: selected.getID()}});
  1502. //更新前节点
  1503. if(selected.preSibling){
  1504. updateDatas.push({updateType: updateType.update, findData: {ID: selected.preSibling.getID()}, updateData: {NextSiblingID: selected.getNextSiblingID()}});
  1505. }
  1506. //更新选中节点
  1507. updateDatas.push({updateType: updateType.update, findData: {ID: selected.getID()}, updateData: {NextSiblingID: selected.nextSibling.getNextSiblingID()}});
  1508. updateGuideItems(updateDatas, function () {
  1509. controller.downMove();
  1510. refreshBtn(bills.tree.selected.guidance.tree.selected);
  1511. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1512. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1513. $.bootstrapLoading.end();
  1514. guideItem.workBook.focus(true)
  1515. });
  1516. }
  1517. //获取定额类型的项目指引名称,通过定额转换
  1518. //@param {Object}ration @return {String}
  1519. function getRationItemName(ration){
  1520. let arr = [];
  1521. arr.push(ration.code ? ration.code : '');
  1522. arr.push(ration.name ? ration.name : '');
  1523. arr.push(ration.basePrice ? ration.basePrice : '');
  1524. let rst = arr.join(' ');
  1525. rst += `/${ration.unit ? ration.unit : ''}`;
  1526. return rst;
  1527. }
  1528. //获取选中的定额表行
  1529. //@return {Array}
  1530. function getCheckedRationRows(all){
  1531. let rst = [];
  1532. let sheet = ration.workBook.getActiveSheet();
  1533. for(let i = 0; i < sheet.getRowCount(); i++){
  1534. // 全选
  1535. if (all) {
  1536. rst.push(i);
  1537. continue;
  1538. }
  1539. let checked = sheet.getValue(i, 0);
  1540. if(checked){
  1541. rst.push(i);
  1542. }
  1543. }
  1544. return rst;
  1545. }
  1546. //清空选中定额表行
  1547. //@param {Array}rows @return {void}
  1548. function clearCheckedRation(rows) {
  1549. let sheet = ration.workBook.getActiveSheet();
  1550. renderSheetFunc(sheet, function () {
  1551. for(let row of rows){
  1552. sheet.setValue(row, 0, 0);
  1553. }
  1554. });
  1555. }
  1556. //获取要插入的定额数据
  1557. //@param {Array}rows @return {Array}
  1558. function getInsertRations(rows){
  1559. let rst = [];
  1560. //当前已存在定额
  1561. let curRationIems = [];
  1562. let selected = bills.tree.selected.guidance.tree.selected;
  1563. if(selected){
  1564. if(selected.data.type === itemType.job){
  1565. curRationIems = selected.children;
  1566. }
  1567. else {
  1568. curRationIems = selected.parent ? selected.parent.children : selected.tree.roots;
  1569. }
  1570. }
  1571. for(let row of rows){
  1572. let selRation = ration.cache[row];
  1573. if(selRation){
  1574. //添加的定额是否已存在,不重复添加
  1575. let isExist = false;
  1576. for(let curRation of curRationIems){
  1577. if(curRation.data.rationID == selRation.ID){
  1578. isExist = true;
  1579. break;
  1580. }
  1581. }
  1582. if(!isExist){
  1583. rst.push({type: itemType.ration, name: getRationItemName(selRation), rationID: selRation.ID});
  1584. }
  1585. }
  1586. }
  1587. return rst;
  1588. }
  1589. //获取块节点父项不存在于选中节点中的节点
  1590. //@param {Array}nodes(选中的节点) @return {Array}
  1591. function getBlockNodes(nodes) {
  1592. let nodeMapping = {};
  1593. for(let node of nodes){
  1594. nodeMapping[node.data.ID] = node;
  1595. }
  1596. //块节点,父项不存在于选中节点中的节点
  1597. let blockNodes = [];
  1598. for(let node of nodes){
  1599. if(!nodeMapping[node.data.ParentID]){
  1600. blockNodes.push(node);
  1601. }
  1602. }
  1603. return blockNodes;
  1604. }
  1605. //允许复制整块,如果有多个块节点,且块节点的父项不同,则不可复制
  1606. //@param {Array}nodes(块节点) @return {Boolean}
  1607. function canCopyBlock(nodes) {
  1608. if(!nodes || nodes.length === 0){
  1609. return false;
  1610. }
  1611. let pID = nodes[0].data.ParentID;
  1612. for(let node of nodes){
  1613. if(node.data.ParentID !== pID){
  1614. return false;
  1615. }
  1616. }
  1617. return true;
  1618. }
  1619. //允许粘贴整块 有粘贴数据,节点存在,如果粘贴到的节点为定额数据,粘贴数据为全定额数据
  1620. //@param {Object}node(粘贴到的节点)
  1621. function canPasteBlock(node) {
  1622. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1623. if(!pasteDatas || pasteDatas.length === 0){
  1624. return false;
  1625. }
  1626. if(!node){
  1627. return false;
  1628. }
  1629. //若粘贴到定额节点,则数据须全为定额
  1630. if(node.data.type === itemType.ration){
  1631. for(let data of pasteDatas){
  1632. if(data.type !== itemType.ration){
  1633. return false;
  1634. }
  1635. }
  1636. }
  1637. //若粘贴到非定额节点,则粘贴的顶层数据须全为非定额
  1638. else {
  1639. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1640. for(let topData of topDatas){
  1641. if(topData.type === itemType.ration){
  1642. return false;
  1643. }
  1644. }
  1645. }
  1646. return true;
  1647. }
  1648. //复制整块,将块节点下所有节点数据复制一份,并且重新生成ID、ParentID、NextSiblingID,使用localStorage存储
  1649. //@param {Array}nodes(块节点) @return {void}
  1650. function copyBlocks(nodes) {
  1651. nodes = _.cloneDeep(nodes);
  1652. //将块节点的ParentID暂时设置为-1
  1653. for(let topNode of nodes){
  1654. topNode.data.ParentID = -1;
  1655. }
  1656. let copyDatas = [];
  1657. let copyNodes = [];
  1658. //获取块节点包含的所有节点(包括自己)
  1659. function containNodes(nodes) {
  1660. for(let node of nodes){
  1661. copyNodes.push(node);
  1662. if(node.children.length > 0){
  1663. containNodes(node.children);
  1664. }
  1665. }
  1666. }
  1667. containNodes(nodes);
  1668. for(let node of copyNodes){
  1669. copyDatas.push(node.data);
  1670. }
  1671. console.log(`copyDatas`);
  1672. console.log(copyDatas);
  1673. setLocalCache(itemCopyBlockKey, JSON.stringify(copyDatas));
  1674. }
  1675. //粘贴整块,整块数据粘贴到相关节点,并成为其后项
  1676. //@param {Object}node(粘贴到的节点) @return {void}
  1677. function pasteBlock(node) {
  1678. let itemObj = bills.tree.selected.guidance;
  1679. let pasteDatas = JSON.parse(getLocalCache(itemCopyBlockKey));
  1680. //整理ID
  1681. let IDMapping = {};
  1682. for(let data of pasteDatas){
  1683. data.newID = uuid.v1();
  1684. IDMapping[data.ID] = data;
  1685. }
  1686. for(let data of pasteDatas){
  1687. let nextData = IDMapping[data.NextSiblingID];
  1688. data.NextSiblingID = nextData ? nextData.newID : -1;
  1689. let parentData = IDMapping[data.ParentID];
  1690. data.ParentID = parentData ? parentData.newID : -1;
  1691. }
  1692. for(let data of pasteDatas){
  1693. data.ID = data.newID;
  1694. delete data.newID;
  1695. }
  1696. let updateDatas = [];
  1697. //将最顶层的块数据的ParentID设置成粘贴到节点的ParentID,并设置新的billsID
  1698. let topDatas = _.filter(pasteDatas, {ParentID: -1});
  1699. for(let topData of topDatas){
  1700. topData.ParentID = node.getParentID();
  1701. }
  1702. //更新数据
  1703. //更新插入的最末顶层数据NextSiblingID
  1704. if(node.nextSibling){
  1705. topDatas[topDatas.length - 1].NextSiblingID = node.getNextSiblingID();
  1706. }
  1707. //新建节点
  1708. for(let data of pasteDatas){
  1709. data.libID = libID;
  1710. data.billsID = node.data.billsID;
  1711. delete data._id;
  1712. updateDatas.push({updateType: updateType.create, updateData: data});
  1713. }
  1714. console.log(`pasteDatas`);
  1715. console.log(pasteDatas);
  1716. //更新粘贴到的节点的NextSiblingID
  1717. updateDatas.push({updateType: updateType.update, findData: {ID: node.data.ID}, updateData: {NextSiblingID: topDatas[0].ID}})
  1718. $.bootstrapLoading.start();
  1719. updateGuideItems(updateDatas, function (rstData) {
  1720. $.bootstrapLoading.end();
  1721. node.data.NextSiblingID = topDatas[0].ID;
  1722. let newNodes = itemObj.tree.insertDatasTo(node.data, pasteDatas);
  1723. cleanData(guideItem.workBook.getActiveSheet(), guideItem.headers, -1);
  1724. itemObj.controller.showTreeData();
  1725. setNodesColor(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1726. setProcessNodes(guideItem.workBook.getActiveSheet(), bills.tree.selected.guidance.tree.items);
  1727. }, function () {
  1728. $.bootstrapLoading.end();
  1729. });
  1730. }
  1731. // 双击定位定额
  1732. async function locateAtRation(row) {
  1733. const node = bills.tree.selected.guidance.tree.items[row];
  1734. if (!node || !node.data.rationID) {
  1735. return;
  1736. }
  1737. const rationItem = ration.datas.find(item => item.ID === node.data.rationID);
  1738. // 当前库没有找到,需要后端查找
  1739. if (!rationItem) {
  1740. const findedRation = await ajaxPost('/rationRepository/api/getRationByID',{ ID: node.data.rationID });
  1741. if (!findedRation || !rationLibIDs.includes(findedRation.rationRepId)) {
  1742. alert('无法定位此定额,此定额已被删除');
  1743. return;
  1744. }
  1745. changeRationLib(findedRation.rationRepId, () => {
  1746. located(findedRation.ID, findedRation.sectionId);
  1747. })
  1748. } else {
  1749. located(rationItem.ID, rationItem.sectionId);
  1750. }
  1751. function located(rationID, sectionID) {
  1752. if (!section.tree) {
  1753. return;
  1754. }
  1755. const sectionNode = section.tree.nodes[section.tree.prefix + sectionID];
  1756. if (!sectionNode) {
  1757. return;
  1758. }
  1759. // 定位到对应章节树
  1760. const sectionSheet = section.workBook.getActiveSheet();
  1761. const sectionRow = sectionNode.serialNo();
  1762. expandSearchNodes(sectionSheet, [sectionNode], section.tree.roots);
  1763. sectionSheet.setSelection(sectionRow, 0, 1, 1);
  1764. sectionSheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.center);
  1765. sectionInitSel(sectionRow);
  1766. // 定位到对应定额
  1767. const locatedRationRow = ration.cache.findIndex(item => item.ID === rationID);
  1768. if (locatedRationRow !== -1) {
  1769. const rationSheet = ration.workBook.getActiveSheet();
  1770. rationSheet.setSelection(locatedRationRow, 1, 1, 1);
  1771. rationSheet.showRow(locatedRationRow, GC.Spread.Sheets.VerticalPosition.center);
  1772. }
  1773. }
  1774. }
  1775. //初始化右键菜单
  1776. //@return {void}
  1777. function initContextMenu() {
  1778. $.contextMenu({
  1779. selector: '#guideItemSpread',
  1780. build: function($triggerElement, e){
  1781. //控制允许右键菜单在哪个位置出现
  1782. let sheet = guideItem.workBook.getSheet(0);
  1783. let offset = $("#guideItemSpread").offset(),
  1784. x = e.pageX - offset.left,
  1785. y = e.pageY - offset.top;
  1786. let target = sheet.hitTest(x, y);
  1787. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1788. let sel = sheet.getSelections()[0];
  1789. if(sel && sel.rowCount === 1){
  1790. sheet.setActiveCell(target.row, target.col);
  1791. }
  1792. sel = sheet.getSelections()[0];
  1793. let selNodes = [];
  1794. if(sel){
  1795. sel.row = sel.row === -1 ? 0 : sel.row;
  1796. for(let i = 0; i < sel.rowCount; i++){
  1797. if(bills.tree.selected.guidance.tree.items[sel.row + i]){
  1798. selNodes.push(bills.tree.selected.guidance.tree.items[sel.row + i]);
  1799. }
  1800. }
  1801. }
  1802. //块节点
  1803. let blockNodes = getBlockNodes(selNodes);
  1804. //右键在多选内则不重设焦点
  1805. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1806. sheet.setActiveCell(target.row, target.col);
  1807. }
  1808. guideItemInitSel(target.row);
  1809. return {
  1810. callback: function(){},
  1811. items: {
  1812. "copy": {
  1813. name: "复制整块",
  1814. disabled: function () {
  1815. return locked || !canCopyBlock(blockNodes);
  1816. },
  1817. icon: "fa-copy",
  1818. callback: function (key, opt) {
  1819. copyBlocks(blockNodes);
  1820. }},
  1821. "paste": {
  1822. name: "粘贴整块",
  1823. disabled: function () {
  1824. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1825. return locked || !canPasteBlock(pasteNode);
  1826. },
  1827. icon: "fa-paste",
  1828. callback: function (key, opt) {
  1829. let pasteNode = bills.tree.selected.guidance.tree.items[target.row];
  1830. pasteBlock(pasteNode);
  1831. }},
  1832. "delRations": {
  1833. name: '删除定额',
  1834. disabled: function () {
  1835. let node = bills.tree.selected.guidance.tree.items[target.row];
  1836. return locked || !node
  1837. },
  1838. icon: "fa-remove",
  1839. callback: function (key, opt) {
  1840. $('#delRationAlert').modal('show');
  1841. }
  1842. },
  1843. "del": {
  1844. name: '删除',
  1845. disabled: function () {
  1846. let node = bills.tree.selected.guidance.tree.items[target.row];
  1847. return locked || !node
  1848. },
  1849. icon: "fa-remove",
  1850. callback: function (key, opt) {
  1851. $('#delAlert').modal('show');
  1852. }
  1853. },
  1854. "insertSibling": {
  1855. name: '插入行',
  1856. disabled: function () {
  1857. let node = bills.tree.selected.guidance.tree.items[target.row];
  1858. return locked || !node || node.data.type !== itemType.job;
  1859. },
  1860. icon: "fa-arrow-left",
  1861. callback: function (key, opt) {
  1862. insert([{type: itemType.job, name: ''}], false);
  1863. }
  1864. },
  1865. "insertChild": {
  1866. name: '插入子项',
  1867. disabled: function () {
  1868. let node = bills.tree.selected.guidance.tree.items[target.row];
  1869. return locked || !node || node.data.type !== itemType.job || !allJobChildren(node);
  1870. },
  1871. icon: 'fa-arrow-left',
  1872. callback: function (key, opt) {
  1873. insert([{type: itemType.job, name: ''}], true);
  1874. }
  1875. }
  1876. }
  1877. };
  1878. }
  1879. else{
  1880. return false;
  1881. }
  1882. }
  1883. });
  1884. }
  1885. // 替换定额
  1886. function replaceRation(newRation, orgItem) {
  1887. if (newRation.ID === orgItem.data.rationID) {
  1888. return;
  1889. }
  1890. $.bootstrapLoading.start();
  1891. const updateAttrs = {name: getRationItemName(newRation), rationID: newRation.ID};
  1892. const updateData = [{updateType: updateType.update, findData: {ID: orgItem.getID()}, updateData: updateAttrs }];
  1893. updateGuideItems(updateData, function () {
  1894. Object.assign(orgItem.data, updateAttrs);
  1895. const row = orgItem.serialNo();
  1896. guideItem.workBook.getSheet(0).setValue(row, 0, orgItem.data.name);
  1897. $.bootstrapLoading.end();
  1898. });
  1899. }
  1900. // 初始化清单右键菜单
  1901. function initRationContextMenu() {
  1902. $.contextMenu({
  1903. selector: '#rationSpread',
  1904. build: function($triggerElement, e){
  1905. //控制允许右键菜单在哪个位置出现
  1906. let sheet = ration.workBook.getActiveSheet();;
  1907. let offset = $("#rationSpread").offset(),
  1908. x = e.pageX - offset.left,
  1909. y = e.pageY - offset.top;
  1910. let target = sheet.hitTest(x, y);
  1911. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1912. let sel = sheet.getSelections()[0];
  1913. if(sel && sel.rowCount === 1){
  1914. sheet.setActiveCell(target.row, target.col);
  1915. }
  1916. sel = sheet.getSelections()[0];
  1917. if(sel){
  1918. sel.row = sel.row === -1 ? 0 : sel.row;
  1919. }
  1920. //右键在多选内则不重设焦点
  1921. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1922. sheet.setActiveCell(target.row, target.col);
  1923. }
  1924. return {
  1925. callback: function(){},
  1926. items: {
  1927. "replace": {
  1928. name: "替换定额",
  1929. disabled: function () {
  1930. return locked || !bills.tree.selected || !bills.tree.selected.guidance || !bills.tree.selected.guidance.tree || !bills.tree.selected.guidance.tree.selected || bills.tree.selected.guidance.tree.selected.data.type !== itemType.ration;
  1931. },
  1932. icon: "fa-copy",
  1933. callback: function (key, opt) {
  1934. const row = sheet.getActiveRowIndex();
  1935. if (!ration.cache[row]) {
  1936. return;
  1937. }
  1938. replaceRation(ration.cache[row], bills.tree.selected.guidance.tree.selected);
  1939. // copyBlocks(blockNodes);
  1940. }},
  1941. }
  1942. };
  1943. }
  1944. else{
  1945. return false;
  1946. }
  1947. }
  1948. });
  1949. }
  1950. // 初始化定额右键菜单
  1951. function initBillsContextMenu() {
  1952. $.contextMenu({
  1953. selector: '#billsSpread',
  1954. build: function($triggerElement, e){
  1955. //控制允许右键菜单在哪个位置出现
  1956. let sheet = bills.workBook.getActiveSheet();;
  1957. let offset = $("#billsSpread").offset(),
  1958. x = e.pageX - offset.left,
  1959. y = e.pageY - offset.top;
  1960. let target = sheet.hitTest(x, y);
  1961. if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
  1962. let sel = sheet.getSelections()[0];
  1963. if(sel && sel.rowCount === 1){
  1964. sheet.setActiveCell(target.row, target.col);
  1965. }
  1966. sel = sheet.getSelections()[0];
  1967. if(sel){
  1968. sel.row = sel.row === -1 ? 0 : sel.row;
  1969. }
  1970. //右键在多选内则不重设焦点
  1971. if(!sel || sel.rowCount === 1 || !(target.row >= sel.row && target.row <= sel.row + sel.rowCount - 1)){
  1972. sheet.setActiveCell(target.row, target.col);
  1973. }
  1974. billsInitSel(target.row, { row: bills.tree.selected.serialNo() });
  1975. return {
  1976. callback: function(){},
  1977. items: {
  1978. "replace": {
  1979. name: "配置材料",
  1980. disabled: function () {
  1981. return !bills.tree.selected;
  1982. },
  1983. icon: "fa-edit",
  1984. callback: function (key, opt) {
  1985. $('#bill-material-modal').modal('show');
  1986. }},
  1987. }
  1988. };
  1989. }
  1990. else{
  1991. return false;
  1992. }
  1993. }
  1994. });
  1995. }
  1996. //展开至搜索出来点的节点
  1997. //@param {Array}nodes @return {void}
  1998. function expandSearchNodes(sheet, nodes, roots){
  1999. renderSheetFunc(sheet, function () {
  2000. function expParentNode(node){
  2001. if(node.parent){
  2002. if (!node.parent.expanded) {
  2003. node.parent.setExpanded(true);
  2004. }
  2005. expParentNode(node.parent);
  2006. }
  2007. }
  2008. for(let node of nodes){
  2009. expParentNode(node);
  2010. }
  2011. TREE_SHEET_HELPER.refreshNodesVisible(roots, sheet, true);
  2012. });
  2013. }
  2014. // 清空搜索高亮
  2015. function clearHighLight(sheet) {
  2016. renderSheetFunc(sheet, () => {
  2017. for (let i = 0; i < sheet.getRowCount(); i++){
  2018. setBgColor(sheet, i, 'white')
  2019. }
  2020. });
  2021. }
  2022. // 清空搜索状态
  2023. // 关闭搜索清单结果
  2024. function closeSearchBills(sheet) {
  2025. if (!bills.tree) {
  2026. return;
  2027. }
  2028. $('#searchBillsResult').hide();
  2029. bills.tree.items.forEach(node => {
  2030. node.isSearch = false;
  2031. });
  2032. clearHighLight(sheet);
  2033. setBgColor(sheet, sheet.getActiveRowIndex(), selectedBgColor);
  2034. }
  2035. // 搜索清单
  2036. function searchBills() {
  2037. if (!bills.tree || !bills.workBook) {
  2038. return;
  2039. }
  2040. const sheet = bills.workBook.getActiveSheet();
  2041. const str = $('#searchBillText').val().trim();
  2042. // 空搜索字符,关闭搜索
  2043. if (!str) {
  2044. if ($('#searchBillsResult').is(':visible')) {
  2045. closeSearchBills(sheet);
  2046. }
  2047. return;
  2048. }
  2049. // 过滤清单
  2050. const result = bills.tree.items.filter(item => {
  2051. const codeIs = item.data.code ? item.data.code.indexOf(str) !== -1 : false;
  2052. const nameIs = item.data.name ? item.data.name.indexOf(str) !== -1 : false;
  2053. return codeIs || nameIs;
  2054. });
  2055. if (!result.length) {
  2056. closeSearchBills(sheet);
  2057. return;
  2058. }
  2059. // 显示搜索结果
  2060. $("#searchBillsResult").show();
  2061. $('#searchBillsCount').text(result.length);
  2062. //展开搜索出来的节点
  2063. expandSearchNodes(sheet, result, bills.tree.roots);
  2064. // 标黄结果
  2065. clearHighLight(sheet);
  2066. const col = sheet.getActiveColumnIndex();
  2067. renderSheetFunc(sheet, function () {
  2068. bills.controller.setTreeSelected(result[0]);
  2069. bills.tree.items.forEach(node => {
  2070. if (result.includes(node)) {
  2071. setBgColor(sheet, node.serialNo(), searchBgColor);
  2072. node.isSearch = true; // 标记为搜索结果,防止被焦点行变更恢复颜色
  2073. } else {
  2074. node.isSearch = false;
  2075. }
  2076. })
  2077. });
  2078. //搜索初始定位
  2079. const row = sheet.getActiveRowIndex();
  2080. sheet.setSelection(result[0].serialNo(), col, 1, 1);
  2081. billsInitSel(result[0].serialNo(), { row });
  2082. sheet.showRow(result[0].serialNo(), GC.Spread.Sheets.VerticalPosition.center);
  2083. let curIndex = 0;
  2084. // 上一条
  2085. $('#preBill').unbind('click');
  2086. $('#preBill').bind('click', () => {
  2087. const node = result[curIndex - 1];
  2088. if (!node) {
  2089. return;
  2090. }
  2091. curIndex -= 1;
  2092. const col = sheet.getActiveColumnIndex();
  2093. const row = node.serialNo();
  2094. const orgRow = sheet.getActiveRowIndex();
  2095. sheet.setSelection(row, col, 1, 1);
  2096. billsInitSel(row, { row: orgRow });
  2097. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2098. });
  2099. // 下一条
  2100. $('#nextBills').unbind('click');
  2101. $('#nextBills').bind('click', () => {
  2102. const node = result[curIndex + 1];
  2103. if (!node) {
  2104. return;
  2105. }
  2106. curIndex += 1;
  2107. const col = sheet.getActiveColumnIndex();
  2108. const row = node.serialNo();
  2109. const orgRow = sheet.getActiveRowIndex();
  2110. sheet.setSelection(row, col, 1, 1);
  2111. billsInitSel(row, { row: orgRow });
  2112. sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
  2113. });
  2114. }
  2115. //初始化dom时间
  2116. //@return {void}
  2117. function initDomEvents(){
  2118. // 清单材料窗口
  2119. $("#bill-material-modal").on('hidden.bs.modal', function () {
  2120. billMaterial.cache = [];
  2121. showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
  2122. });
  2123. $("#bill-material-modal").on('shown.bs.modal', function () {
  2124. if (billMaterial.workBook) {
  2125. billMaterial.workBook.refresh();
  2126. getBillMaterials();
  2127. }
  2128. });
  2129. $('#insert').click(function () {
  2130. insert([{type: itemType.job, name: '', outputItemCharacter: true }], false);
  2131. });
  2132. $('#delConfirm').click(function () {
  2133. del();
  2134. $('#delAlert').modal('hide');
  2135. });
  2136. $('#delRationConfirm').click(function () {
  2137. delRations();
  2138. $('#delRationAlert').modal('hide');
  2139. });
  2140. $('#del').click(function () {
  2141. $('#delAlert').modal('show');
  2142. });
  2143. $('#upLevel').click(function () {
  2144. upLevel();
  2145. });
  2146. $('#downLevel').click(function () {
  2147. downLevel();
  2148. });
  2149. $('#upMove').click(function () {
  2150. upMove();
  2151. });
  2152. $('#downMove').click(function () {
  2153. downMove();
  2154. });
  2155. // 收起清单至第二层
  2156. $('#expandToSecond').click(function() {
  2157. if (!bills.tree || !bills.workBook) {
  2158. return;
  2159. }
  2160. bills.tree.roots.forEach(root => {
  2161. root.setExpanded(true);
  2162. root.children.forEach(item => {
  2163. item.setExpanded(false);
  2164. });
  2165. });
  2166. const billSheet = bills.workBook.getActiveSheet();
  2167. renderSheetFunc(billSheet, function () {
  2168. TREE_SHEET_HELPER.refreshNodesVisible(bills.tree.roots, billSheet, true);
  2169. });
  2170. })
  2171. //收起定额、展开全部
  2172. $('#expandContract').click(function () {
  2173. //目前状态时展开全部节点状态,点击则收起定额
  2174. let tree = bills.tree.selected.guidance.tree,
  2175. itemSheet = guideItem.workBook.getActiveSheet();
  2176. if(curExpandState === itemExpandState.expand){
  2177. curExpandState = itemExpandState.contract;
  2178. $(this).html('<i class="fa fa-plus-square-o" aria-hidden="true"></i> 展开全部');
  2179. setNodesExpandState(tree.items, itemExpandState.contract);
  2180. } else {
  2181. curExpandState = itemExpandState.expand;
  2182. $(this).html('<i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起定额');
  2183. setNodesExpandState(tree.items, itemExpandState.expand);
  2184. }
  2185. renderSheetFunc(itemSheet, function () {
  2186. TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
  2187. });
  2188. });
  2189. // 插入选中定额
  2190. $('#insertRation').click(function () {
  2191. let checkedRows = getCheckedRationRows();
  2192. let insertDatas = getInsertRations(checkedRows);
  2193. if(insertDatas.length > 0){
  2194. insert(insertDatas, false, function () {
  2195. //清空选择
  2196. clearCheckedRation(checkedRows);
  2197. });
  2198. }
  2199. else {
  2200. clearCheckedRation(checkedRows);
  2201. }
  2202. });
  2203. // 插入全部定额
  2204. $('#insertAll').click(function () {
  2205. let isAll = true;
  2206. let checkedRows = getCheckedRationRows(isAll);
  2207. let insertDatas = getInsertRations(checkedRows);
  2208. if(insertDatas.length > 0){
  2209. insert(insertDatas, false);
  2210. }
  2211. });
  2212. // 搜索清单
  2213. $("#searchBillBtn").click(searchBills);
  2214. $('#searchBillText').keyup(function (e) {
  2215. delayKeyup(function () {
  2216. $('#searchBillBtn').click();
  2217. });
  2218. });
  2219. // 关闭搜索清单
  2220. $('#closeSearchBills').click(() => {
  2221. if (!bills.workBook) {
  2222. return;
  2223. }
  2224. const sheet = bills.workBook.getActiveSheet();
  2225. closeSearchBills(sheet);
  2226. })
  2227. //搜索定额
  2228. $('#searchBtn').click(function () {
  2229. let searchStr = $('#searchText').val();
  2230. if(!searchStr || searchStr === ''){
  2231. ration.cache = ration.datas;
  2232. }
  2233. else{
  2234. let reg = new RegExp(searchStr, 'i');
  2235. ration.cache = _.filter(ration.datas, function (data) {
  2236. return reg.test(data.code) || reg.test(data.name);
  2237. });
  2238. }
  2239. $('.top-content').hide();
  2240. $('#deResize').hide();
  2241. $('#searchCount').text(`搜索结果: ${ration.cache.length}`);
  2242. $('#rationSearchResult').show();
  2243. autoFlashHeight();
  2244. ration.workBook.refresh();
  2245. let rationSheet = ration.workBook.getActiveSheet();
  2246. renderSheetFunc(rationSheet, function () {
  2247. clearCheckedRation(getCheckedRationRows());
  2248. showData(rationSheet, ration.headers, ration.cache);
  2249. })
  2250. });
  2251. //关闭搜索
  2252. $('#rationSearchResult a').click(function () {
  2253. $('.top-content').show();
  2254. $('#deResize').show();
  2255. $('#rationSearchResult').hide();
  2256. autoFlashHeight();
  2257. renderSheetFunc(ration.workBook.getActiveSheet(), function () {
  2258. clearCheckedRation(getCheckedRationRows());
  2259. });
  2260. section.workBook.refresh();
  2261. ration.workBook.refresh();
  2262. $('#searchText').val('');
  2263. //恢复章节树下的定额
  2264. sectionInitSel(section.workBook.getActiveSheet().getActiveRowIndex());
  2265. });
  2266. let keyupTime = 0,
  2267. delayTime = 500;
  2268. function delayKeyup(callback) {
  2269. let nowTime = Date.now();
  2270. keyupTime = nowTime;
  2271. setTimeout(function () {
  2272. if (nowTime - keyupTime == 0) {
  2273. callback();
  2274. }
  2275. }, delayTime);
  2276. }
  2277. //执行搜索
  2278. $('#searchText').keyup(function (e) {
  2279. delayKeyup(function () {
  2280. $('#searchBtn').click();
  2281. });
  2282. });
  2283. //编辑清单备注
  2284. $('.main-side-bottom').find('textarea').keyup(function () {
  2285. let me = this;
  2286. let node = bills.tree.selected;
  2287. let comment = $(me).val();
  2288. delayKeyup(function () {
  2289. if (node) {
  2290. let updateData = {lastOperator: userAccount, billsLibId: billsLibId, updateId: node.getID(), field: 'comment', data: comment};
  2291. updateBillsComment(updateData, function () {
  2292. node.data.comment = comment;
  2293. }, function() {
  2294. $(me).val(node.data.comment || '');
  2295. })
  2296. }
  2297. });
  2298. });
  2299. //编辑选项备注
  2300. $('.main-bottom-content').find('textarea').keyup(function () {
  2301. let me = this;
  2302. let node = bills.tree.selected.guidance.tree.selected;
  2303. let comment = $(me).val();
  2304. delayKeyup(function () {
  2305. if(node){
  2306. let updateDatas = [{updateType: updateType.update, findData: {ID: node.getID()}, updateData: {comment: comment}}];
  2307. updateGuideItems(updateDatas, function (rstData) {
  2308. node.data.comment = comment;
  2309. }, function() {
  2310. $(me).val(node.data.comment || '');
  2311. });
  2312. }
  2313. });
  2314. });
  2315. //定额高度拖动调整
  2316. let heightEleObj = {
  2317. module: moduleName,
  2318. resize: $('#deResize'),
  2319. top: $('#topContent'),
  2320. topSpread: $('#sectionSpread'),
  2321. bottom: $('#bottomContent'),
  2322. bottomSpread: $('#rationSpread')
  2323. },
  2324. heightLimit = {
  2325. min: 150,
  2326. max: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-150-10`,
  2327. notTopSpread: 0,
  2328. notBottomSpread: 0,
  2329. };
  2330. SlideResize.verticalSlide(heightEleObj, heightLimit, function () {
  2331. if(section.workBook){
  2332. section.workBook.refresh();
  2333. }
  2334. if(ration.workBook){
  2335. ration.workBook.refresh();
  2336. }
  2337. });
  2338. /*slideResize(rationLibResizeEles, {min: 147, max: 680}, 'height', function() {
  2339. //autoFlashHeight();
  2340. if(section.workBook){
  2341. section.workBook.refresh();
  2342. }
  2343. if(ration.workBook){
  2344. ration.workBook.refresh();
  2345. }
  2346. });*/
  2347. //左右拖动
  2348. //清单表与项目指引表
  2349. let leftElesObj = {};
  2350. leftElesObj.module = moduleName;
  2351. leftElesObj.resize = $('#slideResizeLeft');
  2352. leftElesObj.parent = $('#dataRow');
  2353. leftElesObj.left = $('#leftContent');
  2354. leftElesObj.right = $('#midContent');
  2355. SlideResize.horizontalSlide(leftElesObj, {min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200`}, function () {
  2356. refreshALlWorkBook();
  2357. });
  2358. //人材机表与人材机组成物表
  2359. let rightElesObj = {};
  2360. rightElesObj.module = moduleName;
  2361. rightElesObj.resize = $('#slideResizeRight');
  2362. rightElesObj.parent = $('#dataRow');
  2363. rightElesObj.left = $('#midContent');
  2364. rightElesObj.right = $('#rightContent');
  2365. SlideResize.horizontalSlide(rightElesObj, {min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200`}, function () {
  2366. refreshALlWorkBook();
  2367. });
  2368. }
  2369. //刷新全部工作簿
  2370. //@return {void}
  2371. function refreshALlWorkBook() {
  2372. if (bills.workBook) {
  2373. bills.workBook.refresh();
  2374. }
  2375. if (guideItem.workBook) {
  2376. guideItem.workBook.refresh();
  2377. }
  2378. if (section.workBook) {
  2379. section.workBook.refresh();
  2380. }
  2381. if (ration.workBook) {
  2382. ration.workBook.refresh();
  2383. }
  2384. $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
  2385. $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
  2386. $('.main-bottom-content').find('textarea').height($('.main-bottom-content').height() - 20);
  2387. $('.main-bottom-content').find('textarea').width($('.main-bottom-content').width() - 25);
  2388. }
  2389. //读取拖动相关
  2390. //@return {void}
  2391. function initSlideSize() {
  2392. //定额表上下
  2393. let heightEleObj = {
  2394. module: moduleName,
  2395. top: $('#topContent'),
  2396. topSpread: $('#sectionSpread'),
  2397. bottom: $('#bottomContent'),
  2398. bottomSpread: $('#rationSpread')
  2399. };
  2400. if (!$('#rationSearchResult').is(':visible')) {
  2401. SlideResize.loadVerticalHeight(heightEleObj.module, heightEleObj,
  2402. {totalHeight: `$(window).height()-$('.header').height()-$('.sidebar-tools-bar').height()-10`,
  2403. notTopSpread: 0, notBottomSpread: 0}, function () {
  2404. if(section.workBook){
  2405. section.workBook.refresh();
  2406. }
  2407. if(ration.workBook){
  2408. ration.workBook.refresh();
  2409. }
  2410. });
  2411. }
  2412. //水平
  2413. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  2414. refreshALlWorkBook();
  2415. });
  2416. }
  2417. //初始化视图
  2418. //@param {void} @return {void}
  2419. function initViews(){
  2420. let modules = [bills, guideItem, section, ration, billMaterial];
  2421. initWorkBooks(modules);
  2422. lockUtil.lockTools($(document.body), locked);
  2423. getLibWithBills(libID);
  2424. initDomEvents();
  2425. initContextMenu();
  2426. initRationContextMenu();
  2427. initBillsContextMenu();
  2428. initSlideSize();
  2429. }
  2430. return {initViews, initSlideSize};
  2431. })();
  2432. $(document).ready(function () {
  2433. billsGuidance.initViews();
  2434. });