glj.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. $(document).ready(function () {
  5. let moduleName = 'compleGLj';
  6. SlideResize.loadHorizonWidth(moduleName, [$('#rightResize'), $('#leftResize')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  7. refreshALlWorkBook();
  8. });
  9. //章节树与人材机表
  10. let leftElesObj = {};
  11. leftElesObj.module = moduleName;
  12. leftElesObj.resize = $('#leftResize');
  13. leftElesObj.parent = $('#dataRow');
  14. leftElesObj.left = $('#leftContent');
  15. leftElesObj.right = $('#midContent');
  16. SlideResize.horizontalSlide(leftElesObj, { min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200` }, function () {
  17. refreshALlWorkBook();
  18. });
  19. //人材机表与人材机组成物表
  20. let rightElesObj = {};
  21. rightElesObj.module = moduleName;
  22. rightElesObj.resize = $('#rightResize');
  23. rightElesObj.parent = $('#dataRow');
  24. rightElesObj.left = $('#midContent');
  25. rightElesObj.right = $('#rightContent');
  26. SlideResize.horizontalSlide(rightElesObj, { min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200` }, function () {
  27. let resizeRate = 500 / $('#midContent').width(),
  28. sheetRate = 100 - resizeRate;
  29. $('#leftResize').css('width', `${resizeRate}%`);
  30. $('#GLJListSheet').css('width', `${sheetRate}%`);
  31. refreshALlWorkBook();
  32. });
  33. });
  34. function refreshALlWorkBook() {
  35. if (gljClassTreeObj.workBook) {
  36. gljClassTreeObj.workBook.refresh();
  37. }
  38. if (repositoryGljObj.workBook) {
  39. repositoryGljObj.workBook.refresh();
  40. }
  41. if (gljComponentOprObj.workBook) {
  42. gljComponentOprObj.workBook.refresh();
  43. }
  44. }
  45. let pageOprObj = {
  46. gljLibName: null,
  47. stdGljLibId: null,
  48. userId: null,
  49. compilationId: null,
  50. initPage: function (container, containerComponent, containerC) {
  51. let me = pageOprObj;
  52. me.stdGljLibId = stdGljLibId;
  53. me.userId = userId;
  54. me.compilationId = compilationId;
  55. //生成人材机表格列头
  56. repositoryGljObj.setting.header = repositoryGljObj.initHeaders(priceProperties);
  57. //生成列映射
  58. sheetCommonObj.initColMapping(repositoryGljObj, repositoryGljObj.setting.header);
  59. //生成单价列下标数组
  60. repositoryGljObj.initPriceCols(priceProperties, repositoryGljObj.colMapping);
  61. repositoryGljObj.buildSheet(container);
  62. gljComponentOprObj.buildSheet(containerComponent);
  63. componentOprObj.buildSheet(containerC);
  64. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  65. //repositoryGljObj.getRationGljIds(gljLibId);
  66. repositoryGljObj.getGljDistType(function () {
  67. repositoryGljObj.currentRepositoryId = me.stdGljLibId;
  68. gljClassTreeObj.getGljClassTree(stdGljLibId, function () {
  69. repositoryGljObj.getGljItems(me.stdGljLibId, function () {
  70. gljClassTreeObj.initSelection(gljClassTreeObj.tree.selected);
  71. });
  72. });
  73. });
  74. }
  75. };
  76. let repositoryGljObj = {
  77. colMapping: null,
  78. treeObj: null,
  79. workBook: null,
  80. // 是否获取了完整的人材机数据
  81. // 第一次打开页面只加载补充人材机和标准人材机的编码
  82. // 第一次打开选择组成物的窗口才加载标准人材机剩余数据
  83. pullCompleteData: false,
  84. gljCurTypeId: -1,
  85. currentRepositoryId: -1,
  86. currentCache: null,
  87. parentNodeIds: {},
  88. gljList: [],
  89. stdGljList: [],
  90. complementaryGljList: [],
  91. machineModel: { textArr: ['特', '大', '中', '小'], comboItems: [{ text: '特', value: 1 }, { text: '大', value: 2 }, { text: '中', value: 3 }, { text: '小', value: 4 }] },
  92. machineModelIdx: { '1': '特', '2': '大', '3': '中', '4': '小' },
  93. taxRateTypes: [201, 205, 206, 302, 4, 5],
  94. distTypeTree: null,//add
  95. setting: {
  96. header: [
  97. { headerName: "机型", headerWidth: 60, dataCode: "model", dataType: "Number", hAlign: "center", vAlign: "center" },
  98. { headerName: "是否新增", headerWidth: 60, dataCode: "isComplementary", hAlign: "center", vAlign: "center" }
  99. ],
  100. view: {
  101. comboBox: [
  102. { row: -1, col: 3, rowCount: -1, colCount: 1 }
  103. ],
  104. lockedCells: [
  105. ]
  106. }
  107. },
  108. //根据费用定额的单价属性获取人材机的单价属性
  109. getPriceProperty: function (priceProperties) {
  110. let priceProperty = {};
  111. for (let priceProp of priceProperties) {
  112. priceProperty[priceProp.price.dataCode] = 0;
  113. }
  114. return priceProperty;
  115. },
  116. //根据单价字段获取消耗量字段
  117. getConsumeAmtField: function (consumeAmtProperties, priceField) {
  118. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  119. return 'consumeAmt';
  120. }
  121. for (let consumeAmtProp of consumeAmtProperties) {
  122. if (consumeAmtProp.consumeAmt.refPrice === priceField) {
  123. return consumeAmtProp.consumeAmt.dataCode;
  124. }
  125. }
  126. return 'consumeAmt';
  127. },
  128. //初始单价相关的列(单价列、单价属性列)
  129. initPriceCols: function (priceProperties, colMapping) {
  130. let priceCols = [],
  131. pricePropertyCols = [];
  132. if (!priceProperties || priceProperties.length === 0) {
  133. priceCols.push(colMapping.fieldToCol['basePrice']);
  134. }
  135. for (let priceProp of priceProperties) {
  136. pricePropertyCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  137. priceCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  138. }
  139. this.priceCols = priceCols;
  140. this.pricePropertyCols = pricePropertyCols;
  141. },
  142. getPriceFields: function () {
  143. let rst = [];
  144. for (let priceCol of this.priceCols) {
  145. rst.push(this.colMapping.colToField[priceCol]);
  146. }
  147. return rst;
  148. },
  149. //获取更新定额价的人材机价格(人材机只有一个单价取basePrice, 人材机有多个单价,取第一个单价)
  150. getRationGljPrice: function (glj) {
  151. if (glj.priceProperty) {
  152. let keys = Object.keys(glj.priceProperty);
  153. if (keys.length > 0) {
  154. return glj.priceProperty[keys[0]];
  155. }
  156. }
  157. return glj.basePrice;
  158. },
  159. //生成列头(多单价)
  160. initHeaders: function (priceProperties) {
  161. let headers = [
  162. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  163. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center" },
  164. { headerName: "规格型号", headerWidth: 120, dataCode: "specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  165. { headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  166. { headerName: "类型", headerWidth: 90, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" },
  167. ];
  168. //生成单价列
  169. if (!priceProperties || priceProperties.length === 0) {
  170. headers.push({ headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" });
  171. }
  172. else {
  173. for (let priceProp of priceProperties) {
  174. let colData = {
  175. headerName: priceProp.price.dataName,
  176. headerWidth: 100,
  177. dataCode: priceProp.price.dataCode,
  178. dataType: 'Number',
  179. formatter: '0.00',
  180. hAlign: 'right',
  181. vAlign: 'center'
  182. };
  183. headers.push(colData);
  184. }
  185. }
  186. headers = headers.concat(this.setting.header);
  187. return headers;
  188. },
  189. //工料机单价赋初始值(没有单价属性,则单价字段为basePrice,否则单价字段为单价属性对象中的属性)
  190. initPrice: function (glj) {
  191. if (!priceProperties || priceProperties.length === 0) {
  192. glj.basePrice = glj.basePrice && !isNaN(parseFloat(glj.basePrice)) ? scMathUtil.roundTo(parseFloat(glj.basePrice), -2) : 0;
  193. }
  194. else {
  195. if (!glj.priceProperty) {
  196. glj.priceProperty = {};
  197. }
  198. for (let priceProp of priceProperties) {
  199. let gljPrice = glj['priceProperty'][priceProp.price.dataCode];
  200. gljPrice = gljPrice && !isNaN(parseFloat(gljPrice)) ? scMathUtil.roundTo(parseFloat(gljPrice), -2) : 0;
  201. }
  202. }
  203. },
  204. //人材机单价是否变化
  205. isGljPriceChange: function (glj, newPrice) {
  206. //多单价,与人材机单价属性比较
  207. if (typeof newPrice === 'object') {
  208. return !_.isEqual(glj.priceProperty, newPrice);
  209. }
  210. return !_.isEqual(glj.basePrice, newPrice);
  211. },
  212. //粘贴数据含有单价
  213. pasteIncludesPrice: function (pasteObj) {
  214. let me = repositoryGljObj;
  215. for (let priceCol of me.priceCols) {
  216. let priceField = me.colMapping.colToField[priceCol];
  217. if (typeof pasteObj[priceField] !== 'undefined') {
  218. return true;
  219. }
  220. }
  221. return false;
  222. },
  223. //获取人材机价格
  224. getPrice: function (glj, col) {
  225. let me = repositoryGljObj;
  226. if (!priceProperties || priceProperties.length === 0) {
  227. return glj.basePrice;
  228. }
  229. return glj.priceProperty[me.colMapping.colToField[col]];
  230. },
  231. //工料机价格是否相同
  232. priceIsEqual: function (gljA, gljB) {
  233. if (!priceProperties || priceProperties.length === 0) {
  234. return gljA.basePrice == gljB.basePrice;
  235. }
  236. return _.isEqual(gljA.priceProperty, gljB.priceProperty);
  237. },
  238. setPriceByCol: function (glj, newPrice, col) {
  239. if (!priceProperties || priceProperties.length === 0) {
  240. glj.basePrice = newPrice;
  241. }
  242. else {
  243. glj.priceProperty[this.colMapping.colToField[col]] = newPrice;
  244. }
  245. },
  246. setPrice: function (glj, price) {
  247. if (!priceProperties || priceProperties.length === 0) {
  248. glj.basePrice = price;
  249. } else {
  250. glj.priceProperty = price;
  251. }
  252. },
  253. setUnitCombo: function (sheet, headers) {
  254. let me = this;
  255. sheet.suspendPaint();
  256. sheet.suspendEvent();
  257. let combo = sheetCommonObj.getDynamicCombo();
  258. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  259. let unitCol = me.colMapping.fieldToCol.unit;
  260. if (unitCol) {
  261. sheet.getRange(-1, unitCol, -1, 1).cellType(combo);
  262. }
  263. sheet.resumePaint();
  264. sheet.resumeEvent();
  265. },
  266. getComboData: function (gljDistType) {
  267. let me = this;
  268. let distType;
  269. let distTypeTree = {
  270. prefix: 'gljType',
  271. distTypes: {},
  272. comboDatas: [],
  273. distTypesArr: []
  274. };
  275. gljDistType.forEach(function (typeData) {
  276. let typeObj = {
  277. data: typeData,
  278. children: [],
  279. parent: null
  280. }
  281. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  282. distTypeTree.distTypesArr.push(typeObj);
  283. });
  284. gljDistType.forEach(function (typeData) {
  285. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  286. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  287. if (parent) {
  288. distType.parent = parent;
  289. parent.children.push(distType);
  290. }
  291. });
  292. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  293. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  294. distTypeTree.comboDatas.push({ text: distTypeObj.data.fullName, value: distTypeObj.data.ID });
  295. }
  296. });
  297. return distTypeTree;
  298. },
  299. getGljDistType: function (callback) {
  300. let me = this;
  301. CommonAjax.post('complementartGlj/api/getGljDistType', {}, function (rstData) {
  302. if (callback) {
  303. me.distTypeTree = me.getComboData(rstData);
  304. console.log(me.distTypeTree);
  305. callback();
  306. }
  307. });
  308. },
  309. getGljTree: function (gljLibId, callback) {
  310. let me = this;
  311. CommonAjax.post('complementartGlj/api/getGljTree', { gljLibId: gljLibId }, function (rstData) {
  312. zTreeHelper.createTree(rstData, gljSetting, "repositoryTree", me);
  313. zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
  314. if (rstData && rstData.length > 0) {
  315. me.gljCurTypeId = rstData[0].ID;
  316. } else {
  317. //重新创建库?
  318. // gljTypeTreeOprObj.addRootNode();
  319. }
  320. if (callback) {
  321. callback();
  322. }
  323. });
  324. },
  325. getGljItems: function (stdGljLibId, callback) {
  326. let me = this,
  327. // 一开始获取的标准人材机只包含code,提升打开页面速度
  328. projection = {
  329. _id: 0,
  330. ID: 1,
  331. code: 1,
  332. unit: 1,
  333. name: 1,
  334. priceProperty: 1,
  335. basePrice: 1
  336. };
  337. $.bootstrapLoading.start();
  338. CommonAjax.post('/complementartGlj/api/getGljItems', { stdGljLibId, projection }, function (rstData) {
  339. me.stdGljList = rstData.stdGljs;
  340. // TODO
  341. //兼容多单价情况
  342. for (let sGlj of me.stdGljList) {
  343. if (sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
  344. sGlj.basePrice = sGlj.priceProperty.price1;
  345. }
  346. }
  347. me.sortGlj(me.stdGljList);
  348. me.setProp('isStd', true, me.stdGljList);
  349. me.complementaryGljList = rstData.complementaryGljs;
  350. me.sortGlj(me.complementaryGljList);
  351. if (callback) {
  352. callback();
  353. }
  354. $.bootstrapLoading.end();
  355. }, function () {
  356. $.bootstrapLoading.end();
  357. });
  358. },
  359. // 获取标准人材机数据
  360. getStdItems: function (stdGljLibId, callback) {
  361. $.bootstrapLoading.start();
  362. let me = this;
  363. let projection = {
  364. _id: 0,
  365. ID: 1,
  366. specs: 1,
  367. gljType: 1,
  368. shortName: 1,
  369. gljClass: 1
  370. };
  371. CommonAjax.post('/complementartGlj/api/getStdItems', { stdGljLibId, projection }, function (data) {
  372. me.pullCompleteData = true;
  373. // 更新标准人材机数据
  374. let IDMapping = {};
  375. for (let glj of data) {
  376. IDMapping[glj.ID] = glj;
  377. }
  378. for (let glj of me.stdGljList) {
  379. Object.assign(glj, IDMapping[glj.ID]);
  380. }
  381. callback();
  382. $.bootstrapLoading.end();
  383. }, function () {
  384. $.bootstrapLoading.end();
  385. });
  386. },
  387. showGljItems: function (data, type) {
  388. let me = repositoryGljObj;
  389. let sheet = me.workBook.getActiveSheet();
  390. if (me.workBook) {
  391. let cacheSection = [];
  392. let pArr = me.parentNodeIds["_pNodeId_" + type];
  393. for (let i = 0; i < data.length; i++) {
  394. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  395. cacheSection.push(data[i]);
  396. } else if (type == data[i].gljClass) {
  397. cacheSection.push(data[i]);
  398. }
  399. }
  400. sheetOpr.cleanData(sheet, me.setting, -1);
  401. //清除是否新增复选框
  402. gljClassTreeObj.renderFunc(sheet, function () {
  403. let isComplementaryCol = 0;
  404. for (let colData of me.setting.header) {
  405. if (colData.dataCode === 'isComplementary') {
  406. isComplementaryCol = me.setting.header.indexOf(colData);
  407. }
  408. }
  409. let baseCell = new GC.Spread.Sheets.CellTypes.Base();
  410. for (let row = 0; row < sheet.getRowCount(); row++) {
  411. sheet.setCellType(row, isComplementaryCol, baseCell);
  412. }
  413. });
  414. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree, me.materialTypeIdx, me.machineModelIdx);;
  415. let gljTypeCol = me.colMapping.fieldToCol['gljType'],
  416. modelCol = me.colMapping.fieldToCol['model'];
  417. sheetCommonObj.setDynamicCombo(sheet, 0, gljTypeCol, sheet.getRowCount(), me.distTypeTree.comboDatas, false, 'text');
  418. sheetCommonObj.setDynamicCombo(sheet, 0, modelCol, sheet.getRowCount(), me.machineModel.comboItems, false, 'text');
  419. cacheSection = null;
  420. }
  421. },
  422. bindEnterKey: function () {
  423. let me = this;
  424. let sheet = me.workBook.getActiveSheet();
  425. me.workBook.commandManager().register("myEnter", function () {
  426. let orgRow = sheet.getActiveRowIndex();
  427. let orgCol = sheet.getActiveColumnIndex();
  428. if (sheet.isEditing()) {
  429. sheet.endEdit();
  430. }
  431. let codeCol = me.colMapping.fieldToCol['code'];
  432. let code = sheet.getValue(orgRow, codeCol);
  433. let newRow, newCol;
  434. if (!me.currentCache[orgRow] && code !== undefined && code !== null && orgCol !== me.setting.header.length - 1) {
  435. newRow = orgRow;
  436. newCol = orgCol + 1;
  437. sheet.setActiveCell(newRow, newCol);
  438. }
  439. else {
  440. newRow = orgRow + 1;
  441. newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
  442. sheet.setActiveCell(newRow, newCol);
  443. }
  444. //触发事件
  445. //me.onLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
  446. me.onEnterCell({ type: 'EnterCell' }, { sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol });
  447. let newSels = [{ row: newRow, rowCount: 1, col: newCol, colCount: 1 }];
  448. let oldSels = [{ row: orgRow, rowCount: 1, col: orgRow, colCount: 1 }];
  449. me.onSelectionChanged({ type: 'SelectionChanged' }, { sheet: sheet, sheetName: sheet.name(), newSelections: newSels, oldSelections: oldSels });
  450. });
  451. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  452. me.workBook.commandManager().setShortcutKey("myEnter", GC.Spread.Commands.Key.enter, false, false, false, false);
  453. },
  454. buildSheet: function (container) {
  455. let me = repositoryGljObj;
  456. me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
  457. sheetCommonObj.spreadDefaultStyle(me.workBook);
  458. me.repositoryGljDelOpr();
  459. me.onContextmenuOpr();
  460. me.bindEnterKey();
  461. me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
  462. if (priceProperties && priceProperties.length > 0) {
  463. me.workBook.getSheet(0).frozenColumnCount(5);
  464. }
  465. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  466. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  467. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  468. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  469. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  470. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  471. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  472. },
  473. isDef: function (v) {
  474. return v !== undefined && v !== null;
  475. },
  476. //成为了组成物,暂时只需要判断主材的
  477. isComponent: function (gljId, gljList) {
  478. for (let i = 0, len = gljList.length; i < len; i++) {
  479. let gljComponent = gljList[i].component;
  480. if (gljList[i].gljType === 4 && this.isDef(gljComponent) && gljComponent.length > 0) {
  481. for (let j = 0, jLen = gljComponent.length; j < jLen; j++) {
  482. if (gljComponent[j].ID === gljId) {
  483. return true;
  484. }
  485. }
  486. }
  487. }
  488. return false;
  489. },
  490. getCurrentComponent: function (gljComponent) {
  491. let me = repositoryGljObj,
  492. rst = [];
  493. for (let thisGlj of gljComponent) {
  494. let toFindGljList = thisGlj.isStd
  495. ? me.stdGljList
  496. : me.complementaryGljList;
  497. let matchGlj = toFindGljList.find(glj => glj.ID === thisGlj.ID);
  498. if (matchGlj) {
  499. rst.push({
  500. isStd: thisGlj.isStd ? true : false,
  501. ID: matchGlj.ID,
  502. code: matchGlj.code,
  503. name: matchGlj.name,
  504. unit: matchGlj.unit,
  505. basePrice: matchGlj.basePrice,
  506. priceProperty: matchGlj.priceProperty,
  507. consumeAmt: thisGlj.consumeAmt,
  508. consumeAmtProperty: thisGlj.consumeAmtProperty
  509. });
  510. }
  511. }
  512. rst.sort(function (a, b) {
  513. let r = 0;
  514. if (a.code > b.code) r = 1;
  515. else if (a.code < b.code) r = -1;
  516. return r;
  517. });
  518. return rst;
  519. },
  520. //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
  521. getUpdateGljs: function (rObj, isDelete) {
  522. let me = repositoryGljObj, that = gljComponentOprObj,
  523. rst = { updateArr: [], updateBasePrcArr: [] };
  524. //改变单价,以便reCalGljBasePrc方法可行
  525. if (!isDelete) {
  526. for (let i = 0; i < me.complementaryGljList.length; i++) {
  527. if (me.complementaryGljList[i].ID === rObj.ID) {
  528. me.complementaryGljList[i].basePrice = rObj.basePrice;
  529. me.complementaryGljList[i].priceProperty = rObj.priceProperty || {};
  530. break;
  531. }
  532. }
  533. }
  534. for (let i = 0; i < me.complementaryGljList.length; i++) {
  535. let thisComponent = me.complementaryGljList[i].component, isChange = false;
  536. for (let j = 0; j < thisComponent.length; j++) {
  537. if (thisComponent[j].ID === rObj.ID) {
  538. //删除
  539. isChange = true;
  540. if (isDelete) {
  541. thisComponent.splice(j--, 1);
  542. }
  543. else {
  544. break;
  545. }
  546. }
  547. }
  548. if (isChange) {//引用了此组成物
  549. let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
  550. if (me.isGljPriceChange(me.complementaryGljList[i], gljBasePrc)) {
  551. const orgPriceForRation = me.getRationGljPrice(me.complementaryGljList[i]);
  552. me.setPrice(me.complementaryGljList[i], gljBasePrc);
  553. const newPriceForRation = me.getRationGljPrice(me.complementaryGljList[i]);
  554. // 多单价的情况下只有price1发生变化,才重算定额价格
  555. if (orgPriceForRation !== newPriceForRation) {
  556. rst.updateBasePrcArr.push({ gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: newPriceForRation });
  557. }
  558. }
  559. rst.updateArr.push(me.complementaryGljList[i]);
  560. }
  561. /* if(isChange){//引用了此组成物
  562. let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
  563. if(me.complementaryGljList[i].basePrice !== gljBasePrc){
  564. me.complementaryGljList[i].basePrice = gljBasePrc;
  565. rst.updateBasePrcArr.push({gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: me.complementaryGljList[i].basePrice});
  566. }
  567. rst.updateArr.push(me.complementaryGljList[i]);
  568. } */
  569. }
  570. return rst;
  571. },
  572. reshowGljBasePrc: function (glj) {
  573. /* let me = repositoryGljObj;
  574. let cacheSection = me.currentCache;
  575. for(let i = 0; i < cacheSection.length; i++){
  576. if(glj.ID === cacheSection[i].ID){
  577. cacheSection[i].basePrice = glj.basePrice;
  578. me.workBook.getSheet(0).setValue(i, 4, glj.basePrice);
  579. break;
  580. }
  581. } */
  582. let me = repositoryGljObj;
  583. let cacheSection = me.currentCache;
  584. let sheet = me.workBook.getActiveSheet();
  585. let row = _.findIndex(cacheSection, { ID: glj.ID });
  586. sheet.suspendEvent();
  587. sheet.suspendPaint();
  588. for (let priceCol of me.priceCols) {
  589. const dataCode = me.colMapping.colToField[priceCol];
  590. const priceObj = dataCode === 'basePrice' ? glj : glj.priceProperty;
  591. sheet.setValue(row, priceCol, priceObj[dataCode]);
  592. }
  593. sheet.resumeEvent();
  594. sheet.resumePaint();
  595. },
  596. onSelectionChanged: function (sender, info) {
  597. let me = repositoryGljObj, that = gljComponentOprObj;
  598. //混凝土202、砂浆203、配合比204、机械3
  599. if (typeof info.oldSelections || info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row) {
  600. let row = info.newSelections[0].row;
  601. me.initSel(row);
  602. }
  603. },
  604. initSel: function (row) {
  605. let me = repositoryGljObj, that = gljComponentOprObj, componentCanEdit = false;
  606. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, -1);
  607. me.workBook.focus(true);
  608. me.currentComponent = [];
  609. that.workBook.getSheet(0).setRowCount(5);
  610. if (row < me.currentCache.length) {
  611. //标记当前工料机
  612. me.currentGlj = me.currentCache[row];
  613. if (allowComponent.includes(me.currentCache[row].gljType)) {
  614. componentCanEdit = true;
  615. //展示数据
  616. if (me.currentGlj.component.length > 0) {
  617. me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
  618. if (me.currentComponent.length > 0) {
  619. //sheetOpr.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
  620. sheetOpr.showData(that, that.workBook.getSheet(0), that.setting, me.currentComponent);
  621. }
  622. }
  623. }
  624. }
  625. else {
  626. me.currentGlj = null;
  627. }
  628. //减少触发
  629. if (me.preComponentCanEdit !== componentCanEdit) {
  630. me.spreadControl(componentCanEdit);
  631. refreshALlWorkBook();
  632. }
  633. me.preComponentCanEdit = componentCanEdit;
  634. },
  635. //组成物表能编辑则显示,否则隐藏该工作表
  636. spreadControl: function (showComponent) {
  637. let leftWidth = getLocalCache('compleGLjleftContentWidth') || '50%',
  638. midWidth = getLocalCache('compleGLjmidContentWidth') || '25%',
  639. rightWidth = getLocalCache('compleGLjrightContentWidth') || '25%';
  640. [leftWidth, midWidth, rightWidth] = [leftWidth, midWidth, rightWidth].map((v) => parseFloat(v.replace('%', '')));
  641. let curMidWidth = parseFloat($('#midContent')[0].style.width.replace('%', '')),
  642. curRightWidth = parseFloat($('#rightContent')[0].style.width.replace('%', ''));
  643. if (showComponent) {
  644. if (leftWidth + midWidth + rightWidth > 100) {
  645. leftWidth = 50;
  646. midWidth = rightWidth = 25;
  647. }
  648. } else {
  649. midWidth = curMidWidth + curRightWidth;
  650. rightWidth = 0;
  651. leftWidth = 100 - midWidth;
  652. }
  653. $('#leftContent').css('width', `${leftWidth}%`);
  654. $('#midContent').css('width', `${midWidth}%`);
  655. $('#rightContent').css('width', `${rightWidth}%`);
  656. },
  657. onEnterCell: function (sender, args) {
  658. let me = repositoryGljObj;
  659. args.sheet.repaint();
  660. me.cellRowIdx = args.row;
  661. let isHasData = false;
  662. if (me.addGljObj) {
  663. for (let i = 0; i < me.setting.header.length; i++) {
  664. if (me.addGljObj[me.setting.header[i].dataCode]) {
  665. isHasData = true;
  666. break;
  667. }
  668. }
  669. }
  670. if (isHasData) {
  671. if (me.editingRowIdx !== me.cellRowIdx) {
  672. let isComple = true;
  673. let focusToCol;
  674. function getFocusToCol(me) {
  675. if (!me.addGljObj.code) {
  676. $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
  677. return me.colMapping.fieldToCol.code;
  678. }
  679. else if (!me.addGljObj.name) {
  680. $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
  681. return me.colMapping.fieldToCol.name;
  682. }
  683. else if (!me.addGljObj.unit) {
  684. $('#alertGljTxt').text('计量单位不能为空,继续增加人材机?');
  685. return me.colMapping.fieldToCol.unit;
  686. }
  687. else if (!me.addGljObj.gljType) {
  688. $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
  689. return me.colMapping.fieldToCol.gljType;
  690. }
  691. else {
  692. return -1;
  693. }
  694. }
  695. focusToCol = getFocusToCol(me);
  696. if (focusToCol === -1) {
  697. }
  698. else {
  699. $('#gljAlertBtn').click();
  700. $('#aleConfBtn').unbind('click');
  701. $('#aleConfBtn').bind('click', function () {
  702. args.sheet.setActiveCell(me.editingRowIdx, focusToCol);
  703. });
  704. $('#gljAleClose').unbind('click');
  705. $('#gljAleClose').bind('click', function () {
  706. args.sheet.setActiveCell(me.editingRowIdx, focusToCol);
  707. });
  708. $('#aleCanceBtn').unbind('click');
  709. $('#aleCanceBtn').bind('click', function () {
  710. me.addGljObj = null;
  711. args.sheet.suspendPaint();
  712. args.sheet.suspendEvent();
  713. for (let col = 0; col < me.setting.header.length; col++) {
  714. if (col === 0) {
  715. args.sheet.getCell(me.editingRowIdx, 0).formatter("@");
  716. }
  717. args.sheet.getCell(me.editingRowIdx, col).value('');
  718. }
  719. args.sheet.setActiveCell(me.editingRowIdx, 0);
  720. args.sheet.resumePaint();
  721. args.sheet.resumeEvent();
  722. });
  723. }
  724. }
  725. }
  726. },
  727. onButtonClicked: function (sender, args) {
  728. let me = repositoryGljObj;
  729. if (me.setting.header[args.col].dataCode === 'isComplementary' && args.row < me.currentCache.length) {
  730. args.sheet.setValue(args.row, args.col, true);
  731. }
  732. },
  733. onCellEditStart: function (sender, args) {
  734. let me = repositoryGljObj;
  735. me.orgCode = args.sheet.getValue(args.row, me.colMapping.fieldToCol['code']);
  736. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me);
  737. me.currentEditingGlj = rObj;
  738. me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
  739. if (args.row < me.currentCache.length) {
  740. let dataCode = me.setting.header[args.col].dataCode;
  741. me.currentGlj = me.currentCache[args.row];
  742. if (dataCode === 'code'
  743. || (dataCode === 'taxRate' && !me.taxRateTypes.includes(me.currentGlj.gljType))
  744. || (me.priceCols.includes(args.col) && allowComponent.includes(me.currentGlj.gljType) && me.currentGlj.component.length > 0)
  745. || (dataCode === 'model' && me.currentGlj.gljType !== 301)
  746. || dataCode === 'isComplementary') {
  747. args.cancel = true;
  748. } else {
  749. rObj.ID = me.currentGlj.ID;
  750. rObj.gljClass = me.currentGlj.gljClass;
  751. }
  752. } else {
  753. me.currentGlj = null;
  754. }
  755. },
  756. dataChanged: function (objA, objB, col) {
  757. let me = repositoryGljObj;
  758. if (me.priceCols.includes(col)) {
  759. if (!priceProperties || priceProperties.length === 0) {
  760. return objA.basePrice !== objB.basePrice;
  761. }
  762. else {
  763. return objA.priceProperty[me.colMapping.colToField[col]] !== objB.priceProperty[me.colMapping.colToField[col]]
  764. }
  765. }
  766. return objA[me.colMapping.colToField[col]] !== objB[[me.colMapping.colToField[col]]];
  767. },
  768. onCellEditEnd: function (sender, args) {
  769. let me = repositoryGljObj,
  770. that = gljComponentOprObj;
  771. // 输入编号、名称、规格时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  772. let deESCFields = ['code', 'name', 'specs'];
  773. if (deESCFields.includes(me.setting.header[args.col]['dataCode'])) {
  774. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  775. args.sheet.setValue(args.row, args.col, args.editingText);
  776. }
  777. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
  778. updateArr = [],
  779. addArr = [],
  780. updateBasePrcArr = [];
  781. me.editingRowIdx = args.row;
  782. //rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  783. me.initPrice(rObj);
  784. //更新
  785. if (me.currentEditingGlj["ID"]) {
  786. rObj["ID"] = me.currentEditingGlj["ID"];
  787. rObj.gljClass = me.currentEditingGlj.gljClass;
  788. if (me.dataChanged(me.currentEditingGlj, rObj, args.col)) {
  789. //me.addGljObj = rObj;
  790. //编码、名称、单位、类型不可为空
  791. if (rObj.code && rObj.name && rObj.unit && rObj.gljType
  792. && rObj.code.toString().trim().length !== 0 && rObj.name.toString().trim().length !== 0 && rObj.unit.toString().trim().length !== 0 &&
  793. rObj.gljType.toString().trim().length !== 0) {
  794. if (rObj.gljType !== me.currentEditingGlj.gljType) {//修改了工料机类型
  795. if (me.currentGlj) {
  796. me.currentGlj.component = [];
  797. }
  798. // 工料机类型不为普通材料、商品混凝土、商品砂浆、机械组成物、主材、设备时,清空税率
  799. if (!me.taxRateTypes.includes(rObj.gljType)) {
  800. rObj.taxRate = null;
  801. }
  802. //工料机类型不为机械台班时,清空机型
  803. if (me.currentEditingGlj.gljType === 301 && rObj.gljType !== 301 && me.currentEditingGlj.model) {
  804. rObj.model = null;
  805. }
  806. if (componentType.includes(me.currentEditingGlj.gljType) &&
  807. !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType))
  808. && !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))) {//修改了原本是组成物的工料机
  809. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  810. let updateGljs = me.getUpdateGljs(rObj, true);
  811. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  812. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  813. updateArr.push(updateGljs.updateArr[i]);
  814. }
  815. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  816. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  817. }
  818. }
  819. }
  820. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, me.colMapping.fieldToCol.gljType);
  821. }
  822. // 修改了税率
  823. else if (rObj.taxRate !== me.currentEditingGlj.taxRate) {
  824. if (isNaN(rObj.taxRate)) {
  825. args.sheet.setValue(args.row, args.col, me.currentEditingGlj.taxRate || '');
  826. alert('税率只能输入数值!');
  827. return;
  828. }
  829. rObj.taxRate = scMathUtil.roundTo(parseFloat(rObj.taxRate), -2);
  830. }
  831. else if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {//修改了单价,可修改单价的必为可成为组成物的
  832. let rObjPrice = me.getPrice(rObj, args.col),
  833. editingGljPrice = me.getPrice(me.currentEditingGlj, args.col);
  834. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  835. if (isNaN(parseFloat(rObjPrice))) {
  836. alert('单价只能输入数值!');
  837. args.sheet.setValue(args.row, args.col, editingGljPrice ? editingGljPrice : 0);
  838. return;
  839. }
  840. me.setPriceByCol(rObj, scMathUtil.roundTo(parseFloat(rObjPrice), -2), args.col);
  841. let updateGljs = me.getUpdateGljs(rObj);
  842. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  843. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  844. updateArr.push(updateGljs.updateArr[i]);
  845. }
  846. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  847. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  848. }
  849. }
  850. }
  851. rObj.component = me.currentGlj.component;
  852. updateArr.push(rObj);
  853. }
  854. else {
  855. if (me.setting.header[args.col].dataCode === 'gljType') {
  856. let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[me.setting.header[args.col].dataCode]].data.fullName;
  857. args.sheet.setValue(args.row, args.col, distTypeVal);
  858. }
  859. else {
  860. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[me.setting.header[args.col].dataCode]);
  861. }
  862. }
  863. }
  864. // 价格发生变化,需要重算补充定额
  865. if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  866. //update basePrice of ration when editting basePrice of glj
  867. let gljType = -1;
  868. let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
  869. if (gljTypeParent && gljTypeParent.data.ID <= 3) {
  870. gljType = gljTypeParent.data.ID;
  871. }
  872. if (!gljTypeParent && me.currentEditingGlj.gljType <= 3) {
  873. gljType = me.currentEditingGlj.gljType;
  874. }
  875. let gljBasePrcObj = { gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: me.getRationGljPrice(rObj) };
  876. if (gljBasePrcObj.gljType !== -1) {
  877. updateBasePrcArr.push(gljBasePrcObj);
  878. }
  879. }
  880. // 人材机类型发生变化,需要重算补充定额
  881. else if (me.currentEditingGlj.gljType !== rObj.gljType) {
  882. let gljTypeObj = { gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: me.getRationGljPrice(rObj) };
  883. updateBasePrcArr.push(gljTypeObj);
  884. }
  885. //-----------------------------------------------------------
  886. }
  887. //新增
  888. else {
  889. if (typeof rObj.code !== 'undefined') {
  890. me.addGljObj = rObj;
  891. let isCanSav = true;
  892. if (!rObj.code || !rObj.name || !rObj.unit || !rObj.gljType) {
  893. isCanSav = false;
  894. }
  895. if (isCanSav) {
  896. me.addGljObj = null;
  897. rObj.component = [];
  898. me.initPrice(rObj);
  899. addArr.push(rObj);
  900. }
  901. }
  902. }
  903. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  904. rObj.gljClass = me.gljCurTypeId;
  905. }
  906. /* if (updateBasePrcArr.length) {
  907. me.updateRationBasePrcRq(updateBasePrcArr);
  908. } */
  909. if (updateArr.length > 0 || addArr.length > 0) {
  910. me.currentEditingGlj = null;
  911. me.mixUpdateRequest(updateArr, addArr, []);
  912. }
  913. },
  914. delGljs: function (sels) {
  915. let me = repositoryGljObj;
  916. let sheet = me.workBook.getSheet(0),
  917. updateArr = [], removeArr = [],
  918. tempRemoveArr = [],
  919. refGljCodes = [], //已被引用的工料机
  920. updateBasePrcArr = [],//删除基价单位后重新计算
  921. canUpdate = false,
  922. cacheSection = me.currentCache;
  923. if (sels.length > 0 && cacheSection.length > 0) {
  924. for (let i = 0; i < sels.length; i++) {
  925. if (sels[i].colCount === me.setting.header.length) {
  926. for (let j = 0; j < sels[i].rowCount; j++) {
  927. if (sels[i].row + j < cacheSection.length) {
  928. //删除了已被引用成组成物的工料机,重新计算所有引用此组成物的工料机的单价、组成物数组
  929. let updateGljs = me.getUpdateGljs(cacheSection[sels[i].row + j], true);
  930. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  931. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  932. updateArr.push(updateGljs.updateArr[i]);
  933. }
  934. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  935. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  936. }
  937. }
  938. removeArr.push(cacheSection[sels[i].row + j].ID);
  939. //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
  940. //删除后重新计算引用了此工料机的定额单价
  941. updateBasePrcArr.push({ gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1 });
  942. }
  943. }
  944. }
  945. else {
  946. let maxCol = sels[i].col + sels[i].colCount - 1;
  947. if (sels[i].col >= 2 && maxCol <= 4) {
  948. for (let j = 0; j < sels[i].rowCount; j++) {
  949. if (sels[i].row + j < cacheSection.length) {
  950. let updateObj = cacheSection[sels[i].row + j];
  951. for (let col = sels[i].col; col <= maxCol; col++) {
  952. if (me.setting.header[col].dataCode === 'basePrice') {
  953. //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
  954. if (!allowComponent.includes(updateObj.gljType)) {
  955. canUpdate = true;
  956. updateObj[me.setting.header[col].dataCode] = 0;
  957. updateBasePrcArr.push({ gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0 });
  958. }
  959. }
  960. else {
  961. canUpdate = true;
  962. updateObj[me.setting.header[col].dataCode] = '';
  963. }
  964. }
  965. if (canUpdate) {
  966. updateArr.push(updateObj);
  967. }
  968. }
  969. }
  970. }
  971. //编号、名称、单位、类型不可为空
  972. else {
  973. if (sels[i].row < cacheSection.length) {
  974. let text = '', cantNullStr = ['编码', '名称', '类型'];
  975. for (let col = sels[i].col; col <= sels[i].col + sels[i].colCount - 1; col++) {
  976. if (cantNullStr.indexOf(me.setting.header[col].headerName) !== -1) {
  977. text += me.setting.header[col].headerName + " ";
  978. }
  979. }
  980. $('#alertText').text(text + "不可为空!");
  981. $('#codeAlertBtn').click();
  982. $('#codAleConfBtn').click(function () {
  983. });
  984. $('#codAleClose').click(function () {
  985. });
  986. }
  987. }
  988. }
  989. }
  990. if (removeArr.length > 0 || updateArr.length > 0) {
  991. //删除警告
  992. $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
  993. $('#gljAlertBtn').click();
  994. //确认
  995. $('#aleConfBtn').unbind('click');
  996. $('#aleConfBtn').bind('click', function () {
  997. me.mixUpdateRequest(updateArr, [], removeArr);
  998. /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  999. me.updateRationBasePrcRq(updateBasePrcArr);
  1000. }*/
  1001. });
  1002. }
  1003. }
  1004. },
  1005. repositoryGljDelOpr: function () {
  1006. let me = repositoryGljObj;
  1007. /* me.workBook.commandManager().register('repositoryGljDel', function () {
  1008. let sels = me.workBook.getActiveSheet().getSelections();
  1009. me.delGljs(sels);
  1010. }); */
  1011. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  1012. me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
  1013. },
  1014. onContextmenuOpr: function () {
  1015. let me = repositoryGljObj;
  1016. $.contextMenu({
  1017. selector: '#GLJListSheet',
  1018. build: function ($triggerElement, e) {
  1019. //控制允许右键菜单在哪个位置出现
  1020. let sheet = me.workBook.getSheet(0);
  1021. let offset = $("#GLJListSheet").offset(),
  1022. x = e.pageX - offset.left,
  1023. y = e.pageY - offset.top;
  1024. let target = sheet.hitTest(x, y);
  1025. let sel = sheet.getSelections()[0];
  1026. if (sel.row === -1) {
  1027. sel.row = 0;
  1028. }
  1029. if (sel.col === -1) {
  1030. sel.col = 0;
  1031. }
  1032. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  1033. me.initSel(target.row);
  1034. if (sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
  1035. sel.col > target.col || sel.col + sel.colCount - 1 < target.col) {
  1036. sheet.setActiveCell(target.row, target.col);
  1037. }
  1038. return {
  1039. callback: function () { },
  1040. items: {
  1041. "delete": {
  1042. name: "删除",
  1043. disabled: function () {
  1044. return !(me.currentCache && me.currentCache[target.row]);
  1045. },
  1046. icon: "fa-remove",
  1047. callback: function (key, opt) {
  1048. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  1049. curSel.colCount = me.setting.header.length;
  1050. me.delGljs([curSel]);
  1051. }
  1052. }
  1053. }
  1054. };
  1055. }
  1056. else {
  1057. return false;
  1058. }
  1059. }
  1060. });
  1061. },
  1062. validUpdateObj: function (pasteObj, rowIdx) {
  1063. let rst = { updateGlj: [], updateBasePrcArr: [] }, backUpObj = {},
  1064. me = repositoryGljObj,
  1065. that = gljComponentOprObj,
  1066. tempObj = me.currentCache[rowIdx],
  1067. reCalBasePrc = false,
  1068. isValid = true;
  1069. //备份原始数据
  1070. for (let atr in tempObj) {
  1071. backUpObj[atr] = tempObj[atr];
  1072. }
  1073. if (typeof pasteObj.code !== 'undefined') {
  1074. if (pasteObj.code.trim().length !== 0) {
  1075. let isExist = false;
  1076. for (let i = 0; i < me.stdGljList.length; i++) {
  1077. if (me.stdGljList[i].code === pasteObj.code) {
  1078. isExist = true;
  1079. break;
  1080. }
  1081. }
  1082. if (!isExist) {
  1083. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1084. if (me.complementaryGljList[i].code === pasteObj.code) {
  1085. isExist = true;
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. if (!isExist) {
  1091. tempObj.code = pasteObj.code;
  1092. }
  1093. else isValid = false;
  1094. }
  1095. else isValid = false;
  1096. }
  1097. if (typeof pasteObj.name !== 'undefined') {
  1098. if (pasteObj.name.trim().length === 0) isValid = false;
  1099. else tempObj.name = pasteObj.name;
  1100. }
  1101. if (typeof pasteObj.specs !== 'undefined') {
  1102. tempObj.specs = pasteObj.specs;
  1103. }
  1104. if (typeof pasteObj.unit !== 'undefined') {
  1105. tempObj.unit = pasteObj.unit;
  1106. }
  1107. if (typeof pasteObj.gljType !== 'undefined') {
  1108. let isExsit = false;
  1109. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1110. if (pasteObj.gljType === me.distTypeTree.comboDatas[i].text) {
  1111. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1112. isExsit = true;
  1113. reCalBasePrc = true;
  1114. if (!me.taxRateTypes.includes(pasteObj.taxRate) && me.taxRateTypes.includes(tempObj.taxRate)) {
  1115. tempObj.taxRate = null;
  1116. }
  1117. if (pasteObj.gljType !== 301 && tempObj.gljType === 301) {
  1118. tempObj.model = null;
  1119. }
  1120. if (componentType.includes(tempObj.gljType) &&
  1121. !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
  1122. !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))) {//修改了原本是组成物的工料机
  1123. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1124. let updateGljs = me.getUpdateGljs(tempObj, true);
  1125. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1126. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1127. rst.updateGlj.push(updateGljs.updateArr[i]);
  1128. }
  1129. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1130. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1131. }
  1132. }
  1133. }
  1134. tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
  1135. /*if(me.allowComponent.indexOf(tempObj.gljType) !== -1){
  1136. tempObj.basePrice = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.basePrice : 0;
  1137. }*/
  1138. tempObj.gljType = me.distTypeTree.comboDatas[i].value;
  1139. tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
  1140. break;
  1141. }
  1142. }
  1143. if (!isExsit) isValid = false;
  1144. }
  1145. if (typeof pasteObj.taxRate !== 'undefined'
  1146. && typeof pasteObj.gljType === 'undefined') {
  1147. if (me.taxRateTypes.includes(tempObj.gljType)) {
  1148. tempObj.taxRate = pasteObj.taxRate && !isNaN(pasteObj.taxRate) ? scMathUtil.roundTo(parseFloat(pasteObj.taxRate), -2) : null;
  1149. } else {
  1150. isValid = false;
  1151. }
  1152. }
  1153. //
  1154. /* pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), 2) :
  1155. me.currentCache[rowIdx].basePrice;
  1156. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1157. reCalBasePrc = true;
  1158. tempObj.basePrice = pasteObj.basePrice;
  1159. let updateGljs = me.getUpdateGljs(tempObj, false);
  1160. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1161. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1162. rst.updateGlj.push(updateGljs.updateArr[i]);
  1163. }
  1164. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1165. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1166. }
  1167. }
  1168. } */
  1169. //单价相关
  1170. if (me.pasteIncludesPrice(pasteObj)) {
  1171. if (!priceProperties || priceProperties.length === 0) {
  1172. pasteObj.basePrice = pasteObj.basePrice && !isNaN(parseFloat(pasteObj.basePrice)) ?
  1173. scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2) : me.currentCache[rowIdx].basePrice;
  1174. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1175. reCalBasePrc = true;
  1176. tempObj.basePrice = pasteObj.basePrice;
  1177. }
  1178. }
  1179. else {
  1180. //多单价粘贴
  1181. let pastePriceProperty = {};
  1182. let priceFields = me.getPriceFields();
  1183. for (let priceField of priceFields) {
  1184. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1185. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1186. }
  1187. }
  1188. if (!me.priceIsEqual(tempObj, pasteObj)) {
  1189. reCalBasePrc = true;
  1190. //更新人材机单价
  1191. for (let priceField in pastePriceProperty) {
  1192. tempObj.priceProperty[priceField] = pastePriceProperty[priceField];
  1193. }
  1194. }
  1195. }
  1196. let updateGljs = me.getUpdateGljs(tempObj, false);
  1197. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1198. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1199. rst.updateGlj.push(updateGljs.updateArr[i]);
  1200. }
  1201. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1202. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1203. }
  1204. }
  1205. }
  1206. if (typeof pasteObj.model !== 'undefined') {
  1207. if (!me.machineModel.textArr.includes(pasteObj.model)) {
  1208. isValid = false;
  1209. }
  1210. else {
  1211. let existsModel = false;
  1212. if ((typeof pasteObj.gljType !== 'undefined' && pasteObj.gljType === 301) ||
  1213. (tempObj.gljType && tempObj.gljType === 301)) {
  1214. me.machineModel.comboItems.forEach(function (item) {
  1215. if (item.text === pasteObj.model) {
  1216. tempObj.model = item.value;
  1217. existsModel = true;
  1218. }
  1219. });
  1220. if (!existsModel) {
  1221. isValid = false;
  1222. }
  1223. }
  1224. else {
  1225. isValid = false;
  1226. }
  1227. }
  1228. }
  1229. if (isValid) {
  1230. rst.updateGlj.push(tempObj);
  1231. if (reCalBasePrc) {
  1232. //重新计算定额基价对象
  1233. //rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
  1234. let newReObj = { gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: me.getRationGljPrice(tempObj) };
  1235. rst.updateBasePrcArr.push(newReObj);
  1236. }
  1237. }
  1238. else {
  1239. for (let attr in backUpObj) {
  1240. tempObj[attr] = backUpObj[attr];
  1241. }
  1242. }
  1243. return rst;
  1244. },
  1245. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  1246. isValidObj: function (pasteObj) {
  1247. let me = repositoryGljObj;
  1248. if (!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
  1249. !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')) {
  1250. return false;
  1251. }
  1252. if (pasteObj.gljType && typeof pasteObj.gljType !== 'undefined') {
  1253. let isExist = false;
  1254. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1255. if (me.distTypeTree.comboDatas[i].text === pasteObj.gljType) {
  1256. isExist = true;
  1257. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1258. pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
  1259. break;
  1260. }
  1261. }
  1262. if (!isExist) {
  1263. return false;
  1264. }
  1265. }
  1266. if (pasteObj.code && typeof pasteObj.code !== 'undefined') {
  1267. for (let i = 0; i < me.stdGljList.length; i++) {
  1268. if (me.stdGljList[i].code === pasteObj.code) {
  1269. return false;
  1270. }
  1271. }
  1272. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1273. if (me.complementaryGljList[i].code === pasteObj.code) {
  1274. return false;
  1275. }
  1276. }
  1277. }
  1278. if (pasteObj.taxRate && (isNaN(pasteObj.taxRate) || !me.taxRateTypes.includes(pasteObj.gljType))) {
  1279. return false;
  1280. }
  1281. if (typeof pasteObj.model !== 'undefined' && pasteObj.model) {
  1282. if (!me.machineModel.textArr.includes(pasteObj.model) || pasteObj.gljType !== 301) {
  1283. return false;
  1284. }
  1285. me.machineModel.comboItems.forEach(function (item) {
  1286. if (item.text === pasteObj.model) {
  1287. pasteObj.model = item.value;
  1288. }
  1289. });
  1290. }
  1291. //pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1292. if (!priceProperties || priceProperties.length === 0) {
  1293. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1294. } else {
  1295. let pastePriceProperty = {};
  1296. let priceFields = me.getPriceFields();
  1297. for (let priceField of priceFields) {
  1298. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1299. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1300. }
  1301. else {
  1302. pastePriceProperty[priceField] = 0;
  1303. }
  1304. }
  1305. pasteObj.priceProperty = pastePriceProperty;
  1306. }
  1307. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1308. pasteObj.gljClass = me.gljCurTypeId;
  1309. }
  1310. return true;
  1311. },
  1312. canPasted: function (info) {
  1313. let rst = true;
  1314. let me = repositoryGljObj;
  1315. if (me.gljCurTypeId < 0) {
  1316. return false;
  1317. }
  1318. const maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  1319. if (maxCol > me.setting.header.length - 2) {
  1320. return false;
  1321. }
  1322. if (info.cellRange.row < me.currentCache.length) {
  1323. const minPriceCol = Math.min(...me.priceCols);
  1324. const maxPriceCol = Math.max(...me.priceCols)
  1325. if (info.cellRange.col === 0) {
  1326. return false;
  1327. }
  1328. for (let i = 0, len = info.cellRange.rowCount; i < len; i++) {
  1329. let row = i + info.cellRange.row;
  1330. if (row < me.currentCache.length
  1331. && allowComponent.includes(me.currentCache[row].gljType)
  1332. && me.currentCache[row].component.length
  1333. && !(maxCol < minPriceCol || info.cellRange.col > maxPriceCol)) {// 包含了价格列
  1334. return false;
  1335. } else {
  1336. break;
  1337. }
  1338. }
  1339. }
  1340. return rst;
  1341. },
  1342. onClipboardPasting: function (sender, args) {
  1343. let me = repositoryGljObj;
  1344. if (!me.canPasted(args)) {
  1345. args.cancel = true;
  1346. }
  1347. },
  1348. onClipboardPasted: function (e, info) {
  1349. // if(info.pasteData.text.trim().length > 0){
  1350. let me = repositoryGljObj;
  1351. let updateArr = [], addArr = [];
  1352. let items = sheetOpr.analyzePasteData(me.setting, info);
  1353. let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,//复制的起始行数和结束行数
  1354. maxRow = me.currentCache.length - 1,//当前数据最大行数
  1355. updateBasePrcArr = [],
  1356. updateCount, resumeArr = [];
  1357. if (endRow <= maxRow) {
  1358. for (let i = 0; i < items.length; i++) {
  1359. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1360. if (updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0) {
  1361. updateArr = updateArr.concat(updateObj.updateGlj);
  1362. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1363. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1364. }
  1365. }
  1366. }
  1367. }
  1368. else if (beginRow <= maxRow && endRow > maxRow) {
  1369. updateCount = maxRow - beginRow + 1;
  1370. for (let i = 0; i < updateCount; i++) {
  1371. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1372. if (updateObj && typeof updateObj.updateGlj !== 'undefined') {
  1373. updateArr = updateArr.concat(updateObj.updateGlj);
  1374. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1375. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1376. }
  1377. }
  1378. }
  1379. for (let i = updateCount; i < items.length; i++) {
  1380. if (me.isValidObj(items[i])) {
  1381. items[i].component = [];
  1382. addArr.push(items[i]);
  1383. }
  1384. }
  1385. }
  1386. else {
  1387. for (let i = 0; i < items.length; i++) {
  1388. if (me.isValidObj(items[i])) {
  1389. items[i].component = [];
  1390. addArr.push(items[i]);
  1391. }
  1392. }
  1393. }
  1394. //repaint
  1395. for (let i = 0; i < info.cellRange.rowCount; i++) {
  1396. resumeArr.push(info.cellRange.row + i);
  1397. }
  1398. if (resumeArr.length > 0) {
  1399. let sheet = me.workBook.getActiveSheet();
  1400. sheet.suspendPaint();
  1401. for (let i = 0; i < resumeArr.length; i++) {
  1402. if (resumeArr[i] < me.currentCache.length) {
  1403. for (let col = 0; col < me.setting.header.length - 1; col++) {
  1404. if (me.setting.header[col].dataCode === 'gljType') {
  1405. let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
  1406. sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
  1407. }
  1408. else if (me.setting.header[col].dataCode === 'model') {
  1409. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode] ? me.machineModelIdx[me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]] : '');
  1410. }
  1411. else {
  1412. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
  1413. }
  1414. }
  1415. }
  1416. else {
  1417. for (let col = 0; col < me.setting.header.length - 1; col++) {
  1418. sheet.setValue(resumeArr[i], col, '', GC.Spread.Sheets.SheetArea.viewport);
  1419. }
  1420. }
  1421. }
  1422. sheet.resumePaint();
  1423. }
  1424. if (updateArr.length > 0 || addArr.length > 0) {
  1425. me.mixUpdateRequest(updateArr, addArr, []);
  1426. }
  1427. /* if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1428. me.updateRationBasePrcRq(updateBasePrcArr);
  1429. } */
  1430. // }
  1431. },
  1432. updateRationBasePrcRq: function (basePrcArr) {
  1433. CommonAjax.post('/complementartGlj/api/updateRationBasePrc', { basePrcArr: basePrcArr }, function (rstData) {
  1434. });
  1435. },
  1436. /* getRationGljIds: function (repId) {
  1437. let me = repositoryGljObj;
  1438. $.ajax({
  1439. type: 'post',
  1440. url: 'api/getRationGljIds',
  1441. data: {data: JSON.stringify({repId: repId})},
  1442. dataType: 'json',
  1443. success: function(result){
  1444. if(!result.error){
  1445. me.rationGljIds = result.data;
  1446. }
  1447. }
  1448. });
  1449. },*/
  1450. mixUpdateRequest: function (updateArr, addArr, removeIds) {
  1451. let me = repositoryGljObj;
  1452. if (updateArr.length > 0) {
  1453. me.saveInString(updateArr);
  1454. }
  1455. if (addArr.length > 0) {
  1456. me.saveInString(addArr);
  1457. }
  1458. let url = 'complementartGlj/api/mixUpdateGljItems';
  1459. let post = { updateItems: updateArr, addItems: addArr, removeIds: removeIds };
  1460. let scCaller = function (rstData) {
  1461. me.updateCache(addArr, updateArr, removeIds, rstData);
  1462. me.sortGlj(me.complementaryGljList);
  1463. if (me.currentOprParent === 1) {
  1464. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  1465. }
  1466. else {
  1467. me.currentCache = me.getCache();
  1468. }
  1469. me.showGljItems(me.complementaryGljList, me.gljCurTypeId);
  1470. //getCurrentGlj
  1471. let row = me.workBook.getSheet(0).getSelections()[0].row;
  1472. me.initSel(row);
  1473. }
  1474. let errCaller = function (err) {
  1475. alert('保存失败');
  1476. };
  1477. CommonAjax.post(url, post, scCaller, errCaller);
  1478. },
  1479. saveInString: function (datas) {
  1480. for (let i = 0, len = datas.length; i < len; i++) {
  1481. let data = datas[i];
  1482. if (_exist(data, 'basePrice')) {
  1483. data['basePrice'] = data['basePrice'].toString();
  1484. }
  1485. if (_exist(data, 'component')) {
  1486. for (let j = 0, jLen = data['component'].length; j < jLen; j++) {
  1487. let comGljObj = data['component'][j];
  1488. if (_exist(comGljObj, 'consumeAmt')) {
  1489. comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
  1490. }
  1491. }
  1492. }
  1493. }
  1494. function _exist(data, attr) {
  1495. return data && data[attr] !== undefined && data[attr];
  1496. }
  1497. },
  1498. getParentCache: function (nodes) {
  1499. let me = repositoryGljObj, rst = [];
  1500. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1501. if (nodes.indexOf(me.complementaryGljList[i].gljClass) !== -1) {
  1502. rst.push(me.complementaryGljList[i]);
  1503. }
  1504. }
  1505. rst.sort(function (a, b) {
  1506. let rst = 0;
  1507. if (a.code > b.code) rst = 1;
  1508. else if (a.code < b.code) rst = -1;
  1509. return rst;
  1510. });
  1511. return rst;
  1512. },
  1513. getCache: function () {
  1514. let me = this, rst = [];
  1515. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1516. if (me.complementaryGljList[i].gljClass == me.gljCurTypeId) {
  1517. rst.push(me.complementaryGljList[i]);
  1518. }
  1519. }
  1520. return rst;
  1521. },
  1522. updateCache: function (addArr, updateArr, removeIds, rstData) {
  1523. let me = this, cacheSection = me.complementaryGljList;
  1524. if (addArr.length > 0) {
  1525. me.complementaryGljList = me.complementaryGljList.concat(addArr);
  1526. cacheSection = me.complementaryGljList;
  1527. }
  1528. for (let i = removeIds.length - 1; i >= 0; i--) {
  1529. for (let j = cacheSection.length - 1; j >= 0; j--) {
  1530. if (cacheSection[j]["ID"] == removeIds[i]) {
  1531. cacheSection.splice(j, 1);
  1532. }
  1533. }
  1534. }
  1535. if (rstData && rstData.ops && rstData.ops.length > 0) {
  1536. for (let i = 0; i < rstData.ops.length; i++) {
  1537. for (let j = 0; j < cacheSection.length; j++) {
  1538. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  1539. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  1540. }
  1541. }
  1542. }
  1543. }
  1544. for (let i = 0; i < updateArr.length; i++) {
  1545. for (let j = 0; j < cacheSection.length; j++) {
  1546. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  1547. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  1548. cacheSection[j] = updateArr[i];
  1549. }
  1550. } else if (cacheSection[j].code === updateArr[i].code) {
  1551. cacheSection[j] = updateArr[i];
  1552. }
  1553. }
  1554. }
  1555. //allgljs
  1556. },
  1557. updateParentNodeIds: function (nodes, caller) {
  1558. let private_build_parentNodeIds = function (pNodeId, nodesArr) {
  1559. let rst = [];
  1560. for (let i = 0; i < nodesArr.length; i++) {
  1561. if (nodesArr[i].children.length > 0) {
  1562. rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
  1563. } else {
  1564. rst.push(nodesArr[i].data.ID);
  1565. }
  1566. }
  1567. if (pNodeId && rst.length > 0) {
  1568. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  1569. }
  1570. return rst;
  1571. };
  1572. if (caller.parentNodeIds) {
  1573. private_build_parentNodeIds(null, nodes);
  1574. }
  1575. },
  1576. setProp: function (prop, value, gljList) {
  1577. let me = this;
  1578. for (let i = 0, len = gljList.length; i < len; i++) {
  1579. gljList[i][prop] = value;
  1580. }
  1581. },
  1582. sortGlj: function (gljList) {
  1583. let me = this;
  1584. gljList.sort(function (a, b) {
  1585. let rst = 0;
  1586. if (a.code > b.code) rst = 1
  1587. else if (a.code < b.code) rst = -1;
  1588. return rst;
  1589. });
  1590. }
  1591. }
  1592. let gljTypeTreeOprObj = {
  1593. onClick: function (event, treeId, treeNode) {
  1594. let me = repositoryGljObj,
  1595. that = gljComponentOprObj,
  1596. gljTypeId = treeNode.ID;
  1597. me.gljCurTypeId = treeNode.ID;
  1598. //消除新增到一半的数据
  1599. me.addGljObj = null;
  1600. //me.currentCache = me.getCache();
  1601. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  1602. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  1603. me.currentOprParent = 1;
  1604. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  1605. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  1606. } else {
  1607. me.currentOprParent = 0;
  1608. me.currentCache = me.getCache();
  1609. }
  1610. me.showGljItems(me.complementaryGljList, gljTypeId);
  1611. }
  1612. }