glj_view.js 73 KB

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