glj_view.js 72 KB

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