glj_view.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  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. coeSheetData: [],
  10. checkb: null,
  11. coeSheet: null,
  12. assSheet: null,
  13. assSheetData: [],
  14. detailSheet: null,
  15. detailData: [],
  16. GLJSelection: [],
  17. selectedGLJClass: null,
  18. parentNodeIds: {},
  19. activeTab: '#linkGLJ',
  20. setting: {
  21. header: [
  22. {headerName: "编码", headerWidth: 100, dataCode: "code", dataType: "String", formatter: "@"},
  23. {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String"},
  24. {headerName: "规格型号", headerWidth: 90, dataCode: "specs", dataType: "String", hAlign: "left"},
  25. {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
  26. {headerName: "类型", headerWidth: 45, dataCode: "shortName", dataType: "String", hAlign: "center"},
  27. {
  28. headerName: "定额消耗",
  29. headerWidth: 80,
  30. dataCode: "rationItemQuantity",
  31. dataType: "Number",
  32. hAlign: "right",
  33. decimalField: "glj.quantity"
  34. }, // dataType: "Number", formatter: "0.00"
  35. {
  36. headerName: "自定消耗",
  37. headerWidth: 80,
  38. dataCode: "customQuantity",
  39. dataType: "Number",
  40. hAlign: "right",
  41. decimalField: "glj.quantity"
  42. },
  43. {
  44. headerName: "消耗量",
  45. headerWidth: 80,
  46. dataCode: "quantity",
  47. dataType: "Number",
  48. hAlign: "right",
  49. decimalField: "glj.quantity"
  50. },
  51. {
  52. headerName: "总消耗量",
  53. headerWidth: 80,
  54. dataCode: "totalQuantity",
  55. dataType: "Number",
  56. hAlign: "right",
  57. decimalField: "glj.quantity"
  58. },
  59. {
  60. headerName: "定额价",
  61. headerWidth: 80,
  62. dataCode: "basePrice",
  63. dataType: "Number",
  64. hAlign: "right",
  65. decimalField: "glj.unitPrice"
  66. },
  67. {
  68. headerName: "调整价",
  69. headerWidth: 80,
  70. dataCode: "adjustPrice",
  71. dataType: "Number",
  72. hAlign: "right",
  73. decimalField: "glj.unitPrice"
  74. },
  75. {
  76. headerName: "市场价",
  77. headerWidth: 80,
  78. dataCode: "marketPrice",
  79. dataType: "Number",
  80. hAlign: "right",
  81. decimalField: "glj.unitPrice"
  82. },
  83. {
  84. headerName: "是否暂估",
  85. headerWidth: 65,
  86. dataCode: "isEstimate",
  87. dataType: "String",
  88. hAlign: "center",
  89. vAlign: "center",
  90. cellType: "checkBox"
  91. }
  92. ],
  93. view: {
  94. comboBox: [{row: -1, col: 12, rowCount: -1, colCount: 1}],
  95. lockedCells: [{row: -1, col: 3, rowCount: -1, colCount: 1}],
  96. lockColumns: [0, 4, 5, 7, 8, 10, 12]
  97. },
  98. // 工料机类型是混凝土、砂浆、配合比、机械台班时,价格不可编辑。
  99. editedTyep:[GLJTypeConst.MAIN_MATERIAL,GLJTypeConst.EQUIPMENT]//主材设备
  100. },
  101. coeSetting: {
  102. header: [
  103. {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
  104. {headerName: "条件", headerWidth: 120, dataCode: "name", dataType: "String", cellType: "button"},
  105. {headerName: "内容", headerWidth: 350, dataCode: "content", dataType: "String", hAlign: "left"}
  106. ],
  107. view: {
  108. lockColumns: [0, 1, 2]
  109. }
  110. },
  111. assSetting: {
  112. header: [
  113. {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  114. {headerName: "定额值", headerWidth: 120, dataCode: "stdValue", hAlign: "right", dataType: "String"},
  115. {headerName: "实际值", headerWidth: 120, dataCode: "actualValue", hAlign: "right", dataType: "String"}
  116. ],
  117. view: {
  118. lockColumns: [0, 1]
  119. }
  120. },
  121. detailSetting: {
  122. header: [
  123. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  124. {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
  125. {
  126. headerName: "结果(C)",
  127. headerWidth: 120,
  128. dataCode: "result",
  129. dataType: "Number",
  130. decimalField: "quantity_detail"
  131. },
  132. {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
  133. ],
  134. view: {
  135. lockColumns: [2, 3]
  136. }
  137. },
  138. gljTreeSetting: {
  139. view: {
  140. //addHoverDom: gljTypeTreeOprObj.addHoverDom,
  141. //removeHoverDom: gljTypeTreeOprObj.removeHoverDom,
  142. expandSpeed: "",
  143. selectedMulti: false
  144. },
  145. edit: {
  146. enable: false,
  147. editNameSelectAll: true,
  148. showRemoveBtn: true,
  149. showRenameBtn: true,
  150. removeTitle: "删除节点",
  151. renameTitle: "更改名称"
  152. },
  153. data: {
  154. keep: {
  155. parent: true,
  156. leaf: true
  157. },
  158. key: {
  159. children: "items",
  160. name: "Name"
  161. },
  162. simpleData: {
  163. enable: false,
  164. idKey: "ID",
  165. pIdKey: "ParentID",
  166. rootPId: -1
  167. }
  168. },
  169. callback: {
  170. onClick: function (event, treeId, treeNode) {
  171. if (treeId == 'gljTree') {
  172. let me = gljOprObj, gljTypeId = treeNode.ID;
  173. if (me.gljCurTypeId !== treeNode.ID) {
  174. me.gljCurTypeId = treeNode.ID;
  175. me.filterLibGLJSheetData();
  176. me.showLibGLJSheetData();
  177. }
  178. } else {
  179. if (treeNode.isParent) {
  180. $('#class_selected_conf').attr("disabled", "disabled");
  181. $('#selected_class').val("");
  182. } else {
  183. $('#class_selected_conf').removeAttr("disabled");
  184. $('#selected_class').val(treeNode.ID);
  185. }
  186. }
  187. }
  188. }
  189. },
  190. gljLibSheetSetting: {
  191. owner: 'gljTree',
  192. header: [
  193. {
  194. headerName: "选择",
  195. headerWidth: 40,
  196. dataCode: "select",
  197. hAlign: "center",
  198. vAlign: "center",
  199. cellType: "checkBox"
  200. },
  201. {
  202. headerName: "编码",
  203. headerWidth: 80,
  204. dataCode: "code",
  205. dataType: "String",
  206. formatter: "@",
  207. hAlign: "left",
  208. vAlign: "center"
  209. },
  210. {
  211. headerName: "名称",
  212. headerWidth: 120,
  213. dataCode: "name",
  214. dataType: "String",
  215. hAlign: "left",
  216. vAlign: "center"
  217. },
  218. {
  219. headerName: "规格型号",
  220. headerWidth: 80,
  221. dataCode: "specs",
  222. dataType: "String",
  223. hAlign: "center",
  224. vAlign: "center"
  225. },
  226. {
  227. headerName: "单位",
  228. headerWidth: 40,
  229. dataCode: "unit",
  230. dataType: "String",
  231. hAlign: "center",
  232. vAlign: "center"
  233. },
  234. {
  235. headerName: "单价",
  236. headerWidth: 80,
  237. dataCode: "basePrice",
  238. dataType: "Number",
  239. formatter: "0.00",
  240. hAlign: "right",
  241. vAlign: "center"
  242. },
  243. {
  244. headerName: "类型",
  245. headerWidth: 80,
  246. dataCode: "gljType",
  247. dataType: "String",
  248. hAlign: "center",
  249. vAlign: "center"
  250. }
  251. ],
  252. view: {
  253. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  254. }
  255. },
  256. gljLibSheet: null,
  257. initSheet: function (sheet) {
  258. var me = this;
  259. me.sheet = sheet;
  260. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  261. sheet.name('ration_glj');
  262. me.bindSheetEvent(sheet);
  263. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  264. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  265. gljContextMenu.loadGLJSpreadContextMenu();
  266. },
  267. initCoeSheet: function (sheet) {
  268. var me = this;
  269. me.coeSheet = sheet;
  270. sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
  271. sheet.name('ration_coe');
  272. me.bindSheetEvent(sheet);
  273. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCoeCellClick);
  274. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  275. },
  276. initAssSheet: function (sheet) {
  277. var me = this;
  278. me.assSheet = sheet;
  279. sheetCommonObj.initSheet(me.assSheet, me.assSetting, 30);
  280. sheet.name('ration_ass');
  281. me.bindSheetEvent(sheet);
  282. },
  283. initDetailSheet: function (sheet) {
  284. var me = this;
  285. me.detailSheet = sheet;
  286. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  287. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  288. sheet.name('quantity_detail');
  289. me.bindSheetEvent(sheet);
  290. },
  291. showCoeData: function (sheet, setting, datas) {
  292. sheet.floatingObjects.remove("customerCoe");
  293. sheetCommonObj.showData(sheet, setting, datas);
  294. if (datas.length > 0) {
  295. var cus_index = _.findIndex(datas, function (item) {
  296. return item.coeID == -1;
  297. })
  298. if (cus_index != -1) {
  299. this.addDropDownList();
  300. this.addCusButton(cus_index, 1, datas[cus_index].name);
  301. }
  302. }
  303. },
  304. bindSheetEvent: function (sheet) {
  305. var me = this;
  306. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  307. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  308. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  309. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  310. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  311. },
  312. onClipboardPasting: function (sender, args) {
  313. var me = gljOprObj;
  314. if (!me.ration) {
  315. args.cancel = true;
  316. }
  317. },
  318. onClipboardPasted: function (e, info) {
  319. var me = gljOprObj;
  320. console.log('past');
  321. // if (!me.ration) {return;};
  322. // your code...
  323. },
  324. onEditEnded: function (sender, args) {
  325. var me = gljOprObj;
  326. if (args.sheetName == 'ration_glj') {
  327. me.onEditGLJSheet(args)
  328. }
  329. if (args.sheetName == 'ration_ass') {
  330. me.onEditAssSheet(args);
  331. }
  332. if (args.sheetName == 'quantity_detail') {
  333. me.onEditDetailSheet(args);
  334. }
  335. },
  336. onEditDetailSheet: function (args) {
  337. var me = gljOprObj;
  338. if (args.row > me.detailData.length) {
  339. return;
  340. }
  341. if (args.row == me.detailData.length && args.editingText == null) {
  342. return;
  343. }
  344. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  345. var detailList = me.detailData;
  346. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  347. args.editingText = args.editingText.replace(/)/g, ")");
  348. setTimeout(function () {//这里须用延时执行的办法,不然的弹窗确认窗口会和spreadjs 的事件有冲突,造成定额工料机数据不会根据树结点更新的问题
  349. if (args.row == detailList.length) {
  350. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected);
  351. }
  352. if (args.row < detailList.length) {
  353. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected);
  354. }
  355. }, 100);
  356. },
  357. onEditGLJSheet: function (args) {
  358. var me = gljOprObj;
  359. if (args.row >= me.sheetData.length) {
  360. me.sheet.getCell(args.row, args.col).value(null);
  361. return;
  362. }
  363. me.updateRationGLJ(args);
  364. },
  365. onEditAssSheet: function (args) {
  366. var me = gljOprObj;
  367. if (args.row >= me.assSheetData.length) {
  368. me.assSheet.getCell(args.row, args.col).value(null);
  369. return;
  370. }
  371. if (me.assSetting.header[args.col].dataCode == 'actualValue') {//自定义消耗量
  372. me.updateRationAss(args);
  373. }
  374. },
  375. onButtonClick: function (sender, args) {
  376. var me = gljOprObj;
  377. var sheet = args.sheet, row = args.row, col = args.col;
  378. var cellType = sheet.getCellType(row, col);
  379. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  380. me.onCusButtonClick(sender, args);
  381. } else {
  382. me.onCheckBoxClick(sender, args)
  383. }
  384. },
  385. onCheckBoxClick: function (sender, args) {
  386. let selected = projectObj.project.mainTree.selected;
  387. if(selected.sourceType == ModuleNames.ration_glj||(selected.sourceType == ModuleNames.ration&&selected.data.type==rationType.gljRation)){//选中的是工料机时不可编辑
  388. return ;
  389. }
  390. var checkboxValue = args.sheet.getCell(args.row, args.col).value();
  391. var newval = 0;
  392. if (checkboxValue) {
  393. newval = 0;
  394. args.sheet.getCell(args.row, args.col).value(newval);
  395. } else {
  396. newval = 1;
  397. args.sheet.getCell(args.row, args.col).value(newval);
  398. }
  399. if (args.sheetName == 'ration_glj') {
  400. gljOprObj.updateIsEstimate(args,newval);
  401. } else if (args.sheetName == 'ration_coe') {
  402. gljOprObj.updateRationCoe(args, newval)
  403. } else if (args.sheetName == 'quantity_detail') {
  404. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  405. } else if (args.sheetName == 'glj_lib') {
  406. gljOprObj.setGLJSelection(args, newval);
  407. }
  408. },
  409. onCusButtonClick: function (sender, args) {
  410. var me = gljOprObj;
  411. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  412. var isVisable = floatingObject.isVisible();
  413. if (!isVisable) {
  414. me.coeSheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  415. me.showFloationObject(floatingObject, me.coeSheetData[args.row]);
  416. } else {
  417. var result = me.checkIfNeedUpdate();
  418. if (result.isNeed) {
  419. projectObj.project.ration_coe.updateCustomerCoe(result);
  420. }
  421. floatingObject.isVisible(false);
  422. }
  423. },
  424. onCellClick: function (sender, args) {
  425. var me = gljOprObj;
  426. if (args.row >= me.sheetData.length) {
  427. return;
  428. }
  429. me.editChecking(args);
  430. },
  431. onCellDoubleClick:function (sender, args) {
  432. var me = gljOprObj;
  433. var header = me.setting.header;
  434. if (args.row >= me.sheetData.length) {
  435. return;
  436. }
  437. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  438. if(me.hasComposition(me.sheetData[args.row])){
  439. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  440. }
  441. }
  442. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  443. var isAdd = me.sheetData[args.row].isAdd;
  444. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  445. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  446. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  447. }
  448. }
  449. }
  450. },
  451. onCoeCellClick: function (sender, args) {
  452. var me = gljOprObj;
  453. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  454. var isVisable = floatingObject.isVisible();
  455. /* if($('#dropdown').css("display") == 'none'){
  456. if(args.col==1&&me.coeSheetData.length>args.row&&me.coeSheetData[args.row].coeID==-1){
  457. me.showFloationObject(floatingObject,me.coeSheetData[args.row]);
  458. }
  459. }*/
  460. if (isVisable) {
  461. var result = me.checkIfNeedUpdate();
  462. if (result.isNeed) {
  463. projectObj.project.ration_coe.updateCustomerCoe(result);
  464. }
  465. floatingObject.isVisible(false);
  466. // $('#dropdown').hide();
  467. }
  468. },
  469. showFloationObject(floatingObject, data){
  470. floatingObject.isVisible(true);
  471. var sheet = this.coeSheet;
  472. var startRow = this.coeSheetData.length;
  473. var endRow = startRow + 7;
  474. floatingObject.startRow(startRow);
  475. floatingObject.startColumn(1);
  476. floatingObject.endColumn(2);
  477. floatingObject.endRow(endRow);
  478. this.bindFloadingObjectValue(data);
  479. sheet.repaint();
  480. // var editPosition = $("#edit").offset();
  481. //$('#dropdown').show();
  482. //var top =editPosition.top>=825?825:editPosition.top
  483. //$('#dropdown').offset({left:editPosition.left,top:top});//top: 791px; left:70px;
  484. },
  485. bindFloadingObjectValue(data){
  486. $('#coe_ration').val(data.coes[0].amount);
  487. $('#manual').val(data.coes[1].amount);
  488. $('#material').val(data.coes[2].amount);
  489. $('#manchine').val(data.coes[3].amount);
  490. $('#mainM').val(data.coes[4].amount);
  491. $('#equipment').val(data.coes[5].amount);
  492. },
  493. onInputChange(id, name){
  494. var coe = _.find(gljOprObj.coeSheetData, function (c) {
  495. return c.coeID == -1;
  496. });
  497. var newValue = gljOprObj.numberValueChecking($('#' + id).val());
  498. if (newValue) {
  499. newValue = _.round(newValue, 2);
  500. if (newValue == coe.coes[name].amount) return;
  501. if (id == 'coe_ration') {
  502. $('#coe_ration').val(newValue);
  503. $('#manual').val(newValue);
  504. $('#material').val(newValue);
  505. $('#manchine').val(newValue);
  506. $('#mainM').val(newValue);
  507. $('#equipment').val(newValue);
  508. } else {
  509. $('#' + id).val(newValue);
  510. }
  511. } else {
  512. $('#' + id).val(coe.coes[name].amount);
  513. }
  514. },
  515. checkIfNeedUpdate(){
  516. var data = _.find(gljOprObj.coeSheetData, function (c) {
  517. return c.coeID == -1;
  518. });
  519. var result = {
  520. isNeed: false
  521. }
  522. var coe_ration = $('#coe_ration').val();
  523. var manual = $('#manual').val();
  524. var material = $('#material').val();
  525. var manchine = $('#manchine').val();
  526. var mainM = $('#mainM').val();
  527. var equipment = $('#equipment').val();
  528. if (coe_ration != data.coes[0].amount) {
  529. result.isNeed = true;
  530. data.coes[0].amount = coe_ration;
  531. }
  532. if (manual != data.coes[1].amount) {
  533. result.isNeed = true;
  534. data.coes[1].amount = manual;
  535. }
  536. if (material != data.coes[2].amount) {
  537. result.isNeed = true;
  538. data.coes[2].amount = material;
  539. }
  540. if (manchine != data.coes[3].amount) {
  541. result.isNeed = true;
  542. data.coes[3].amount = manchine;
  543. }
  544. if (mainM != data.coes[4].amount) {
  545. result.isNeed = true;
  546. data.coes[4].amount = mainM;
  547. }
  548. if (equipment != data.coes[5].amount) {
  549. result.isNeed = true;
  550. data.coes[5].amount = equipment;
  551. }
  552. if (result.isNeed) {
  553. result.doc = {
  554. coes: data.coes
  555. };
  556. result.query = {
  557. projectID: data.projectID,
  558. ID: data.ID,
  559. rationID: data.rationID
  560. };
  561. }
  562. return result;
  563. },
  564. editChecking: function (args) {
  565. var me = gljOprObj;
  566. var header = me.setting.header;
  567. var disable = null;
  568. if (me.sheetData[args.row] != undefined) {
  569. if (me.sheetData[args.row].isMixRatio) {
  570. disable = true;
  571. }else {
  572. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  573. if(me.hasComposition(me.sheetData[args.row])){
  574. disable = true;
  575. }else {
  576. disable = false;
  577. }
  578. }
  579. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  580. var isAdd = me.sheetData[args.row].isAdd;
  581. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  582. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  583. disable = true;
  584. }else {
  585. disable = false;
  586. }
  587. } else {
  588. disable = true;
  589. }
  590. }
  591. }
  592. }
  593. if (disable != null) {
  594. me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
  595. }
  596. },
  597. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  598. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  599. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  600. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  601. let con_key = this.getIndex(ration_glj,keyArray);
  602. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  603. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  604. return true;
  605. }
  606. }
  607. return false;
  608. },
  609. addDropDownList: function () {
  610. var sheet = this.coeSheet;
  611. sheet.suspendPaint();
  612. var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe");
  613. var div = document.createElement('div');
  614. div.innerHTML = this.generateHtmlString();
  615. customFloatingObject.startRow(1);
  616. customFloatingObject.startColumn(1);
  617. customFloatingObject.endColumn(2);
  618. customFloatingObject.endRow(2);
  619. $(div).css('background', 'white');
  620. customFloatingObject.content(div);
  621. sheet.floatingObjects.add(customFloatingObject);
  622. customFloatingObject.isVisible(false);
  623. sheet.resumePaint();
  624. },
  625. addCusButton: function (row, col, text) {
  626. var cus_button = new GC.Spread.Sheets.CellTypes.Button();
  627. gljOprObj.coeSheet.setCellType(row, col, cus_button, GC.Spread.Sheets.SheetArea.viewport);
  628. cus_button.marginLeft(0);
  629. cus_button.marginTop(0);
  630. cus_button.marginRight(0);
  631. cus_button.marginBottom(0);
  632. cus_button.text(text);
  633. cus_button.buttonBackColor('white');
  634. gljOprObj.coeSheet.repaint();
  635. },
  636. onRangeChanged: function (sender, args) {
  637. var me = gljOprObj;
  638. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  639. args.editingText = null;
  640. if (args.sheetName == 'ration_glj') {
  641. me.onEditGLJSheet(args);
  642. }
  643. if (args.sheetName == 'ration_ass') {
  644. me.updateRationAss(args);
  645. }
  646. }
  647. ;
  648. },
  649. generateHtmlString: function () {
  650. // return "<div id='edit'><div>";
  651. var newString = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
  652. //newString +="<tr><td style='height:15px' colspan='2'>自定义系数</td></tr>"
  653. newString += this.getOneRow('定额', 0, 'coe_ration');
  654. newString += this.getOneRow('人工', 1, 'manual');
  655. newString += this.getOneRow('材料', 2, 'material');
  656. newString += this.getOneRow('机械', 3, 'manchine');
  657. newString += this.getOneRow('主材', 4, 'mainM');
  658. newString += this.getOneRow('设备', 5, 'equipment');
  659. newString += "</table></form>";
  660. return newString;
  661. //"<form id='edit'><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;><tr style='height:10px'><td style='width: 50px'>定额:</td><td style='width: 70px' align='right'><input type='text'value='1' name='ration' style='width:30px;border:0;height:14px' align='right'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr ><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr><tr><td>定额:</td><td><input type='text' style='width:50px;border:0;height:10px'></td></tr></table></form>";
  662. },
  663. getOneRow: function (text, name, id) {
  664. var rowstr = "<tr style='height:10px'><td style='width: 50px'>" + text
  665. + ":</td><td style='width: 70px' align='right'><input type='text'value='1' name=" + name
  666. + " style='width:30px;border:0;height:14px' align='right' id=" + id + " onchange='gljOprObj.onInputChange(this.id,this.name)'></td></tr>";
  667. return rowstr;
  668. },
  669. showDataIfRationSelect: function (node) {
  670. var isShow = false;
  671. if (node) {
  672. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  673. return;
  674. } else {
  675. this.selectedNodeId = node.getID();
  676. }
  677. if (node.sourceType == "ration") {
  678. if(node.data.type==rationType.gljRation){
  679. this.showMixRatio(node);
  680. }else {
  681. this.showRationGLJData(node);
  682. this.showRationCoeData(node);
  683. this.showRationAssData(node);
  684. }
  685. isShow = true;
  686. }
  687. if(node.sourceType == ModuleNames.ration_glj){
  688. this.showMixRatio(node);
  689. isShow = true;
  690. }
  691. this.showQuantityDetailData(node);
  692. } else {
  693. this.selectedNodeId = null;
  694. }
  695. if (!isShow) {
  696. this.clearSheetData();
  697. }
  698. //hide floatingObject
  699. var floatingObject = this.coeSheet.floatingObjects.get('customerCoe');
  700. if (floatingObject) {
  701. floatingObject.isVisible(false);
  702. }
  703. // $('#dropdown').hide();
  704. },
  705. showMixRatio:function (node) {//显示组成物到定额工料机
  706. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  707. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  708. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  709. let connect_index = this.getIndex(node.data,indexArray);
  710. let gljList=[];
  711. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  712. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  713. }
  714. if(gljList.length>0){//计算总消耗量
  715. if(node.sourceType==ModuleNames.ration){
  716. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  717. }else {
  718. let totalQuantity = this.getTotalQuantity(node.data);
  719. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  720. }
  721. }
  722. this.sheetData = gljList;
  723. this.sheet.setRowCount(0);
  724. this.sheetData = sortRationGLJ(this.sheetData);
  725. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  726. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  727. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  728. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  729. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  730. this.coeSheetData = [];
  731. this.assSheetData = [];
  732. },
  733. showRationGLJData: function (node) {
  734. var gljList = [];
  735. var ration_glj = projectObj.project.ration_glj;
  736. node = node ? node : projectObj.project.mainTree.selected;
  737. if (node.sourceType == ModuleNames.ration) {
  738. let ration = node.data;
  739. gljList = this.filterGljByRation(ration, ration_glj.datas);
  740. this.showInSheet(gljList);
  741. }
  742. },
  743. showRationGLJSheetData: function (init) {
  744. this.combineWithProjectGlj(this.sheetData);
  745. this.sheet.setRowCount(0);
  746. //console.log(+new Date())
  747. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  748. this.sheetData = sortRationGLJ(this.sheetData);
  749. this.sumQuantity();//计算总消耗量
  750. this.addMixRatioToShow();//显示组成物信息
  751. this.initRationTree(init);
  752. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  753. },
  754. initRationTree: function (init) {
  755. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  756. for (var i = 0; i < this.sheetData.length; i++) {
  757. if (this.sheetData[i].hasOwnProperty('subList')) {
  758. var collapsed = false;
  759. if (init) {
  760. this.sheetData[i].collapsed = true;
  761. collapsed = true;
  762. } else {
  763. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  764. }
  765. if (collapsed == true) {
  766. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  767. }
  768. //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);
  769. //这个方法导致加载缓慢
  770. }
  771. }
  772. },
  773. filterGljByRation: function (ration, datas) {
  774. var gljList = [];
  775. if (datas && datas.length > 0) {
  776. gljList = _.filter(datas, {'rationID': ration.ID})
  777. }
  778. return gljList;
  779. },
  780. showInSheet: function (gljList) {
  781. this.sheetData = gljList;
  782. this.showRationGLJSheetData(true);
  783. },
  784. sumQuantity: function (node) {
  785. if (this.sheetData.length > 0) {
  786. node = node ? node : projectObj.project.mainTree.selected;
  787. let ration = node.data;
  788. let quantity = ration.quantity;
  789. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
  790. for (let glj of this.sheetData) {
  791. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  792. }
  793. }
  794. },
  795. getTotalQuantity:function(glj,ration){
  796. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  797. if(ration){
  798. let quantity = ration.quantity;
  799. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
  800. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  801. return;
  802. }
  803. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  804. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  805. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  806. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  807. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  808. }
  809. return glj.totalQuantity;
  810. }
  811. },
  812. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  813. for (let subG of mList) {
  814. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  815. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  816. }
  817. },
  818. addMixRatioToShow: function () {
  819. var newList = [];
  820. _.remove(this.sheetData, {'isMixRatio': true});
  821. for (var i = 0; i < this.sheetData.length; i++) {
  822. newList.push(this.sheetData[i]);
  823. if (this.sheetData[i].hasOwnProperty('subList')) {
  824. newList = newList.concat(this.sheetData[i].subList);
  825. }
  826. }
  827. this.sheetData = newList;
  828. },
  829. combineWithProjectGlj: function (ration_gljs) {
  830. var projectGLJData = projectObj.project.projectGLJ.datas;
  831. var projectGljs = projectGLJData.gljList;
  832. var mixRatioMap = projectGLJData.mixRatioMap;
  833. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  834. for (var i = 0; i < ration_gljs.length; i++) {
  835. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  836. if (glj) {
  837. let typeString = ration_gljs[i].type + "";
  838. if (typeString.startsWith("2") != -1||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  839. ration_gljs[i].isEstimate = glj.is_evaluate;
  840. }
  841. ration_gljs[i].isAdd = glj.unit_price.is_add;
  842. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  843. var connect_index = this.getIndex(glj, gljKeyArray);
  844. if (mixRatioMap.hasOwnProperty(connect_index)) {
  845. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  846. ration_gljs[i].subList = mixRatios;
  847. }
  848. }
  849. }
  850. }
  851. return ration_gljs;
  852. },
  853. setGLJPrice:function (data,glj) {
  854. glj = glj?glj:_.find(projectObj.project.projectGLJ.datas.projectGljs, {'id': ration_gljs[i].projectGLJID});
  855. if(this.calcPriceDiff(glj)==true) {//计取价差
  856. data.basePrice = glj.unit_price.base_price;
  857. data.marketPrice = glj.unit_price.market_price;
  858. data.adjustPrice = projectObj.project.projectGLJ.getAdjustPrice(glj);
  859. }else {//不计价差
  860. data.basePrice = glj.unit_price.market_price;
  861. data.marketPrice = glj.unit_price.market_price;
  862. data.adjustPrice = glj.unit_price.market_price;
  863. }
  864. return data;
  865. },
  866. calcPriceDiff:function (glj) {
  867. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  868. if(glj.is_evaluate==1){//先按是否暂估判断
  869. return calcOptions.calc_est;
  870. }
  871. if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
  872. return calcOptions.calc_main;
  873. }
  874. if(glj.unit_price.is_add==1){//再判断是否新增
  875. return calcOptions.calc_add;
  876. }
  877. return true;
  878. },
  879. getIndex(obj, pops){
  880. let t_index = '';
  881. let k_arr = [];
  882. for (let p of pops) {
  883. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  884. k_arr.push(tmpK);
  885. }
  886. t_index = k_arr.join("|-|");
  887. return t_index;
  888. },
  889. getConditionByKey(conKey){//将连接字符串转换成对象
  890. let valueArray = conKey.split("|-|");
  891. let obj ={};
  892. for(let i = 0;i<valueArray.length;i++){
  893. if(valueArray[i]!='null'){
  894. obj[gljKeyArray[i]]=valueArray[i];
  895. }
  896. }
  897. return obj;
  898. },
  899. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  900. var temRationGLJs = [];
  901. for (var i = 0; i < mixRatioList.length; i++) {
  902. var pg = _.find(projectGljs, {
  903. 'code': mixRatioList[i].code,
  904. 'name': mixRatioList[i].name,
  905. 'specs': mixRatioList[i].specs,
  906. 'type': mixRatioList[i].type,
  907. 'unit': mixRatioList[i].unit
  908. });//改关联关系
  909. var tem = {
  910. projectGLJID: pg.id,
  911. code: pg.code,
  912. name: pg.name,
  913. specs: pg.specs,
  914. unit: pg.unit,
  915. shortName: pg.unit_price.short_name,
  916. consumption:mixRatioList[i].consumption,
  917. rationItemQuantity: mixRatioList[i].consumption,
  918. // quantity:mixRatioList[i].consumption,
  919. /* basePrice: pg.unit_price.base_price,
  920. marketPrice: pg.unit_price.market_price,
  921. adjustPrice: pg.adjust_price,*/
  922. //isEstimate: pg.is_evaluate,
  923. isMixRatio: true,
  924. isAdd: pg.unit_price.is_add,
  925. GLJID: pg.glj_id
  926. };
  927. let typeString = pg.type + "";
  928. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  929. tem.isEstimate = pg.is_evaluate;
  930. }
  931. this.setGLJPrice(tem,pg);
  932. temRationGLJs.push(tem);
  933. }
  934. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  935. return temRationGLJs;
  936. },
  937. showRationCoeData: function (node) {
  938. var coeList = [];
  939. var ration_coe = projectObj.project.ration_coe;
  940. var ration = node.data;
  941. if (ration_coe.datas && ration_coe.datas.length > 0) {
  942. coeList = _.filter(ration_coe.datas, {'projectID': ration.projectID, 'rationID': ration.ID})
  943. }
  944. this.showCoeData(this.coeSheet, this.coeSetting, coeList);
  945. this.coeSheetData = coeList;
  946. },
  947. showRationAssData: function (node) {
  948. var assList = node.data.rationAssList ? node.data.rationAssList : [];
  949. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  950. this.assSheetData = assList;
  951. },
  952. showQuantityDetailData: function (node) {
  953. var details = [];
  954. node = node ? node : projectObj.project.mainTree.selected;
  955. var quantity_detail = projectObj.project.quantity_detail;
  956. if (node.sourceType == ModuleNames.ration) {
  957. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  958. } else if (node.sourceType == ModuleNames.bills) {
  959. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  960. }
  961. details = _.sortBy(details, 'seq');
  962. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  963. this.detailData = details;
  964. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  965. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  966. }
  967. },
  968. clearSheetData: function () {
  969. sheetCommonObj.showData(this.sheet, this.setting, []);
  970. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  971. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  972. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  973. this.sheetData = [];
  974. this.coeSheetData = [];
  975. this.assSheetData = [];
  976. //this.detailData=[];
  977. },
  978. /* lockRationGLJCell:function(){
  979. sheetCommonObj.lockCells(this.sheet,this.setting);
  980. },
  981. lockRationCoeCell:function () {
  982. sheetCommonObj.lockCells(this.coeSheet,this.coeSetting);
  983. /!* if(this.coeSheetData){
  984. for(var i =0;i<this.coeSheetData.length;i++){
  985. if(this.coeSheetData[i].coeID==-1){
  986. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  987. }
  988. }
  989. }*!/
  990. },
  991. lockRationGLJCell:function(){
  992. sheetCommonObj.lockCells(this.sheet,this.setting);
  993. },*/
  994. updateRationGLJ: function (args) {
  995. var me = this;
  996. var updateField = me.setting.header[args.col].dataCode;
  997. var recode = me.sheetData[args.row];
  998. var newval;
  999. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  1000. if (args.editingText == null) {
  1001. updateField == 'marketPrice' ? newval = 0 : newval = "";
  1002. } else {
  1003. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  1004. newval = number_util.checkNumberValue(args.editingText, decimal);
  1005. if (newval == null) {
  1006. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1007. return;
  1008. }
  1009. }
  1010. } else {
  1011. if (updateField == 'name' || updateField == 'unit') {
  1012. if (args.editingText === null) {
  1013. alert(me.setting.header[args.col].headerName + '不能为空!');
  1014. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1015. return;
  1016. }
  1017. }
  1018. newval = args.editingText == null ? "" : args.editingText;
  1019. }
  1020. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  1021. return
  1022. }
  1023. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  1024. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  1025. } else {
  1026. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  1027. }
  1028. },
  1029. updateRationTypeGLJ: function (value, node, fieldName) {
  1030. let newval;
  1031. let updatePrice = false;
  1032. if (fieldName == "marketUnitFee") {
  1033. updatePrice = true;
  1034. if (value == null) {
  1035. newval = 0;
  1036. } else {
  1037. var decimal = getDecimal("glj.unitPrice");
  1038. newval = number_util.checkNumberValue(value, decimal);
  1039. }
  1040. } else {
  1041. if (value != null) {
  1042. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value)
  1043. return;
  1044. //update
  1045. }
  1046. }
  1047. if (newval && updatePrice == true) {
  1048. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  1049. return
  1050. }
  1051. projectObj.mainController.refreshTreeNode([node]);
  1052. },
  1053. updateRationAss: function (args) {
  1054. var me = gljOprObj;
  1055. var newval;
  1056. newval = me.numberValueChecking(args.editingText);
  1057. var recode = me.assSheetData[args.row];
  1058. if (args.editingText === null) {
  1059. newval = parseFloat(recode.stdValue);
  1060. }
  1061. var isValidate = false;
  1062. if (newval) {
  1063. isValidate = me.checkingActualValue(recode, newval)
  1064. }
  1065. if (isValidate) {
  1066. newval = scMathUtil.roundTo(newval, -2);
  1067. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
  1068. } else {
  1069. newval = recode.actualValue;
  1070. me.assSheet.getCell(args.row, args.col).value(newval);
  1071. }
  1072. },
  1073. updateRationCoe: function (args, newval) {
  1074. var me = gljOprObj;
  1075. var recode = me.coeSheetData[args.row];
  1076. projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  1077. },
  1078. updateIsEstimate:function (args, newval) {
  1079. var me = gljOprObj;
  1080. if(me.setting.header[args.col].dataCode=="isEstimate"){
  1081. var pspread= new ProjectGLJSpread();
  1082. var recode = me.sheetData[args.row];
  1083. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1084. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  1085. if(glj){
  1086. glj["is_evaluate"]=newval;
  1087. args.fromRG=true;
  1088. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  1089. }
  1090. }
  1091. },
  1092. numberValueChecking: function (val) {
  1093. var newval = Number(val);
  1094. if (number_util.isNumber(newval)) {
  1095. return newval;
  1096. } else {
  1097. if (val) {
  1098. alert('您输入的数据类型不正确,请重新输入。');
  1099. }
  1100. newval = null;
  1101. }
  1102. return newval;
  1103. },
  1104. checkingActualValue(record, newval){
  1105. var minExist = record.minValue && record.minValue != '0' ? true : false;
  1106. var maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  1107. var minValue = parseFloat(record.minValue);
  1108. var maxValue = parseFloat(record.maxValue);
  1109. var stdVale = parseFloat(record.stdValue);
  1110. if (!maxExist && minExist) {
  1111. if (newval < minValue) {
  1112. alert('实际值应≥' + minValue);
  1113. return false;
  1114. }
  1115. }
  1116. if (maxExist && !minExist) {
  1117. if (newval > maxValue) {
  1118. alert('实际值应≤' + maxValue);
  1119. return false;
  1120. }
  1121. }
  1122. if (maxExist && minExist) {
  1123. if (newval < minValue || newval > maxValue) {
  1124. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  1125. return false;
  1126. }
  1127. }
  1128. return true;
  1129. },
  1130. showLibGLJSheetData: function () {
  1131. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1132. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1133. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  1134. },
  1135. filterLibGLJSheetData: function () {
  1136. let me = this;
  1137. let val = $("input[name='glj']:checked").val();
  1138. if (val == 'allGljs') {
  1139. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  1140. } else {
  1141. me.gljLibSheetData = me[val];
  1142. }
  1143. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  1144. me.filterLibGLJByType();
  1145. }
  1146. if (me.gljCurTypeId == undefined) {
  1147. return;
  1148. }
  1149. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1150. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1151. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  1152. });
  1153. } else {
  1154. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  1155. }
  1156. },
  1157. setGLJSelection: function (args, newVal) {
  1158. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1159. this.addGLJsSelection(args, newVal);
  1160. } else {
  1161. this.replaceGLJSelection(args, newVal);
  1162. }
  1163. },
  1164. addGLJsSelection: function (args, newVal) {
  1165. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1166. if (newVal == 1) {
  1167. this.GLJSelection.push(con_key);
  1168. this.gljLibSheetData[args.row].select = 1;
  1169. } else if (newVal == 0) {
  1170. _.pull(this.GLJSelection, con_key);
  1171. this.gljLibSheetData[args.row].select = 0;
  1172. }
  1173. },
  1174. replaceGLJSelection: function (args, newVal) {
  1175. var me = this;
  1176. var oldSelection = this.GLJSelection[0];
  1177. if (newVal == 0) {
  1178. args.sheet.getCell(args.row, args.col).value(1);
  1179. return;
  1180. }
  1181. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  1182. this.gljLibSheetData[args.row].select = 1;
  1183. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1184. var i_key = me.getIndex(item, gljLibKeyArray);
  1185. return oldSelection == i_key;
  1186. });
  1187. if (oindex != -1) {
  1188. args.sheet.getCell(oindex, args.col).value(0);
  1189. this.gljLibSheetData[oindex].select = 0;
  1190. } else {
  1191. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1192. var i_key = me.getIndex(item, gljLibKeyArray);
  1193. return oldSelection == i_key;
  1194. });
  1195. oldData ? oldData.select = 0 : "";
  1196. }
  1197. },
  1198. filterLibGLJByType: function () {
  1199. var me = this;
  1200. var selected = me.sheetData[gljContextMenu.selectedRow];
  1201. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1202. },
  1203. getComboData: function (gljDistType) {
  1204. let me = this;
  1205. let distType;
  1206. let distTypeTree = {
  1207. prefix: 'gljType',
  1208. distTypes: {},
  1209. comboDatas: [],
  1210. distTypesArr: []
  1211. };
  1212. gljDistType.forEach(function (typeData) {
  1213. let typeObj = {
  1214. data: typeData,
  1215. children: [],
  1216. parent: null
  1217. }
  1218. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1219. distTypeTree.distTypesArr.push(typeObj);
  1220. });
  1221. gljDistType.forEach(function (typeData) {
  1222. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1223. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1224. if (parent) {
  1225. distType.parent = parent;
  1226. parent.children.push(distType);
  1227. }
  1228. });
  1229. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1230. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1231. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1232. }
  1233. });
  1234. return distTypeTree;
  1235. },
  1236. doInsertGLJ: function () {
  1237. var me = this;
  1238. var selected = projectObj.project.mainTree.selected;
  1239. var project = projectObj.project;
  1240. if (me.GLJSelection.length <= 0) {
  1241. return;
  1242. }
  1243. $("#glj_tree_div").modal('hide');
  1244. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (node) {
  1245. project.projectGLJ.loadData(function () {
  1246. if(me.hasComposition(node.data,true)){
  1247. me.showMixRatio(node);
  1248. }else {
  1249. me.showRationGLJSheetData();
  1250. }
  1251. });
  1252. })
  1253. },
  1254. doAddGLJ: function () {
  1255. var selected = projectObj.project.mainTree.selected;
  1256. var project = projectObj.project;
  1257. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1258. var rg = _.find(gljOprObj.sheetData, function (item) {
  1259. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1260. return n == i_key
  1261. })
  1262. return rg ? false : true;
  1263. })
  1264. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1265. $("#glj_tree_div").modal('hide');
  1266. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1267. if (result) {
  1268. selected.data.adjustState = result.adjustState;
  1269. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1270. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1271. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1272. gljOprObj.showRationGLJSheetData();
  1273. project.ration_glj.addToMainTree(result.showData);
  1274. project.projectGLJ.loadData(function () {
  1275. project.calcProgram.calcAndSave(selected);
  1276. projectObj.mainController.refreshTreeNode([selected]);
  1277. $.bootstrapLoading.end();
  1278. });
  1279. }
  1280. });//doc.rationID=selected.data.ID;
  1281. } else {
  1282. $("#glj_tree_div").modal('hide');
  1283. }
  1284. },
  1285. doReplaceGLJ: function () {
  1286. var me = this;
  1287. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1288. var project = projectObj.project;
  1289. var selectCode = gljOprObj.GLJSelection[0];
  1290. var selected = projectObj.project.mainTree.selected;
  1291. $("#glj_tree_div").modal('hide');
  1292. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1293. if (result) {
  1294. //result.adjustState;
  1295. var glj_list = projectObj.project.ration_glj.datas;
  1296. var data = result.data;
  1297. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1298. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1299. var nodes = [selected];
  1300. gljOprObj.sheetData[index] = data;
  1301. glj_list[list_index] = data;
  1302. gljOprObj.showRationGLJSheetData();
  1303. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1304. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1305. if (node) {
  1306. project.ration_glj.transferToNodeData(data);
  1307. node.source = data;
  1308. node.data = data;
  1309. }
  1310. node ? nodes.push(node) : "";
  1311. }
  1312. //project.ration_glj.addToMainTree(data);
  1313. selected.data.adjustState = result.adjustState;
  1314. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1315. projectObj.mainController.refreshTreeNode(nodes);
  1316. project.calcProgram.calcAndSave(selected);
  1317. });
  1318. }
  1319. $.bootstrapLoading.end();
  1320. })
  1321. },
  1322. doMReplaceGLJ: function () {
  1323. var me = this;
  1324. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1325. var project = projectObj.project;
  1326. var selectCode = me.GLJSelection[0];
  1327. $("#glj_tree_div").modal('hide');
  1328. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
  1329. var data = result.data;
  1330. var stateList = result.stateList;
  1331. var n_index = me.getIndex(data.query, gljKeyArray);
  1332. var nodes = [];
  1333. _.forEach(project.ration_glj.datas, function (t) {
  1334. var t_index = me.getIndex(t, gljKeyArray);
  1335. if (n_index == t_index) {
  1336. me.updateProperty(t, data.doc);
  1337. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1338. project.ration_glj.transferToNodeData(t);
  1339. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1340. nodes.push(node);
  1341. }
  1342. }
  1343. })
  1344. me.showRationGLJSheetData();
  1345. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1346. project.projectGLJ.loadData(function () {
  1347. project.calcProgram.calcRationsAndSave(rationNodes);
  1348. $.bootstrapLoading.end();
  1349. });
  1350. })
  1351. },
  1352. updateProperty: function (obj, doc) {
  1353. _.forEach(doc, function (n, key) {
  1354. obj[key] = n;
  1355. });
  1356. },
  1357. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1358. var nodes = [];
  1359. var rationNodes = [];
  1360. _.forEach(stateList, function (s) {
  1361. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1362. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1363. })
  1364. if (node) {
  1365. node.data.adjustState = s.adjustState;
  1366. nodes.push(node);
  1367. rationNodes.push(node);
  1368. }
  1369. });
  1370. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1371. projectObj.mainController.refreshTreeNode(nodes);
  1372. return rationNodes;
  1373. },
  1374. refreshView: function () {
  1375. this.showRationGLJData();
  1376. },
  1377. //
  1378. refreshTreeNode: function (obj) {
  1379. if (!obj) {
  1380. return;
  1381. }
  1382. var objectArray = [];
  1383. var nodes = [];
  1384. if (obj instanceof Array) {
  1385. objectArray.concat(obj);
  1386. } else {
  1387. objectArray.push(obj);
  1388. }
  1389. for (let o of objectArray) {
  1390. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1391. return n.sourceType == o.type && n.data.ID == o.ID;
  1392. })
  1393. if (node) {
  1394. for (var k in o.data) {
  1395. node.data[k] = o.data[k];
  1396. }
  1397. nodes.push(node);
  1398. }
  1399. }
  1400. projectObj.mainController.refreshTreeNode(nodes);
  1401. return nodes;
  1402. },
  1403. getTreeNodeCellType: function (data) {
  1404. var ns = GC.Spread.Sheets;
  1405. var rectW = 10;
  1406. var rectH = 10;
  1407. var margin = 3;
  1408. function TreeNodeCellType() {
  1409. }
  1410. function drowRect(ctx, x, y, w, h) {
  1411. ctx.save();
  1412. ctx.strokeStyle = "gray";
  1413. ctx.translate(0.5, 0.5);
  1414. ctx.beginPath();
  1415. var rectX = x + margin;
  1416. var rectY = y + Math.round(h / 2) - rectH / 2;
  1417. ctx.moveTo(rectX, rectY);
  1418. ctx.lineTo(rectX, rectY + rectH);
  1419. ctx.lineTo(rectX + rectW, rectY + rectH);
  1420. ctx.lineTo(rectX + rectW, rectY);
  1421. ctx.lineTo(rectX, rectY);
  1422. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1423. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1424. ctx.stroke();
  1425. ctx.restore();
  1426. }
  1427. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1428. ctx.save();
  1429. ctx.strokeStyle = "#000000";
  1430. ctx.translate(0.5, 0.5);
  1431. ctx.beginPath();
  1432. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1433. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1434. var rectY = y + Math.round(h / 2) - rectH / 2;
  1435. if (collapsed) {
  1436. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1437. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1438. }
  1439. ctx.stroke();
  1440. ctx.restore();
  1441. }
  1442. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1443. offset += 6;
  1444. ctx.save();
  1445. ctx.strokeStyle = "gray";
  1446. ctx.translate(0.5, 0.5);
  1447. ctx.beginPath();
  1448. ctx.moveTo(x + offset, y);
  1449. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1450. offset += 9;
  1451. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1452. if (nextItem && nextItem.isMixRatio) {
  1453. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1454. ctx.lineTo(x + offset - 9, y + h);
  1455. }
  1456. ctx.stroke();
  1457. ctx.restore();
  1458. return offset;
  1459. }
  1460. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1461. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1462. if (value != null) {
  1463. var offset = margin + rectW + 6;
  1464. var recode = data[options.row];
  1465. if (recode && recode.hasOwnProperty('subList')) {
  1466. drowRect(ctx, x, y, w, h);
  1467. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1468. drowSymbol(ctx, x, y, w, h, collapsed);
  1469. } else if (recode && recode.isMixRatio) {
  1470. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1471. offset += 1;
  1472. }
  1473. ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
  1474. }
  1475. };
  1476. // override getHitInfo to allow cell type get mouse messages
  1477. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1478. return {
  1479. x: x,
  1480. y: y,
  1481. row: context.row,
  1482. col: context.col,
  1483. cellStyle: cellStyle,
  1484. cellRect: cellRect,
  1485. sheetArea: context.sheetArea
  1486. };
  1487. }
  1488. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1489. var recode = data[hitinfo.row];
  1490. if (recode && recode.hasOwnProperty('subList')) {
  1491. var hoffset = hitinfo.cellRect.x + 3;
  1492. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1493. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1494. collapsed = !collapsed
  1495. recode.collapsed = collapsed;
  1496. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1497. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1498. hitinfo.sheet.invalidateLayout();
  1499. hitinfo.sheet.repaint();
  1500. }
  1501. }
  1502. };
  1503. return new TreeNodeCellType()
  1504. },
  1505. marketPriceReadOnly: function (node) {
  1506. return node.data.type == gljType.CONCRETE || node.data.type == gljType.MORTAR || node.data.type == gljType.MIX_RATIO || node.data.type == gljType.GENERAL_MACHINE || node.data.isEstimate == 1
  1507. }
  1508. }
  1509. $(function () {
  1510. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1511. if (gljOprObj.gljLibSpresd == undefined) {
  1512. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1513. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1514. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1515. gljOprObj.gljLibSheet.options.isProtected = true;
  1516. gljOprObj.gljLibSheet.name('glj_lib');
  1517. }
  1518. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1519. var selected = null;
  1520. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1521. gljOprObj.GLJSelection = [];
  1522. } else {
  1523. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1524. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1525. gljOprObj.GLJSelection = [connect_key];
  1526. gljOprObj.filterLibGLJByType();
  1527. }
  1528. if (selected != null) {
  1529. var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
  1530. var r = _.find(gljOprObj.gljLibSheetData, function (item) {
  1531. var item_key = gljOprObj.getIndex(item, gljKeyArray);
  1532. return s_key == item_key;
  1533. });
  1534. r ? r.select = 1 : "";
  1535. }
  1536. gljOprObj.showLibGLJSheetData();
  1537. });
  1538. $('.glj-radio').change(function () {
  1539. let val = $("input[name='glj']:checked").val();
  1540. if (val == 'allGljs') {
  1541. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1542. gljOprObj.filterLibGLJSheetData();
  1543. gljOprObj.showLibGLJSheetData();
  1544. } else {
  1545. gljOprObj.gljLibSheetData = gljOprObj[val];
  1546. gljOprObj.filterLibGLJSheetData();
  1547. gljOprObj.showLibGLJSheetData();
  1548. }
  1549. })
  1550. $('#glj_selected_conf').click(function () {
  1551. if (gljOprObj.GLJSelection.length < 1) {
  1552. return;
  1553. }
  1554. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1555. gljOprObj.doInsertGLJ();
  1556. } else if ($('#actionType').val() == 'add') { //添加工料机
  1557. gljOprObj.doAddGLJ();
  1558. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1559. gljOprObj.doReplaceGLJ();
  1560. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1561. gljOprObj.doMReplaceGLJ();
  1562. }
  1563. })
  1564. $('#class_selected_conf').click(function () {
  1565. var gljClass = $('#selected_class').val();
  1566. var glj = gljOprObj.selectedGLJClass;
  1567. if (glj && gljClass && gljClass != "") {
  1568. //保存到我的工料机库
  1569. /*1 检查是否有组成物
  1570. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1571. * 3 保存
  1572. * */
  1573. var newItem = {
  1574. code: glj.code,
  1575. name: glj.name,
  1576. specs: glj.specs,
  1577. unit: glj.unit,
  1578. basePrice: glj.basePrice,
  1579. gljType: glj.type,
  1580. shortName: glj.shortName,
  1581. component: [],
  1582. gljClass: gljClass
  1583. };
  1584. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1585. for (var i = 0; i < glj.subList.length; i++) {
  1586. let tem = {
  1587. ID: glj.subList[i].GLJID,
  1588. consumeAmt: glj.rationItemQuantity,
  1589. isStd: true
  1590. }
  1591. newItem.component.push(tem);
  1592. }
  1593. }
  1594. var data = getcmpUpdateData([newItem]);
  1595. $.bootstrapLoading.start();
  1596. var callback = function (data) {
  1597. $("#glj_class_div").modal('hide');
  1598. $.bootstrapLoading.end();
  1599. }
  1600. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1601. $.bootstrapLoading.end();
  1602. });
  1603. }
  1604. })
  1605. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1606. gljOprObj.selectedGLJClass = null;
  1607. $('#class_selected_conf').attr("disabled", "disabled");
  1608. $('#selected_class').val("");
  1609. })
  1610. function getcmpUpdateData(items) {
  1611. var data = {
  1612. "updateItems": [],
  1613. "removeIds": []
  1614. }
  1615. data.addItems = items;
  1616. return data;
  1617. }
  1618. })
  1619. function operationWithRound(value1,value2,field,symble) {
  1620. let decimal = getDecimal(field);
  1621. value1 = scMathUtil.roundForObj(value1,decimal);
  1622. value2 = scMathUtil.roundForObj(value2,decimal);
  1623. let result;
  1624. switch (symble){
  1625. case "+" :
  1626. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1627. break;
  1628. case "-":
  1629. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1630. break;
  1631. case "*":
  1632. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1633. break;
  1634. case "/":
  1635. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1636. break
  1637. }
  1638. return result;
  1639. }
  1640. function getDecimal(fieldID, node) {
  1641. if (node) {
  1642. return decimalObj.decimal(fieldID, node);
  1643. } else if (fieldID.indexOf(".") != -1) {
  1644. var keyArray = fieldID.split(".");
  1645. return decimalObj[keyArray[0]][keyArray[1]];
  1646. } else {
  1647. return decimalObj.decimal(fieldID);
  1648. }
  1649. }
  1650. function getFormatter(decimal) {
  1651. var pre = "0.";
  1652. if (decimal <= 0) {
  1653. return "0";
  1654. }
  1655. for (i = 0; i < decimal; i++) {
  1656. pre += "0"
  1657. }
  1658. return pre;
  1659. }
  1660. function sortRationGLJ(list) {
  1661. list = _.sortByAll(list, [function (item) {
  1662. return item.type + "";
  1663. }, "code"])
  1664. return list;
  1665. }
  1666. function compareRationGLJ(a, b) {
  1667. if ((a.type + "") < (b.type + "")) {
  1668. return true
  1669. }
  1670. if ((a.type + "") == (b.type + "")) {
  1671. if (a.code < b.code) {
  1672. return true
  1673. }
  1674. }
  1675. return false;
  1676. }