glj_view.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  1. /**
  2. * Created by CSL on 2017-05-12.
  3. */
  4. var gljOprObj = {
  5. sheet: null,
  6. libID: null,
  7. ration: null,
  8. sheetData: [],
  9. checkb: null,
  10. detailSheet: null,
  11. detailData: [],
  12. GLJSelection: [],
  13. selectedGLJClass: null,
  14. parentNodeIds: {},
  15. activeTab: '#linkGLJ',
  16. setting: {},
  17. detailSetting: {
  18. header: [
  19. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  20. {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
  21. {headerName: "结果(C)", headerWidth: 120, dataCode: "result", dataType: "Number", decimalField: "quantity_detail"},
  22. {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
  23. ],
  24. view: {
  25. lockColumns: [2, 3]
  26. }
  27. },
  28. gljTreeSetting: {
  29. view: {
  30. expandSpeed: "",
  31. selectedMulti: false
  32. },
  33. edit: {
  34. enable: false,
  35. editNameSelectAll: true,
  36. showRemoveBtn: true,
  37. showRenameBtn: true,
  38. removeTitle: "删除节点",
  39. renameTitle: "更改名称"
  40. },
  41. data: {
  42. keep: {
  43. parent: true,
  44. leaf: true
  45. },
  46. key: {
  47. children: "items",
  48. name: "Name"
  49. },
  50. simpleData: {
  51. enable: false,
  52. idKey: "ID",
  53. pIdKey: "ParentID",
  54. rootPId: -1
  55. }
  56. },
  57. callback: {
  58. onClick: function (event, treeId, treeNode) {
  59. if (treeId == 'gljTree') {
  60. let me = gljOprObj, gljTypeId = treeNode.ID;
  61. if (treeNode.ID) {
  62. me.gljCurTypeId = treeNode.ID;
  63. me.filterLibGLJSheetData();
  64. me.showLibGLJSheetData();
  65. }
  66. } else {
  67. if (treeNode.isParent) {
  68. $('#class_selected_conf').attr("disabled", "disabled");
  69. $('#selected_class').val("");
  70. } else {
  71. $('#class_selected_conf').removeAttr("disabled");
  72. $('#selected_class').val(treeNode.ID);
  73. }
  74. }
  75. }
  76. }
  77. },
  78. gljLibSheetSetting: {
  79. owner: 'gljTree',
  80. header: [
  81. {headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center", cellType: "checkBox"},
  82. {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  83. {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center"},
  84. {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center", vAlign: "center"},
  85. {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center"},
  86. {headerName: "单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  87. {headerName: "类型", headerWidth: 80, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center"},
  88. {headerName: "是否新增", headerWidth: 80, dataCode: "isComplementary", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
  89. ],
  90. view: {
  91. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  92. }
  93. },
  94. gljLibSheet: null,
  95. initSheet: function (sheet) {
  96. var me = this;
  97. me.sheet = sheet;
  98. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  99. sheet.name('ration_glj');
  100. me.bindSheetEvent(sheet);
  101. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  102. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  103. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  104. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  105. sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
  106. if (args.row>=me.sheetData.length){
  107. args.cancel = true;
  108. }else if (me.sheetData[args.row].isMixRatio) {
  109. args.cancel = true;
  110. }
  111. });
  112. if(!projectReadOnly){
  113. gljContextMenu.loadGLJSpreadContextMenu();
  114. }
  115. },
  116. initDetailSheet: function (sheet) {
  117. var me = this;
  118. me.detailSheet = sheet;
  119. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  120. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  121. sheet.name('quantity_detail');
  122. me.bindSheetEvent(sheet);
  123. sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
  124. if(me.detailSheetReadonly()){
  125. args.cancel = true;
  126. }else {
  127. if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  128. args.sheet.setValue(args.row,args.col,"");
  129. }
  130. }
  131. });
  132. },
  133. detailSheetReadonly:function () {
  134. let selected = projectObj.project.mainTree.selected;
  135. let Bills = projectObj.project.Bills;
  136. if(selected) {
  137. //清单锁定时只读
  138. if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked() && projectObj.project.withinBillsLocked(selected)){
  139. return true;
  140. }
  141. //大项费用、分部节点层次时,工程量明细只读。
  142. if(indicativeInfoObj.isDXFY(selected) || indicativeInfoObj.isFB(selected)){
  143. return true;
  144. }
  145. //是主材或者是设备时只读
  146. if(selected.sourceType == ModuleNames.ration_glj){
  147. return true;
  148. }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
  149. return true;
  150. }
  151. return false;
  152. }
  153. return true;
  154. },
  155. bindSheetEvent: function (sheet) {
  156. var me = this;
  157. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  158. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  159. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  160. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  161. sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
  162. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  163. },
  164. onClipboardPasting: function (sender, args) {
  165. var me = gljOprObj;
  166. if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
  167. args.cancel = true;
  168. }
  169. },
  170. onClipboardPasted: function (e, info) {
  171. var me = gljOprObj;
  172. console.log('past');
  173. // if (!me.ration) {return;};
  174. // your code...
  175. },
  176. startEditChecking:function (sender,args) {
  177. let me = gljOprObj;
  178. let selected = projectObj.project.mainTree.selected;
  179. if(selected){
  180. if(me.isInstallationNode(selected)==true){
  181. args.cancel = true;
  182. }
  183. }else {
  184. args.cancel = true;
  185. }
  186. },
  187. isInstallationNode:function(node){
  188. if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
  189. return true;
  190. }
  191. return false
  192. },
  193. onEditEnded: function (sender, args) {
  194. var me = gljOprObj;
  195. if (args.sheetName == 'ration_glj') {
  196. me.onEditGLJSheet(args)
  197. }
  198. if (args.sheetName == 'quantity_detail') {
  199. me.onEditDetailSheet(args);
  200. }
  201. },
  202. onEditDetailSheet: function (args,callback) {
  203. var me = gljOprObj;
  204. if (args.row > me.detailData.length) {
  205. return;
  206. }
  207. if (args.row == me.detailData.length && args.editingText == null) {
  208. return;
  209. }
  210. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  211. var detailList = me.detailData;
  212. if(args.editingText){
  213. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  214. args.editingText = args.editingText.replace(/)/g, ")");
  215. }
  216. if (args.row == detailList.length) {
  217. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
  218. }
  219. if (args.row < detailList.length) {
  220. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
  221. }
  222. },
  223. onEditGLJSheet: function (args) {
  224. var me = gljOprObj;
  225. if (args.row >= me.sheetData.length) {
  226. me.sheet.getCell(args.row, args.col).value(null);
  227. return;
  228. }
  229. me.updateRationGLJ(args);
  230. },
  231. onButtonClick: function (sender, args) {
  232. if(args.sheet.isEditing()){
  233. args.sheet.endEdit();
  234. }
  235. var me = gljOprObj;
  236. var sheet = args.sheet, row = args.row, col = args.col;
  237. var cellType = sheet.getCellType(row, col);
  238. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  239. if(args.sheetName == 'rationInstallSheet'){
  240. installationFeeObj.onPositionButtonClick(sender,args);
  241. }
  242. } else {
  243. me.onCheckBoxClick(sender, args)
  244. }
  245. },
  246. onCheckBoxClick: function (sender, args) {
  247. let selected = projectObj.project.mainTree.selected;
  248. if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
  249. return ;
  250. }
  251. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  252. if(args.sheetName == 'rationInstallSheet' && checkboxValue){
  253. return;
  254. }
  255. if(gljOprObj.isInstallationNode(selected)==true){
  256. return;
  257. }
  258. let newval = 0;
  259. if (checkboxValue) {
  260. newval = 0;
  261. args.sheet.getCell(args.row, args.col).value(newval);
  262. } else {
  263. newval = 1;
  264. args.sheet.getCell(args.row, args.col).value(newval);
  265. }
  266. if (args.sheetName == 'ration_glj') {
  267. gljOprObj.updateIsEstimate(args,newval);
  268. } else if (args.sheetName == 'quantity_detail') {
  269. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  270. } else if (args.sheetName == 'glj_lib') {
  271. if(gljOprObj.gljLibSheetSetting.header[args.col].dataCode === 'select'){
  272. gljOprObj.setGLJSelection(args, newval);
  273. }
  274. }else if(args.sheetName == 'rationInstallSheet'){
  275. args.newValue = newval;
  276. installationFeeObj.onRationInstallValueChange(sender,args);
  277. }
  278. },
  279. onCellClick: function (sender, args) {
  280. console.log('cellClick');
  281. var me = gljOprObj;
  282. if (args.row >= me.sheetData.length) {
  283. return;
  284. }
  285. me.editChecking(args);
  286. },
  287. onCellDoubleClick:function (sender, args) {
  288. var me = gljOprObj;
  289. var header = me.setting.header;
  290. if (args.row >= me.sheetData.length) {
  291. return;
  292. }
  293. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  294. if(me.hasComposition(me.sheetData[args.row])){
  295. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  296. }
  297. }
  298. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  299. var isAdd = me.sheetData[args.row].isAdd;
  300. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  301. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  302. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  303. }
  304. }
  305. }
  306. },
  307. onClipboardChanged: function (sender, info) {
  308. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  309. sheetCommonObj.copyTextToClipboard(cDatas);
  310. return;
  311. },
  312. editChecking: function (args) {
  313. var me = gljOprObj;
  314. var header = me.setting.header;
  315. var disable = null;
  316. if (me.sheetData[args.row] != undefined) {
  317. if (me.sheetData[args.row].isMixRatio) {
  318. disable = true;
  319. }else {
  320. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  321. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){
  322. disable = true;
  323. }else {
  324. disable = false;
  325. }
  326. }
  327. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  328. var isAdd = me.sheetData[args.row].isAdd;
  329. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  330. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){//如果有组成物,不可修改
  331. disable = true;
  332. }else {
  333. disable = false;
  334. }
  335. } else {
  336. disable = true;
  337. }
  338. }
  339. }
  340. }
  341. if (disable != null) {
  342. me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
  343. }
  344. },
  345. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  346. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  347. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  348. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  349. let con_key = this.getIndex(ration_glj,keyArray);
  350. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  351. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  352. return true;
  353. }
  354. }
  355. return false;
  356. },
  357. onRangeChanged: function (sender, args) {
  358. var me = gljOprObj;
  359. if(args.sheetName == 'quantity_detail'){
  360. me.batchUpdateQuantityDetail(args);
  361. }else {
  362. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  363. args.editingText = null;
  364. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  365. args.editingText = args.sheet.getCell(args.row,args.col).value();
  366. }else {
  367. return;
  368. }
  369. if (args.sheetName == 'ration_glj') {
  370. me.onEditGLJSheet(args);
  371. }
  372. }
  373. },
  374. batchUpdateQuantityDetail:function (args) {
  375. let me = gljOprObj;
  376. let updateArray = [];
  377. for(let i =0;i<args.changedCells.length;i++){
  378. let c = args.changedCells[i];
  379. let tem = {
  380. row:c.row,
  381. col:c.col,
  382. editingText:args.sheet.getCell(c.row,c.col).text(),
  383. sheet:args.sheet,
  384. sheetName:args.sheetName,
  385. index:i
  386. };
  387. updateArray.push(tem);
  388. }
  389. if(updateArray.length>0){
  390. updateArray.length == 1?me.onEditDetailSheet(updateArray[0]):me.onEditDetailSheet(updateArray[0],updateCallback);
  391. }
  392. function updateCallback(i_args) {
  393. let index = i_args.index;
  394. if(index < updateArray.length-1){
  395. let nextIndex = index+1;
  396. updateArray[nextIndex].replace = i_args.replace;
  397. if(nextIndex == updateArray.length-1){//是最后一个,则不用调callback了
  398. me.onEditDetailSheet(updateArray[nextIndex]);
  399. }else {
  400. me.onEditDetailSheet(updateArray[nextIndex],updateCallback);
  401. }
  402. }
  403. }
  404. },
  405. showDataIfRationSelect: function (node,selectedNodeId) {
  406. var isShow = false;
  407. if(projectReadOnly && this.setting.view.lockColumns){
  408. this.setting.view.lockColumns = null;
  409. }
  410. if(selectedNodeId){
  411. this.selectedNodeId = selectedNodeId;
  412. }
  413. if (node) {
  414. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  415. return;
  416. } else {
  417. this.selectedNodeId = node.getID();
  418. }
  419. if (node.sourceType == "ration") {
  420. if(node.data.type==rationType.gljRation){
  421. if($('#linkGLJ').hasClass('active')){
  422. this.showMixRatio(node);
  423. }
  424. }else {
  425. if($('#linkGLJ').hasClass('active')){
  426. this.showRationGLJData(node);
  427. }
  428. if($('#linkAZZJF').hasClass('active')){
  429. installationFeeObj.showRationInstallationData(node);
  430. }
  431. }
  432. isShow = true;
  433. }
  434. if(node.sourceType == ModuleNames.ration_glj){
  435. if($('#linkGLJ').hasClass('active')) {
  436. this.showMixRatio(node);
  437. }
  438. isShow = true;
  439. }
  440. if($('#linkGCLMX').hasClass('active')){
  441. this.showQuantityDetailData(node);
  442. }
  443. } else {
  444. this.selectedNodeId = null;
  445. }
  446. if (!isShow) {
  447. this.clearSheetData();
  448. }
  449. //子目换算
  450. zmhs_obj.showZMHSData(node);
  451. // $('#dropdown').hide();
  452. },
  453. showMixRatio:function (node) {//显示组成物到定额工料机
  454. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  455. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  456. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  457. let connect_index = this.getIndex(node.data,indexArray);
  458. let gljList=[];
  459. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  460. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  461. }
  462. if(gljList.length>0){//计算总消耗量
  463. if(node.sourceType==ModuleNames.ration){
  464. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  465. }else {
  466. let totalQuantity = this.getTotalQuantity(node.data);
  467. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  468. }
  469. }
  470. this.sheetData = gljList;
  471. this.sheet.setRowCount(0);
  472. this.sheetData = sortRationGLJ(this.sheetData);
  473. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  474. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  475. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  476. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  477. },
  478. showRationGLJData: function (node) {
  479. var gljList = [];
  480. var ration_glj = projectObj.project.ration_glj;
  481. node = node ? node : projectObj.project.mainTree.selected;
  482. if (node.sourceType == ModuleNames.ration) {
  483. if(node.data.type==rationType.gljRation){
  484. this.showMixRatio(node);
  485. }else {
  486. let ration = node.data;
  487. gljList = this.filterGljByRation(ration, ration_glj.datas);
  488. this.showInSheet(gljList);
  489. }
  490. }else if(node.sourceType == ModuleNames.ration_glj){
  491. this.showMixRatio(node);
  492. }
  493. },
  494. showRationGLJSheetData: function (init) {
  495. let selected = this.sheet.getSelections();
  496. this.combineWithProjectGlj(this.sheetData);
  497. this.sheet.setRowCount(0);
  498. //console.log(+new Date())
  499. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  500. this.sheetData = sortRationGLJ(this.sheetData);
  501. this.sumQuantity();//计算总消耗量
  502. this.addMixRatioToShow();//显示组成物信息
  503. this.initRationTree(init);
  504. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  505. if(selected){//定位光标到之前的位置
  506. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  507. }
  508. },
  509. initRationTree: function (init) {
  510. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  511. for (var i = 0; i < this.sheetData.length; i++) {
  512. if (this.sheetData[i].hasOwnProperty('subList')) {
  513. /* var collapsed = false;
  514. if (init) {
  515. this.sheetData[i].collapsed = true;
  516. collapsed = true;
  517. } else {
  518. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  519. }*/
  520. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  521. if (collapsed == true) {
  522. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  523. }
  524. //this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
  525. //这个方法导致加载缓慢
  526. }
  527. }
  528. },
  529. filterGljByRation: function (ration, datas) {
  530. var gljList = [];
  531. if (datas && datas.length > 0) {
  532. gljList = _.filter(datas, {'rationID': ration.ID})
  533. }
  534. return gljList;
  535. },
  536. showInSheet: function (gljList) {
  537. this.sheetData = gljList;
  538. this.showRationGLJSheetData(true);
  539. },
  540. sumQuantity: function (node) {
  541. if (this.sheetData.length > 0) {
  542. node = node ? node : projectObj.project.mainTree.selected;
  543. let ration = node.data;
  544. let quantity = ration.quantity;
  545. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  546. for (let glj of this.sheetData) {
  547. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  548. }
  549. }
  550. },
  551. getTotalQuantity:function(glj,ration){
  552. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  553. if(ration){
  554. let quantity = ration.quantity;
  555. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  556. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  557. return;
  558. }
  559. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  560. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  561. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  562. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  563. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  564. }
  565. return glj.totalQuantity;
  566. }
  567. },
  568. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  569. for (let subG of mList) {
  570. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  571. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  572. }
  573. },
  574. addMixRatioToShow: function () {
  575. var newList = [];
  576. _.remove(this.sheetData, {'isMixRatio': true});
  577. for (var i = 0; i < this.sheetData.length; i++) {
  578. newList.push(this.sheetData[i]);
  579. if (this.sheetData[i].hasOwnProperty('subList')) {
  580. newList = newList.concat(this.sheetData[i].subList);
  581. }
  582. }
  583. this.sheetData = newList;
  584. },
  585. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  586. var projectGLJData = projectObj.project.projectGLJ.datas;
  587. var projectGljs = projectGLJData.gljList;
  588. var mixRatioMap = projectGLJData.mixRatioMap;
  589. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  590. for (var i = 0; i < ration_gljs.length; i++) {
  591. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  592. if (glj) {
  593. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  594. ration_gljs[i].isEstimate = glj.is_evaluate;
  595. }
  596. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  597. ration_gljs[i].isAdd = glj.unit_price.is_add;
  598. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  599. var connect_index = this.getIndex(glj, gljKeyArray);
  600. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  601. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  602. ration_gljs[i].subList = mixRatios;
  603. }
  604. }
  605. }
  606. }
  607. return ration_gljs;
  608. },
  609. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  610. let proGLJ = projectObj.project.projectGLJ;
  611. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  612. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  613. let labourCoeDatas = projectObj.project.labourCoe.datas;
  614. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  615. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  616. data.marketPrice = result.marketPrice;
  617. data.basePrice = result.basePrice;
  618. data.adjustPrice = result.adjustPrice;
  619. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  620. return data;
  621. },
  622. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  623. let proGLJ = projectObj.project.projectGLJ;
  624. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  625. if(this.calcPriceDiff(glj)==true){
  626. return proGLJ.getBasePrice(glj);
  627. }else {
  628. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  629. }
  630. },
  631. calcPriceDiff:function (glj) {
  632. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  633. return gljUtil.calcPriceDiff(glj,calcOptions);
  634. },
  635. getIndex(obj, pops){
  636. let t_index = '';
  637. let k_arr = [];
  638. for (let p of pops) {
  639. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  640. k_arr.push(tmpK);
  641. }
  642. t_index = k_arr.join("|-|");
  643. return t_index;
  644. },
  645. getConditionByKey(conKey){//将连接字符串转换成对象
  646. let valueArray = conKey.split("|-|");
  647. let obj ={};
  648. for(let i = 0;i<valueArray.length;i++){
  649. if(valueArray[i]!='null'){
  650. if(gljKeyArray[i]=='type'){
  651. valueArray[i] = parseInt(valueArray[i]);
  652. }
  653. obj[gljKeyArray[i]]=valueArray[i];
  654. }
  655. }
  656. return obj;
  657. },
  658. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  659. var temRationGLJs = [];
  660. for (var i = 0; i < mixRatioList.length; i++) {
  661. var pg = _.find(projectGljs, {
  662. 'code': mixRatioList[i].code,
  663. 'name': mixRatioList[i].name,
  664. 'specs': mixRatioList[i].specs,
  665. 'type': mixRatioList[i].type,
  666. 'unit': mixRatioList[i].unit
  667. });//改关联关系
  668. var tem = {
  669. projectGLJID: pg.id,
  670. code: pg.code,
  671. name: pg.name,
  672. specs: pg.specs,
  673. unit: pg.unit,
  674. type:mixRatioList[i].type,
  675. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  676. consumption:mixRatioList[i].consumption,
  677. rationItemQuantity: mixRatioList[i].consumption,
  678. // quantity:mixRatioList[i].consumption,
  679. /* basePrice: pg.unit_price.base_price,
  680. marketPrice: pg.unit_price.market_price,
  681. adjustPrice: pg.adjust_price,*/
  682. //isEstimate: pg.is_evaluate,
  683. isMixRatio: true,
  684. isAdd: pg.unit_price.is_add,
  685. GLJID: pg.glj_id
  686. };
  687. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  688. tem.isEstimate = pg.is_evaluate;
  689. }
  690. this.setGLJPrice(tem,pg);
  691. temRationGLJs.push(tem);
  692. }
  693. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  694. return temRationGLJs;
  695. },
  696. showQuantityDetailData: function (node) {
  697. var details = [];
  698. node = node ? node : projectObj.project.mainTree.selected;
  699. var quantity_detail = projectObj.project.quantity_detail;
  700. if (node.sourceType == ModuleNames.ration) {
  701. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  702. } else if (node.sourceType == ModuleNames.bills) {
  703. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  704. }
  705. details = _.sortBy(details, 'seq');
  706. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  707. this.detailData = details;
  708. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  709. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  710. }
  711. },
  712. clearSheetData: function () {
  713. if($('#linkGLJ').hasClass('active')){
  714. sheetCommonObj.showData(this.sheet, this.setting, []);
  715. }
  716. if($('#linkAZZJF').hasClass('active')){
  717. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  718. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  719. }
  720. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  721. this.sheetData = [];
  722. installationFeeObj.rationInstallData = [];
  723. //this.detailData=[];
  724. },
  725. updateRationGLJ: function (args) {
  726. var me = this;
  727. var updateField = me.setting.header[args.col].dataCode;
  728. var recode = me.sheetData[args.row];
  729. var newval;
  730. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  731. if (args.editingText == null) {
  732. updateField == 'marketPrice' ? newval = 0 : newval = "";
  733. } else {
  734. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  735. newval = number_util.checkNumberValue(args.editingText, decimal);
  736. if (newval == null) {
  737. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  738. return;
  739. }
  740. }
  741. } else {
  742. if (updateField == 'name' || updateField == 'unit') {
  743. if (args.editingText === null) {
  744. alert(me.setting.header[args.col].headerName + '不能为空!');
  745. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  746. return;
  747. }
  748. }
  749. newval = args.editingText == null ? "" : args.editingText;
  750. }
  751. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  752. return
  753. }
  754. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  755. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  756. } else {
  757. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  758. }
  759. },
  760. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  761. let newval;
  762. let updatePrice = false;
  763. if (fieldName == "marketUnitFee") {
  764. updatePrice = true;
  765. if (value == null) {
  766. newval = 0;
  767. } else {
  768. var decimal = getDecimal("glj.unitPrice");
  769. newval = number_util.checkNumberValue(value, decimal);
  770. }
  771. } else {
  772. if (value != null) {
  773. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  774. return;
  775. //update
  776. }
  777. }
  778. if (newval && updatePrice == true) {
  779. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  780. return
  781. }
  782. projectObj.mainController.refreshTreeNode([node]);
  783. },
  784. updateIsEstimate:function (args, newval) {
  785. var me = gljOprObj;
  786. if(me.setting.header[args.col].dataCode=="isEstimate"){
  787. var pspread= new ProjectGLJSpread();
  788. var recode = me.sheetData[args.row];
  789. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  790. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  791. if(glj){
  792. glj["is_evaluate"]=newval;
  793. args.fromRG=true;
  794. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  795. }
  796. }
  797. },
  798. showLibGLJSheetData: function () {
  799. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  800. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  801. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  802. },
  803. filterLibGLJSheetData: function () {
  804. let me = this;
  805. let val = $("input[name='glj']:checked").val();
  806. if (val == 'allGljs') {
  807. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  808. } else {
  809. me.gljLibSheetData = me[val];
  810. }
  811. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  812. me.filterLibGLJByType();
  813. }else if($('#actionType').val() == 'addMix'){
  814. projectGljObject.filterLibGLJForMixRatio();
  815. }
  816. //文本筛选
  817. let searchStr = $('#gljSearchKeyword').val();
  818. if(searchStr && searchStr.trim() != ''){
  819. let reg = new RegExp(searchStr);
  820. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  821. return reg.test(data.code) || reg.test(data.name);
  822. });
  823. }
  824. if (me.gljCurTypeId == undefined) {
  825. return;
  826. }
  827. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  828. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  829. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  830. });
  831. } else {
  832. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  833. }
  834. },
  835. setGLJSelection: function (args, newVal) {
  836. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  837. this.addGLJsSelection(args, newVal);
  838. } else {
  839. this.replaceGLJSelection(args, newVal);
  840. }
  841. },
  842. addGLJsSelection: function (args, newVal) {
  843. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  844. if (newVal == 1) {
  845. this.GLJSelection.push(con_key);
  846. this.gljLibSheetData[args.row].select = 1;
  847. } else if (newVal == 0) {
  848. _.pull(this.GLJSelection, con_key);
  849. this.gljLibSheetData[args.row].select = 0;
  850. }
  851. },
  852. replaceGLJSelection: function (args, newVal) {
  853. var me = this;
  854. var oldSelection = this.GLJSelection[0];
  855. if (newVal == 0) {
  856. args.sheet.getCell(args.row, args.col).value(1);
  857. return;
  858. }
  859. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  860. this.gljLibSheetData[args.row].select = 1;
  861. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  862. var i_key = me.getIndex(item, gljLibKeyArray);
  863. return oldSelection == i_key;
  864. });
  865. if (oindex != -1) {
  866. args.sheet.getCell(oindex, args.col).value(0);
  867. this.gljLibSheetData[oindex].select = 0;
  868. } else {
  869. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  870. var i_key = me.getIndex(item, gljLibKeyArray);
  871. return oldSelection == i_key;
  872. });
  873. oldData ? oldData.select = 0 : "";
  874. }
  875. },
  876. filterLibGLJByType: function () {
  877. var me = this;
  878. var selected = me.sheetData[gljContextMenu.selectedRow];
  879. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  880. },
  881. getComboData: function (gljDistType) {
  882. let me = this;
  883. let distType;
  884. let distTypeTree = {
  885. prefix: 'gljType',
  886. distTypes: {},
  887. comboDatas: [],
  888. distTypesArr: []
  889. };
  890. gljDistType.forEach(function (typeData) {
  891. let typeObj = {
  892. data: typeData,
  893. children: [],
  894. parent: null
  895. }
  896. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  897. distTypeTree.distTypesArr.push(typeObj);
  898. });
  899. gljDistType.forEach(function (typeData) {
  900. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  901. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  902. if (parent) {
  903. distType.parent = parent;
  904. parent.children.push(distType);
  905. }
  906. });
  907. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  908. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  909. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  910. }
  911. });
  912. return distTypeTree;
  913. },
  914. doInsertGLJ: function () {
  915. var me = this;
  916. var selected = projectObj.project.mainTree.selected;
  917. var project = projectObj.project;
  918. if (me.GLJSelection.length <= 0) {
  919. return;
  920. }
  921. $("#glj_tree_div").modal('hide');
  922. $.bootstrapLoading.start();
  923. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  924. let newNode=null;
  925. for (let r_glj of data) {
  926. r_glj.quantity = r_glj.quantity + "";
  927. project.Ration.datas.push(r_glj);
  928. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  929. project.projectGLJ.loadData(function () {
  930. for(let r_glj of data){
  931. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  932. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  933. newNode.source = r_glj;
  934. newNode.sourceType = project.Ration.getSourceType();
  935. newNode.data = r_glj;
  936. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  937. }
  938. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  939. projectObj.mainController.refreshTreeNode([newNode]);
  940. if(me.hasComposition(newNode.data,true)){
  941. me.showMixRatio(newNode);
  942. }else {
  943. me.showRationGLJSheetData();
  944. }
  945. $.bootstrapLoading.end();
  946. });
  947. })
  948. },
  949. doAddGLJ: function () {
  950. var selected = projectObj.project.mainTree.selected;
  951. var project = projectObj.project;
  952. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  953. var rg = _.find(gljOprObj.sheetData, function (item) {
  954. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  955. return n == i_key
  956. })
  957. return rg ? false : true;
  958. })
  959. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  960. $("#glj_tree_div").modal('hide');
  961. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  962. if (result) {
  963. selected.data.adjustState = result.adjustState;
  964. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  965. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  966. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  967. project.projectGLJ.loadData(function () {
  968. project.ration_glj.addToMainTree(result.showData);
  969. gljOprObj.showRationGLJSheetData();
  970. project.calcProgram.calcAndSave(selected);
  971. projectObj.mainController.refreshTreeNode([selected]);
  972. $.bootstrapLoading.end();
  973. });
  974. }
  975. });//doc.rationID=selected.data.ID;
  976. } else {
  977. $("#glj_tree_div").modal('hide');
  978. }
  979. },
  980. doReplaceGLJ: function () {
  981. var me = this;
  982. var oldData = me.sheetData[gljContextMenu.selectedRow];
  983. var project = projectObj.project;
  984. var selectCode = gljOprObj.GLJSelection[0];
  985. var selected = projectObj.project.mainTree.selected;
  986. $("#glj_tree_div").modal('hide');
  987. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  988. if (result) {
  989. //result.adjustState;
  990. var glj_list = projectObj.project.ration_glj.datas;
  991. var data = result.data;
  992. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  993. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  994. var nodes = [selected];
  995. gljOprObj.sheetData[index] = data;
  996. glj_list[list_index] = data;
  997. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  998. gljOprObj.showRationGLJSheetData();
  999. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1000. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1001. if (node) {
  1002. project.ration_glj.transferToNodeData(data);
  1003. node.source = data;
  1004. node.data = data;
  1005. }
  1006. node ? nodes.push(node) : "";
  1007. }
  1008. //project.ration_glj.addToMainTree(data);
  1009. selected.data.adjustState = result.adjustState;
  1010. projectObj.mainController.refreshTreeNode(nodes);
  1011. project.calcProgram.calcAndSave(selected);
  1012. $.bootstrapLoading.end();
  1013. });
  1014. }
  1015. })
  1016. },
  1017. doMReplaceGLJ: function () {
  1018. let me = this;
  1019. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1020. let project = projectObj.project;
  1021. let selectCode = me.GLJSelection[0];
  1022. $("#glj_tree_div").modal('hide');
  1023. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1024. if(result == null){
  1025. return;
  1026. }
  1027. let data = result.data;
  1028. let stateList = result.stateList;
  1029. //let n_index = me.getIndex(data.query, gljKeyArray);
  1030. let nodes = [];
  1031. _.forEach(project.ration_glj.datas, function (t) {
  1032. // let t_index = me.getIndex(t, gljKeyArray);
  1033. if (updateMap[t.ID]) {
  1034. me.updateProperty(t, data.doc);
  1035. me.updateProperty(t, updateMap[t.ID]);
  1036. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1037. project.ration_glj.transferToNodeData(t);
  1038. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1039. node ? nodes.push(node):'';
  1040. }
  1041. }
  1042. })
  1043. project.projectGLJ.loadData(function () {
  1044. me.showRationGLJSheetData();
  1045. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1046. project.calcProgram.calcNodesAndSave(rationNodes);
  1047. $.bootstrapLoading.end();
  1048. });
  1049. })
  1050. },
  1051. updateProperty: function (obj, doc) {
  1052. _.forEach(doc, function (n, key) {
  1053. obj[key] = n;
  1054. });
  1055. },
  1056. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1057. var nodes = [];
  1058. var rationNodes = [];
  1059. _.forEach(stateList, function (s) {
  1060. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1061. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1062. })
  1063. if (node) {
  1064. node.data.adjustState = s.adjustState;
  1065. nodes.push(node);
  1066. rationNodes.push(node);
  1067. }
  1068. });
  1069. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1070. projectObj.mainController.refreshTreeNode(nodes);
  1071. return rationNodes;
  1072. },
  1073. refreshView: function () {
  1074. let node = projectObj.project.mainTree.selected;
  1075. this.showDataIfRationSelect(node,"111111");
  1076. //this.showRationGLJData();
  1077. },
  1078. //
  1079. refreshTreeNode: function (obj) {
  1080. if (!obj) {
  1081. return;
  1082. }
  1083. var objectArray = [];
  1084. var nodes = [];
  1085. if (obj instanceof Array) {
  1086. objectArray.concat(obj);
  1087. } else {
  1088. objectArray.push(obj);
  1089. }
  1090. for (let o of objectArray) {
  1091. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1092. return n.sourceType == o.type && n.data.ID == o.ID;
  1093. })
  1094. if (node) {
  1095. for (var k in o.data) {
  1096. node.data[k] = o.data[k];
  1097. }
  1098. nodes.push(node);
  1099. }
  1100. }
  1101. projectObj.mainController.refreshTreeNode(nodes);
  1102. return nodes;
  1103. },
  1104. getTreeNodeCellType: function (data) {
  1105. var ns = GC.Spread.Sheets;
  1106. var rectW = 10;
  1107. var rectH = 10;
  1108. var margin = 3;
  1109. function TreeNodeCellType() {
  1110. }
  1111. function drowRect(ctx, x, y, w, h) {
  1112. ctx.save();
  1113. ctx.strokeStyle = "gray";
  1114. ctx.translate(0.5, 0.5);
  1115. ctx.beginPath();
  1116. var rectX = x + margin;
  1117. var rectY = y + Math.round(h / 2) - rectH / 2;
  1118. ctx.moveTo(rectX, rectY);
  1119. ctx.lineTo(rectX, rectY + rectH);
  1120. ctx.lineTo(rectX + rectW, rectY + rectH);
  1121. ctx.lineTo(rectX + rectW, rectY);
  1122. ctx.lineTo(rectX, rectY);
  1123. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1124. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1125. ctx.stroke();
  1126. ctx.restore();
  1127. }
  1128. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1129. ctx.save();
  1130. ctx.strokeStyle = "#000000";
  1131. ctx.translate(0.5, 0.5);
  1132. ctx.beginPath();
  1133. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1134. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1135. var rectY = y + Math.round(h / 2) - rectH / 2;
  1136. if (collapsed) {
  1137. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1138. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1139. }
  1140. ctx.stroke();
  1141. ctx.restore();
  1142. }
  1143. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1144. offset += 6;
  1145. ctx.save();
  1146. ctx.strokeStyle = "gray";
  1147. ctx.translate(0.5, 0.5);
  1148. ctx.beginPath();
  1149. ctx.moveTo(x + offset, y);
  1150. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1151. offset += 9;
  1152. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1153. if (nextItem && nextItem.isMixRatio) {
  1154. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1155. ctx.lineTo(x + offset - 9, y + h);
  1156. }
  1157. ctx.stroke();
  1158. ctx.restore();
  1159. return offset;
  1160. }
  1161. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1162. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1163. if (value != null) {
  1164. var offset = margin + rectW + 6;
  1165. var recode = data[options.row];
  1166. if (recode && recode.hasOwnProperty('subList')) {
  1167. drowRect(ctx, x, y, w, h);
  1168. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1169. drowSymbol(ctx, x, y, w, h, collapsed);
  1170. } else if (recode && recode.isMixRatio) {
  1171. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1172. offset += 1;
  1173. }
  1174. arguments[2] = x + offset;
  1175. arguments[4] = w - offset;
  1176. //x = x + offset;
  1177. //w = w - offset;
  1178. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1179. }
  1180. };
  1181. // override getHitInfo to allow cell type get mouse messages
  1182. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1183. return {
  1184. x: x,
  1185. y: y,
  1186. row: context.row,
  1187. col: context.col,
  1188. cellStyle: cellStyle,
  1189. cellRect: cellRect,
  1190. sheetArea: context.sheetArea
  1191. };
  1192. };
  1193. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1194. var recode = data[hitinfo.row];
  1195. if (recode && recode.hasOwnProperty('subList')) {
  1196. var hoffset = hitinfo.cellRect.x + 3;
  1197. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1198. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1199. collapsed = !collapsed
  1200. recode.collapsed = collapsed;
  1201. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1202. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1203. hitinfo.sheet.invalidateLayout();
  1204. hitinfo.sheet.repaint();
  1205. }
  1206. }
  1207. };
  1208. return new TreeNodeCellType()
  1209. },
  1210. marketPriceReadOnly: function (node) {
  1211. let hasCom = false;
  1212. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1213. hasCom = this.hasComposition(node.data,true);
  1214. }else {
  1215. hasCom = this.hasComposition(node.data);
  1216. }
  1217. return hasCom|| node.data.isEstimate == 1;
  1218. }
  1219. }
  1220. $(function () {
  1221. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1222. if (gljOprObj.gljLibSpresd == undefined) {
  1223. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1224. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1225. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1226. gljOprObj.gljLibSheet.options.isProtected = true;
  1227. gljOprObj.gljLibSheet.name('glj_lib');
  1228. }
  1229. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1230. let selections = [],selectMap = {};
  1231. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1232. gljOprObj.GLJSelection = [];
  1233. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1234. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1235. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1236. gljOprObj.GLJSelection = [connect_key];
  1237. selectMap[connect_key] = true;
  1238. gljOprObj.filterLibGLJByType();
  1239. }else if($('#actionType').val() =='addMix'){//添加组成物
  1240. gljOprObj.GLJSelection = [];
  1241. projectGljObject.filterLibGLJForMixRatio();
  1242. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1243. gljOprObj.GLJSelection = [];
  1244. for(let s of selections){
  1245. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1246. selectMap[s_key] = true;
  1247. gljOprObj.GLJSelection.push(s_key);
  1248. }*/
  1249. }
  1250. for(let item of gljOprObj.gljLibSheetData){
  1251. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1252. if(selectMap[item_key]){
  1253. item.select = 1 ;
  1254. }
  1255. }
  1256. gljOprObj.showLibGLJSheetData();
  1257. });
  1258. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1259. $('#gljSearchKeyword').val('');
  1260. });
  1261. $('.glj-radio').change(function () {
  1262. let val = $("input[name='glj']:checked").val();
  1263. if (val == 'allGljs') {
  1264. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1265. gljOprObj.filterLibGLJSheetData();
  1266. gljOprObj.showLibGLJSheetData();
  1267. } else {
  1268. gljOprObj.gljLibSheetData = gljOprObj[val];
  1269. gljOprObj.filterLibGLJSheetData();
  1270. gljOprObj.showLibGLJSheetData();
  1271. }
  1272. })
  1273. //工料机搜索
  1274. $('#gljSearchKeyword').change(function () {
  1275. gljOprObj.filterLibGLJSheetData();
  1276. gljOprObj.showLibGLJSheetData();
  1277. });
  1278. $('#gljSearchKeyword').bind('keypress', function (e) {
  1279. if(e.keyCode === 13){
  1280. $(this).blur();
  1281. return false;
  1282. }
  1283. });
  1284. $('#glj_selected_conf').click(function () {
  1285. if (gljOprObj.GLJSelection.length < 1) {
  1286. return;
  1287. }
  1288. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1289. gljOprObj.doInsertGLJ();
  1290. } else if ($('#actionType').val() == 'add') { //添加工料机
  1291. gljOprObj.doAddGLJ();
  1292. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1293. gljOprObj.doReplaceGLJ();
  1294. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1295. gljOprObj.doMReplaceGLJ();
  1296. }else if($('#actionType').val() == 'addMix'){
  1297. projectGljObject.addMixRatio();
  1298. }
  1299. })
  1300. $('#class_selected_conf').click(function () {
  1301. var gljClass = $('#selected_class').val();
  1302. var glj = gljOprObj.selectedGLJClass;
  1303. if (glj && gljClass && gljClass != "") {
  1304. //保存到我的工料机库
  1305. /*1 检查是否有组成物
  1306. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1307. * 3 保存
  1308. * */
  1309. var newItem = {
  1310. code: glj.code,
  1311. name: glj.name,
  1312. specs: glj.specs,
  1313. unit: glj.unit,
  1314. basePrice: glj.basePrice,
  1315. gljType: glj.type,
  1316. shortName: glj.shortName,
  1317. component: [],
  1318. gljClass: gljClass
  1319. };
  1320. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1321. for (var i = 0; i < glj.subList.length; i++) {
  1322. let tem = {
  1323. ID: glj.subList[i].GLJID,
  1324. consumeAmt: glj.rationItemQuantity,
  1325. isStd: true
  1326. }
  1327. newItem.component.push(tem);
  1328. }
  1329. }
  1330. var data = getcmpUpdateData([newItem]);
  1331. $.bootstrapLoading.start();
  1332. var callback = function (data) {
  1333. $("#glj_class_div").modal('hide');
  1334. $.bootstrapLoading.end();
  1335. }
  1336. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1337. $.bootstrapLoading.end();
  1338. });
  1339. }
  1340. })
  1341. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1342. gljOprObj.selectedGLJClass = null;
  1343. $('#class_selected_conf').attr("disabled", "disabled");
  1344. $('#selected_class').val("");
  1345. })
  1346. function getcmpUpdateData(items) {
  1347. var data = {
  1348. "updateItems": [],
  1349. "removeIds": []
  1350. }
  1351. data.addItems = items;
  1352. return data;
  1353. }
  1354. })
  1355. function operationWithRound(value1,value2,field,symble) {
  1356. let decimal = getDecimal(field);
  1357. value1 = scMathUtil.roundForObj(value1,decimal);
  1358. value2 = scMathUtil.roundForObj(value2,decimal);
  1359. let result;
  1360. switch (symble){
  1361. case "+" :
  1362. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1363. break;
  1364. case "-":
  1365. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1366. break;
  1367. case "*":
  1368. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1369. break;
  1370. case "/":
  1371. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1372. break
  1373. }
  1374. return result;
  1375. }
  1376. function getDecimal(fieldID, node) {
  1377. if (node) {
  1378. return decimalObj.decimal(fieldID, node);
  1379. } else if (fieldID.indexOf(".") != -1) {
  1380. var keyArray = fieldID.split(".");
  1381. return decimalObj[keyArray[0]][keyArray[1]];
  1382. } else {
  1383. return decimalObj.decimal(fieldID);
  1384. }
  1385. }
  1386. function sortRationGLJ(list) {
  1387. list = _.sortByAll(list, [function (item) {
  1388. return item.type + "";
  1389. }, "code"])
  1390. return list;
  1391. }
  1392. function compareRationGLJ(a, b) {
  1393. if ((a.type + "") < (b.type + "")) {
  1394. return true
  1395. }
  1396. if ((a.type + "") == (b.type + "")) {
  1397. if (a.code < b.code) {
  1398. return true
  1399. }
  1400. }
  1401. return false;
  1402. }