glj_view.js 72 KB

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