glj_view.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912
  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. expandSpeed: "",
  141. selectedMulti: false
  142. },
  143. edit: {
  144. enable: false,
  145. editNameSelectAll: true,
  146. showRemoveBtn: true,
  147. showRenameBtn: true,
  148. removeTitle: "删除节点",
  149. renameTitle: "更改名称"
  150. },
  151. data: {
  152. keep: {
  153. parent: true,
  154. leaf: true
  155. },
  156. key: {
  157. children: "items",
  158. name: "Name"
  159. },
  160. simpleData: {
  161. enable: false,
  162. idKey: "ID",
  163. pIdKey: "ParentID",
  164. rootPId: -1
  165. }
  166. },
  167. callback: {
  168. onClick: function (event, treeId, treeNode) {
  169. if (treeId == 'gljTree') {
  170. let me = gljOprObj, gljTypeId = treeNode.ID;
  171. if (treeNode.ID) {
  172. me.gljCurTypeId = treeNode.ID;
  173. me.filterLibGLJSheetData();
  174. me.showLibGLJSheetData();
  175. }
  176. } else {
  177. if (treeNode.isParent) {
  178. $('#class_selected_conf').attr("disabled", "disabled");
  179. $('#selected_class').val("");
  180. } else {
  181. $('#class_selected_conf').removeAttr("disabled");
  182. $('#selected_class').val(treeNode.ID);
  183. }
  184. }
  185. }
  186. }
  187. },
  188. gljLibSheetSetting: {
  189. owner: 'gljTree',
  190. header: [
  191. {
  192. headerName: "选择",
  193. headerWidth: 40,
  194. dataCode: "select",
  195. hAlign: "center",
  196. vAlign: "center",
  197. cellType: "checkBox"
  198. },
  199. {
  200. headerName: "编码",
  201. headerWidth: 80,
  202. dataCode: "code",
  203. dataType: "String",
  204. formatter: "@",
  205. hAlign: "left",
  206. vAlign: "center"
  207. },
  208. {
  209. headerName: "名称",
  210. headerWidth: 120,
  211. dataCode: "name",
  212. dataType: "String",
  213. hAlign: "left",
  214. vAlign: "center"
  215. },
  216. {
  217. headerName: "规格型号",
  218. headerWidth: 80,
  219. dataCode: "specs",
  220. dataType: "String",
  221. hAlign: "center",
  222. vAlign: "center"
  223. },
  224. {
  225. headerName: "单位",
  226. headerWidth: 40,
  227. dataCode: "unit",
  228. dataType: "String",
  229. hAlign: "center",
  230. vAlign: "center"
  231. },
  232. {
  233. headerName: "单价",
  234. headerWidth: 80,
  235. dataCode: "basePrice",
  236. dataType: "Number",
  237. formatter: "0.00",
  238. hAlign: "right",
  239. vAlign: "center"
  240. },
  241. {
  242. headerName: "类型",
  243. headerWidth: 80,
  244. dataCode: "gljType",
  245. dataType: "String",
  246. hAlign: "center",
  247. vAlign: "center"
  248. },
  249. {
  250. headerName: "是否新增",
  251. headerWidth: 80,
  252. dataCode: "isComplementary",
  253. dataType: "String",
  254. hAlign: "center",
  255. vAlign: "center",
  256. cellType: "checkBox"
  257. }
  258. ],
  259. view: {
  260. lockColumns: [0, 1, 2, 3, 4, 5, 6]
  261. }
  262. },
  263. gljLibSheet: null,
  264. initSheet: function (sheet) {
  265. var me = this;
  266. me.sheet = sheet;
  267. sheetCommonObj.initSheet(me.sheet, me.setting, 30);
  268. sheet.name('ration_glj');
  269. me.bindSheetEvent(sheet);
  270. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  271. sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
  272. sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
  273. sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
  274. if (args.row>=me.sheetData.length){
  275. args.cancel = true;
  276. }
  277. if (me.sheetData[args.row].isMixRatio) {
  278. args.cancel = true;
  279. }
  280. });
  281. gljContextMenu.loadGLJSpreadContextMenu();
  282. },
  283. initCoeSheet: function (sheet) {
  284. var me = this;
  285. me.coeSheet = sheet;
  286. sheetCommonObj.initSheet(me.coeSheet, me.coeSetting, 30);
  287. sheet.name('ration_coe');
  288. me.bindSheetEvent(sheet);
  289. sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCoeCellClick);
  290. subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
  291. },
  292. initAssSheet: function (sheet) {
  293. var me = this;
  294. me.assSheet = sheet;
  295. sheetCommonObj.initSheet(me.assSheet, me.assSetting, 30);
  296. sheet.name('ration_ass');
  297. me.bindSheetEvent(sheet);
  298. },
  299. initDetailSheet: function (sheet) {
  300. var me = this;
  301. me.detailSheet = sheet;
  302. sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
  303. // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
  304. sheet.name('quantity_detail');
  305. me.bindSheetEvent(sheet);
  306. sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
  307. if(me.detailSheetReadonly()){
  308. args.cancel = true;
  309. }else {
  310. if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
  311. args.sheet.setValue(args.row,args.col,"");
  312. }
  313. }
  314. });
  315. },
  316. detailSheetReadonly:function () {
  317. let selected = projectObj.project.mainTree.selected;
  318. if(selected) {
  319. //清单锁定时只读
  320. if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked()){
  321. return true;
  322. }
  323. //是主材或者是设备时只读
  324. if(selected.sourceType == ModuleNames.ration_glj){
  325. return true;
  326. }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
  327. return true;
  328. }
  329. return false;
  330. }
  331. return true;
  332. },
  333. showCoeData: function (sheet, setting, datas) {
  334. sheet.floatingObjects.remove("customerCoe");
  335. sheetCommonObj.showData(sheet, setting, datas);
  336. if (datas.length > 0) {
  337. var cus_index = _.findIndex(datas, function (item) {
  338. return item.coeID == -1;
  339. })
  340. if (cus_index != -1) {
  341. this.addDropDownList();
  342. this.addCusButton(cus_index, 1, datas[cus_index].name);
  343. }
  344. }
  345. },
  346. bindSheetEvent: function (sheet) {
  347. var me = this;
  348. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  349. sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  350. sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
  351. sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
  352. sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
  353. // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
  354. },
  355. onClipboardPasting: function (sender, args) {
  356. var me = gljOprObj;
  357. if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
  358. args.cancel = true;
  359. }
  360. },
  361. onClipboardPasted: function (e, info) {
  362. var me = gljOprObj;
  363. console.log('past');
  364. // if (!me.ration) {return;};
  365. // your code...
  366. },
  367. startEditChecking:function (sender,args) {
  368. let me = gljOprObj;
  369. let selected = projectObj.project.mainTree.selected;
  370. if(selected){
  371. if(me.isInstallationNode(selected)==true){
  372. args.cancel = true;
  373. }
  374. }else {
  375. args.cancel = true;
  376. }
  377. },
  378. isInstallationNode:function(node){
  379. if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
  380. return true;
  381. }
  382. return false
  383. },
  384. onEditEnded: function (sender, args) {
  385. var me = gljOprObj;
  386. if (args.sheetName == 'ration_glj') {
  387. me.onEditGLJSheet(args)
  388. }
  389. if (args.sheetName == 'ration_ass') {
  390. me.onEditAssSheet(args);
  391. }
  392. if (args.sheetName == 'quantity_detail') {
  393. me.onEditDetailSheet(args);
  394. }
  395. },
  396. onEditDetailSheet: function (args,callback) {
  397. console.log(args);
  398. var me = gljOprObj;
  399. if (args.row > me.detailData.length) {
  400. return;
  401. }
  402. if (args.row == me.detailData.length && args.editingText == null) {
  403. return;
  404. }
  405. var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
  406. var detailList = me.detailData;
  407. if(args.editingText){
  408. args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
  409. args.editingText = args.editingText.replace(/)/g, ")");
  410. }
  411. setTimeout(function () {//这里须用延时执行的办法,不然的弹窗确认窗口会和spreadjs 的事件有冲突,造成定额工料机数据不会根据树结点更新的问题
  412. if (args.row == detailList.length) {
  413. projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
  414. }
  415. if (args.row < detailList.length) {
  416. projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
  417. }
  418. }, 100);
  419. },
  420. onEditGLJSheet: function (args) {
  421. var me = gljOprObj;
  422. if (args.row >= me.sheetData.length) {
  423. me.sheet.getCell(args.row, args.col).value(null);
  424. return;
  425. }
  426. me.updateRationGLJ(args);
  427. },
  428. onEditAssSheet: function (args) {
  429. var me = gljOprObj;
  430. if (args.row >= me.assSheetData.length) {
  431. me.assSheet.getCell(args.row, args.col).value(null);
  432. return;
  433. }
  434. if (me.assSetting.header[args.col].dataCode == 'actualValue') {//自定义消耗量
  435. me.updateRationAss(args);
  436. }
  437. },
  438. onButtonClick: function (sender, args) {
  439. if(args.sheet.isEditing()){
  440. args.sheet.endEdit();
  441. }
  442. var me = gljOprObj;
  443. var sheet = args.sheet, row = args.row, col = args.col;
  444. var cellType = sheet.getCellType(row, col);
  445. if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
  446. if(args.sheetName == 'ration_coe'){
  447. me.onCusButtonClick(sender, args);
  448. }else if(args.sheetName == 'rationInstallSheet'){
  449. installationFeeObj.onPositionButtonClick(sender,args);
  450. }
  451. } else {
  452. me.onCheckBoxClick(sender, args)
  453. }
  454. },
  455. onCheckBoxClick: function (sender, args) {
  456. let selected = projectObj.project.mainTree.selected;
  457. if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
  458. return ;
  459. }
  460. let checkboxValue = args.sheet.getCell(args.row, args.col).value();
  461. if(args.sheetName == 'rationInstallSheet' && checkboxValue){
  462. return;
  463. }
  464. if(gljOprObj.isInstallationNode(selected)==true){
  465. return;
  466. }
  467. let newval = 0;
  468. if (checkboxValue) {
  469. newval = 0;
  470. args.sheet.getCell(args.row, args.col).value(newval);
  471. } else {
  472. newval = 1;
  473. args.sheet.getCell(args.row, args.col).value(newval);
  474. }
  475. if (args.sheetName == 'ration_glj') {
  476. gljOprObj.updateIsEstimate(args,newval);
  477. } else if (args.sheetName == 'ration_coe') {
  478. gljOprObj.updateRationCoe(args, newval)
  479. } else if (args.sheetName == 'quantity_detail') {
  480. projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
  481. } else if (args.sheetName == 'glj_lib') {
  482. gljOprObj.setGLJSelection(args, newval);
  483. }else if(args.sheetName == 'rationInstallSheet'){
  484. args.newValue = newval;
  485. installationFeeObj.onRationInstallValueChange(sender,args);
  486. }
  487. },
  488. onCusButtonClick: function (sender, args) {
  489. var me = gljOprObj;
  490. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  491. var isVisable = floatingObject.isVisible();
  492. if (!isVisable) {
  493. me.coeSheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false);
  494. me.showFloationObject(floatingObject, me.coeSheetData[args.row]);
  495. } else {
  496. var result = me.checkIfNeedUpdate();
  497. if (result.isNeed) {
  498. projectObj.project.ration_coe.updateCustomerCoe(result);
  499. }
  500. floatingObject.isVisible(false);
  501. }
  502. },
  503. onCellClick: function (sender, args) {
  504. var me = gljOprObj;
  505. if (args.row >= me.sheetData.length) {
  506. return;
  507. }
  508. me.editChecking(args);
  509. },
  510. onCellDoubleClick:function (sender, args) {
  511. var me = gljOprObj;
  512. var header = me.setting.header;
  513. if (args.row >= me.sheetData.length) {
  514. return;
  515. }
  516. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  517. if(me.hasComposition(me.sheetData[args.row])){
  518. alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
  519. }
  520. }
  521. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  522. var isAdd = me.sheetData[args.row].isAdd;
  523. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  524. if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
  525. alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
  526. }
  527. }
  528. }
  529. },
  530. onClipboardChanged: function (sender, info) {
  531. let cDatas = sheetCommonObj.getTableData(info.sheet, null);
  532. sheetCommonObj.copyTextToClipboard(cDatas);
  533. return;
  534. },
  535. onCoeCellClick: function (sender, args) {
  536. var me = gljOprObj;
  537. var floatingObject = me.coeSheet.floatingObjects.get('customerCoe');
  538. var isVisable = floatingObject.isVisible();
  539. /* if($('#dropdown').css("display") == 'none'){
  540. if(args.col==1&&me.coeSheetData.length>args.row&&me.coeSheetData[args.row].coeID==-1){
  541. me.showFloationObject(floatingObject,me.coeSheetData[args.row]);
  542. }
  543. }*/
  544. if (isVisable) {
  545. var result = me.checkIfNeedUpdate();
  546. if (result.isNeed) {
  547. projectObj.project.ration_coe.updateCustomerCoe(result);
  548. }
  549. floatingObject.isVisible(false);
  550. // $('#dropdown').hide();
  551. }
  552. },
  553. showFloationObject(floatingObject, data){
  554. floatingObject.isVisible(true);
  555. var sheet = this.coeSheet;
  556. var startRow = this.coeSheetData.length;
  557. var endRow = startRow + 7;
  558. floatingObject.startRow(startRow);
  559. floatingObject.startColumn(1);
  560. floatingObject.endColumn(2);
  561. floatingObject.endRow(endRow);
  562. this.bindFloadingObjectValue(data);
  563. sheet.repaint();
  564. // var editPosition = $("#edit").offset();
  565. //$('#dropdown').show();
  566. //var top =editPosition.top>=825?825:editPosition.top
  567. //$('#dropdown').offset({left:editPosition.left,top:top});//top: 791px; left:70px;
  568. },
  569. bindFloadingObjectValue(data){
  570. $('#coe_ration').val(data.coes[0].amount);
  571. $('#manual').val(data.coes[1].amount);
  572. $('#material').val(data.coes[2].amount);
  573. $('#manchine').val(data.coes[3].amount);
  574. $('#mainM').val(data.coes[4].amount);
  575. $('#equipment').val(data.coes[5].amount);
  576. },
  577. onInputChange(id, name){
  578. var coe = _.find(gljOprObj.coeSheetData, function (c) {
  579. return c.coeID == -1;
  580. });
  581. var newValue = gljOprObj.numberValueChecking($('#' + id).val());
  582. if (newValue) {
  583. newValue = _.round(newValue, 2);
  584. if (newValue == coe.coes[name].amount) return;
  585. if (id == 'coe_ration') {
  586. $('#coe_ration').val(newValue);
  587. $('#manual').val(newValue);
  588. $('#material').val(newValue);
  589. $('#manchine').val(newValue);
  590. $('#mainM').val(newValue);
  591. $('#equipment').val(newValue);
  592. } else {
  593. $('#' + id).val(newValue);
  594. }
  595. } else {
  596. $('#' + id).val(coe.coes[name].amount);
  597. }
  598. },
  599. checkIfNeedUpdate(){
  600. var data = _.find(gljOprObj.coeSheetData, function (c) {
  601. return c.coeID == -1;
  602. });
  603. var result = {
  604. isNeed: false
  605. }
  606. var coe_ration = $('#coe_ration').val();
  607. var manual = $('#manual').val();
  608. var material = $('#material').val();
  609. var manchine = $('#manchine').val();
  610. var mainM = $('#mainM').val();
  611. var equipment = $('#equipment').val();
  612. if (coe_ration != data.coes[0].amount) {
  613. result.isNeed = true;
  614. data.coes[0].amount = coe_ration;
  615. }
  616. if (manual != data.coes[1].amount) {
  617. result.isNeed = true;
  618. data.coes[1].amount = manual;
  619. }
  620. if (material != data.coes[2].amount) {
  621. result.isNeed = true;
  622. data.coes[2].amount = material;
  623. }
  624. if (manchine != data.coes[3].amount) {
  625. result.isNeed = true;
  626. data.coes[3].amount = manchine;
  627. }
  628. if (mainM != data.coes[4].amount) {
  629. result.isNeed = true;
  630. data.coes[4].amount = mainM;
  631. }
  632. if (equipment != data.coes[5].amount) {
  633. result.isNeed = true;
  634. data.coes[5].amount = equipment;
  635. }
  636. if (result.isNeed) {
  637. result.doc = {
  638. coes: data.coes
  639. };
  640. result.query = {
  641. projectID: data.projectID,
  642. ID: data.ID,
  643. rationID: data.rationID
  644. };
  645. }
  646. return result;
  647. },
  648. editChecking: function (args) {
  649. var me = gljOprObj;
  650. var header = me.setting.header;
  651. var disable = null;
  652. if (me.sheetData[args.row] != undefined) {
  653. if (me.sheetData[args.row].isMixRatio) {
  654. disable = true;
  655. }else {
  656. if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
  657. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){
  658. disable = true;
  659. }else {
  660. disable = false;
  661. }
  662. }
  663. if (header[args.col] && header[args.col].dataCode == 'basePrice') {
  664. var isAdd = me.sheetData[args.row].isAdd;
  665. if(isAdd==1){//是新增但没有组成物时允许修改定额价
  666. if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){//如果有组成物,不可修改
  667. disable = true;
  668. }else {
  669. disable = false;
  670. }
  671. } else {
  672. disable = true;
  673. }
  674. }
  675. }
  676. }
  677. if (disable != null) {
  678. me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
  679. }
  680. },
  681. hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
  682. let type = isRationType==true? ration_glj.subType:ration_glj.type;
  683. if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
  684. let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
  685. let con_key = this.getIndex(ration_glj,keyArray);
  686. var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  687. if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
  688. return true;
  689. }
  690. }
  691. return false;
  692. },
  693. addDropDownList: function () {
  694. var sheet = this.coeSheet;
  695. sheet.suspendPaint();
  696. var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe");
  697. var div = document.createElement('div');
  698. div.innerHTML = this.generateHtmlString();
  699. customFloatingObject.startRow(1);
  700. customFloatingObject.startColumn(1);
  701. customFloatingObject.endColumn(2);
  702. customFloatingObject.endRow(2);
  703. $(div).css('background', 'white');
  704. customFloatingObject.content(div);
  705. sheet.floatingObjects.add(customFloatingObject);
  706. customFloatingObject.isVisible(false);
  707. sheet.resumePaint();
  708. },
  709. addCusButton: function (row, col, text) {
  710. var cus_button = new GC.Spread.Sheets.CellTypes.Button();
  711. gljOprObj.coeSheet.setCellType(row, col, cus_button, GC.Spread.Sheets.SheetArea.viewport);
  712. cus_button.marginLeft(0);
  713. cus_button.marginTop(0);
  714. cus_button.marginRight(0);
  715. cus_button.marginBottom(0);
  716. cus_button.text(text);
  717. cus_button.buttonBackColor('white');
  718. gljOprObj.coeSheet.repaint();
  719. },
  720. onRangeChanged: function (sender, args) {
  721. var me = gljOprObj;
  722. console.log(args);
  723. if(args.sheetName == 'quantity_detail'){
  724. me.batchUpdateQuantityDetail(args);
  725. }else {
  726. if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
  727. args.editingText = null;
  728. }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
  729. args.editingText = args.sheet.getCell(args.row,args.col).value();
  730. }else {
  731. return;
  732. }
  733. if (args.sheetName == 'ration_glj') {
  734. me.onEditGLJSheet(args);
  735. }
  736. if (args.sheetName == 'ration_ass') {
  737. me.updateRationAss(args);
  738. }
  739. }
  740. },
  741. batchUpdateQuantityDetail:function (args) {
  742. let me = gljOprObj;
  743. let updateArray = [];
  744. for(let i =0;i<args.changedCells.length;i++){
  745. let c = args.changedCells[i];
  746. let tem = {
  747. row:c.row,
  748. col:c.col,
  749. editingText:args.sheet.getCell(c.row,c.col).text(),
  750. sheet:args.sheet,
  751. sheetName:args.sheetName,
  752. index:i
  753. };
  754. updateArray.push(tem);
  755. }
  756. console.log(updateArray);
  757. },
  758. testBatchUpdate:function () {
  759. let me=gljOprObj;
  760. let temA = [1,2,3];
  761. me.b(1,a);
  762. function a(v) {
  763. let index = temA.indexOf(v);
  764. if(index < temA.length-1){
  765. me.b(temA[index+1],a)
  766. }
  767. }
  768. },
  769. b:function (g,callback) {
  770. console.log(g);
  771. callback(g);
  772. },
  773. generateHtmlString: function () {
  774. // return "<div id='edit'><div>";
  775. var newString = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
  776. //newString +="<tr><td style='height:15px' colspan='2'>自定义系数</td></tr>"
  777. newString += this.getOneRow('定额', 0, 'coe_ration');
  778. newString += this.getOneRow('人工', 1, 'manual');
  779. newString += this.getOneRow('材料', 2, 'material');
  780. newString += this.getOneRow('机械', 3, 'manchine');
  781. newString += this.getOneRow('主材', 4, 'mainM');
  782. newString += this.getOneRow('设备', 5, 'equipment');
  783. newString += "</table></form>";
  784. return newString;
  785. //"<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>";
  786. },
  787. getOneRow: function (text, name, id) {
  788. var rowstr = "<tr style='height:10px'><td style='width: 50px'>" + text
  789. + ":</td><td style='width: 70px' align='right'><input type='text'value='1' name=" + name
  790. + " style='width:30px;border:0;height:14px' align='right' id=" + id + " onchange='gljOprObj.onInputChange(this.id,this.name)'></td></tr>";
  791. return rowstr;
  792. },
  793. showDataIfRationSelect: function (node,selectedNodeId) {
  794. var isShow = false;
  795. if(selectedNodeId){
  796. this.selectedNodeId = selectedNodeId;
  797. }
  798. if (node) {
  799. if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
  800. return;
  801. } else {
  802. this.selectedNodeId = node.getID();
  803. }
  804. if (node.sourceType == "ration") {
  805. if(node.data.type==rationType.gljRation){
  806. this.showMixRatio(node);
  807. }else {
  808. this.showRationGLJData(node);
  809. this.showRationCoeData(node);
  810. this.showRationAssData(node);
  811. installationFeeObj.showRationInstallationData(node);
  812. }
  813. isShow = true;
  814. }
  815. if(node.sourceType == ModuleNames.ration_glj){
  816. this.showMixRatio(node);
  817. isShow = true;
  818. }
  819. this.showQuantityDetailData(node);
  820. } else {
  821. this.selectedNodeId = null;
  822. }
  823. if (!isShow) {
  824. this.clearSheetData();
  825. }
  826. //hide floatingObject
  827. var floatingObject = this.coeSheet.floatingObjects.get('customerCoe');
  828. if (floatingObject) {
  829. floatingObject.isVisible(false);
  830. }
  831. // $('#dropdown').hide();
  832. },
  833. showMixRatio:function (node) {//显示组成物到定额工料机
  834. let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
  835. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  836. let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
  837. let connect_index = this.getIndex(node.data,indexArray);
  838. let gljList=[];
  839. if(mixRatioMap[connect_index]){ //说明是有组成物的类型
  840. gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  841. }
  842. if(gljList.length>0){//计算总消耗量
  843. if(node.sourceType==ModuleNames.ration){
  844. this.calcMixRationTotalQuantity(gljList,node.data.quantity);
  845. }else {
  846. let totalQuantity = this.getTotalQuantity(node.data);
  847. this.calcMixRationTotalQuantity(gljList,totalQuantity)
  848. }
  849. }
  850. this.sheetData = gljList;
  851. this.sheet.setRowCount(0);
  852. this.sheetData = sortRationGLJ(this.sheetData);
  853. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
  854. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  855. this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
  856. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
  857. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  858. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  859. this.coeSheetData = [];
  860. this.assSheetData = [];
  861. },
  862. showRationGLJData: function (node) {
  863. var gljList = [];
  864. var ration_glj = projectObj.project.ration_glj;
  865. node = node ? node : projectObj.project.mainTree.selected;
  866. if (node.sourceType == ModuleNames.ration) {
  867. if(node.data.type==rationType.gljRation){
  868. this.showMixRatio(node);
  869. }else {
  870. let ration = node.data;
  871. gljList = this.filterGljByRation(ration, ration_glj.datas);
  872. this.showInSheet(gljList);
  873. }
  874. }else if(node.sourceType == ModuleNames.ration_glj){
  875. this.showMixRatio(node);
  876. }
  877. },
  878. showRationGLJSheetData: function (init) {
  879. let selected = this.sheet.getSelections();
  880. this.combineWithProjectGlj(this.sheetData);
  881. this.sheet.setRowCount(0);
  882. //console.log(+new Date())
  883. //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
  884. this.sheetData = sortRationGLJ(this.sheetData);
  885. this.sumQuantity();//计算总消耗量
  886. this.addMixRatioToShow();//显示组成物信息
  887. this.initRationTree(init);
  888. sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
  889. if(selected){//定位光标到之前的位置
  890. this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
  891. }
  892. },
  893. initRationTree: function (init) {
  894. this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
  895. for (var i = 0; i < this.sheetData.length; i++) {
  896. if (this.sheetData[i].hasOwnProperty('subList')) {
  897. /* var collapsed = false;
  898. if (init) {
  899. this.sheetData[i].collapsed = true;
  900. collapsed = true;
  901. } else {
  902. collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  903. }*/
  904. var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
  905. if (collapsed == true) {
  906. this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
  907. }
  908. //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);
  909. //这个方法导致加载缓慢
  910. }
  911. }
  912. },
  913. filterGljByRation: function (ration, datas) {
  914. var gljList = [];
  915. if (datas && datas.length > 0) {
  916. gljList = _.filter(datas, {'rationID': ration.ID})
  917. }
  918. return gljList;
  919. },
  920. showInSheet: function (gljList) {
  921. this.sheetData = gljList;
  922. this.showRationGLJSheetData(true);
  923. },
  924. sumQuantity: function (node) {
  925. if (this.sheetData.length > 0) {
  926. node = node ? node : projectObj.project.mainTree.selected;
  927. let ration = node.data;
  928. let quantity = ration.quantity;
  929. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  930. for (let glj of this.sheetData) {
  931. glj.totalQuantity= this.getTotalQuantity(glj,ration);
  932. }
  933. }
  934. },
  935. getTotalQuantity:function(glj,ration){
  936. ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
  937. if(ration){
  938. let quantity = ration.quantity;
  939. quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
  940. if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
  941. return;
  942. }
  943. quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
  944. glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
  945. glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
  946. if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
  947. this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
  948. }
  949. return glj.totalQuantity;
  950. }
  951. },
  952. calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
  953. for (let subG of mList) {
  954. subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
  955. subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
  956. }
  957. },
  958. addMixRatioToShow: function () {
  959. var newList = [];
  960. _.remove(this.sheetData, {'isMixRatio': true});
  961. for (var i = 0; i < this.sheetData.length; i++) {
  962. newList.push(this.sheetData[i]);
  963. if (this.sheetData[i].hasOwnProperty('subList')) {
  964. newList = newList.concat(this.sheetData[i].subList);
  965. }
  966. }
  967. this.sheetData = newList;
  968. },
  969. combineWithProjectGlj: function (ration_gljs,needRatio=true) {
  970. var projectGLJData = projectObj.project.projectGLJ.datas;
  971. var projectGljs = projectGLJData.gljList;
  972. var mixRatioMap = projectGLJData.mixRatioMap;
  973. if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
  974. for (var i = 0; i < ration_gljs.length; i++) {
  975. var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
  976. if (glj) {
  977. if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
  978. ration_gljs[i].isEstimate = glj.is_evaluate;
  979. }
  980. ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
  981. ration_gljs[i].isAdd = glj.unit_price.is_add;
  982. ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
  983. var connect_index = this.getIndex(glj, gljKeyArray);
  984. if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
  985. var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  986. ration_gljs[i].subList = mixRatios;
  987. }
  988. }
  989. }
  990. }
  991. return ration_gljs;
  992. },
  993. setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
  994. let proGLJ = projectObj.project.projectGLJ;
  995. glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
  996. data.marketPrice = proGLJ.getMarketPrice(glj,isRadio);
  997. if(this.calcPriceDiff(glj)==true) {//计取价差
  998. data.basePrice = proGLJ.getBasePrice(glj,isRadio);
  999. data.adjustPrice = proGLJ.getAdjustPrice(glj,isRadio);
  1000. }else {//不计价差
  1001. data.basePrice = proGLJ.getMarketPrice(glj,isRadio);
  1002. data.adjustPrice = proGLJ.getMarketPrice(glj,isRadio);
  1003. }
  1004. return data;
  1005. },
  1006. getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
  1007. let proGLJ = projectObj.project.projectGLJ;
  1008. let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
  1009. if(this.calcPriceDiff(glj)==true){
  1010. return proGLJ.getBasePrice(glj);
  1011. }else {
  1012. return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
  1013. }
  1014. },
  1015. calcPriceDiff:function (glj) {
  1016. let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
  1017. if(glj.is_evaluate==1){//先按是否暂估判断
  1018. return calcOptions.calc_est;
  1019. }
  1020. if(glj.type==gljType.MAIN_MATERIAL||glj.type==gljType.EQUIPMENT){//再判断是否是主材和设备
  1021. return calcOptions.calc_main;
  1022. }
  1023. if(glj.unit_price.is_add==1){//再判断是否新增
  1024. return calcOptions.calc_add;
  1025. }
  1026. return true;
  1027. },
  1028. getIndex(obj, pops){
  1029. let t_index = '';
  1030. let k_arr = [];
  1031. for (let p of pops) {
  1032. let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
  1033. k_arr.push(tmpK);
  1034. }
  1035. t_index = k_arr.join("|-|");
  1036. return t_index;
  1037. },
  1038. getConditionByKey(conKey){//将连接字符串转换成对象
  1039. let valueArray = conKey.split("|-|");
  1040. let obj ={};
  1041. for(let i = 0;i<valueArray.length;i++){
  1042. if(valueArray[i]!='null'){
  1043. if(gljKeyArray[i]=='type'){
  1044. valueArray[i] = parseInt(valueArray[i]);
  1045. }
  1046. obj[gljKeyArray[i]]=valueArray[i];
  1047. }
  1048. }
  1049. return obj;
  1050. },
  1051. getMixRationShowDatas: function (mixRatioList, projectGljs) {
  1052. var temRationGLJs = [];
  1053. for (var i = 0; i < mixRatioList.length; i++) {
  1054. var pg = _.find(projectGljs, {
  1055. 'code': mixRatioList[i].code,
  1056. 'name': mixRatioList[i].name,
  1057. 'specs': mixRatioList[i].specs,
  1058. 'type': mixRatioList[i].type,
  1059. 'unit': mixRatioList[i].unit
  1060. });//改关联关系
  1061. var tem = {
  1062. projectGLJID: pg.id,
  1063. code: pg.code,
  1064. name: pg.name,
  1065. specs: pg.specs,
  1066. unit: pg.unit,
  1067. type:mixRatioList[i].type,
  1068. shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
  1069. consumption:mixRatioList[i].consumption,
  1070. rationItemQuantity: mixRatioList[i].consumption,
  1071. // quantity:mixRatioList[i].consumption,
  1072. /* basePrice: pg.unit_price.base_price,
  1073. marketPrice: pg.unit_price.market_price,
  1074. adjustPrice: pg.adjust_price,*/
  1075. //isEstimate: pg.is_evaluate,
  1076. isMixRatio: true,
  1077. isAdd: pg.unit_price.is_add,
  1078. GLJID: pg.glj_id
  1079. };
  1080. if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
  1081. tem.isEstimate = pg.is_evaluate;
  1082. }
  1083. this.setGLJPrice(tem,pg);
  1084. temRationGLJs.push(tem);
  1085. }
  1086. temRationGLJs = _.sortBy(temRationGLJs, 'code');
  1087. return temRationGLJs;
  1088. },
  1089. showRationCoeData: function (node) {
  1090. var coeList = [];
  1091. var ration_coe = projectObj.project.ration_coe;
  1092. var ration = node.data;
  1093. if (ration_coe.datas && ration_coe.datas.length > 0) {
  1094. coeList = _.filter(ration_coe.datas, {'projectID': ration.projectID, 'rationID': ration.ID})
  1095. }
  1096. this.showCoeData(this.coeSheet, this.coeSetting, coeList);
  1097. this.coeSheetData = coeList;
  1098. },
  1099. showRationAssData: function (node) {
  1100. var assList = node.data.rationAssList ? node.data.rationAssList : [];
  1101. sheetCommonObj.showData(this.assSheet, this.assSetting, assList);
  1102. this.assSheetData = assList;
  1103. },
  1104. showQuantityDetailData: function (node) {
  1105. var details = [];
  1106. node = node ? node : projectObj.project.mainTree.selected;
  1107. var quantity_detail = projectObj.project.quantity_detail;
  1108. if (node.sourceType == ModuleNames.ration) {
  1109. details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
  1110. } else if (node.sourceType == ModuleNames.bills) {
  1111. details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
  1112. }
  1113. details = _.sortBy(details, 'seq');
  1114. sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
  1115. this.detailData = details;
  1116. if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
  1117. this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
  1118. }
  1119. },
  1120. clearSheetData: function () {
  1121. sheetCommonObj.showData(this.sheet, this.setting, []);
  1122. sheetCommonObj.showData(this.coeSheet, this.coeSetting, []);
  1123. sheetCommonObj.showData(this.assSheet, this.assSetting, []);
  1124. installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
  1125. sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
  1126. // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
  1127. this.sheetData = [];
  1128. this.coeSheetData = [];
  1129. this.assSheetData = [];
  1130. installationFeeObj.rationInstallData = [];
  1131. //this.detailData=[];
  1132. },
  1133. updateRationGLJ: function (args) {
  1134. var me = this;
  1135. var updateField = me.setting.header[args.col].dataCode;
  1136. var recode = me.sheetData[args.row];
  1137. var newval;
  1138. if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
  1139. if (args.editingText == null) {
  1140. updateField == 'marketPrice' ? newval = 0 : newval = "";
  1141. } else {
  1142. var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
  1143. newval = number_util.checkNumberValue(args.editingText, decimal);
  1144. if (newval == null) {
  1145. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1146. return;
  1147. }
  1148. }
  1149. } else {
  1150. if (updateField == 'name' || updateField == 'unit') {
  1151. if (args.editingText === null) {
  1152. alert(me.setting.header[args.col].headerName + '不能为空!');
  1153. me.sheet.getCell(args.row, args.col).value(recode[updateField]);
  1154. return;
  1155. }
  1156. }
  1157. newval = args.editingText == null ? "" : args.editingText;
  1158. }
  1159. if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
  1160. return
  1161. }
  1162. if (updateField == 'marketPrice' || updateField == 'basePrice') {
  1163. projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
  1164. } else {
  1165. projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
  1166. }
  1167. },
  1168. updateRationTypeGLJ: function (value, node, fieldName) {
  1169. let newval;
  1170. let updatePrice = false;
  1171. if (fieldName == "marketUnitFee") {
  1172. updatePrice = true;
  1173. if (value == null) {
  1174. newval = 0;
  1175. } else {
  1176. var decimal = getDecimal("glj.unitPrice");
  1177. newval = number_util.checkNumberValue(value, decimal);
  1178. }
  1179. } else {
  1180. if (value != null) {
  1181. projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value)
  1182. return;
  1183. //update
  1184. }
  1185. }
  1186. if (newval && updatePrice == true) {
  1187. projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
  1188. return
  1189. }
  1190. projectObj.mainController.refreshTreeNode([node]);
  1191. },
  1192. updateRationAss: function (args) {
  1193. var me = gljOprObj;
  1194. var newval;
  1195. newval = me.numberValueChecking(args.editingText);
  1196. var recode = me.assSheetData[args.row];
  1197. if (args.editingText === null) {
  1198. newval = parseFloat(recode.stdValue);
  1199. }
  1200. var isValidate = false;
  1201. if (newval) {
  1202. isValidate = me.checkingActualValue(recode, newval)
  1203. }
  1204. if (isValidate) {
  1205. newval = scMathUtil.roundTo(newval, -2);
  1206. projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
  1207. } else {
  1208. newval = recode.actualValue;
  1209. me.assSheet.getCell(args.row, args.col).value(newval);
  1210. }
  1211. },
  1212. updateRationCoe: function (args, newval) {
  1213. var me = gljOprObj;
  1214. var recode = me.coeSheetData[args.row];
  1215. projectObj.project.ration_coe.adjustCoeClick(recode, newval);
  1216. },
  1217. updateIsEstimate:function (args, newval) {
  1218. var me = gljOprObj;
  1219. if(me.setting.header[args.col].dataCode=="isEstimate"){
  1220. var pspread= new ProjectGLJSpread();
  1221. var recode = me.sheetData[args.row];
  1222. let projectGljs = projectObj.project.projectGLJ.datas.gljList;
  1223. let glj = _.find(projectGljs, {'id': recode.projectGLJID});
  1224. if(glj){
  1225. glj["is_evaluate"]=newval;
  1226. args.fromRG=true;
  1227. pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
  1228. }
  1229. }
  1230. },
  1231. numberValueChecking: function (val) {
  1232. var newval = Number(val);
  1233. if (number_util.isNumber(newval)) {
  1234. return newval;
  1235. } else {
  1236. if (val) {
  1237. alert('您输入的数据类型不正确,请重新输入。');
  1238. }
  1239. newval = null;
  1240. }
  1241. return newval;
  1242. },
  1243. checkingActualValue(record, newval){
  1244. var minExist = record.minValue && record.minValue != '0' ? true : false;
  1245. var maxExist = record.maxValue && record.maxValue != '0' ? true : false;
  1246. var minValue = parseFloat(record.minValue);
  1247. var maxValue = parseFloat(record.maxValue);
  1248. var stdVale = parseFloat(record.stdValue);
  1249. if (!maxExist && minExist) {
  1250. if (newval < minValue) {
  1251. alert('实际值应≥' + minValue);
  1252. return false;
  1253. }
  1254. }
  1255. if (maxExist && !minExist) {
  1256. if (newval > maxValue) {
  1257. alert('实际值应≤' + maxValue);
  1258. return false;
  1259. }
  1260. }
  1261. if (maxExist && minExist) {
  1262. if (newval < minValue || newval > maxValue) {
  1263. alert('实际值应介于' + minValue + '~' + maxValue + '之间');
  1264. return false;
  1265. }
  1266. }
  1267. return true;
  1268. },
  1269. showLibGLJSheetData: function () {
  1270. this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
  1271. sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
  1272. this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
  1273. },
  1274. filterLibGLJSheetData: function () {
  1275. let me = this;
  1276. let val = $("input[name='glj']:checked").val();
  1277. if (val == 'allGljs') {
  1278. me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
  1279. } else {
  1280. me.gljLibSheetData = me[val];
  1281. }
  1282. if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
  1283. me.filterLibGLJByType();
  1284. }
  1285. //文本筛选
  1286. let searchStr = $('#gljSearchKeyword').val();
  1287. if(searchStr && searchStr.trim() != ''){
  1288. let reg = new RegExp(searchStr);
  1289. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
  1290. return reg.test(data.code) || reg.test(data.name);
  1291. });
  1292. }
  1293. if (me.gljCurTypeId == undefined) {
  1294. return;
  1295. }
  1296. if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1297. me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
  1298. return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
  1299. });
  1300. } else {
  1301. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
  1302. }
  1303. },
  1304. setGLJSelection: function (args, newVal) {
  1305. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1306. this.addGLJsSelection(args, newVal);
  1307. } else {
  1308. this.replaceGLJSelection(args, newVal);
  1309. }
  1310. },
  1311. addGLJsSelection: function (args, newVal) {
  1312. var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
  1313. if (newVal == 1) {
  1314. this.GLJSelection.push(con_key);
  1315. this.gljLibSheetData[args.row].select = 1;
  1316. } else if (newVal == 0) {
  1317. _.pull(this.GLJSelection, con_key);
  1318. this.gljLibSheetData[args.row].select = 0;
  1319. }
  1320. },
  1321. replaceGLJSelection: function (args, newVal) {
  1322. var me = this;
  1323. var oldSelection = this.GLJSelection[0];
  1324. if (newVal == 0) {
  1325. args.sheet.getCell(args.row, args.col).value(1);
  1326. return;
  1327. }
  1328. this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
  1329. this.gljLibSheetData[args.row].select = 1;
  1330. var oindex = _.findIndex(this.gljLibSheetData, function (item) {
  1331. var i_key = me.getIndex(item, gljLibKeyArray);
  1332. return oldSelection == i_key;
  1333. });
  1334. if (oindex != -1) {
  1335. args.sheet.getCell(oindex, args.col).value(0);
  1336. this.gljLibSheetData[oindex].select = 0;
  1337. } else {
  1338. var oldData = _.find(gljOprObj.AllRecode, function (item) {
  1339. var i_key = me.getIndex(item, gljLibKeyArray);
  1340. return oldSelection == i_key;
  1341. });
  1342. oldData ? oldData.select = 0 : "";
  1343. }
  1344. },
  1345. filterLibGLJByType: function () {
  1346. var me = this;
  1347. var selected = me.sheetData[gljContextMenu.selectedRow];
  1348. me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
  1349. },
  1350. getComboData: function (gljDistType) {
  1351. let me = this;
  1352. let distType;
  1353. let distTypeTree = {
  1354. prefix: 'gljType',
  1355. distTypes: {},
  1356. comboDatas: [],
  1357. distTypesArr: []
  1358. };
  1359. gljDistType.forEach(function (typeData) {
  1360. let typeObj = {
  1361. data: typeData,
  1362. children: [],
  1363. parent: null
  1364. }
  1365. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  1366. distTypeTree.distTypesArr.push(typeObj);
  1367. });
  1368. gljDistType.forEach(function (typeData) {
  1369. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  1370. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  1371. if (parent) {
  1372. distType.parent = parent;
  1373. parent.children.push(distType);
  1374. }
  1375. });
  1376. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  1377. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  1378. distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
  1379. }
  1380. });
  1381. return distTypeTree;
  1382. },
  1383. doInsertGLJ: function () {
  1384. var me = this;
  1385. var selected = projectObj.project.mainTree.selected;
  1386. var project = projectObj.project;
  1387. if (me.GLJSelection.length <= 0) {
  1388. return;
  1389. }
  1390. $("#glj_tree_div").modal('hide');
  1391. $.bootstrapLoading.start();
  1392. project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
  1393. project.projectGLJ.loadData(function () {
  1394. let newNode=null;
  1395. for (let r_glj of data) {
  1396. r_glj = me.setGLJPrice(r_glj);//设置工料机价格
  1397. r_glj.marketUnitFee = r_glj.marketPrice;
  1398. r_glj.quantity = r_glj.quantity + "";
  1399. project.Ration.datas.push(r_glj);
  1400. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  1401. newNode.source = r_glj;
  1402. newNode.sourceType = project.Ration.getSourceType();
  1403. newNode.data = r_glj;
  1404. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  1405. }
  1406. project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
  1407. projectObj.mainController.refreshTreeNode([newNode]);
  1408. if(me.hasComposition(newNode.data,true)){
  1409. me.showMixRatio(newNode);
  1410. }else {
  1411. me.showRationGLJSheetData();
  1412. }
  1413. $.bootstrapLoading.end();
  1414. });
  1415. })
  1416. },
  1417. doAddGLJ: function () {
  1418. var selected = projectObj.project.mainTree.selected;
  1419. var project = projectObj.project;
  1420. gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
  1421. var rg = _.find(gljOprObj.sheetData, function (item) {
  1422. var i_key = gljOprObj.getIndex(item, gljKeyArray);
  1423. return n == i_key
  1424. })
  1425. return rg ? false : true;
  1426. })
  1427. if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
  1428. $("#glj_tree_div").modal('hide');
  1429. project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
  1430. if (result) {
  1431. selected.data.adjustState = result.adjustState;
  1432. //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
  1433. project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
  1434. gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
  1435. project.projectGLJ.loadData(function () {
  1436. project.ration_glj.addToMainTree(result.showData);
  1437. gljOprObj.showRationGLJSheetData();
  1438. project.calcProgram.calcAndSave(selected);
  1439. projectObj.mainController.refreshTreeNode([selected]);
  1440. $.bootstrapLoading.end();
  1441. });
  1442. }
  1443. });//doc.rationID=selected.data.ID;
  1444. } else {
  1445. $("#glj_tree_div").modal('hide');
  1446. }
  1447. },
  1448. doReplaceGLJ: function () {
  1449. var me = this;
  1450. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1451. var project = projectObj.project;
  1452. var selectCode = gljOprObj.GLJSelection[0];
  1453. var selected = projectObj.project.mainTree.selected;
  1454. $("#glj_tree_div").modal('hide');
  1455. project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
  1456. if (result) {
  1457. //result.adjustState;
  1458. var glj_list = projectObj.project.ration_glj.datas;
  1459. var data = result.data;
  1460. var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
  1461. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  1462. var nodes = [selected];
  1463. gljOprObj.sheetData[index] = data;
  1464. glj_list[list_index] = data;
  1465. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  1466. gljOprObj.showRationGLJSheetData();
  1467. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  1468. var node = project.ration_glj.findGLJNodeByID(data.ID);
  1469. if (node) {
  1470. project.ration_glj.transferToNodeData(data);
  1471. node.source = data;
  1472. node.data = data;
  1473. }
  1474. node ? nodes.push(node) : "";
  1475. }
  1476. //project.ration_glj.addToMainTree(data);
  1477. selected.data.adjustState = result.adjustState;
  1478. projectObj.mainController.refreshTreeNode(nodes);
  1479. project.calcProgram.calcAndSave(selected);
  1480. $.bootstrapLoading.end();
  1481. });
  1482. }
  1483. })
  1484. },
  1485. doMReplaceGLJ: function () {
  1486. var me = this;
  1487. var oldData = me.sheetData[gljContextMenu.selectedRow];
  1488. var project = projectObj.project;
  1489. var selectCode = me.GLJSelection[0];
  1490. $("#glj_tree_div").modal('hide');
  1491. project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result) {
  1492. var data = result.data;
  1493. var stateList = result.stateList;
  1494. var n_index = me.getIndex(data.query, gljKeyArray);
  1495. var nodes = [];
  1496. _.forEach(project.ration_glj.datas, function (t) {
  1497. var t_index = me.getIndex(t, gljKeyArray);
  1498. if (n_index == t_index) {
  1499. me.updateProperty(t, data.doc);
  1500. if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
  1501. project.ration_glj.transferToNodeData(t);
  1502. var node = project.ration_glj.findGLJNodeByID(t.ID);
  1503. nodes.push(node);
  1504. }
  1505. }
  1506. })
  1507. project.projectGLJ.loadData(function () {
  1508. me.showRationGLJSheetData();
  1509. var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
  1510. project.calcProgram.calcRationsAndSave(rationNodes);
  1511. $.bootstrapLoading.end();
  1512. });
  1513. })
  1514. },
  1515. updateProperty: function (obj, doc) {
  1516. _.forEach(doc, function (n, key) {
  1517. obj[key] = n;
  1518. });
  1519. },
  1520. refreshStateAfterMreplace: function (stateList, gljNodes) {
  1521. var nodes = [];
  1522. var rationNodes = [];
  1523. _.forEach(stateList, function (s) {
  1524. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1525. return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
  1526. })
  1527. if (node) {
  1528. node.data.adjustState = s.adjustState;
  1529. nodes.push(node);
  1530. rationNodes.push(node);
  1531. }
  1532. });
  1533. gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
  1534. projectObj.mainController.refreshTreeNode(nodes);
  1535. return rationNodes;
  1536. },
  1537. refreshView: function () {
  1538. this.showRationGLJData();
  1539. },
  1540. //
  1541. refreshTreeNode: function (obj) {
  1542. if (!obj) {
  1543. return;
  1544. }
  1545. var objectArray = [];
  1546. var nodes = [];
  1547. if (obj instanceof Array) {
  1548. objectArray.concat(obj);
  1549. } else {
  1550. objectArray.push(obj);
  1551. }
  1552. for (let o of objectArray) {
  1553. var node = _.find(projectObj.project.mainTree.items, function (n) {
  1554. return n.sourceType == o.type && n.data.ID == o.ID;
  1555. })
  1556. if (node) {
  1557. for (var k in o.data) {
  1558. node.data[k] = o.data[k];
  1559. }
  1560. nodes.push(node);
  1561. }
  1562. }
  1563. projectObj.mainController.refreshTreeNode(nodes);
  1564. return nodes;
  1565. },
  1566. getTreeNodeCellType: function (data) {
  1567. var ns = GC.Spread.Sheets;
  1568. var rectW = 10;
  1569. var rectH = 10;
  1570. var margin = 3;
  1571. function TreeNodeCellType() {
  1572. }
  1573. function drowRect(ctx, x, y, w, h) {
  1574. ctx.save();
  1575. ctx.strokeStyle = "gray";
  1576. ctx.translate(0.5, 0.5);
  1577. ctx.beginPath();
  1578. var rectX = x + margin;
  1579. var rectY = y + Math.round(h / 2) - rectH / 2;
  1580. ctx.moveTo(rectX, rectY);
  1581. ctx.lineTo(rectX, rectY + rectH);
  1582. ctx.lineTo(rectX + rectW, rectY + rectH);
  1583. ctx.lineTo(rectX + rectW, rectY);
  1584. ctx.lineTo(rectX, rectY);
  1585. ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
  1586. ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
  1587. ctx.stroke();
  1588. ctx.restore();
  1589. }
  1590. function drowSymbol(ctx, x, y, w, h, collapsed) {
  1591. ctx.save();
  1592. ctx.strokeStyle = "#000000";
  1593. ctx.translate(0.5, 0.5);
  1594. ctx.beginPath();
  1595. ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
  1596. ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
  1597. var rectY = y + Math.round(h / 2) - rectH / 2;
  1598. if (collapsed) {
  1599. ctx.moveTo(x + margin + rectW / 2, rectY + 2);
  1600. ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
  1601. }
  1602. ctx.stroke();
  1603. ctx.restore();
  1604. }
  1605. function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
  1606. offset += 6;
  1607. ctx.save();
  1608. ctx.strokeStyle = "gray";
  1609. ctx.translate(0.5, 0.5);
  1610. ctx.beginPath();
  1611. ctx.moveTo(x + offset, y);
  1612. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1613. offset += 9;
  1614. ctx.lineTo(x + offset, y + Math.round(h / 2));
  1615. if (nextItem && nextItem.isMixRatio) {
  1616. ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
  1617. ctx.lineTo(x + offset - 9, y + h);
  1618. }
  1619. ctx.stroke();
  1620. ctx.restore();
  1621. return offset;
  1622. }
  1623. TreeNodeCellType.prototype = new ns.CellTypes.Text();
  1624. TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  1625. if (value != null) {
  1626. var offset = margin + rectW + 6;
  1627. var recode = data[options.row];
  1628. if (recode && recode.hasOwnProperty('subList')) {
  1629. drowRect(ctx, x, y, w, h);
  1630. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
  1631. drowSymbol(ctx, x, y, w, h, collapsed);
  1632. } else if (recode && recode.isMixRatio) {
  1633. offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
  1634. offset += 1;
  1635. }
  1636. ctx.fillText(value, x + offset + ctx.measureText(value).width, y + h - 5);
  1637. }
  1638. };
  1639. // override getHitInfo to allow cell type get mouse messages
  1640. TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  1641. return {
  1642. x: x,
  1643. y: y,
  1644. row: context.row,
  1645. col: context.col,
  1646. cellStyle: cellStyle,
  1647. cellRect: cellRect,
  1648. sheetArea: context.sheetArea
  1649. };
  1650. };
  1651. TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
  1652. var recode = data[hitinfo.row];
  1653. if (recode && recode.hasOwnProperty('subList')) {
  1654. var hoffset = hitinfo.cellRect.x + 3;
  1655. if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
  1656. var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
  1657. collapsed = !collapsed
  1658. recode.collapsed = collapsed;
  1659. //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
  1660. hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
  1661. hitinfo.sheet.invalidateLayout();
  1662. hitinfo.sheet.repaint();
  1663. }
  1664. }
  1665. };
  1666. return new TreeNodeCellType()
  1667. },
  1668. marketPriceReadOnly: function (node) {
  1669. let hasCom = false;
  1670. if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
  1671. hasCom = this.hasComposition(node.data,true);
  1672. }else {
  1673. hasCom = this.hasComposition(node.data);
  1674. }
  1675. return hasCom|| node.data.isEstimate == 1;
  1676. }
  1677. }
  1678. $(function () {
  1679. $('#glj_tree_div').on('shown.bs.modal', function (e) {
  1680. if (gljOprObj.gljLibSpresd == undefined) {
  1681. gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
  1682. gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
  1683. gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
  1684. gljOprObj.gljLibSheet.options.isProtected = true;
  1685. gljOprObj.gljLibSheet.name('glj_lib');
  1686. }
  1687. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1688. var selected = null;
  1689. if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {
  1690. gljOprObj.GLJSelection = [];
  1691. } else {
  1692. selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
  1693. var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
  1694. gljOprObj.GLJSelection = [connect_key];
  1695. gljOprObj.filterLibGLJByType();
  1696. }
  1697. if (selected != null) {
  1698. var s_key = gljOprObj.getIndex(selected, gljLibKeyArray);
  1699. var r = _.find(gljOprObj.gljLibSheetData, function (item) {
  1700. var item_key = gljOprObj.getIndex(item, gljKeyArray);
  1701. return s_key == item_key;
  1702. });
  1703. r ? r.select = 1 : "";
  1704. }
  1705. gljOprObj.showLibGLJSheetData();
  1706. });
  1707. $('#glj_tree_div').on('hidden.bs.modal', function () {
  1708. $('#gljSearchKeyword').val('');
  1709. });
  1710. $('.glj-radio').change(function () {
  1711. let val = $("input[name='glj']:checked").val();
  1712. if (val == 'allGljs') {
  1713. gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
  1714. gljOprObj.filterLibGLJSheetData();
  1715. gljOprObj.showLibGLJSheetData();
  1716. } else {
  1717. gljOprObj.gljLibSheetData = gljOprObj[val];
  1718. gljOprObj.filterLibGLJSheetData();
  1719. gljOprObj.showLibGLJSheetData();
  1720. }
  1721. })
  1722. //工料机搜索
  1723. $('#gljSearchKeyword').change(function () {
  1724. gljOprObj.filterLibGLJSheetData();
  1725. gljOprObj.showLibGLJSheetData();
  1726. });
  1727. $('#gljSearchKeyword').bind('keypress', function (e) {
  1728. if(e.keyCode === 13){
  1729. $(this).blur();
  1730. return false;
  1731. }
  1732. });
  1733. $('#glj_selected_conf').click(function () {
  1734. if (gljOprObj.GLJSelection.length < 1) {
  1735. return;
  1736. }
  1737. if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
  1738. gljOprObj.doInsertGLJ();
  1739. } else if ($('#actionType').val() == 'add') { //添加工料机
  1740. gljOprObj.doAddGLJ();
  1741. } else if ($('#actionType').val() == 'replace') {//替换工料机
  1742. gljOprObj.doReplaceGLJ();
  1743. } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
  1744. gljOprObj.doMReplaceGLJ();
  1745. }
  1746. })
  1747. $('#class_selected_conf').click(function () {
  1748. var gljClass = $('#selected_class').val();
  1749. var glj = gljOprObj.selectedGLJClass;
  1750. if (glj && gljClass && gljClass != "") {
  1751. //保存到我的工料机库
  1752. /*1 检查是否有组成物
  1753. * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
  1754. * 3 保存
  1755. * */
  1756. var newItem = {
  1757. code: glj.code,
  1758. name: glj.name,
  1759. specs: glj.specs,
  1760. unit: glj.unit,
  1761. basePrice: glj.basePrice,
  1762. gljType: glj.type,
  1763. shortName: glj.shortName,
  1764. component: [],
  1765. gljClass: gljClass
  1766. };
  1767. if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
  1768. for (var i = 0; i < glj.subList.length; i++) {
  1769. let tem = {
  1770. ID: glj.subList[i].GLJID,
  1771. consumeAmt: glj.rationItemQuantity,
  1772. isStd: true
  1773. }
  1774. newItem.component.push(tem);
  1775. }
  1776. }
  1777. var data = getcmpUpdateData([newItem]);
  1778. $.bootstrapLoading.start();
  1779. var callback = function (data) {
  1780. $("#glj_class_div").modal('hide');
  1781. $.bootstrapLoading.end();
  1782. }
  1783. CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
  1784. $.bootstrapLoading.end();
  1785. });
  1786. }
  1787. })
  1788. $('#glj_class_div').on('hidden.bs.modal', function (e) {
  1789. gljOprObj.selectedGLJClass = null;
  1790. $('#class_selected_conf').attr("disabled", "disabled");
  1791. $('#selected_class').val("");
  1792. })
  1793. function getcmpUpdateData(items) {
  1794. var data = {
  1795. "updateItems": [],
  1796. "removeIds": []
  1797. }
  1798. data.addItems = items;
  1799. return data;
  1800. }
  1801. })
  1802. function operationWithRound(value1,value2,field,symble) {
  1803. let decimal = getDecimal(field);
  1804. value1 = scMathUtil.roundForObj(value1,decimal);
  1805. value2 = scMathUtil.roundForObj(value2,decimal);
  1806. let result;
  1807. switch (symble){
  1808. case "+" :
  1809. result=scMathUtil.roundForObj(value1 + value2,decimal);
  1810. break;
  1811. case "-":
  1812. result=scMathUtil.roundForObj(value1 - value2,decimal);
  1813. break;
  1814. case "*":
  1815. result=scMathUtil.roundForObj(value1 * value2,decimal);
  1816. break;
  1817. case "/":
  1818. result=scMathUtil.roundForObj(value1 / value2,decimal);
  1819. break
  1820. }
  1821. return result;
  1822. }
  1823. function getDecimal(fieldID, node) {
  1824. if (node) {
  1825. return decimalObj.decimal(fieldID, node);
  1826. } else if (fieldID.indexOf(".") != -1) {
  1827. var keyArray = fieldID.split(".");
  1828. return decimalObj[keyArray[0]][keyArray[1]];
  1829. } else {
  1830. return decimalObj.decimal(fieldID);
  1831. }
  1832. }
  1833. function getFormatter(decimal) {
  1834. var pre = "0.";
  1835. if (decimal <= 0) {
  1836. return "0";
  1837. }
  1838. for (i = 0; i < decimal; i++) {
  1839. pre += "0"
  1840. }
  1841. return pre;
  1842. }
  1843. function sortRationGLJ(list) {
  1844. list = _.sortByAll(list, [function (item) {
  1845. return item.type + "";
  1846. }, "code"])
  1847. return list;
  1848. }
  1849. function compareRationGLJ(a, b) {
  1850. if ((a.type + "") < (b.type + "")) {
  1851. return true
  1852. }
  1853. if ((a.type + "") == (b.type + "")) {
  1854. if (a.code < b.code) {
  1855. return true
  1856. }
  1857. }
  1858. return false;
  1859. }