glj_view.js 72 KB

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