glj_view.js 63 KB

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