glj_view.js 77 KB

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