glj_view.js 64 KB

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