glj_view.js 71 KB

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