glj.js 74 KB

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