glj_view.js 69 KB

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