glj_view.js 74 KB

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