glj_view.js 81 KB

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