glj_view.js 70 KB

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