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. let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
  742. var pg = _.find(projectGljs, function (item) {
  743. return gljOprObj.getIndex(item,gljKeyArray) == mIndex
  744. });//改关联关系
  745. if(pg){
  746. var tem = {
  747. projectGLJID: pg.id,
  748. code: pg.code,
  749. name: pg.name,
  750. specs: pg.specs,
  751. unit: pg.unit,
  752. type:mixRatioList[i].type,
  753. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  754. consumption:mixRatioList[i].consumption,
  755. rationItemQuantity: mixRatioList[i].consumption,
  756. // quantity:mixRatioList[i].consumption,
  757. /* basePrice: pg.unit_price.base_price,
  758. marketPrice: pg.unit_price.market_price,
  759. adjustPrice: pg.adjust_price,*/
  760. //isEstimate: pg.is_evaluate,
  761. isMixRatio: true,
  762. isAdd: pg.unit_price.is_add,
  763. GLJID: pg.glj_id
  764. };
  765. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  766. tem.isEstimate = pg.is_evaluate;
  767. }
  768. this.setGLJPrice(tem,pg);
  769. }
  770. temRationGLJs.push(tem);
  771. }
  772. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  773. return temRationGLJs;
  774. },
  775. showQuantityDetailData: function (node) {
  776. node = node ? node : projectObj.project.mainTree.selected;
  777. var quantity_detail = projectObj.project.quantity_detail;
  778. let field = node.sourceType == ModuleNames.ration?'rationID':'billID';
  779. let details = quantity_detail.getListByID(node.data.ID,field);
  780. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  781. this.detailData = details;
  782. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  783. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  784. }
  785. },
  786. clearSheetData: function () {
  787. if($('#linkGLJ').hasClass('active')){
  788. sheetCommonObj.showData(this.sheet, this.setting, []);
  789. }
  790. if($('#linkAZZJF').hasClass('active')){
  791. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  792. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  793. }
  794. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  795. this.sheetData = [];
  796. installationFeeObj.rationInstallData = [];
  797. //this.detailData=[];
  798. },
  799. updateRationGLJ: function (args) {
  800. var me = this;
  801. var updateField = me.setting.header[args.col].dataCode;
  802. var recode = me.sheetData[args.row];
  803. var newval;
  804. if(!me.rationGLJEditCheck(args)){
  805. recode? me.sheet.getCell(args.row, args.col).value(recode[updateField]): me.sheet.getCell(args.row, args.col).value(null);
  806. return;
  807. }
  808. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  809. if (args.editingText == null) {
  810. updateField == 'marketPrice' ? newval = 0 : newval = "";
  811. } else {
  812. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
  813. newval = number_util.checkNumberValue(args.editingText, decimal);
  814. if (newval == null) {
  815. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  816. return;
  817. }
  818. }
  819. } else {
  820. if (updateField == 'name' || updateField == 'unit') {
  821. if (args.editingText === null) {
  822. alert(me.setting.header[args.col].headerName + '不能为空!');
  823. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  824. return;
  825. }
  826. }
  827. if(updateField == 'code'){
  828. if (!gljUtil.isDef(args.editingText)||args.editingText==''||args.editingText.indexOf('|-|') === -1||this.isRationGLJExit(args.editingText)) {//说明是选中自已,或者是已存在的工料机
  829. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  830. return;
  831. }
  832. }
  833. newval = args.editingText == null ? "" : args.editingText;
  834. }
  835. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  836. return
  837. }
  838. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  839. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  840. }else if(updateField == 'code'){//替换单价文件中已经有的工料机
  841. projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
  842. } else {
  843. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  844. }
  845. },
  846. isRationGLJExit:function (connectKey) {
  847. for(let rg of gljOprObj.sheetData){
  848. if(rg.isMixRatio == true){
  849. continue;
  850. }
  851. if(gljOprObj.getIndex(rg, gljKeyArray) == connectKey){//存在一样的工料机
  852. return true;
  853. }
  854. }
  855. return false;
  856. },
  857. updateRationTypeGLJ: function (value, node, fieldName,editingText) {
  858. let newval;
  859. let updatePrice = false;
  860. if (fieldName == "marketUnitFee") {
  861. updatePrice = true;
  862. if (value == null) {
  863. newval = 0;
  864. } else {
  865. var decimal = getDecimal("glj.unitPrice");
  866. newval = number_util.checkNumberValue(value, decimal);
  867. }
  868. } else {
  869. if (value != null) {
  870. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
  871. return;
  872. //update
  873. }
  874. }
  875. if (newval && updatePrice == true) {
  876. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  877. return
  878. }
  879. projectObj.mainController.refreshTreeNode([node]);
  880. },
  881. updateIsEstimate:function (args, newval) {
  882. var me = gljOprObj;
  883. if(me.setting.header[args.col].dataCode=="isEstimate"){
  884. var pspread= new ProjectGLJSpread();
  885. var recode = me.sheetData[args.row];
  886. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  887. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  888. if(glj){
  889. glj["is_evaluate"]=newval;
  890. args.fromRG=true;
  891. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  892. }
  893. }
  894. },
  895. showLibGLJSheetData: function () {
  896. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  897. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  898. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  899. },
  900. filterLibGLJSheetData: function () {
  901. let me = this;
  902. let val = $("input[name='glj']:checked").val();
  903. if (val == 'allGljs') {
  904. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  905. } else {
  906. me.gljLibSheetData = me[val];
  907. }
  908. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  909. me.filterLibGLJByType();
  910. }else if($('#actionType').val() == 'addMix'){
  911. projectGljObject.filterLibGLJForMixRatio();
  912. }
  913. //文本筛选
  914. let searchStr = $('#gljSearchKeyword').val();
  915. if(searchStr && searchStr.trim() != ''){
  916. let reg = new RegExp(searchStr);
  917. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  918. return reg.test(data.code) || reg.test(data.name);
  919. });
  920. }
  921. if (me.gljCurTypeId == undefined) {
  922. return;
  923. }
  924. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  925. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  926. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  927. });
  928. } else {
  929. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  930. }
  931. },
  932. setGLJSelection: function (args, newVal) {
  933. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
  934. this.addGLJsSelection(args, newVal);
  935. } else {
  936. this.replaceGLJSelection(args, newVal);
  937. }
  938. },
  939. addGLJsSelection: function (args, newVal) {
  940. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  941. if (newVal == 1) {
  942. this.GLJSelection.push(con_key);
  943. this.gljLibSheetData[args.row].select = 1;
  944. } else if (newVal == 0) {
  945. _.pull(this.GLJSelection, con_key);
  946. this.gljLibSheetData[args.row].select = 0;
  947. }
  948. },
  949. replaceGLJSelection: function (args, newVal) {
  950. var me = this;
  951. var oldSelection = this.GLJSelection[0];
  952. if (newVal == 0) {
  953. args.sheet.getCell(args.row, args.col).value(1);
  954. return;
  955. }
  956. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  957. this.gljLibSheetData[args.row].select = 1;
  958. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  959. var i_key = me.getIndex(item, gljLibKeyArray);
  960. return oldSelection == i_key;
  961. });
  962. if (oindex != -1) {
  963. args.sheet.getCell(oindex, args.col).value(0);
  964. this.gljLibSheetData[oindex].select = 0;
  965. } else {
  966. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  967. var i_key = me.getIndex(item, gljLibKeyArray);
  968. return oldSelection == i_key;
  969. });
  970. oldData ? oldData.select = 0 : "";
  971. }
  972. },
  973. filterLibGLJByType: function () {
  974. var me = this;
  975. var selected = me.sheetData[gljContextMenu.selectedRow];
  976. //当前人材机类型是“混凝土、砂浆、配合比、商品混凝土、商品砂浆”时,筛选的可替换的人材机类型应是“混凝土、或砂浆、或配合比、或商品混凝土、或商品砂浆”。
  977. let materialTypes = [202, 203, 204, 205, 206];//除了普通材料
  978. let filterTypes = materialTypes.includes(selected.type) ? materialTypes : [selected.type];
  979. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  980. return filterTypes.includes(data.gljType);
  981. });
  982. //me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  983. },
  984. getComboData: function (gljDistType) {
  985. let me = this;
  986. let distType;
  987. let distTypeTree = {
  988. prefix: 'gljType',
  989. distTypes: {},
  990. comboDatas: [],
  991. distTypesArr: []
  992. };
  993. gljDistType.forEach(function (typeData) {
  994. let typeObj = {
  995. data: typeData,
  996. children: [],
  997. parent: null
  998. }
  999. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1000. distTypeTree.distTypesArr.push(typeObj);
  1001. });
  1002. gljDistType.forEach(function (typeData) {
  1003. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1004. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1005. if (parent) {
  1006. distType.parent = parent;
  1007. parent.children.push(distType);
  1008. }
  1009. });
  1010. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1011. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1012. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1013. }
  1014. });
  1015. return distTypeTree;
  1016. },
  1017. doInsertGLJ: function () {
  1018. var me = this;
  1019. var selected = projectObj.project.mainTree.selected;
  1020. var project = projectObj.project;
  1021. if (me.GLJSelection.length <= 0) {
  1022. return;
  1023. }
  1024. $("#glj_tree_div").modal('hide');
  1025. $.bootstrapLoading.start();
  1026. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1027. let newNode=null;
  1028. for (let r_glj of data) {
  1029. r_glj.quantity = r_glj.quantity + "";
  1030. project.Ration.datas.push(r_glj);
  1031. }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
  1032. project.projectGLJ.loadData(function () {
  1033. for(let r_glj of data){
  1034. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1035. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1036. newNode.source = r_glj;
  1037. newNode.sourceType = project.Ration.getSourceType();
  1038. newNode.data = r_glj;
  1039. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1040. }
  1041. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1042. projectObj.mainController.refreshTreeNode([newNode]);
  1043. if(me.hasComposition(newNode.data,true)){
  1044. me.showMixRatio(newNode);
  1045. }else {
  1046. me.showRationGLJSheetData();
  1047. }
  1048. $.bootstrapLoading.end();
  1049. });
  1050. })
  1051. },
  1052. doAddGLJ: function () {
  1053. var selected = projectObj.project.mainTree.selected;
  1054. var project = projectObj.project;
  1055. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1056. var rg = _.find(gljOprObj.sheetData, function (item) {
  1057. if(item.isMixRatio == true){
  1058. return false;
  1059. }
  1060. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1061. return n == i_key
  1062. });
  1063. return rg ? false : true;
  1064. })
  1065. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1066. $("#glj_tree_div").modal('hide');
  1067. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1068. if (result) {
  1069. selected.data.adjustState = result.adjustState;
  1070. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1071. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1072. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1073. project.projectGLJ.loadData(function () {
  1074. project.ration_glj.addToMainTree(result.showData);
  1075. gljOprObj.showRationGLJSheetData();
  1076. project.calcProgram.calcAndSave(selected);
  1077. projectObj.mainController.refreshTreeNode([selected]);
  1078. $.bootstrapLoading.end();
  1079. });
  1080. }
  1081. });//doc.rationID=selected.data.ID;
  1082. } else {
  1083. $("#glj_tree_div").modal('hide');
  1084. }
  1085. },
  1086. doReplaceGLJ: function () {
  1087. var me = this;
  1088. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1089. var project = projectObj.project;
  1090. var selectCode = gljOprObj.GLJSelection[0];
  1091. var selected = projectObj.project.mainTree.selected;
  1092. $("#glj_tree_div").modal('hide');
  1093. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1094. if (result) {
  1095. //result.adjustState;
  1096. var glj_list = projectObj.project.ration_glj.datas;
  1097. var data = result.data;
  1098. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1099. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1100. var nodes = [selected];
  1101. gljOprObj.sheetData[index] = data;
  1102. glj_list[list_index] = data;
  1103. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1104. gljOprObj.showRationGLJSheetData();
  1105. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1106. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1107. if (node) {
  1108. project.ration_glj.transferToNodeData(data);
  1109. node.source = data;
  1110. node.data = data;
  1111. }
  1112. node ? nodes.push(node) : "";
  1113. }
  1114. //project.ration_glj.addToMainTree(data);
  1115. selected.data.adjustState = result.adjustState;
  1116. selected.data.name = result.name;
  1117. projectObj.mainController.refreshTreeNode(nodes);
  1118. project.calcProgram.calcAndSave(selected);
  1119. $.bootstrapLoading.end();
  1120. });
  1121. }
  1122. })
  1123. },
  1124. doMReplaceGLJ: function () {
  1125. let me = this;
  1126. let oldData = me.sheetData[gljContextMenu.selectedRow];
  1127. let project = projectObj.project;
  1128. let selectCode = me.GLJSelection[0];
  1129. $("#glj_tree_div").modal('hide');
  1130. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
  1131. if(result == null){
  1132. return;
  1133. }
  1134. let data = result.data;
  1135. let stateList = result.stateList;
  1136. //let n_index = me.getIndex(data.query, gljKeyArray);
  1137. let nodes = [];
  1138. _.forEach(project.ration_glj.datas, function (t) {
  1139. // let t_index = me.getIndex(t, gljKeyArray);
  1140. if (updateMap[t.ID]) {
  1141. me.updateProperty(t, data.doc);
  1142. me.updateProperty(t, updateMap[t.ID]);
  1143. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1144. project.ration_glj.transferToNodeData(t);
  1145. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1146. node ? nodes.push(node):'';
  1147. }
  1148. }
  1149. })
  1150. project.projectGLJ.loadData(function () {
  1151. me.showRationGLJSheetData();
  1152. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1153. project.calcProgram.calcNodesAndSave(rationNodes);
  1154. $.bootstrapLoading.end();
  1155. });
  1156. })
  1157. },
  1158. updateProperty: function (obj, doc) {
  1159. _.forEach(doc, function (n, key) {
  1160. obj[key] = n;
  1161. });
  1162. },
  1163. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1164. var nodes = [];
  1165. var rationNodes = [];
  1166. _.forEach(stateList, function (s) {
  1167. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1168. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1169. })
  1170. if (node) {
  1171. node.data.adjustState = s.adjustState;
  1172. node.data.name = s.name;
  1173. nodes.push(node);
  1174. rationNodes.push(node);
  1175. }
  1176. });
  1177. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1178. projectObj.mainController.refreshTreeNode(nodes);
  1179. return rationNodes;
  1180. },
  1181. refreshView: function () {
  1182. let node = projectObj.project.mainTree.selected;
  1183. this.showDataIfRationSelect(node,"111111");
  1184. //this.showRationGLJData();
  1185. },
  1186. //
  1187. refreshTreeNode: function (obj) {
  1188. if (!obj) {
  1189. return;
  1190. }
  1191. var objectArray = [];
  1192. var nodes = [];
  1193. if (obj instanceof Array) {
  1194. objectArray.concat(obj);
  1195. } else {
  1196. objectArray.push(obj);
  1197. }
  1198. for (let o of objectArray) {
  1199. let node = this.updateDataNodeProperty(o.ID,o.data);
  1200. if (node) {
  1201. nodes.push(node);
  1202. }
  1203. }
  1204. projectObj.mainController.refreshTreeNode(nodes);
  1205. return nodes;
  1206. },
  1207. updateDataNodeProperty:function(nodeID,data){
  1208. let node = projectObj.project.mainTree.findNode(nodeID);
  1209. if (node) {
  1210. for (let k in data) {
  1211. node.data[k] = data[k];
  1212. }
  1213. }
  1214. return node;
  1215. },
  1216. getTreeNodeCellType: function (data,comboboxOptions) {
  1217. var ns = GC.Spread.Sheets;
  1218. var rectW = 10;
  1219. var rectH = 10;
  1220. var margin = 3;
  1221. function TreeNodeCellType() {
  1222. }
  1223. function drowRect(ctx, x, y, w, h) {
  1224. ctx.save();
  1225. ctx.strokeStyle = "gray";
  1226. ctx.translate(0.5, 0.5);
  1227. ctx.beginPath();
  1228. var rectX = x + margin;
  1229. var rectY = y + Math.round(h / 2) - rectH / 2;
  1230. ctx.moveTo(rectX, rectY);
  1231. ctx.lineTo(rectX, rectY + rectH);
  1232. ctx.lineTo(rectX + rectW, rectY + rectH);
  1233. ctx.lineTo(rectX + rectW, rectY);
  1234. ctx.lineTo(rectX, rectY);
  1235. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1236. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1237. ctx.stroke();
  1238. ctx.restore();
  1239. }
  1240. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1241. ctx.save();
  1242. ctx.strokeStyle = "#000000";
  1243. ctx.translate(0.5, 0.5);
  1244. ctx.beginPath();
  1245. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1246. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1247. var rectY = y + Math.round(h / 2) - rectH / 2;
  1248. if (collapsed) {
  1249. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1250. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1251. }
  1252. ctx.stroke();
  1253. ctx.restore();
  1254. }
  1255. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1256. offset += 6;
  1257. ctx.save();
  1258. ctx.strokeStyle = "gray";
  1259. ctx.translate(0.5, 0.5);
  1260. ctx.beginPath();
  1261. ctx.moveTo(x + offset, y);
  1262. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1263. offset += 9;
  1264. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1265. if (nextItem && nextItem.isMixRatio) {
  1266. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1267. ctx.lineTo(x + offset - 9, y + h);
  1268. }
  1269. ctx.stroke();
  1270. ctx.restore();
  1271. return offset;
  1272. }
  1273. TreeNodeCellType.prototype = comboboxOptions?sheetCommonObj.getDynamicCombo():new ns.CellTypes.Text();
  1274. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1275. if (style.backColor) {//先画背景色
  1276. ctx.save();
  1277. ctx.fillStyle = style.backColor;
  1278. ctx.fillRect(x, y, w, h);
  1279. ctx.restore();
  1280. } else {
  1281. ctx.clearRect(x, y, w, h);
  1282. }
  1283. if (value != null) {
  1284. var offset = margin + rectW + 6;
  1285. var recode = data[options.row];
  1286. if (recode && recode.hasOwnProperty('subList')) {
  1287. drowRect(ctx, x, y, w, h);
  1288. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1289. drowSymbol(ctx, x, y, w, h, collapsed);
  1290. } else if (recode && recode.isMixRatio) {
  1291. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1292. offset += 1;
  1293. }
  1294. arguments[2] = x + offset;
  1295. arguments[4] = w - offset;
  1296. //x = x + offset;
  1297. //w = w - offset;
  1298. GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1299. }
  1300. };
  1301. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1302. if(x < cellRect.x+cellRect.width -15){//这里要判断点击的位置来决定return的内容,不能直接用combobox的方法
  1303. return {
  1304. x: x,
  1305. y: y,
  1306. row: context.row,
  1307. col: context.col,
  1308. cellStyle: cellStyle,
  1309. cellRect: cellRect,
  1310. sheetArea: context.sheetArea
  1311. };
  1312. }else {
  1313. return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
  1314. }
  1315. };
  1316. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1317. var recode = data[hitinfo.row];
  1318. if (recode && recode.hasOwnProperty('subList')) {
  1319. var hoffset = hitinfo.cellRect.x + 3;
  1320. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1321. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1322. collapsed = !collapsed
  1323. recode.collapsed = collapsed;
  1324. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1325. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1326. hitinfo.sheet.invalidateLayout();
  1327. hitinfo.sheet.repaint();
  1328. return;
  1329. }
  1330. }
  1331. GC.Spread.Sheets.CellTypes.ComboBox.prototype.processMouseDown.apply(this, arguments);
  1332. // GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
  1333. };
  1334. let cellType = new TreeNodeCellType();
  1335. if(comboboxOptions){
  1336. cellType.editorValueType(GC.Spread.Sheets.CellTypes.EditorValueType.value);
  1337. cellType.itemHeight(comboboxOptions.length).items(comboboxOptions);
  1338. }
  1339. return cellType;
  1340. },
  1341. marketPriceReadOnly: function (node) {
  1342. let hasCom = false;
  1343. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1344. hasCom = this.hasComposition(node.data,true);
  1345. }else {
  1346. hasCom = this.hasComposition(node.data);
  1347. }
  1348. return hasCom|| node.data.isEstimate == 1;
  1349. },
  1350. locateZTree: function(ID) {
  1351. let zTree = $.fn.zTree.getZTreeObj("gljTree");
  1352. let node = null;
  1353. if (ID) node = zTree.getNodesByParam('ID', ID, null)[0]
  1354. if (!node) node = zTree.getNodeByTId('gljTree_1');
  1355. zTree.selectNode(node);
  1356. gljOprObj.gljCurTypeId = ID;
  1357. gljOprObj.filterLibGLJSheetData();
  1358. gljOprObj.showLibGLJSheetData();
  1359. }
  1360. }
  1361. $(function () {
  1362. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1363. if (gljOprObj.gljLibSpresd == undefined) {
  1364. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1365. sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
  1366. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1367. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1368. gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
  1369. gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
  1370. gljOprObj.gljLibSheet.options.isProtected = true;
  1371. gljOprObj.gljLibSheet.name('glj_lib');
  1372. }
  1373. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1374. let gljClass = 0, selectMap = {};
  1375. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
  1376. gljOprObj.GLJSelection = [];
  1377. } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
  1378. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1379. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1380. gljOprObj.GLJSelection = [connect_key];
  1381. selectMap[connect_key] = true;
  1382. gljOprObj.filterLibGLJByType();
  1383. }else if($('#actionType').val() =='addMix'){//添加组成物
  1384. gljOprObj.GLJSelection = [];
  1385. projectGljObject.filterLibGLJForMixRatio();
  1386. /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
  1387. gljOprObj.GLJSelection = [];
  1388. for(let s of selections){
  1389. let s_key = gljOprObj.getIndex(s, gljKeyArray);
  1390. selectMap[s_key] = true;
  1391. gljOprObj.GLJSelection.push(s_key);
  1392. }*/
  1393. }
  1394. for(let item of gljOprObj.gljLibSheetData){
  1395. let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
  1396. if(selectMap[item_key]){
  1397. item.select = 1 ;
  1398. gljClass = item.gljClass;
  1399. }
  1400. }
  1401. //替换,焦点定位至当前选中人材机
  1402. if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
  1403. gljOprObj.locateZTree(gljClass);
  1404. let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1405. let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
  1406. gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
  1407. gljOprObj.gljLibSheet.setActiveCell(index, 0);
  1408. gljOprObj.initSelection({row: index});
  1409. gljOprObj.gljLibSpresd.focus(true);
  1410. }
  1411. else gljOprObj.showLibGLJSheetData();
  1412. });
  1413. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1414. $('#gljSearchKeyword').val('');
  1415. });
  1416. $('.glj-radio').change(function () {
  1417. let val = $("input[name='glj']:checked").val();
  1418. if (val == 'allGljs') {
  1419. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1420. gljOprObj.filterLibGLJSheetData();
  1421. gljOprObj.showLibGLJSheetData();
  1422. } else {
  1423. gljOprObj.gljLibSheetData = gljOprObj[val];
  1424. gljOprObj.filterLibGLJSheetData();
  1425. gljOprObj.showLibGLJSheetData();
  1426. }
  1427. })
  1428. /* //工料机搜索
  1429. $('#gljSearchKeyword').change(function () {
  1430. gljOprObj.filterLibGLJSheetData();
  1431. gljOprObj.showLibGLJSheetData();
  1432. });
  1433. $('#gljSearchKeyword').bind('keypress', function (e) {
  1434. if(e.keyCode === 13){
  1435. alert('2');
  1436. $(this).blur();
  1437. return false;
  1438. }
  1439. });*/
  1440. $('#gljSearchKeyword').bind('keyup', function (e) {
  1441. gljOprObj.filterLibGLJSheetData();
  1442. gljOprObj.showLibGLJSheetData();
  1443. });
  1444. $('#glj_selected_conf').click(function () {
  1445. if (gljOprObj.GLJSelection.length < 1) {
  1446. return;
  1447. }
  1448. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1449. gljOprObj.doInsertGLJ();
  1450. } else if ($('#actionType').val() == 'add') { //添加工料机
  1451. gljOprObj.doAddGLJ();
  1452. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1453. gljOprObj.doReplaceGLJ();
  1454. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1455. gljOprObj.doMReplaceGLJ();
  1456. }else if($('#actionType').val() == 'addMix'){
  1457. projectGljObject.addMixRatio();
  1458. }
  1459. })
  1460. $('#class_selected_conf').click(function () {
  1461. var gljClass = $('#selected_class').val();
  1462. var glj = gljOprObj.selectedGLJClass;
  1463. if (glj && gljClass && gljClass != "") {
  1464. //保存到我的工料机库
  1465. /*1 检查是否有组成物
  1466. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1467. * 3 保存
  1468. * */
  1469. var newItem = {
  1470. code: glj.code,
  1471. name: glj.name,
  1472. specs: glj.specs,
  1473. unit: glj.unit,
  1474. basePrice: glj.basePrice,
  1475. gljType: glj.type,
  1476. shortName: glj.shortName,
  1477. component: [],
  1478. gljClass: gljClass
  1479. };
  1480. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1481. for (var i = 0; i < glj.subList.length; i++) {
  1482. let tem = {
  1483. ID: glj.subList[i].GLJID,
  1484. consumeAmt: glj.rationItemQuantity,
  1485. isStd: true
  1486. }
  1487. newItem.component.push(tem);
  1488. }
  1489. }
  1490. var data = getcmpUpdateData([newItem]);
  1491. $.bootstrapLoading.start();
  1492. var callback = function (data) {
  1493. $("#glj_class_div").modal('hide');
  1494. $.bootstrapLoading.end();
  1495. }
  1496. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1497. $.bootstrapLoading.end();
  1498. });
  1499. }
  1500. })
  1501. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1502. gljOprObj.selectedGLJClass = null;
  1503. $('#class_selected_conf').attr("disabled", "disabled");
  1504. $('#selected_class').val("");
  1505. })
  1506. function getcmpUpdateData(items) {
  1507. var data = {
  1508. "updateItems": [],
  1509. "removeIds": []
  1510. }
  1511. data.addItems = items;
  1512. return data;
  1513. }
  1514. })
  1515. function operationWithRound(value1,value2,field,symble) {
  1516. let decimal = getDecimal(field);
  1517. value1 = scMathUtil.roundForObj(value1,decimal);
  1518. value2 = scMathUtil.roundForObj(value2,decimal);
  1519. let result;
  1520. switch (symble){
  1521. case "+" :
  1522. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1523. break;
  1524. case "-":
  1525. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1526. break;
  1527. case "*":
  1528. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1529. break;
  1530. case "/":
  1531. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1532. break
  1533. }
  1534. return result;
  1535. }
  1536. function getDecimal(fieldID, node) {
  1537. if (node) {
  1538. return decimalObj.decimal(fieldID, node);
  1539. } else if (fieldID.indexOf(".") != -1) {
  1540. var keyArray = fieldID.split(".");
  1541. return decimalObj[keyArray[0]][keyArray[1]];
  1542. } else {
  1543. return decimalObj.decimal(fieldID);
  1544. }
  1545. }
  1546. function sortRationGLJ(list) {
  1547. list = _.sortByAll(list, [function (item) {
  1548. return item.type + "";
  1549. }, "code"])
  1550. return list;
  1551. }
  1552. function compareRationGLJ(a, b) {
  1553. if ((a.type + "") < (b.type + "")) {
  1554. return true
  1555. }
  1556. if ((a.type + "") == (b.type + "")) {
  1557. if (a.code < b.code) {
  1558. return true
  1559. }
  1560. }
  1561. return false;
  1562. }