glj_view.js 72 KB

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