glj_view.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  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. checkb: null,
  10. mainTreeSelectedChange:false,
  11. detailSheet: null,
  12. detailData: [],
  13. GLJSelection: [],
  14. selectedGLJClass: null,
  15. parentNodeIds: {},
  16. activeTab: '#linkGLJ',
  17. setting: {},
  18. detailSetting: {
  19. header: [
  20. {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
  21. {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
  22. {headerName: "结果(C)", headerWidth: 120, dataCode: "result", dataType: "Number", decimalField: "quantity_detail"},
  23. {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
  24. ],
  25. view: {
  26. lockColumns: [2, 3]
  27. }
  28. },
  29. gljTreeSetting: {
  30. view: {
  31. expandSpeed: "",
  32. selectedMulti: false
  33. },
  34. edit: {
  35. enable: false,
  36. editNameSelectAll: true,
  37. showRemoveBtn: true,
  38. showRenameBtn: true,
  39. removeTitle: "删除节点",
  40. renameTitle: "更改名称"
  41. },
  42. data: {
  43. keep: {
  44. parent: true,
  45. leaf: true
  46. },
  47. key: {
  48. children: "items",
  49. name: "Name"
  50. },
  51. simpleData: {
  52. enable: false,
  53. idKey: "ID",
  54. pIdKey: "ParentID",
  55. rootPId: -1
  56. }
  57. },
  58. callback: {
  59. onClick: function (event, treeId, treeNode) {
  60. if (treeId == 'gljTree') {
  61. let me = gljOprObj, gljTypeId = treeNode.ID;
  62. if (treeNode.ID) {
  63. me.gljCurTypeId = treeNode.ID;
  64. me.filterLibGLJSheetData();
  65. me.showLibGLJSheetData();
  66. }
  67. } else {
  68. if (treeNode.isParent) {
  69. $('#class_selected_conf').attr("disabled", "disabled");
  70. $('#selected_class').val("");
  71. } else {
  72. $('#class_selected_conf').removeAttr("disabled");
  73. $('#selected_class').val(treeNode.ID);
  74. }
  75. }
  76. }
  77. }
  78. },
  79. gljLibSheetSetting: {
  80. owner: 'gljTree',
  81. header: [
  82. {headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center", cellType: "checkBox"},
  83. {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
  84. {headerName: "名称", headerWidth: 220, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center"},
  85. {headerName: "规格型号", headerWidth: 185, dataCode: "specs", dataType: "String", hAlign: "left", vAlign: "center"},
  86. {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center"},
  87. {headerName: "单价", headerWidth: 55, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
  88. {headerName: "类型", headerWidth: 60, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center"},
  89. {headerName: "新增", headerWidth: 40, dataCode: "isComplementary", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
  90. ],
  91. view: {
  92. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  93. }
  94. },
  95. gljLibSheet: null,
  96. initSheet: function (sheet) {
  97. var me = this;
  98. me.sheet = sheet;
  99. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  100. sheet.name('ration_glj');
  101. me.bindSheetEvent(sheet);
  102. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  103. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  104. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  105. if(!projectReadOnly){
  106. gljContextMenu.loadGLJSpreadContextMenu();
  107. //me.bindGLJEnterKey(subSpread,sheet);
  108. }
  109. sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,function (sender,args) {
  110. let selected = args.newSelections[0] ? args.newSelections[0] : {row: 0, col: 0};
  111. me.sheetInitSelection(selected);
  112. });
  113. },
  114. bindGLJEnterKey:function (spread,sheet) {
  115. let me = this;
  116. subSpread.commandManager().register('myEnter', enterKeyAction);
  117. subSpread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  118. subSpread.commandManager().setShortcutKey('myEnter', GC.Spread.Commands.Key.enter, false, false, false, false);
  119. function enterKeyAction(spd,sheeName) {
  120. let editRow = sheet.getActiveRowIndex(),orgCol = sheet.getActiveColumnIndex();
  121. if(sheet.isEditing()) sheet.endEdit();
  122. //GC.Spread.Sheets.Commands.commitInputNavigationDown.execute(spd,sheeName);
  123. //sheet.setSelection(editRow,orgCol+1,1,1);
  124. GC.Spread.Sheets.Commands.navigationRight.execute(spd,sheeName);
  125. //sheet.setActiveCell(editRow, orgCol+1)
  126. }
  127. },
  128. sheetInitSelection: function (selected) {
  129. let me = gljOprObj;
  130. if(selected.row < me.sheetData.length){
  131. me.sheet.setStyle(selected.row, -1, me.getSelStyle(true));
  132. }
  133. me.sheet.repaint();
  134. if(me.preGljSelection && me.preGljSelection.row !== selected.row){
  135. me.sheet.setStyle(me.preGljSelection.row, -1, me.getSelStyle(false));
  136. }
  137. me.preGljSelection = selected;
  138. },
  139. initDetailSheet: function (sheet) {
  140. var me = this;
  141. me.detailSheet = sheet;
  142. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  143. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  144. sheet.name('quantity_detail');
  145. me.bindSheetEvent(sheet);
  146. },
  147. detailSheetReadonly:function () {
  148. let selected = projectObj.project.mainTree.selected;
  149. let Bills = projectObj.project.Bills;
  150. if(selected) {
  151. //清单锁定时只读
  152. if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked() && projectObj.project.withinBillsLocked(selected)){
  153. return true;
  154. }
  155. //大项费用、分部节点层次时,工程量明细只读。
  156. if(indicativeInfoObj.isDXFY(selected) || indicativeInfoObj.isFB(selected)){
  157. return true;
  158. }
  159. //是主材或者是设备时只读
  160. if(selected.sourceType == ModuleNames.ration_glj){
  161. return true;
  162. }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
  163. return true;
  164. }
  165. return false;
  166. }
  167. return true;
  168. },
  169. bindSheetEvent: function (sheet) {
  170. var me = this;
  171. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  172. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  173. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  174. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  175. sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
  176. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  177. },
  178. onClipboardPasting: function (sender, args) {
  179. var me = gljOprObj;
  180. if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
  181. args.cancel = true;
  182. }
  183. },
  184. onClipboardPasted: function (e, info) {
  185. var me = gljOprObj;
  186. console.log('past');
  187. // if (!me.ration) {return;};
  188. // your code...
  189. },
  190. startEditChecking:function (sender,args) {
  191. let me = gljOprObj;
  192. let selected = projectObj.project.mainTree.selected;
  193. if(selected){
  194. if(me.isInstallationNode(selected)==true){
  195. args.cancel = true;
  196. }else {
  197. if(args.sheetName == 'quantity_detail'){//工程量明细表
  198. if(me.detailSheetReadonly()){
  199. args.cancel = true;
  200. }else {
  201. if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  202. args.sheet.setValue(args.row,args.col,"");
  203. }
  204. }
  205. }
  206. if(args.sheetName == 'ration_glj'){//定额工料机表
  207. if(!me.rationGLJEditCheck(args)) args.cancel = true;
  208. }
  209. }
  210. }else {
  211. args.cancel = true;
  212. }
  213. },
  214. isInstallationNode:function(node){
  215. if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
  216. return true;
  217. }
  218. return false
  219. },
  220. onEditEnded: function (sender, args) {
  221. var me = gljOprObj;
  222. if (args.sheetName == 'ration_glj') {
  223. me.onEditGLJSheet(args)
  224. }
  225. if (args.sheetName == 'quantity_detail') {
  226. me.onEditDetailSheet(args);
  227. }
  228. },
  229. onEditDetailSheet: function (args,callback) {
  230. var me = gljOprObj;
  231. if (args.row > me.detailData.length) {
  232. return;
  233. }
  234. if (args.row == me.detailData.length && args.editingText == null) {
  235. return;
  236. }
  237. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  238. var detailList = me.detailData;
  239. if(args.editingText){
  240. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  241. args.editingText = args.editingText.replace(/)/g, ")");
  242. }
  243. if (args.row == detailList.length) {
  244. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
  245. }
  246. if (args.row < detailList.length) {
  247. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
  248. }
  249. },
  250. onEditGLJSheet: function (args) {
  251. var me = gljOprObj;
  252. if (args.row >= me.sheetData.length) {
  253. me.sheet.getCell(args.row, args.col).value(null);
  254. return;
  255. }
  256. me.updateRationGLJ(args);
  257. },
  258. onSelectionChanged: function (sender, args) {
  259. let me = gljOprObj;
  260. me.initSelection(args.newSelections.length > 0 ? {row: args.newSelections[0].row} : {row: 0});
  261. },
  262. getSelStyle: function (selected) {
  263. let style = new GC.Spread.Sheets.Style();
  264. style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  265. style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  266. style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  267. style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
  268. let colorOpts = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
  269. let selectedColor = colorOpts.SELECTED.backColor,
  270. recColor = 'White';
  271. style.backColor = selected ? selectedColor : recColor;
  272. return style;
  273. },
  274. initSelection: function (sel) {
  275. let me = gljOprObj;
  276. if(sel){
  277. me.gljLibSheet.setStyle(sel.row, -1, me.getSelStyle(true));
  278. }
  279. if(me.preGljLibSelection && me.preGljLibSelection.row !== sel.row){
  280. me.gljLibSheet.setStyle(me.preGljLibSelection.row, -1, me.getSelStyle(false));
  281. }
  282. me.preGljLibSelection = sel;
  283. },
  284. onButtonClick: function (sender, args) {
  285. if(args.sheet.isEditing()){
  286. args.sheet.endEdit();
  287. }
  288. var me = gljOprObj;
  289. var sheet = args.sheet, row = args.row, col = args.col;
  290. var cellType = sheet.getCellType(row, col);
  291. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  292. if(args.sheetName == 'rationInstallSheet'){
  293. installationFeeObj.onPositionButtonClick(sender,args);
  294. }
  295. } else {
  296. me.onCheckBoxClick(sender, args)
  297. }
  298. },
  299. onCheckBoxClick: function (sender, args) {
  300. let selected = projectObj.project.mainTree.selected;
  301. if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
  302. return ;
  303. }
  304. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  305. if(args.sheetName == 'rationInstallSheet' && checkboxValue){
  306. return;
  307. }
  308. if(gljOprObj.isInstallationNode(selected)==true){
  309. return;
  310. }
  311. let newval = 0;
  312. if (checkboxValue) {
  313. newval = 0;
  314. args.sheet.getCell(args.row, args.col).value(newval);
  315. } else {
  316. newval = 1;
  317. args.sheet.getCell(args.row, args.col).value(newval);
  318. }
  319. if (args.sheetName == 'ration_glj') {
  320. gljOprObj.updateIsEstimate(args,newval);
  321. } else if (args.sheetName == 'quantity_detail') {
  322. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  323. } else if (args.sheetName == 'glj_lib') {
  324. if(gljOprObj.gljLibSheetSetting.header[args.col].dataCode === 'select'){
  325. gljOprObj.setGLJSelection(args, newval);
  326. }
  327. }else if(args.sheetName == 'rationInstallSheet'){
  328. args.newValue = newval;
  329. installationFeeObj.onRationInstallValueChange(sender,args);
  330. }
  331. },
  332. onCellDoubleClick:function (sender, args) {
  333. var me = gljOprObj;
  334. var header = me.setting.header;
  335. if (args.row >= me.sheetData.length) {
  336. return;
  337. }
  338. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  339. if(me.hasComposition(me.sheetData[args.row])){
  340. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  341. }
  342. }
  343. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  344. var isAdd = me.sheetData[args.row].isAdd;
  345. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  346. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  347. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  348. }
  349. }
  350. }
  351. },
  352. onClipboardChanged: function (sender, info) {
  353. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  354. sheetCommonObj.copyTextToClipboard(cDatas);
  355. return;
  356. },
  357. rationGLJEditCheck:function (args) {//true 可以编辑,false 不能编辑
  358. var me = gljOprObj;
  359. var header = me.setting.header;
  360. if (_.includes(me.setting.view.lockColumns, args.col)) return false;//如果是锁定的列,不能编辑
  361. if(me.sheetData[args.row] != undefined){
  362. if(me.sheetData[args.row].isMixRatio){//对于组成物列
  363. return header[args.col].dataCode == 'marketPrice'//允许修改组成物市单价,其它的不可以
  364. }else {
  365. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  366. return !me.marketPriceReadOnly({data:me.sheetData[args.row]});
  367. }
  368. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  369. var isAdd = me.sheetData[args.row].isAdd;
  370. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  371. return !me.marketPriceReadOnly({data:me.sheetData[args.row]});//如果有组成物,不可修改
  372. } else {
  373. return false;
  374. }
  375. }
  376. return true;
  377. }
  378. }else {
  379. return false
  380. }
  381. }
  382. ,
  383. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  384. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  385. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  386. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  387. let con_key = this.getIndex(ration_glj,keyArray);
  388. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  389. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  390. return true;
  391. }
  392. }
  393. return false;
  394. },
  395. onRangeChanged: function (sender, args) {
  396. var me = gljOprObj;
  397. if(args.sheetName == 'quantity_detail'){
  398. me.batchUpdateQuantityDetail(args);
  399. }else {
  400. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  401. args.editingText = null;
  402. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  403. args.editingText = args.sheet.getCell(args.row,args.col).value();
  404. }else {
  405. return;
  406. }
  407. if (args.sheetName == 'ration_glj') {
  408. me.onEditGLJSheet(args);
  409. }
  410. }
  411. },
  412. batchUpdateQuantityDetail:function (args) {
  413. let me = gljOprObj;
  414. let updateArray = [];
  415. for(let i =0;i<args.changedCells.length;i++){
  416. let c = args.changedCells[i];
  417. let tem = {
  418. row:c.row,
  419. col:c.col,
  420. editingText:args.sheet.getCell(c.row,c.col).text(),
  421. sheet:args.sheet,
  422. sheetName:args.sheetName,
  423. index:i
  424. };
  425. updateArray.push(tem);
  426. }
  427. if(updateArray.length>0){
  428. updateArray.length == 1?me.onEditDetailSheet(updateArray[0]):me.onEditDetailSheet(updateArray[0],updateCallback);
  429. }
  430. function updateCallback(i_args) {
  431. let index = i_args.index;
  432. if(index < updateArray.length-1){
  433. let nextIndex = index+1;
  434. updateArray[nextIndex].replace = i_args.replace;
  435. if(nextIndex == updateArray.length-1){//是最后一个,则不用调callback了
  436. me.onEditDetailSheet(updateArray[nextIndex]);
  437. }else {
  438. me.onEditDetailSheet(updateArray[nextIndex],updateCallback);
  439. }
  440. }
  441. }
  442. },
  443. showDataIfRationSelect: function (node,selectedNodeId) {
  444. var isShow = false;
  445. //恢复底色
  446. this.sheet.setStyle(this.sheet.getActiveRowIndex(), -1, this.getSelStyle(false));
  447. if(projectReadOnly && this.setting.view.lockColumns){
  448. this.setting.view.lockColumns = null;
  449. }
  450. if(selectedNodeId){
  451. this.selectedNodeId = selectedNodeId;
  452. }
  453. if (node) {
  454. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  455. return;
  456. } else {
  457. this.selectedNodeId = node.getID();
  458. }
  459. if (node.sourceType == "ration") {
  460. if(node.data.type==rationType.gljRation){
  461. if($('#linkGLJ').hasClass('active')){
  462. this.showMixRatio(node);
  463. }
  464. }else {
  465. if($('#linkGLJ').hasClass('active')){
  466. this.showRationGLJData(node);
  467. }
  468. if($('#linkAZZJF').hasClass('active')){
  469. installationFeeObj.showRationInstallationData(node);
  470. }
  471. }
  472. isShow = true;
  473. }
  474. if(node.sourceType == ModuleNames.ration_glj){
  475. if($('#linkGLJ').hasClass('active')) {
  476. this.showMixRatio(node);
  477. }
  478. isShow = true;
  479. }
  480. if($('#linkGCLMX').hasClass('active')){
  481. this.showQuantityDetailData(node);
  482. }
  483. } else {
  484. this.selectedNodeId = null;
  485. }
  486. if (!isShow) {
  487. this.clearSheetData();
  488. }
  489. //子目换算
  490. zmhs_obj.showZMHSData(node);
  491. // $('#dropdown').hide();
  492. },
  493. showMixRatio:function (node) {//显示组成物到定额工料机
  494. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  495. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  496. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  497. let connect_index = this.getIndex(node.data,indexArray);
  498. let gljList=[];
  499. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  500. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  501. }
  502. if(gljList.length>0){//计算总消耗量
  503. if(node.sourceType==ModuleNames.ration){
  504. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  505. }else {
  506. let totalQuantity = this.getTotalQuantity(node.data);
  507. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  508. }
  509. }
  510. this.sheetData = gljList;
  511. this.sheet.setRowCount(0);
  512. this.sheetData = sortRationGLJ(this.sheetData);
  513. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  514. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  515. //初始选择
  516. this.preGljSelection = null;
  517. this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: 0});
  518. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  519. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  520. },
  521. showRationGLJData: function (node) {
  522. var gljList = [];
  523. var ration_glj = projectObj.project.ration_glj;
  524. node = node ? node : projectObj.project.mainTree.selected;
  525. if (node.sourceType == ModuleNames.ration) {
  526. if(node.data.type==rationType.gljRation){
  527. this.showMixRatio(node);
  528. }else {
  529. let ration = node.data;
  530. gljList = this.filterGljByRation(ration, ration_glj.datas);
  531. this.showInSheet(gljList);
  532. }
  533. }else if(node.sourceType == ModuleNames.ration_glj){
  534. this.showMixRatio(node);
  535. }
  536. },
  537. showRationGLJSheetData: function (init) {
  538. let selected = this.sheet.getSelections();
  539. this.combineWithProjectGlj(this.sheetData);
  540. this.sheet.setRowCount(0);
  541. this.sheetData = sortRationGLJ(this.sheetData);
  542. this.sumQuantity();//计算总消耗量
  543. this.addMixRatioToShow();//显示组成物信息
  544. this.initRationTree(init,this.getUnitPriceCodeMap());
  545. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  546. if(this.mainTreeSelectedChange == true){
  547. this.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
  548. this.mainTreeSelectedChange = false;
  549. }else if(selected){//定位光标到之前的位置
  550. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  551. }
  552. //初始选择
  553. this.preGljSelection = null;
  554. this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: this.sheet.getActiveColumnIndex()});
  555. },
  556. getUnitPriceCodeMap : function () {//取单价文件中,编码前缀一样的映射表
  557. let codeMap = {};
  558. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  559. if(priceMap){
  560. for(let connectKey in priceMap){
  561. let code = priceMap[connectKey].code;
  562. let name = priceMap[connectKey].name;
  563. let specs = priceMap[connectKey].specs;
  564. if(code){
  565. let displayText = code +" "+name +" "+specs;
  566. let preCode = code.split("-")[0];
  567. if(codeMap[preCode]) {
  568. codeMap[preCode].push({text:displayText,value:connectKey});
  569. }else {
  570. codeMap[preCode]=[{text:displayText ,value:connectKey}];
  571. }
  572. }
  573. }
  574. }
  575. return codeMap;
  576. },
  577. initRationTree: function (init,codeMap) {
  578. this.sheet.suspendPaint();
  579. this.sheet.suspendEvent();
  580. this.sheet.setRowCount(this.sheetData.length >30?this.sheetData.length:30);
  581. for (var i = 0; i < this.sheetData.length; i++) {
  582. let options = this.getCodeOptions(this.sheetData[i],codeMap);
  583. this.sheet.setCellType(i, 0,this.getTreeNodeCellType(this.sheetData,options),GC.Spread.Sheets.SheetArea.viewport);
  584. if (this.sheetData[i].hasOwnProperty('subList')) {
  585. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  586. if (collapsed == true) {
  587. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  588. }
  589. }
  590. }
  591. this.sheet.resumeEvent();
  592. this.sheet.resumePaint();
  593. },
  594. getCodeOptions:function (recode,codeMap) {
  595. let options = [];
  596. if(recode.isMixRatio ===true){
  597. return null;
  598. }
  599. let code = recode.code;
  600. if(code) {
  601. let preCode = code.split("-")[0];
  602. if( codeMap[preCode]) options = codeMap[preCode];
  603. if(options.length>0) _.remove(options,{'value':gljOprObj.getIndex(recode, gljKeyArray)})//去掉本身
  604. }
  605. return options;
  606. },
  607. filterGljByRation: function (ration, datas) {
  608. var gljList = [];
  609. if (datas && datas.length > 0) {
  610. gljList = _.filter(datas, {'rationID': ration.ID})
  611. }
  612. return gljList;
  613. },
  614. showInSheet: function (gljList) {
  615. this.sheetData = gljList;
  616. this.showRationGLJSheetData(true);
  617. },
  618. sumQuantity: function (node) {
  619. if (this.sheetData.length > 0) {
  620. node = node ? node : projectObj.project.mainTree.selected;
  621. let ration = node.data;
  622. let quantity = ration.quantity;
  623. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  624. for (let glj of this.sheetData) {
  625. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  626. }
  627. }
  628. },
  629. getTotalQuantity:function(glj,ration){
  630. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  631. if(ration){
  632. let quantity = ration.quantity;
  633. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  634. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  635. return;
  636. }
  637. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  638. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  639. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  640. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  641. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  642. }
  643. return glj.totalQuantity;
  644. }
  645. },
  646. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  647. for (let subG of mList) {
  648. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  649. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  650. }
  651. },
  652. addMixRatioToShow: function () {
  653. var newList = [];
  654. _.remove(this.sheetData, {'isMixRatio': true});
  655. for (var i = 0; i < this.sheetData.length; i++) {
  656. newList.push(this.sheetData[i]);
  657. if (this.sheetData[i].hasOwnProperty('subList')) {
  658. newList = newList.concat(this.sheetData[i].subList);
  659. }
  660. }
  661. this.sheetData = newList;
  662. },
  663. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  664. var projectGLJData = projectObj.project.projectGLJ.datas;
  665. var projectGljs = projectGLJData.gljList;
  666. var mixRatioMap = projectGLJData.mixRatioMap;
  667. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  668. for (var i = 0; i < ration_gljs.length; i++) {
  669. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  670. if (glj) {
  671. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  672. ration_gljs[i].isEstimate = glj.is_evaluate;
  673. }
  674. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  675. ration_gljs[i].isAdd = glj.unit_price.is_add;
  676. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  677. var connect_index = this.getIndex(glj, gljKeyArray);
  678. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  679. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  680. ration_gljs[i].subList = mixRatios;
  681. }
  682. }
  683. }
  684. }
  685. return ration_gljs;
  686. },
  687. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  688. let proGLJ = projectObj.project.projectGLJ;
  689. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  690. let decimalObj = projectInfoObj.projectInfo.property.decimal;
  691. let labourCoeDatas = projectObj.project.labourCoe.datas;
  692. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  693. if(glj){
  694. let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  695. data.marketPrice = result.marketPrice;
  696. data.basePrice = result.basePrice;
  697. data.adjustPrice = result.adjustPrice;
  698. data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
  699. }
  700. return data;
  701. },
  702. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  703. let proGLJ = projectObj.project.projectGLJ;
  704. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  705. if(this.calcPriceDiff(glj)==true){
  706. return proGLJ.getBasePrice(glj);
  707. }else {
  708. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  709. }
  710. },
  711. calcPriceDiff:function (glj) {
  712. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  713. return gljUtil.calcPriceDiff(glj,calcOptions);
  714. },
  715. getIndex(obj, pops){
  716. let t_index = '';
  717. let k_arr = [];
  718. for (let p of pops) {
  719. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  720. k_arr.push(tmpK);
  721. }
  722. t_index = k_arr.join("|-|");
  723. return t_index;
  724. },
  725. getConditionByKey(conKey){//将连接字符串转换成对象
  726. let valueArray = conKey.split("|-|");
  727. let obj ={};
  728. for(let i = 0;i<valueArray.length;i++){
  729. if(valueArray[i]!='null'){
  730. if(gljKeyArray[i]=='type'){
  731. valueArray[i] = parseInt(valueArray[i]);
  732. }
  733. obj[gljKeyArray[i]]=valueArray[i];
  734. }
  735. }
  736. return obj;
  737. },
  738. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  739. var temRationGLJs = [];
  740. for (var i = 0; i < mixRatioList.length; i++) {
  741. var pg = _.find(projectGljs, {
  742. 'code': mixRatioList[i].code,
  743. 'name': mixRatioList[i].name,
  744. 'specs': mixRatioList[i].specs,
  745. 'type': mixRatioList[i].type,
  746. 'unit': mixRatioList[i].unit
  747. });//改关联关系
  748. var tem = {
  749. projectGLJID: pg.id,
  750. code: pg.code,
  751. name: pg.name,
  752. specs: pg.specs,
  753. unit: pg.unit,
  754. type:mixRatioList[i].type,
  755. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  756. consumption:mixRatioList[i].consumption,
  757. rationItemQuantity: mixRatioList[i].consumption,
  758. // quantity:mixRatioList[i].consumption,
  759. /* basePrice: pg.unit_price.base_price,
  760. marketPrice: pg.unit_price.market_price,
  761. adjustPrice: pg.adjust_price,*/
  762. //isEstimate: pg.is_evaluate,
  763. isMixRatio: true,
  764. isAdd: pg.unit_price.is_add,
  765. GLJID: pg.glj_id
  766. };
  767. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  768. tem.isEstimate = pg.is_evaluate;
  769. }
  770. this.setGLJPrice(tem,pg);
  771. temRationGLJs.push(tem);
  772. }
  773. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  774. return temRationGLJs;
  775. },
  776. showQuantityDetailData: function (node) {
  777. node = node ? node : projectObj.project.mainTree.selected;
  778. var quantity_detail = projectObj.project.quantity_detail;
  779. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  780. let details = quantity_detail.getListByID(node.data.ID,field);
  781. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  782. this.detailData = details;
  783. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  784. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  785. }
  786. },
  787. clearSheetData: function () {
  788. if($('#linkGLJ').hasClass('active')){
  789. sheetCommonObj.showData(this.sheet, this.setting, []);
  790. }
  791. if($('#linkAZZJF').hasClass('active')){
  792. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  793. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  794. }
  795. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  796. this.sheetData = [];
  797. installationFeeObj.rationInstallData = [];
  798. //this.detailData=[];
  799. },
  800. updateRationGLJ: function (args) {
  801. var me = this;
  802. var updateField = me.setting.header[args.col].dataCode;
  803. var recode = me.sheetData[args.row];
  804. var newval;
  805. if(!me.rationGLJEditCheck(args)){
  806. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  807. return;
  808. }
  809. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  810. if (args.editingText == null) {
  811. updateField == 'marketPrice' ? newval = 0 : newval = "";
  812. } else {
  813. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  814. newval = number_util.checkNumberValue(args.editingText, decimal);
  815. if (newval == null) {
  816. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  817. return;
  818. }
  819. }
  820. } else {
  821. if (updateField == 'name' || updateField == 'unit') {
  822. if (args.editingText === null) {
  823. alert(me.setting.header[args.col].headerName + '不能为空!');
  824. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  825. return;
  826. }
  827. }
  828. if(updateField == 'code'){
  829. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  830. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  831. return;
  832. }
  833. }
  834. newval = args.editingText == null ? "" : args.editingText;
  835. }
  836. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  837. return
  838. }
  839. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  840. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  841. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  842. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  843. } else {
  844. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  845. }
  846. },
  847. isRationGLJExit:function (connectKey) {
  848. for(let rg of gljOprObj.sheetData){
  849. if(rg.isMixRatio == true){
  850. continue;
  851. }
  852. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  853. return true;
  854. }
  855. }
  856. return false;
  857. },
  858. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  859. let newval;
  860. let updatePrice = false;
  861. if (fieldName == "marketUnitFee") {
  862. updatePrice = true;
  863. if (value == null) {
  864. newval = 0;
  865. } else {
  866. var decimal = getDecimal("glj.unitPrice");
  867. newval = number_util.checkNumberValue(value, decimal);
  868. }
  869. } else {
  870. if (value != null) {
  871. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  872. return;
  873. //update
  874. }
  875. }
  876. if (newval && updatePrice == true) {
  877. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  878. return
  879. }
  880. projectObj.mainController.refreshTreeNode([node]);
  881. },
  882. updateIsEstimate:function (args, newval) {
  883. var me = gljOprObj;
  884. if(me.setting.header[args.col].dataCode=="isEstimate"){
  885. var pspread= new ProjectGLJSpread();
  886. var recode = me.sheetData[args.row];
  887. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  888. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  889. if(glj){
  890. glj["is_evaluate"]=newval;
  891. args.fromRG=true;
  892. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  893. }
  894. }
  895. },
  896. showLibGLJSheetData: function () {
  897. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  898. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  899. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  900. },
  901. filterLibGLJSheetData: function () {
  902. let me = this;
  903. let val = $("input[name='glj']:checked").val();
  904. if (val == 'allGljs') {
  905. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  906. } else {
  907. me.gljLibSheetData = me[val];
  908. }
  909. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  910. me.filterLibGLJByType();
  911. }else if($('#actionType').val() == 'addMix'){
  912. projectGljObject.filterLibGLJForMixRatio();
  913. }
  914. //文本筛选
  915. let searchStr = $('#gljSearchKeyword').val();
  916. if(searchStr && searchStr.trim() != ''){
  917. let reg = new RegExp(searchStr);
  918. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  919. return reg.test(data.code) || reg.test(data.name);
  920. });
  921. }
  922. if (me.gljCurTypeId == undefined) {
  923. return;
  924. }
  925. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  926. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  927. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  928. });
  929. } else {
  930. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  931. }
  932. },
  933. setGLJSelection: function (args, newVal) {
  934. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  935. this.addGLJsSelection(args, newVal);
  936. } else {
  937. this.replaceGLJSelection(args, newVal);
  938. }
  939. },
  940. addGLJsSelection: function (args, newVal) {
  941. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  942. if (newVal == 1) {
  943. this.GLJSelection.push(con_key);
  944. this.gljLibSheetData[args.row].select = 1;
  945. } else if (newVal == 0) {
  946. _.pull(this.GLJSelection, con_key);
  947. this.gljLibSheetData[args.row].select = 0;
  948. }
  949. },
  950. replaceGLJSelection: function (args, newVal) {
  951. var me = this;
  952. var oldSelection = this.GLJSelection[0];
  953. if (newVal == 0) {
  954. args.sheet.getCell(args.row, args.col).value(1);
  955. return;
  956. }
  957. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  958. this.gljLibSheetData[args.row].select = 1;
  959. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  960. var i_key = me.getIndex(item, gljLibKeyArray);
  961. return oldSelection == i_key;
  962. });
  963. if (oindex != -1) {
  964. args.sheet.getCell(oindex, args.col).value(0);
  965. this.gljLibSheetData[oindex].select = 0;
  966. } else {
  967. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  968. var i_key = me.getIndex(item, gljLibKeyArray);
  969. return oldSelection == i_key;
  970. });
  971. oldData ? oldData.select = 0 : "";
  972. }
  973. },
  974. filterLibGLJByType: function () {
  975. var me = this;
  976. var selected = me.sheetData[gljContextMenu.selectedRow];
  977. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  978. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  979. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  980. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  981. return filterTypes.includes(data.gljType);
  982. });
  983. //me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  984. },
  985. getComboData: function (gljDistType) {
  986. let me = this;
  987. let distType;
  988. let distTypeTree = {
  989. prefix: 'gljType',
  990. distTypes: {},
  991. comboDatas: [],
  992. distTypesArr: []
  993. };
  994. gljDistType.forEach(function (typeData) {
  995. let typeObj = {
  996. data: typeData,
  997. children: [],
  998. parent: null
  999. }
  1000. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1001. distTypeTree.distTypesArr.push(typeObj);
  1002. });
  1003. gljDistType.forEach(function (typeData) {
  1004. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1005. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1006. if (parent) {
  1007. distType.parent = parent;
  1008. parent.children.push(distType);
  1009. }
  1010. });
  1011. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1012. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1013. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1014. }
  1015. });
  1016. return distTypeTree;
  1017. },
  1018. doInsertGLJ: function () {
  1019. var me = this;
  1020. var selected = projectObj.project.mainTree.selected;
  1021. var project = projectObj.project;
  1022. if (me.GLJSelection.length <= 0) {
  1023. return;
  1024. }
  1025. $("#glj_tree_div").modal('hide');
  1026. $.bootstrapLoading.start();
  1027. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1028. let newNode=null;
  1029. for (let r_glj of data) {
  1030. r_glj.quantity = r_glj.quantity + "";
  1031. project.Ration.datas.push(r_glj);
  1032. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1033. project.projectGLJ.loadData(function () {
  1034. for(let r_glj of data){
  1035. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1036. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1037. newNode.source = r_glj;
  1038. newNode.sourceType = project.Ration.getSourceType();
  1039. newNode.data = r_glj;
  1040. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1041. }
  1042. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1043. projectObj.mainController.refreshTreeNode([newNode]);
  1044. if(me.hasComposition(newNode.data,true)){
  1045. me.showMixRatio(newNode);
  1046. }else {
  1047. me.showRationGLJSheetData();
  1048. }
  1049. $.bootstrapLoading.end();
  1050. });
  1051. })
  1052. },
  1053. doAddGLJ: function () {
  1054. var selected = projectObj.project.mainTree.selected;
  1055. var project = projectObj.project;
  1056. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1057. var rg = _.find(gljOprObj.sheetData, function (item) {
  1058. if(item.isMixRatio == true){
  1059. return false;
  1060. }
  1061. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1062. return n == i_key
  1063. });
  1064. return rg ? false : true;
  1065. })
  1066. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1067. $("#glj_tree_div").modal('hide');
  1068. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1069. if (result) {
  1070. selected.data.adjustState = result.adjustState;
  1071. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1072. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1073. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1074. project.projectGLJ.loadData(function () {
  1075. project.ration_glj.addToMainTree(result.showData);
  1076. gljOprObj.showRationGLJSheetData();
  1077. project.calcProgram.calcAndSave(selected);
  1078. projectObj.mainController.refreshTreeNode([selected]);
  1079. $.bootstrapLoading.end();
  1080. });
  1081. }
  1082. });//doc.rationID=selected.data.ID;
  1083. } else {
  1084. $("#glj_tree_div").modal('hide');
  1085. }
  1086. },
  1087. doReplaceGLJ: function () {
  1088. var me = this;
  1089. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1090. var project = projectObj.project;
  1091. var selectCode = gljOprObj.GLJSelection[0];
  1092. var selected = projectObj.project.mainTree.selected;
  1093. $("#glj_tree_div").modal('hide');
  1094. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1095. if (result) {
  1096. //result.adjustState;
  1097. var glj_list = projectObj.project.ration_glj.datas;
  1098. var data = result.data;
  1099. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1100. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1101. var nodes = [selected];
  1102. gljOprObj.sheetData[index] = data;
  1103. glj_list[list_index] = data;
  1104. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1105. gljOprObj.showRationGLJSheetData();
  1106. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1107. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1108. if (node) {
  1109. project.ration_glj.transferToNodeData(data);
  1110. node.source = data;
  1111. node.data = data;
  1112. }
  1113. node ? nodes.push(node) : "";
  1114. }
  1115. //project.ration_glj.addToMainTree(data);
  1116. selected.data.adjustState = result.adjustState;
  1117. selected.data.name = result.name;
  1118. projectObj.mainController.refreshTreeNode(nodes);
  1119. project.calcProgram.calcAndSave(selected);
  1120. $.bootstrapLoading.end();
  1121. });
  1122. }
  1123. })
  1124. },
  1125. doMReplaceGLJ: function () {
  1126. let me = this;
  1127. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1128. let project = projectObj.project;
  1129. let selectCode = me.GLJSelection[0];
  1130. $("#glj_tree_div").modal('hide');
  1131. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1132. if(result == null){
  1133. return;
  1134. }
  1135. let data = result.data;
  1136. let stateList = result.stateList;
  1137. //let n_index = me.getIndex(data.query, gljKeyArray);
  1138. let nodes = [];
  1139. _.forEach(project.ration_glj.datas, function (t) {
  1140. // let t_index = me.getIndex(t, gljKeyArray);
  1141. if (updateMap[t.ID]) {
  1142. me.updateProperty(t, data.doc);
  1143. me.updateProperty(t, updateMap[t.ID]);
  1144. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1145. project.ration_glj.transferToNodeData(t);
  1146. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1147. node ? nodes.push(node):'';
  1148. }
  1149. }
  1150. })
  1151. project.projectGLJ.loadData(function () {
  1152. me.showRationGLJSheetData();
  1153. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1154. project.calcProgram.calcNodesAndSave(rationNodes);
  1155. $.bootstrapLoading.end();
  1156. });
  1157. })
  1158. },
  1159. updateProperty: function (obj, doc) {
  1160. _.forEach(doc, function (n, key) {
  1161. obj[key] = n;
  1162. });
  1163. },
  1164. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1165. var nodes = [];
  1166. var rationNodes = [];
  1167. _.forEach(stateList, function (s) {
  1168. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1169. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1170. })
  1171. if (node) {
  1172. node.data.adjustState = s.adjustState;
  1173. node.data.name = s.name;
  1174. nodes.push(node);
  1175. rationNodes.push(node);
  1176. }
  1177. });
  1178. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1179. projectObj.mainController.refreshTreeNode(nodes);
  1180. return rationNodes;
  1181. },
  1182. refreshView: function () {
  1183. let node = projectObj.project.mainTree.selected;
  1184. this.showDataIfRationSelect(node,"111111");
  1185. //this.showRationGLJData();
  1186. },
  1187. //
  1188. refreshTreeNode: function (obj) {
  1189. if (!obj) {
  1190. return;
  1191. }
  1192. var objectArray = [];
  1193. var nodes = [];
  1194. if (obj instanceof Array) {
  1195. objectArray.concat(obj);
  1196. } else {
  1197. objectArray.push(obj);
  1198. }
  1199. for (let o of objectArray) {
  1200. let node = this.updateDataNodeProperty(o.ID,o.data);
  1201. if (node) {
  1202. nodes.push(node);
  1203. }
  1204. }
  1205. projectObj.mainController.refreshTreeNode(nodes);
  1206. return nodes;
  1207. },
  1208. updateDataNodeProperty:function(nodeID,data){
  1209. let node = projectObj.project.mainTree.findNode(nodeID);
  1210. if (node) {
  1211. for (let k in data) {
  1212. node.data[k] = data[k];
  1213. }
  1214. }
  1215. return node;
  1216. },
  1217. getTreeNodeCellType: function (data,comboboxOptions) {
  1218. var ns = GC.Spread.Sheets;
  1219. var rectW = 10;
  1220. var rectH = 10;
  1221. var margin = 3;
  1222. function TreeNodeCellType() {
  1223. }
  1224. function drowRect(ctx, x, y, w, h) {
  1225. ctx.save();
  1226. ctx.strokeStyle = "gray";
  1227. ctx.translate(0.5, 0.5);
  1228. ctx.beginPath();
  1229. var rectX = x + margin;
  1230. var rectY = y + Math.round(h / 2) - rectH / 2;
  1231. ctx.moveTo(rectX, rectY);
  1232. ctx.lineTo(rectX, rectY + rectH);
  1233. ctx.lineTo(rectX + rectW, rectY + rectH);
  1234. ctx.lineTo(rectX + rectW, rectY);
  1235. ctx.lineTo(rectX, rectY);
  1236. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1237. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1238. ctx.stroke();
  1239. ctx.restore();
  1240. }
  1241. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1242. ctx.save();
  1243. ctx.strokeStyle = "#000000";
  1244. ctx.translate(0.5, 0.5);
  1245. ctx.beginPath();
  1246. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1247. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1248. var rectY = y + Math.round(h / 2) - rectH / 2;
  1249. if (collapsed) {
  1250. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1251. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1252. }
  1253. ctx.stroke();
  1254. ctx.restore();
  1255. }
  1256. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1257. offset += 6;
  1258. ctx.save();
  1259. ctx.strokeStyle = "gray";
  1260. ctx.translate(0.5, 0.5);
  1261. ctx.beginPath();
  1262. ctx.moveTo(x + offset, y);
  1263. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1264. offset += 9;
  1265. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1266. if (nextItem && nextItem.isMixRatio) {
  1267. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1268. ctx.lineTo(x + offset - 9, y + h);
  1269. }
  1270. ctx.stroke();
  1271. ctx.restore();
  1272. return offset;
  1273. }
  1274. TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
  1275. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1276. if (style.backColor) {//先画背景色
  1277. ctx.save();
  1278. ctx.fillStyle = style.backColor;
  1279. ctx.fillRect(x, y, w, h);
  1280. ctx.restore();
  1281. } else {
  1282. ctx.clearRect(x, y, w, h);
  1283. }
  1284. if (value != null) {
  1285. var offset = margin + rectW + 6;
  1286. var recode = data[options.row];
  1287. if (recode && recode.hasOwnProperty('subList')) {
  1288. drowRect(ctx, x, y, w, h);
  1289. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1290. drowSymbol(ctx, x, y, w, h, collapsed);
  1291. } else if (recode && recode.isMixRatio) {
  1292. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1293. offset += 1;
  1294. }
  1295. arguments[2] = x + offset;
  1296. arguments[4] = w - offset;
  1297. //x = x + offset;
  1298. //w = w - offset;
  1299. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1300. }
  1301. };
  1302. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1303. if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1304. return {
  1305. x: x,
  1306. y: y,
  1307. row: context.row,
  1308. col: context.col,
  1309. cellStyle: cellStyle,
  1310. cellRect: cellRect,
  1311. sheetArea: context.sheetArea
  1312. };
  1313. }else {
  1314. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1315. }
  1316. };
  1317. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1318. var recode = data[hitinfo.row];
  1319. if (recode && recode.hasOwnProperty('subList')) {
  1320. var hoffset = hitinfo.cellRect.x + 3;
  1321. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1322. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1323. collapsed = !collapsed
  1324. recode.collapsed = collapsed;
  1325. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1326. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1327. hitinfo.sheet.invalidateLayout();
  1328. hitinfo.sheet.repaint();
  1329. return;
  1330. }
  1331. }
  1332. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1333. // GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1334. };
  1335. let cellType = new TreeNodeCellType();
  1336. if(comboboxOptions){
  1337. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1338. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1339. }
  1340. return cellType;
  1341. },
  1342. marketPriceReadOnly: function (node) {
  1343. let hasCom = false;
  1344. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1345. hasCom = this.hasComposition(node.data,true);
  1346. }else {
  1347. hasCom = this.hasComposition(node.data);
  1348. }
  1349. return hasCom|| node.data.isEstimate == 1;
  1350. },
  1351. locateZTree: function(ID) {
  1352. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1353. let node = null;
  1354. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0]
  1355. if (!node) node = zTree.getNodeByTId('gljTree_1');
  1356. zTree.selectNode(node);
  1357. gljOprObj.gljCurTypeId = ID;
  1358. gljOprObj.filterLibGLJSheetData();
  1359. gljOprObj.showLibGLJSheetData();
  1360. }
  1361. }
  1362. $(function () {
  1363. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1364. if (gljOprObj.gljLibSpresd == undefined) {
  1365. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1366. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1367. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1368. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1369. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1370. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1371. gljOprObj.gljLibSheet.options.isProtected = true;
  1372. gljOprObj.gljLibSheet.name('glj_lib');
  1373. }
  1374. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1375. let gljClass = 0, selectMap = {};
  1376. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1377. gljOprObj.GLJSelection = [];
  1378. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1379. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1380. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1381. gljOprObj.GLJSelection = [connect_key];
  1382. selectMap[connect_key] = true;
  1383. gljOprObj.filterLibGLJByType();
  1384. }else if($('#actionType').val() =='addMix'){//添加组成物
  1385. gljOprObj.GLJSelection = [];
  1386. projectGljObject.filterLibGLJForMixRatio();
  1387. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1388. gljOprObj.GLJSelection = [];
  1389. for(let s of selections){
  1390. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1391. selectMap[s_key] = true;
  1392. gljOprObj.GLJSelection.push(s_key);
  1393. }*/
  1394. }
  1395. for(let item of gljOprObj.gljLibSheetData){
  1396. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1397. if(selectMap[item_key]){
  1398. item.select = 1 ;
  1399. gljClass = item.gljClass;
  1400. }
  1401. }
  1402. //替换,焦点定位至当前选中人材机
  1403. if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
  1404. gljOprObj.locateZTree(gljClass);
  1405. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1406. let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
  1407. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1408. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1409. gljOprObj.initSelection({row: index});
  1410. gljOprObj.gljLibSpresd.focus(true);
  1411. }
  1412. else gljOprObj.showLibGLJSheetData();
  1413. });
  1414. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1415. $('#gljSearchKeyword').val('');
  1416. });
  1417. $('.glj-radio').change(function () {
  1418. let val = $("input[name='glj']:checked").val();
  1419. if (val == 'allGljs') {
  1420. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1421. gljOprObj.filterLibGLJSheetData();
  1422. gljOprObj.showLibGLJSheetData();
  1423. } else {
  1424. gljOprObj.gljLibSheetData = gljOprObj[val];
  1425. gljOprObj.filterLibGLJSheetData();
  1426. gljOprObj.showLibGLJSheetData();
  1427. }
  1428. })
  1429. /* //工料机搜索
  1430. $('#gljSearchKeyword').change(function () {
  1431. gljOprObj.filterLibGLJSheetData();
  1432. gljOprObj.showLibGLJSheetData();
  1433. });
  1434. $('#gljSearchKeyword').bind('keypress', function (e) {
  1435. if(e.keyCode === 13){
  1436. alert('2');
  1437. $(this).blur();
  1438. return false;
  1439. }
  1440. });*/
  1441. $('#gljSearchKeyword').bind('keyup', function (e) {
  1442. gljOprObj.filterLibGLJSheetData();
  1443. gljOprObj.showLibGLJSheetData();
  1444. });
  1445. $('#glj_selected_conf').click(function () {
  1446. if (gljOprObj.GLJSelection.length < 1) {
  1447. return;
  1448. }
  1449. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1450. gljOprObj.doInsertGLJ();
  1451. } else if ($('#actionType').val() == 'add') { //添加工料机
  1452. gljOprObj.doAddGLJ();
  1453. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1454. gljOprObj.doReplaceGLJ();
  1455. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1456. gljOprObj.doMReplaceGLJ();
  1457. }else if($('#actionType').val() == 'addMix'){
  1458. projectGljObject.addMixRatio();
  1459. }
  1460. })
  1461. $('#class_selected_conf').click(function () {
  1462. var gljClass = $('#selected_class').val();
  1463. var glj = gljOprObj.selectedGLJClass;
  1464. if (glj && gljClass && gljClass != "") {
  1465. //保存到我的工料机库
  1466. /*1 检查是否有组成物
  1467. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1468. * 3 保存
  1469. * */
  1470. var newItem = {
  1471. code: glj.code,
  1472. name: glj.name,
  1473. specs: glj.specs,
  1474. unit: glj.unit,
  1475. basePrice: glj.basePrice,
  1476. gljType: glj.type,
  1477. shortName: glj.shortName,
  1478. component: [],
  1479. gljClass: gljClass
  1480. };
  1481. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1482. for (var i = 0; i < glj.subList.length; i++) {
  1483. let tem = {
  1484. ID: glj.subList[i].GLJID,
  1485. consumeAmt: glj.rationItemQuantity,
  1486. isStd: true
  1487. }
  1488. newItem.component.push(tem);
  1489. }
  1490. }
  1491. var data = getcmpUpdateData([newItem]);
  1492. $.bootstrapLoading.start();
  1493. var callback = function (data) {
  1494. $("#glj_class_div").modal('hide');
  1495. $.bootstrapLoading.end();
  1496. }
  1497. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1498. $.bootstrapLoading.end();
  1499. });
  1500. }
  1501. })
  1502. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1503. gljOprObj.selectedGLJClass = null;
  1504. $('#class_selected_conf').attr("disabled", "disabled");
  1505. $('#selected_class').val("");
  1506. })
  1507. function getcmpUpdateData(items) {
  1508. var data = {
  1509. "updateItems": [],
  1510. "removeIds": []
  1511. }
  1512. data.addItems = items;
  1513. return data;
  1514. }
  1515. })
  1516. function operationWithRound(value1,value2,field,symble) {
  1517. let decimal = getDecimal(field);
  1518. value1 = scMathUtil.roundForObj(value1,decimal);
  1519. value2 = scMathUtil.roundForObj(value2,decimal);
  1520. let result;
  1521. switch (symble){
  1522. case "+" :
  1523. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1524. break;
  1525. case "-":
  1526. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1527. break;
  1528. case "*":
  1529. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1530. break;
  1531. case "/":
  1532. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1533. break
  1534. }
  1535. return result;
  1536. }
  1537. function getDecimal(fieldID, node) {
  1538. if (node) {
  1539. return decimalObj.decimal(fieldID, node);
  1540. } else if (fieldID.indexOf(".") != -1) {
  1541. var keyArray = fieldID.split(".");
  1542. return decimalObj[keyArray[0]][keyArray[1]];
  1543. } else {
  1544. return decimalObj.decimal(fieldID);
  1545. }
  1546. }
  1547. function sortRationGLJ(list) {
  1548. list = _.sortByAll(list, [function (item) {
  1549. return item.type + "";
  1550. }, "code"])
  1551. return list;
  1552. }
  1553. function compareRationGLJ(a, b) {
  1554. if ((a.type + "") < (b.type + "")) {
  1555. return true
  1556. }
  1557. if ((a.type + "") == (b.type + "")) {
  1558. if (a.code < b.code) {
  1559. return true
  1560. }
  1561. }
  1562. return false;
  1563. }