glj_view.js 63 KB

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