glj_view.js 63 KB

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