glj_view.js 62 KB

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