glj_view.js 64 KB

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