glj_view.js 72 KB

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