glj_view.js 61 KB

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