glj_view.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  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. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  731. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  732. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  733. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  734. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  735. this.coeSheetData = [];
  736. this.assSheetData = [];
  737. },
  738. showRationGLJData: function (node) {
  739. var gljList = [];
  740. var ration_glj = projectObj.project.ration_glj;
  741. node = node ? node : projectObj.project.mainTree.selected;
  742. if (node.sourceType == ModuleNames.ration) {
  743. if(node.data.type==rationType.gljRation){
  744. this.showMixRatio(node);
  745. }else {
  746. let ration = node.data;
  747. gljList = this.filterGljByRation(ration, ration_glj.datas);
  748. this.showInSheet(gljList);
  749. }
  750. }else if(node.sourceType == ModuleNames.ration_glj){
  751. this.showMixRatio(node);
  752. }
  753. },
  754. showRationGLJSheetData: function (init) {
  755. let selected = this.sheet.getSelections();
  756. this.combineWithProjectGlj(this.sheetData);
  757. this.sheet.setRowCount(0);
  758. //console.log(+new Date())
  759. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  760. this.sheetData = sortRationGLJ(this.sheetData);
  761. this.sumQuantity();//计算总消耗量
  762. this.addMixRatioToShow();//显示组成物信息
  763. this.initRationTree(init);
  764. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  765. if(selected){//定位光标到之前的位置
  766. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  767. }
  768. },
  769. initRationTree: function (init) {
  770. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  771. for (var i = 0; i < this.sheetData.length; i++) {
  772. if (this.sheetData[i].hasOwnProperty('subList')) {
  773. var collapsed = false;
  774. if (init) {
  775. this.sheetData[i].collapsed = true;
  776. collapsed = true;
  777. } else {
  778. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  779. }
  780. if (collapsed == true) {
  781. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  782. }
  783. //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);
  784. //这个方法导致加载缓慢
  785. }
  786. }
  787. },
  788. filterGljByRation: function (ration, datas) {
  789. var gljList = [];
  790. if (datas && datas.length > 0) {
  791. gljList = _.filter(datas, {'rationID': ration.ID})
  792. }
  793. return gljList;
  794. },
  795. showInSheet: function (gljList) {
  796. this.sheetData = gljList;
  797. this.showRationGLJSheetData(true);
  798. },
  799. sumQuantity: function (node) {
  800. if (this.sheetData.length > 0) {
  801. node = node ? node : projectObj.project.mainTree.selected;
  802. let ration = node.data;
  803. let quantity = ration.quantity;
  804. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
  805. for (let glj of this.sheetData) {
  806. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  807. }
  808. }
  809. },
  810. getTotalQuantity:function(glj,ration){
  811. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  812. if(ration){
  813. let quantity = ration.quantity;
  814. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 1 : quantity;
  815. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  816. return;
  817. }
  818. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  819. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  820. console.log(glj.quantity);
  821. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  822. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  823. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  824. }
  825. return glj.totalQuantity;
  826. }
  827. },
  828. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  829. for (let subG of mList) {
  830. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  831. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  832. }
  833. },
  834. addMixRatioToShow: function () {
  835. var newList = [];
  836. _.remove(this.sheetData, {'isMixRatio': true});
  837. for (var i = 0; i < this.sheetData.length; i++) {
  838. newList.push(this.sheetData[i]);
  839. if (this.sheetData[i].hasOwnProperty('subList')) {
  840. newList = newList.concat(this.sheetData[i].subList);
  841. }
  842. }
  843. this.sheetData = newList;
  844. },
  845. combineWithProjectGlj: function (ration_gljs) {
  846. var projectGLJData = projectObj.project.projectGLJ.datas;
  847. var projectGljs = projectGLJData.gljList;
  848. var mixRatioMap = projectGLJData.mixRatioMap;
  849. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  850. for (var i = 0; i < ration_gljs.length; i++) {
  851. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  852. if (glj) {
  853. let typeString = ration_gljs[i].type + "";
  854. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  855. ration_gljs[i].isEstimate = glj.is_evaluate;
  856. }
  857. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  858. ration_gljs[i].isAdd = glj.unit_price.is_add;
  859. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  860. var connect_index = this.getIndex(glj, gljKeyArray);
  861. if (mixRatioMap.hasOwnProperty(connect_index)) {
  862. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  863. ration_gljs[i].subList = mixRatios;
  864. }
  865. }
  866. }
  867. }
  868. return ration_gljs;
  869. },
  870. setGLJPrice:function (data,glj) {
  871. glj = glj?glj:_.find(projectObj.project.projectGLJ.datas.projectGljs, {'id': ration_gljs[i].projectGLJID});
  872. if(this.calcPriceDiff(glj)==true) {//计取价差
  873. data.basePrice = glj.unit_price.base_price;
  874. data.marketPrice = glj.unit_price.market_price;
  875. data.adjustPrice = projectObj.project.projectGLJ.getAdjustPrice(glj);
  876. }else {//不计价差
  877. data.basePrice = glj.unit_price.market_price;
  878. data.marketPrice = glj.unit_price.market_price;
  879. data.adjustPrice = glj.unit_price.market_price;
  880. }
  881. return data;
  882. },
  883. calcPriceDiff:function (glj) {
  884. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  885. if(glj.is_evaluate==1){//先按是否暂估判断
  886. return calcOptions.calc_est;
  887. }
  888. if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
  889. return calcOptions.calc_main;
  890. }
  891. if(glj.unit_price.is_add==1){//再判断是否新增
  892. return calcOptions.calc_add;
  893. }
  894. return true;
  895. },
  896. getIndex(obj, pops){
  897. let t_index = '';
  898. let k_arr = [];
  899. for (let p of pops) {
  900. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  901. k_arr.push(tmpK);
  902. }
  903. t_index = k_arr.join("|-|");
  904. return t_index;
  905. },
  906. getConditionByKey(conKey){//将连接字符串转换成对象
  907. let valueArray = conKey.split("|-|");
  908. let obj ={};
  909. for(let i = 0;i<valueArray.length;i++){
  910. if(valueArray[i]!='null'){
  911. if(gljKeyArray[i]=='type'){
  912. valueArray[i] = parseInt(valueArray[i]);
  913. }
  914. obj[gljKeyArray[i]]=valueArray[i];
  915. }
  916. }
  917. return obj;
  918. },
  919. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  920. var temRationGLJs = [];
  921. for (var i = 0; i < mixRatioList.length; i++) {
  922. var pg = _.find(projectGljs, {
  923. 'code': mixRatioList[i].code,
  924. 'name': mixRatioList[i].name,
  925. 'specs': mixRatioList[i].specs,
  926. 'type': mixRatioList[i].type,
  927. 'unit': mixRatioList[i].unit
  928. });//改关联关系
  929. var tem = {
  930. projectGLJID: pg.id,
  931. code: pg.code,
  932. name: pg.name,
  933. specs: pg.specs,
  934. unit: pg.unit,
  935. type:mixRatioList[i].type,
  936. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  937. consumption:mixRatioList[i].consumption,
  938. rationItemQuantity: mixRatioList[i].consumption,
  939. // quantity:mixRatioList[i].consumption,
  940. /* basePrice: pg.unit_price.base_price,
  941. marketPrice: pg.unit_price.market_price,
  942. adjustPrice: pg.adjust_price,*/
  943. //isEstimate: pg.is_evaluate,
  944. isMixRatio: true,
  945. isAdd: pg.unit_price.is_add,
  946. GLJID: pg.glj_id
  947. };
  948. let typeString = pg.type + "";
  949. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
  950. tem.isEstimate = pg.is_evaluate;
  951. }
  952. this.setGLJPrice(tem,pg);
  953. temRationGLJs.push(tem);
  954. }
  955. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  956. return temRationGLJs;
  957. },
  958. showRationCoeData: function (node) {
  959. var coeList = [];
  960. var ration_coe = projectObj.project.ration_coe;
  961. var ration = node.data;
  962. if (ration_coe.datas && ration_coe.datas.length > 0) {
  963. coeList = _.filter(ration_coe.datas, {'projectID': ration.projectID, 'rationID': ration.ID})
  964. }
  965. this.showCoeData(this.coeSheet, this.coeSetting, coeList);
  966. this.coeSheetData = coeList;
  967. },
  968. showRationAssData: function (node) {
  969. var assList = node.data.rationAssList ? node.data.rationAssList : [];
  970. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  971. this.assSheetData = assList;
  972. },
  973. showQuantityDetailData: function (node) {
  974. var details = [];
  975. node = node ? node : projectObj.project.mainTree.selected;
  976. var quantity_detail = projectObj.project.quantity_detail;
  977. if (node.sourceType == ModuleNames.ration) {
  978. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  979. } else if (node.sourceType == ModuleNames.bills) {
  980. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  981. }
  982. details = _.sortBy(details, 'seq');
  983. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  984. this.detailData = details;
  985. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  986. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  987. }
  988. },
  989. clearSheetData: function () {
  990. sheetCommonObj.showData(this.sheet, this.setting, []);
  991. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  992. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  993. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  994. this.sheetData = [];
  995. this.coeSheetData = [];
  996. this.assSheetData = [];
  997. //this.detailData=[];
  998. },
  999. /* lockRationGLJCell:function(){
  1000. sheetCommonObj.lockCells(this.sheet,this.setting);
  1001. },
  1002. lockRationCoeCell:function () {
  1003. sheetCommonObj.lockCells(this.coeSheet,this.coeSetting);
  1004. /!* if(this.coeSheetData){
  1005. for(var i =0;i<this.coeSheetData.length;i++){
  1006. if(this.coeSheetData[i].coeID==-1){
  1007. this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  1008. }
  1009. }
  1010. }*!/
  1011. },
  1012. lockRationGLJCell:function(){
  1013. sheetCommonObj.lockCells(this.sheet,this.setting);
  1014. },*/
  1015. updateRationGLJ: function (args) {
  1016. var me = this;
  1017. var updateField = me.setting.header[args.col].dataCode;
  1018. var recode = me.sheetData[args.row];
  1019. var newval;
  1020. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  1021. if (args.editingText == null) {
  1022. updateField == 'marketPrice' ? newval = 0 : newval = "";
  1023. } else {
  1024. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  1025. newval = number_util.checkNumberValue(args.editingText, decimal);
  1026. if (newval == null) {
  1027. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1028. return;
  1029. }
  1030. }
  1031. } else {
  1032. if (updateField == 'name' || updateField == 'unit') {
  1033. if (args.editingText === null) {
  1034. alert(me.setting.header[args.col].headerName + '不能为空!');
  1035. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1036. return;
  1037. }
  1038. }
  1039. newval = args.editingText == null ? "" : args.editingText;
  1040. }
  1041. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  1042. return
  1043. }
  1044. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  1045. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  1046. } else {
  1047. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  1048. }
  1049. },
  1050. updateRationTypeGLJ: function (value, node, fieldName) {
  1051. let newval;
  1052. let updatePrice = false;
  1053. if (fieldName == "marketUnitFee") {
  1054. updatePrice = true;
  1055. if (value == null) {
  1056. newval = 0;
  1057. } else {
  1058. var decimal = getDecimal("glj.unitPrice");
  1059. newval = number_util.checkNumberValue(value, decimal);
  1060. }
  1061. } else {
  1062. if (value != null) {
  1063. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value)
  1064. return;
  1065. //update
  1066. }
  1067. }
  1068. if (newval && updatePrice == true) {
  1069. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  1070. return
  1071. }
  1072. projectObj.mainController.refreshTreeNode([node]);
  1073. },
  1074. updateRationAss: function (args) {
  1075. var me = gljOprObj;
  1076. var newval;
  1077. newval = me.numberValueChecking(args.editingText);
  1078. var recode = me.assSheetData[args.row];
  1079. if (args.editingText === null) {
  1080. newval = parseFloat(recode.stdValue);
  1081. }
  1082. var isValidate = false;
  1083. if (newval) {
  1084. isValidate = me.checkingActualValue(recode, newval)
  1085. }
  1086. if (isValidate) {
  1087. newval = scMathUtil.roundTo(newval, -2);
  1088. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
  1089. } else {
  1090. newval = recode.actualValue;
  1091. me.assSheet.getCell(args.row, args.col).value(newval);
  1092. }
  1093. },
  1094. updateRationCoe: function (args, newval) {
  1095. var me = gljOprObj;
  1096. var recode = me.coeSheetData[args.row];
  1097. projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  1098. },
  1099. updateIsEstimate:function (args, newval) {
  1100. var me = gljOprObj;
  1101. if(me.setting.header[args.col].dataCode=="isEstimate"){
  1102. var pspread= new ProjectGLJSpread();
  1103. var recode = me.sheetData[args.row];
  1104. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1105. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  1106. if(glj){
  1107. glj["is_evaluate"]=newval;
  1108. args.fromRG=true;
  1109. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  1110. }
  1111. }
  1112. },
  1113. numberValueChecking: function (val) {
  1114. var newval = Number(val);
  1115. if (number_util.isNumber(newval)) {
  1116. return newval;
  1117. } else {
  1118. if (val) {
  1119. alert('您输入的数据类型不正确,请重新输入。');
  1120. }
  1121. newval = null;
  1122. }
  1123. return newval;
  1124. },
  1125. checkingActualValue(record, newval){
  1126. var minExist = record.minValue && record.minValue != '0' ? true : false;
  1127. var maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  1128. var minValue = parseFloat(record.minValue);
  1129. var maxValue = parseFloat(record.maxValue);
  1130. var stdVale = parseFloat(record.stdValue);
  1131. if (!maxExist && minExist) {
  1132. if (newval < minValue) {
  1133. alert('实际值应≥' + minValue);
  1134. return false;
  1135. }
  1136. }
  1137. if (maxExist && !minExist) {
  1138. if (newval > maxValue) {
  1139. alert('实际值应≤' + maxValue);
  1140. return false;
  1141. }
  1142. }
  1143. if (maxExist && minExist) {
  1144. if (newval < minValue || newval > maxValue) {
  1145. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  1146. return false;
  1147. }
  1148. }
  1149. return true;
  1150. },
  1151. showLibGLJSheetData: function () {
  1152. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1153. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1154. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  1155. },
  1156. filterLibGLJSheetData: function () {
  1157. let me = this;
  1158. let val = $("input[name='glj']:checked").val();
  1159. if (val == 'allGljs') {
  1160. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  1161. } else {
  1162. me.gljLibSheetData = me[val];
  1163. }
  1164. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  1165. me.filterLibGLJByType();
  1166. }
  1167. if (me.gljCurTypeId == undefined) {
  1168. return;
  1169. }
  1170. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1171. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1172. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  1173. });
  1174. } else {
  1175. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  1176. }
  1177. },
  1178. setGLJSelection: function (args, newVal) {
  1179. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1180. this.addGLJsSelection(args, newVal);
  1181. } else {
  1182. this.replaceGLJSelection(args, newVal);
  1183. }
  1184. },
  1185. addGLJsSelection: function (args, newVal) {
  1186. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1187. if (newVal == 1) {
  1188. this.GLJSelection.push(con_key);
  1189. this.gljLibSheetData[args.row].select = 1;
  1190. } else if (newVal == 0) {
  1191. _.pull(this.GLJSelection, con_key);
  1192. this.gljLibSheetData[args.row].select = 0;
  1193. }
  1194. },
  1195. replaceGLJSelection: function (args, newVal) {
  1196. var me = this;
  1197. var oldSelection = this.GLJSelection[0];
  1198. if (newVal == 0) {
  1199. args.sheet.getCell(args.row, args.col).value(1);
  1200. return;
  1201. }
  1202. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  1203. this.gljLibSheetData[args.row].select = 1;
  1204. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1205. var i_key = me.getIndex(item, gljLibKeyArray);
  1206. return oldSelection == i_key;
  1207. });
  1208. if (oindex != -1) {
  1209. args.sheet.getCell(oindex, args.col).value(0);
  1210. this.gljLibSheetData[oindex].select = 0;
  1211. } else {
  1212. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1213. var i_key = me.getIndex(item, gljLibKeyArray);
  1214. return oldSelection == i_key;
  1215. });
  1216. oldData ? oldData.select = 0 : "";
  1217. }
  1218. },
  1219. filterLibGLJByType: function () {
  1220. var me = this;
  1221. var selected = me.sheetData[gljContextMenu.selectedRow];
  1222. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1223. },
  1224. getComboData: function (gljDistType) {
  1225. let me = this;
  1226. let distType;
  1227. let distTypeTree = {
  1228. prefix: 'gljType',
  1229. distTypes: {},
  1230. comboDatas: [],
  1231. distTypesArr: []
  1232. };
  1233. gljDistType.forEach(function (typeData) {
  1234. let typeObj = {
  1235. data: typeData,
  1236. children: [],
  1237. parent: null
  1238. }
  1239. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1240. distTypeTree.distTypesArr.push(typeObj);
  1241. });
  1242. gljDistType.forEach(function (typeData) {
  1243. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1244. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1245. if (parent) {
  1246. distType.parent = parent;
  1247. parent.children.push(distType);
  1248. }
  1249. });
  1250. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1251. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1252. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1253. }
  1254. });
  1255. return distTypeTree;
  1256. },
  1257. doInsertGLJ: function () {
  1258. var me = this;
  1259. var selected = projectObj.project.mainTree.selected;
  1260. var project = projectObj.project;
  1261. if (me.GLJSelection.length <= 0) {
  1262. return;
  1263. }
  1264. $("#glj_tree_div").modal('hide');
  1265. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (node) {
  1266. project.projectGLJ.loadData(function () {
  1267. if(me.hasComposition(node.data,true)){
  1268. me.showMixRatio(node);
  1269. }else {
  1270. me.showRationGLJSheetData();
  1271. }
  1272. });
  1273. })
  1274. },
  1275. doAddGLJ: function () {
  1276. var selected = projectObj.project.mainTree.selected;
  1277. var project = projectObj.project;
  1278. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1279. var rg = _.find(gljOprObj.sheetData, function (item) {
  1280. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1281. return n == i_key
  1282. })
  1283. return rg ? false : true;
  1284. })
  1285. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1286. $("#glj_tree_div").modal('hide');
  1287. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1288. if (result) {
  1289. selected.data.adjustState = result.adjustState;
  1290. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1291. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1292. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1293. project.ration_glj.addToMainTree(result.showData);
  1294. project.projectGLJ.loadData(function () {
  1295. gljOprObj.showRationGLJSheetData();
  1296. project.calcProgram.calcAndSave(selected);
  1297. projectObj.mainController.refreshTreeNode([selected]);
  1298. $.bootstrapLoading.end();
  1299. });
  1300. }
  1301. });//doc.rationID=selected.data.ID;
  1302. } else {
  1303. $("#glj_tree_div").modal('hide');
  1304. }
  1305. },
  1306. doReplaceGLJ: function () {
  1307. var me = this;
  1308. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1309. var project = projectObj.project;
  1310. var selectCode = gljOprObj.GLJSelection[0];
  1311. var selected = projectObj.project.mainTree.selected;
  1312. $("#glj_tree_div").modal('hide');
  1313. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1314. if (result) {
  1315. //result.adjustState;
  1316. var glj_list = projectObj.project.ration_glj.datas;
  1317. var data = result.data;
  1318. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1319. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1320. var nodes = [selected];
  1321. gljOprObj.sheetData[index] = data;
  1322. glj_list[list_index] = data;
  1323. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1324. gljOprObj.showRationGLJSheetData();
  1325. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1326. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1327. if (node) {
  1328. project.ration_glj.transferToNodeData(data);
  1329. node.source = data;
  1330. node.data = data;
  1331. }
  1332. node ? nodes.push(node) : "";
  1333. }
  1334. //project.ration_glj.addToMainTree(data);
  1335. selected.data.adjustState = result.adjustState;
  1336. projectObj.mainController.refreshTreeNode(nodes);
  1337. project.calcProgram.calcAndSave(selected);
  1338. $.bootstrapLoading.end();
  1339. });
  1340. }
  1341. })
  1342. },
  1343. doMReplaceGLJ: function () {
  1344. var me = this;
  1345. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1346. var project = projectObj.project;
  1347. var selectCode = me.GLJSelection[0];
  1348. $("#glj_tree_div").modal('hide');
  1349. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
  1350. var data = result.data;
  1351. var stateList = result.stateList;
  1352. var n_index = me.getIndex(data.query, gljKeyArray);
  1353. var nodes = [];
  1354. _.forEach(project.ration_glj.datas, function (t) {
  1355. var t_index = me.getIndex(t, gljKeyArray);
  1356. if (n_index == t_index) {
  1357. me.updateProperty(t, data.doc);
  1358. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1359. project.ration_glj.transferToNodeData(t);
  1360. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1361. nodes.push(node);
  1362. }
  1363. }
  1364. })
  1365. project.projectGLJ.loadData(function () {
  1366. me.showRationGLJSheetData();
  1367. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1368. project.calcProgram.calcRationsAndSave(rationNodes);
  1369. $.bootstrapLoading.end();
  1370. });
  1371. })
  1372. },
  1373. updateProperty: function (obj, doc) {
  1374. _.forEach(doc, function (n, key) {
  1375. obj[key] = n;
  1376. });
  1377. },
  1378. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1379. var nodes = [];
  1380. var rationNodes = [];
  1381. _.forEach(stateList, function (s) {
  1382. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1383. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1384. })
  1385. if (node) {
  1386. node.data.adjustState = s.adjustState;
  1387. nodes.push(node);
  1388. rationNodes.push(node);
  1389. }
  1390. });
  1391. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1392. projectObj.mainController.refreshTreeNode(nodes);
  1393. return rationNodes;
  1394. },
  1395. refreshView: function () {
  1396. this.showRationGLJData();
  1397. },
  1398. //
  1399. refreshTreeNode: function (obj) {
  1400. if (!obj) {
  1401. return;
  1402. }
  1403. var objectArray = [];
  1404. var nodes = [];
  1405. if (obj instanceof Array) {
  1406. objectArray.concat(obj);
  1407. } else {
  1408. objectArray.push(obj);
  1409. }
  1410. for (let o of objectArray) {
  1411. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1412. return n.sourceType == o.type && n.data.ID == o.ID;
  1413. })
  1414. if (node) {
  1415. for (var k in o.data) {
  1416. node.data[k] = o.data[k];
  1417. }
  1418. nodes.push(node);
  1419. }
  1420. }
  1421. projectObj.mainController.refreshTreeNode(nodes);
  1422. return nodes;
  1423. },
  1424. getTreeNodeCellType: function (data) {
  1425. var ns = GC.Spread.Sheets;
  1426. var rectW = 10;
  1427. var rectH = 10;
  1428. var margin = 3;
  1429. function TreeNodeCellType() {
  1430. }
  1431. function drowRect(ctx, x, y, w, h) {
  1432. ctx.save();
  1433. ctx.strokeStyle = "gray";
  1434. ctx.translate(0.5, 0.5);
  1435. ctx.beginPath();
  1436. var rectX = x + margin;
  1437. var rectY = y + Math.round(h / 2) - rectH / 2;
  1438. ctx.moveTo(rectX, rectY);
  1439. ctx.lineTo(rectX, rectY + rectH);
  1440. ctx.lineTo(rectX + rectW, rectY + rectH);
  1441. ctx.lineTo(rectX + rectW, rectY);
  1442. ctx.lineTo(rectX, rectY);
  1443. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1444. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1445. ctx.stroke();
  1446. ctx.restore();
  1447. }
  1448. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1449. ctx.save();
  1450. ctx.strokeStyle = "#000000";
  1451. ctx.translate(0.5, 0.5);
  1452. ctx.beginPath();
  1453. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1454. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1455. var rectY = y + Math.round(h / 2) - rectH / 2;
  1456. if (collapsed) {
  1457. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1458. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1459. }
  1460. ctx.stroke();
  1461. ctx.restore();
  1462. }
  1463. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1464. offset += 6;
  1465. ctx.save();
  1466. ctx.strokeStyle = "gray";
  1467. ctx.translate(0.5, 0.5);
  1468. ctx.beginPath();
  1469. ctx.moveTo(x + offset, y);
  1470. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1471. offset += 9;
  1472. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1473. if (nextItem && nextItem.isMixRatio) {
  1474. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1475. ctx.lineTo(x + offset - 9, y + h);
  1476. }
  1477. ctx.stroke();
  1478. ctx.restore();
  1479. return offset;
  1480. }
  1481. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1482. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1483. if (value != null) {
  1484. var offset = margin + rectW + 6;
  1485. var recode = data[options.row];
  1486. if (recode && recode.hasOwnProperty('subList')) {
  1487. drowRect(ctx, x, y, w, h);
  1488. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1489. drowSymbol(ctx, x, y, w, h, collapsed);
  1490. } else if (recode && recode.isMixRatio) {
  1491. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1492. offset += 1;
  1493. }
  1494. ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
  1495. }
  1496. };
  1497. // override getHitInfo to allow cell type get mouse messages
  1498. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1499. return {
  1500. x: x,
  1501. y: y,
  1502. row: context.row,
  1503. col: context.col,
  1504. cellStyle: cellStyle,
  1505. cellRect: cellRect,
  1506. sheetArea: context.sheetArea
  1507. };
  1508. }
  1509. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1510. var recode = data[hitinfo.row];
  1511. if (recode && recode.hasOwnProperty('subList')) {
  1512. var hoffset = hitinfo.cellRect.x + 3;
  1513. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1514. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1515. collapsed = !collapsed
  1516. recode.collapsed = collapsed;
  1517. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1518. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1519. hitinfo.sheet.invalidateLayout();
  1520. hitinfo.sheet.repaint();
  1521. }
  1522. }
  1523. };
  1524. return new TreeNodeCellType()
  1525. },
  1526. marketPriceReadOnly: function (node) {
  1527. let hasCom = false;
  1528. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1529. hasCom = this.hasComposition(node.data,true);
  1530. }else {
  1531. hasCom = this.hasComposition(node.data);
  1532. }
  1533. return hasCom|| node.data.isEstimate == 1;
  1534. }
  1535. }
  1536. $(function () {
  1537. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1538. if (gljOprObj.gljLibSpresd == undefined) {
  1539. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1540. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1541. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1542. gljOprObj.gljLibSheet.options.isProtected = true;
  1543. gljOprObj.gljLibSheet.name('glj_lib');
  1544. }
  1545. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1546. var selected = null;
  1547. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1548. gljOprObj.GLJSelection = [];
  1549. } else {
  1550. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1551. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1552. gljOprObj.GLJSelection = [connect_key];
  1553. gljOprObj.filterLibGLJByType();
  1554. }
  1555. if (selected != null) {
  1556. var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
  1557. var r = _.find(gljOprObj.gljLibSheetData, function (item) {
  1558. var item_key = gljOprObj.getIndex(item, gljKeyArray);
  1559. return s_key == item_key;
  1560. });
  1561. r ? r.select = 1 : "";
  1562. }
  1563. gljOprObj.showLibGLJSheetData();
  1564. });
  1565. $('.glj-radio').change(function () {
  1566. let val = $("input[name='glj']:checked").val();
  1567. if (val == 'allGljs') {
  1568. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1569. gljOprObj.filterLibGLJSheetData();
  1570. gljOprObj.showLibGLJSheetData();
  1571. } else {
  1572. gljOprObj.gljLibSheetData = gljOprObj[val];
  1573. gljOprObj.filterLibGLJSheetData();
  1574. gljOprObj.showLibGLJSheetData();
  1575. }
  1576. })
  1577. $('#glj_selected_conf').click(function () {
  1578. if (gljOprObj.GLJSelection.length < 1) {
  1579. return;
  1580. }
  1581. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1582. gljOprObj.doInsertGLJ();
  1583. } else if ($('#actionType').val() == 'add') { //添加工料机
  1584. gljOprObj.doAddGLJ();
  1585. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1586. gljOprObj.doReplaceGLJ();
  1587. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1588. gljOprObj.doMReplaceGLJ();
  1589. }
  1590. })
  1591. $('#class_selected_conf').click(function () {
  1592. var gljClass = $('#selected_class').val();
  1593. var glj = gljOprObj.selectedGLJClass;
  1594. if (glj && gljClass && gljClass != "") {
  1595. //保存到我的工料机库
  1596. /*1 检查是否有组成物
  1597. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1598. * 3 保存
  1599. * */
  1600. var newItem = {
  1601. code: glj.code,
  1602. name: glj.name,
  1603. specs: glj.specs,
  1604. unit: glj.unit,
  1605. basePrice: glj.basePrice,
  1606. gljType: glj.type,
  1607. shortName: glj.shortName,
  1608. component: [],
  1609. gljClass: gljClass
  1610. };
  1611. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1612. for (var i = 0; i < glj.subList.length; i++) {
  1613. let tem = {
  1614. ID: glj.subList[i].GLJID,
  1615. consumeAmt: glj.rationItemQuantity,
  1616. isStd: true
  1617. }
  1618. newItem.component.push(tem);
  1619. }
  1620. }
  1621. var data = getcmpUpdateData([newItem]);
  1622. $.bootstrapLoading.start();
  1623. var callback = function (data) {
  1624. $("#glj_class_div").modal('hide');
  1625. $.bootstrapLoading.end();
  1626. }
  1627. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1628. $.bootstrapLoading.end();
  1629. });
  1630. }
  1631. })
  1632. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1633. gljOprObj.selectedGLJClass = null;
  1634. $('#class_selected_conf').attr("disabled", "disabled");
  1635. $('#selected_class').val("");
  1636. })
  1637. function getcmpUpdateData(items) {
  1638. var data = {
  1639. "updateItems": [],
  1640. "removeIds": []
  1641. }
  1642. data.addItems = items;
  1643. return data;
  1644. }
  1645. })
  1646. function operationWithRound(value1,value2,field,symble) {
  1647. let decimal = getDecimal(field);
  1648. value1 = scMathUtil.roundForObj(value1,decimal);
  1649. value2 = scMathUtil.roundForObj(value2,decimal);
  1650. let result;
  1651. switch (symble){
  1652. case "+" :
  1653. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1654. break;
  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. }
  1665. return result;
  1666. }
  1667. function getDecimal(fieldID, node) {
  1668. if (node) {
  1669. return decimalObj.decimal(fieldID, node);
  1670. } else if (fieldID.indexOf(".") != -1) {
  1671. var keyArray = fieldID.split(".");
  1672. return decimalObj[keyArray[0]][keyArray[1]];
  1673. } else {
  1674. return decimalObj.decimal(fieldID);
  1675. }
  1676. }
  1677. function getFormatter(decimal) {
  1678. var pre = "0.";
  1679. if (decimal <= 0) {
  1680. return "0";
  1681. }
  1682. for (i = 0; i < decimal; i++) {
  1683. pre += "0"
  1684. }
  1685. return pre;
  1686. }
  1687. function sortRationGLJ(list) {
  1688. list = _.sortByAll(list, [function (item) {
  1689. return item.type + "";
  1690. }, "code"])
  1691. return list;
  1692. }
  1693. function compareRationGLJ(a, b) {
  1694. if ((a.type + "") < (b.type + "")) {
  1695. return true
  1696. }
  1697. if ((a.type + "") == (b.type + "")) {
  1698. if (a.code < b.code) {
  1699. return true
  1700. }
  1701. }
  1702. return false;
  1703. }