glj.js 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. const locked = lockUtil.getLocked();
  5. $(document).ready(function () {
  6. let moduleName = 'stdGLj';
  7. function refreshALlWorkBook() {
  8. if (gljClassTreeObj.workBook) {
  9. gljClassTreeObj.workBook.refresh();
  10. }
  11. if (repositoryGljObj.workBook) {
  12. repositoryGljObj.workBook.refresh();
  13. }
  14. if (gljComponentOprObj.workBook) {
  15. gljComponentOprObj.workBook.refresh();
  16. }
  17. }
  18. SlideResize.loadHorizonWidth(moduleName, [$('#slideResizeLeft'), $('#slideResizeRight')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  19. refreshALlWorkBook();
  20. });
  21. //章节树与人材机表
  22. let leftElesObj = {};
  23. leftElesObj.module = moduleName;
  24. leftElesObj.resize = $('#slideResizeLeft');
  25. leftElesObj.parent = $('#dataRow');
  26. leftElesObj.left = $('#leftContent');
  27. leftElesObj.right = $('#midContent');
  28. SlideResize.horizontalSlide(leftElesObj, { min: 375, max: `$('#dataRow').width() - $('#rightContent').width() - 375` }, function () {
  29. refreshALlWorkBook();
  30. });
  31. //人材机表与人材机组成物表
  32. let rightElesObj = {};
  33. rightElesObj.module = moduleName;
  34. rightElesObj.resize = $('#slideResizeRight');
  35. rightElesObj.parent = $('#dataRow');
  36. rightElesObj.left = $('#midContent');
  37. rightElesObj.right = $('#rightContent');
  38. SlideResize.horizontalSlide(rightElesObj, { min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200` }, function () {
  39. let resizeRate = SlideResize.resizeWidth * 100 / $('#midContent').width(),
  40. sheetRate = 100 - resizeRate;
  41. $('#slideResizeLeft').css('width', `${resizeRate}%`);
  42. $('#GLJListSheet').css('width', `${sheetRate}%`);
  43. refreshALlWorkBook();
  44. });
  45. $('#gljSearch').keydown(function (event) {
  46. if (event.keyCode === 13) {
  47. $(this).blur();
  48. const gljCode = $(this).val();
  49. if (gljCode) {
  50. repositoryGljObj.locateGlj(gljCode);
  51. // sectionTreeObj.locateToSection(rationCode);
  52. }
  53. }
  54. });
  55. });
  56. const digital = {
  57. basePrice: -2,
  58. consumeAmt: -3
  59. };
  60. let pageOprObj = {
  61. gljLibName: null,
  62. gljLibId: null,
  63. initPage: function (container, containerComponent, containerC) {
  64. let me = this, gljLibId = getQueryString("gljLibId");//获取定额库参数
  65. me.gljLibId = gljLibId;
  66. //生成人材机表格列头
  67. repositoryGljObj.setting.header = repositoryGljObj.initHeaders(priceProperties);
  68. //生成列映射
  69. sheetCommonObj.initColMapping(repositoryGljObj, repositoryGljObj.setting.header);
  70. //生成单价列下标数组
  71. repositoryGljObj.initPriceCols(priceProperties, repositoryGljObj.colMapping);
  72. repositoryGljObj.getGljLib(gljLibId, function () {
  73. repositoryGljObj.buildSheet(container);
  74. gljComponentOprObj.buildSheet(containerComponent);
  75. componentOprObj.buildSheet(containerC);
  76. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  77. //repositoryGljObj.getRationGljIds(gljLibId);
  78. repositoryGljObj.getGljDistType(function () {
  79. repositoryGljObj.currentRepositoryId = parseInt(gljLibId);
  80. repositoryGljObj.getGljItems(gljLibId, function () {
  81. gljClassTreeObj.getGljClassTree(gljLibId, function () {
  82. const spreads = [gljClassTreeObj.workBook, repositoryGljObj.workBook, gljComponentOprObj.workBook];
  83. const $range = $(document.body);
  84. lockUtil.lockSpreadsAndTools(spreads, $range, locked);
  85. });
  86. })
  87. });
  88. });
  89. }
  90. };
  91. let repositoryGljObj = {
  92. colMapping: null,
  93. treeObj: null,
  94. workBook: null,
  95. gljCurTypeId: -1,
  96. currentRepositoryId: -1,
  97. currentCache: null,
  98. parentNodeIds: {},
  99. gljList: [],
  100. feeDataCode: ['grossWeightCoe', 'purchaseStorageRate', 'offSiteTransportLossRate', 'handlingLossRate'],
  101. distTypeTree: null,//add
  102. setting: {
  103. owner: "glj",
  104. header: [
  105. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  106. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  107. { headerName: "规格型号", headerWidth: 120, dataCode: "specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  108. { headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  109. { headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" },
  110. { headerName: "类型", headerWidth: 90, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" },
  111. ],
  112. view: {
  113. comboBox: [
  114. { row: -1, col: 3, rowCount: -1, colCount: 1 }
  115. ],
  116. lockedCells: [
  117. ]
  118. }
  119. },
  120. locateGlj: function (gljCode) {
  121. const glj = repositoryGljObj.gljList.find(glj => glj.code === gljCode);
  122. if (!glj) {
  123. alert(`不存在人材机${gljCode}`);
  124. }
  125. const gljClassNode = gljClassTreeObj.cache.find(node => node.data.ID === glj.gljClass) || gljClassTreeObj.cache[0];
  126. if (!gljClassNode) {
  127. alert('无法定位到分类节点');
  128. }
  129. const gljClassRow = gljClassTreeObj.cache.indexOf(gljClassNode);
  130. const classSheet = gljClassTreeObj.workBook.getSheet(0);
  131. classSheet.showRow(gljClassRow, GC.Spread.Sheets.VerticalPosition.center);
  132. classSheet.setActiveCell(gljClassRow, 0);
  133. gljClassTreeObj.initSelection(gljClassNode);
  134. const theGlj = repositoryGljObj.currentCache.find(item => item.code === gljCode);
  135. if (!theGlj) {
  136. alert(`不存在人材机${gljCode}`);
  137. }
  138. const sheet = repositoryGljObj.workBook.getSheet(0);
  139. const gljRow = repositoryGljObj.currentCache.indexOf(theGlj);
  140. sheet.showRow(gljRow, GC.Spread.Sheets.VerticalPosition.center);
  141. sheet.setActiveCell(gljRow, 0);
  142. },
  143. //根据费用定额的单价属性获取人材机的单价属性
  144. getPriceProperty: function (priceProperties) {
  145. let priceProperty = {};
  146. for (let priceProp of priceProperties) {
  147. priceProperty[priceProp.price.dataCode] = 0;
  148. }
  149. return priceProperty;
  150. },
  151. //根据单价字段获取消耗量字段
  152. getConsumeAmtField: function (consumeAmtProperties, priceField) {
  153. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  154. return 'consumeAmt';
  155. }
  156. for (let consumeAmtProp of consumeAmtProperties) {
  157. if (consumeAmtProp.consumeAmt.refPrice === priceField) {
  158. return consumeAmtProp.consumeAmt.dataCode;
  159. }
  160. }
  161. return 'consumeAmt';
  162. },
  163. //初始单价相关的列(单价列、单价属性列)
  164. initPriceCols: function (priceProperties, colMapping) {
  165. let priceCols = [],
  166. pricePropertyCols = [];
  167. if (!priceProperties || priceProperties.length === 0) {
  168. priceCols.push(colMapping.fieldToCol['basePrice']);
  169. }
  170. for (let priceProp of priceProperties) {
  171. pricePropertyCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  172. priceCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  173. }
  174. this.priceCols = priceCols;
  175. this.pricePropertyCols = pricePropertyCols;
  176. },
  177. getPriceFields: function () {
  178. let rst = [];
  179. for (let priceCol of this.priceCols) {
  180. rst.push(this.colMapping.colToField[priceCol]);
  181. }
  182. return rst;
  183. },
  184. //获取更新定额价的人材机价格(人材机只有一个单价取basePrice, 人材机有多个单价,取第一个单价)
  185. getRationGljPrice: function (glj) {
  186. if (glj.priceProperty) {
  187. let keys = Object.keys(glj.priceProperty);
  188. if (keys.length > 0) {
  189. return glj.priceProperty[keys[0]];
  190. }
  191. }
  192. return glj.basePrice;
  193. },
  194. //生成列头(多单价)
  195. initHeaders: function (priceProperties) {
  196. let headers = [
  197. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  198. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  199. { headerName: "规格型号", headerWidth: 120, dataCode: "specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  200. { headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  201. { headerName: "类型", headerWidth: 90, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" },
  202. ];
  203. //生成单价列
  204. if (!priceProperties || priceProperties.length === 0) {
  205. headers.push({ headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" });
  206. }
  207. else {
  208. for (let priceProp of priceProperties) {
  209. let colData = {
  210. headerName: priceProp.price.dataName,
  211. headerWidth: 100,
  212. dataCode: priceProp.price.dataCode,
  213. dataType: 'Number',
  214. formatter: '0.00',
  215. hAlign: 'right',
  216. vAlign: 'center'
  217. };
  218. headers.push(colData);
  219. }
  220. }
  221. let tailHeaders = [
  222. { headerName: "损耗率", headerWidth: 90, dataCode: "lossRate", dataType: "Number", hAlign: "center", vAlign: "center" },
  223. { headerName: "毛重系数", headerWidth: 90, dataCode: "grossWeightCoe", dataType: "Number", hAlign: "center", vAlign: "center" },
  224. { headerName: "采购保管费率", headerWidth: 90, dataCode: "purchaseStorageRate", dataType: "Number", hAlign: "center", vAlign: "center" },
  225. { headerName: "场外运输损耗率", headerWidth: 100, dataCode: "offSiteTransportLossRate", dataType: "Number", hAlign: "center", vAlign: "center" },
  226. { headerName: "每增一次装卸损耗率", headerWidth: 100, dataCode: "handlingLossRate", dataType: "Number", hAlign: "center", vAlign: "center" },
  227. ];
  228. headers = headers.concat(tailHeaders);
  229. return headers;
  230. },
  231. //工料机单价赋初始值(没有单价属性,则单价字段为basePrice,否则单价字段为单价属性对象中的属性)
  232. initPrice: function (glj) {
  233. if (!priceProperties || priceProperties.length === 0) {
  234. glj.basePrice = glj.basePrice && !isNaN(parseFloat(glj.basePrice)) ? scMathUtil.roundTo(parseFloat(glj.basePrice), -2) : 0;
  235. }
  236. else {
  237. if (!glj.priceProperty) {
  238. glj.priceProperty = {};
  239. }
  240. for (let priceProp of priceProperties) {
  241. let gljPrice = glj['priceProperty'][priceProp.price.dataCode];
  242. gljPrice = gljPrice && !isNaN(parseFloat(gljPrice)) ? scMathUtil.roundTo(parseFloat(gljPrice), -2) : 0;
  243. }
  244. }
  245. },
  246. //人材机单价是否变化
  247. isGljPriceChange: function (glj, newPrice) {
  248. //多单价,与人材机单价属性比较
  249. if (typeof newPrice === 'object') {
  250. return !_.isEqual(glj.priceProperty, newPrice);
  251. }
  252. return !_.isEqual(glj.basePrice, newPrice);
  253. },
  254. //粘贴数据含有单价
  255. pasteIncludesPrice: function (pasteObj) {
  256. let me = repositoryGljObj;
  257. for (let priceCol of me.priceCols) {
  258. let priceField = me.colMapping.colToField[priceCol];
  259. if (typeof pasteObj[priceField] !== 'undefined') {
  260. return true;
  261. }
  262. }
  263. return false;
  264. },
  265. //获取人材机价格
  266. getPrice: function (glj, col) {
  267. let me = repositoryGljObj;
  268. if (!priceProperties || priceProperties.length === 0) {
  269. return glj.basePrice;
  270. }
  271. return glj.priceProperty[me.colMapping.colToField[col]];
  272. },
  273. //工料机价格是否相同
  274. priceIsEqual: function (gljA, gljB) {
  275. if (!priceProperties || priceProperties.length === 0) {
  276. return gljA.basePrice === gljB.basePrice;
  277. }
  278. return _.isEqual(gljA.priceProperty, gljB.priceProperty);
  279. },
  280. setGljPrice: function (glj, newPrice, col) {
  281. if (!priceProperties || priceProperties.length === 0) {
  282. glj.basePrice = newPrice;
  283. }
  284. else {
  285. glj.priceProperty[this.colMapping.colToField[col]] = newPrice;
  286. }
  287. },
  288. setUnitCombo: function (sheet, headers) {
  289. let me = this;
  290. sheet.suspendPaint();
  291. sheet.suspendEvent();
  292. let combo = sheetCommonObj.getDynamicCombo();
  293. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  294. let unitCol = me.colMapping.fieldToCol['unit'];
  295. if (unitCol) {
  296. sheet.getRange(-1, unitCol, -1, 1).cellType(combo);
  297. }
  298. sheet.resumePaint();
  299. sheet.resumeEvent();
  300. },
  301. getComboData: function (gljDistType) {
  302. let me = this;
  303. let distType;
  304. let distTypeTree = {
  305. prefix: 'gljType',
  306. distTypes: {},
  307. comboDatas: [],
  308. distTypesArr: []
  309. };
  310. gljDistType.forEach(function (typeData) {
  311. let typeObj = {
  312. data: typeData,
  313. children: [],
  314. parent: null
  315. };
  316. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  317. distTypeTree.distTypesArr.push(typeObj);
  318. });
  319. gljDistType.forEach(function (typeData) {
  320. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  321. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  322. if (parent) {
  323. distType.parent = parent;
  324. parent.children.push(distType);
  325. }
  326. });
  327. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  328. if (allowGljType.includes(distTypeObj.data.ID)) {
  329. distTypeTree.comboDatas.push({ text: distTypeObj.data.fullName, value: distTypeObj.data.ID });
  330. }
  331. });
  332. return distTypeTree;
  333. },
  334. getGljDistType: function (callback) {
  335. let me = this;
  336. $.ajax({
  337. type: 'post',
  338. url: "api/getGljDistType",
  339. dataType: 'json',
  340. success: function (result) {
  341. if (!result.error && callback) {
  342. me.distTypeTree = me.getComboData(result.data);
  343. console.log(me.distTypeTree);
  344. callback();
  345. }
  346. }
  347. })
  348. },
  349. //获取工料机类型大类
  350. getParentType: function (type) {
  351. return parseInt(type.toString()[0]);
  352. },
  353. getGljLib: function (libId, callback) {
  354. let me = repositoryGljObj;
  355. $.ajax({
  356. type: 'post',
  357. url: 'api/getGljLib',
  358. data: { libId: libId },
  359. dataType: 'json',
  360. success: function (result) {
  361. if (!result.error) {
  362. if (result.data.length > 0) {
  363. me.rationLibs = result.data[0].rationLibs;
  364. $(".navbar-text").append(
  365. "<a href='/stdGljRepository/main'>人材机库</a><i class='fa fa-angle-right fa-fw'></i>" + result.data[0].dispName
  366. );
  367. pageOprObj.gljLibName = result.data[0].dispName;
  368. }
  369. callback();
  370. }
  371. }
  372. })
  373. },
  374. getGljTree: function (gljLibId, callback) {
  375. let me = this;
  376. $.ajax({
  377. type: "POST",
  378. url: "api/getGljTree",
  379. data: { "gljLibId": gljLibId },
  380. dataType: "json",
  381. cache: false,
  382. timeout: 20000,
  383. success: function (result, textStatus, status) {
  384. if (status.status == 200) {
  385. zTreeHelper.createTree(result.data, gljSetting, "repositoryTree", me);
  386. zTreeHelper.createTree(result.data, componentSetting, "componentTree", componentOprObj);
  387. if (result.data && result.data.length > 0) {
  388. me.gljCurTypeId = result.data[0].ID;
  389. } else {
  390. //重新创建库?
  391. gljTypeTreeOprObj.addRootNode();
  392. }
  393. callback();
  394. }
  395. },
  396. error: function (err) {
  397. alert(err.responseJSON.error);
  398. }
  399. })
  400. },
  401. getGljItems: function (repId, callback) {
  402. let me = this;
  403. $.ajax({
  404. type: "POST",
  405. url: "api/getGljItems",
  406. data: { "repositoryId": repId },
  407. dataType: "json",
  408. cache: false,
  409. timeout: 20000,
  410. success: function (result) {
  411. if (!result.error) {
  412. me.gljList = result.data;
  413. me.workBook.getSheet(0).setRowCount(result.data.length);
  414. me.sortGlj();
  415. me.currentGlj = me.gljList.length > 0 ? me.gljList[0] : null;//初始
  416. if (callback) {
  417. callback();
  418. }
  419. }
  420. },
  421. error: function (err) {
  422. alert(err.responseJSON.error);
  423. }
  424. })
  425. },
  426. showGljItems: function (data, type) {
  427. let me = repositoryGljObj;
  428. if (me.workBook) {
  429. let cacheSection = data;
  430. me.sortGljDeep(cacheSection);
  431. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  432. sheetsOprObj.showData(me, me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree);
  433. let gljTypeCol = me.colMapping.fieldToCol['gljType'];
  434. sheetCommonObj.setDynamicCombo(me.workBook.getActiveSheet(), 0, gljTypeCol, me.workBook.getActiveSheet().getRowCount(), me.distTypeTree.comboDatas, 10, 'text');
  435. cacheSection = null;
  436. let selRow = me.workBook.getActiveSheet().getSelections()[0].row;
  437. me.initSel(selRow);
  438. }
  439. },
  440. bindEnterKey: function () {
  441. let me = this;
  442. let sheet = me.workBook.getActiveSheet();
  443. me.workBook.commandManager().register("myEnter", function () {
  444. let orgRow = sheet.getActiveRowIndex();
  445. let orgCol = sheet.getActiveColumnIndex();
  446. if (sheet.isEditing()) {
  447. sheet.endEdit();
  448. }
  449. let codeCol = me.colMapping.fieldToCol['code'];
  450. let code = sheet.getValue(orgRow, codeCol);
  451. let newRow, newCol;
  452. if (!me.currentCache[orgRow] && code !== undefined && code !== null && orgCol !== me.setting.header.length - 1) {
  453. newRow = orgRow;
  454. newCol = orgCol + 1;
  455. sheet.setActiveCell(newRow, newCol);
  456. }
  457. else {
  458. newRow = orgRow + 1;
  459. newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
  460. sheet.setActiveCell(newRow, newCol);
  461. }
  462. //触发事件
  463. me.onLeaveCell({ type: 'LeaveCell' }, { sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol });
  464. me.onEnterCell({ type: 'EnterCell' }, { sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol });
  465. let newSels = [{ row: newRow, rowCount: 1, col: newCol, colCount: 1 }];
  466. let oldSels = [{ row: orgRow, rowCount: 1, col: orgRow, colCount: 1 }];
  467. me.onSelectionChanged({ type: 'SelectionChanged' }, { sheet: sheet, sheetName: sheet.name(), newSelections: newSels, oldSelections: oldSels });
  468. });
  469. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  470. me.workBook.commandManager().setShortcutKey("myEnter", GC.Spread.Commands.Key.enter, false, false, false, false);
  471. },
  472. buildSheet: function (container) {
  473. let me = repositoryGljObj;
  474. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
  475. sheetCommonObj.bindEscKey(me.workBook, [{ sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd }]);
  476. me.bindEnterKey();
  477. me.repositoryGljDelOpr();
  478. me.onContextmenuOpr();
  479. me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
  480. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  481. me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  482. if (priceProperties && priceProperties.length > 0) {
  483. me.workBook.getSheet(0).frozenColumnCount(5);
  484. }
  485. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  486. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  487. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  488. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  489. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  490. },
  491. isDef: function (v) {
  492. return v !== undefined && v !== null;
  493. },
  494. //成为了组成物
  495. isComponent: function (gljId, gljList) {
  496. //暂时只需要判断主材(可成为主材的组成物)、机械组成物(可成为机械台班的组成物,但是机械组成物可能引用了普通材料)
  497. let gljTypes = [302, 4];
  498. for (let i = 0, len = gljList.length; i < len; i++) {
  499. let gljComponent = gljList[i].component;
  500. if (gljTypes.includes(gljList[i].gljType) && this.isDef(gljComponent) && gljComponent.length > 0) {
  501. for (let j = 0, jLen = gljComponent.length; j < jLen; j++) {
  502. if (gljComponent[j].ID === gljId) {
  503. return true;
  504. }
  505. }
  506. }
  507. }
  508. return false;
  509. },
  510. getCurrentComponent: function (gljComponent, sort = false) {
  511. let me = repositoryGljObj,
  512. rst = [],
  513. IDCodeMapping = {};
  514. for (let i = 0; i < gljComponent.length; i++) {
  515. let obj = {};
  516. for (let j = 0; j < me.gljList.length; j++) {
  517. let specs = me.gljList[j].specs ? ' ' + me.gljList[j].specs : '';
  518. if (gljComponent[i].ID == me.gljList[j].ID) {
  519. obj.ID = me.gljList[j].ID;
  520. obj.code = me.gljList[j].code;
  521. obj.name = me.gljList[j].name + specs;
  522. obj.unit = me.gljList[j].unit;
  523. obj.basePrice = me.gljList[j].basePrice;
  524. obj.priceProperty = me.gljList[j].priceProperty ? me.gljList[j].priceProperty : {};
  525. obj.consumeAmt = gljComponent[i].consumeAmt;
  526. obj.consumeAmtProperty = gljComponent[i].consumeAmtProperty ? gljComponent[i].consumeAmtProperty : {};
  527. rst.push(obj);
  528. IDCodeMapping[obj.ID] = obj.code;
  529. }
  530. }
  531. }
  532. if (sort) {
  533. rst.sort(function (a, b) {
  534. let r = 0;
  535. if (a.code > b.code) r = 1;
  536. else if (a.code < b.code) r = -1;
  537. return r;
  538. });
  539. gljComponent.sort(function (a, b) {
  540. let aV = IDCodeMapping[a.ID],
  541. bV = IDCodeMapping[b.ID];
  542. if (aV > bV) {
  543. return 1;
  544. } else if (aV < bV) {
  545. return -1;
  546. }
  547. return 0;
  548. });
  549. }
  550. return rst;
  551. },
  552. //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
  553. getUpdateGljs: function (rObj, isDelete) {
  554. let me = repositoryGljObj, that = gljComponentOprObj,
  555. rst = { updateArr: [], updateBasePrcArr: [] };
  556. //改变单价,以便reCalGljBasePrc方法可行
  557. if (!isDelete) {
  558. for (let i = 0; i < me.gljList.length; i++) {
  559. if (me.gljList[i].ID === rObj.ID) {
  560. me.gljList[i].basePrice = rObj.basePrice;
  561. me.gljList[i].priceProperty = rObj.priceProperty ? rObj.priceProperty : {};
  562. break;
  563. }
  564. }
  565. }
  566. for (let i = 0; i < me.gljList.length; i++) {
  567. let thisComponent = me.gljList[i].component, isChange = false;
  568. for (let j = 0; j < thisComponent.length; j++) {
  569. if (thisComponent[j].ID === rObj.ID) {
  570. //删除
  571. isChange = true;
  572. if (isDelete) {
  573. thisComponent.splice(j--, 1);
  574. }
  575. else {
  576. break;
  577. }
  578. }
  579. }
  580. if (isChange) {//引用了此组成物
  581. rst.updateArr.push(me.gljList[i]);
  582. }
  583. }
  584. return rst;
  585. },
  586. reshowGljBasePrc: function (glj) {
  587. let me = repositoryGljObj;
  588. let cacheSection = me.currentCache;
  589. let sheet = me.workBook.getActiveSheet();
  590. let row = _.findIndex(cacheSection, { ID: glj.ID });
  591. sheet.suspendEvent();
  592. sheet.suspendPaint();
  593. for (let priceCol of me.priceCols) {
  594. sheet.setValue(row, priceCol, glj[me.colMapping.colToField[priceCol]]);
  595. }
  596. sheet.resumeEvent();
  597. sheet.resumePaint();
  598. },
  599. reSetGljBasePrc: function (gljs) {
  600. let me = repositoryGljObj;
  601. let cacheSection = me.currentCache;
  602. let sheet = me.workBook.getSheet(0);
  603. let basePriceCol = me.colMapping.fieldToCol['basePrice'];
  604. sheet.suspendPaint();
  605. sheet.suspendEvent();
  606. for (let i = 0; i < cacheSection.length; i++) {
  607. for (let glj of gljs) {
  608. if (glj.ID === cacheSection[i].ID) {
  609. for (let priceCol of me.priceCols) {
  610. sheet.setValue(i, priceCol, glj[me.colMapping.colToField[priceCol]]);
  611. }
  612. //sheet.setValue(i, basePriceCol, glj.basePrice);
  613. }
  614. }
  615. }
  616. sheet.resumePaint();
  617. sheet.resumeEvent();
  618. },
  619. initSel: function (row) {
  620. let me = repositoryGljObj, that = gljComponentOprObj;
  621. sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, -1);
  622. //sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, -1);
  623. me.workBook.focus(true);
  624. me.currentComponent = [];
  625. that.workBook.getSheet(0).setRowCount(10);
  626. if (row < me.currentCache.length) {
  627. //标记当前工料机
  628. me.currentGlj = me.currentCache[row];
  629. if (allowComponent.includes(me.currentCache[row].gljType)) {
  630. //展示数据
  631. if (me.currentGlj.component.length > 0) {
  632. me.currentComponent = me.getCurrentComponent(me.currentGlj.component, true);
  633. if (me.currentComponent.length > 0) {
  634. sheetsOprObj.showData(that, that.workBook.getSheet(0), that.setting, me.currentComponent);
  635. }
  636. }
  637. }
  638. }
  639. else {
  640. me.currentGlj = null;
  641. }
  642. },
  643. onSelectionChanged: function (sender, info) {
  644. let me = repositoryGljObj, that = gljComponentOprObj;
  645. //混凝土202、砂浆203、配合比204、机械3
  646. if (info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row) {
  647. let row = info.newSelections[0].row;
  648. me.initSel(row);
  649. }
  650. },
  651. onLeaveCell: function (sender, args) {
  652. let me = repositoryGljObj;
  653. me.lastCell = { row: args.row, col: args.col };
  654. },
  655. onEnterCell: function (sender, args) {
  656. let me = repositoryGljObj;
  657. let thisDataCode = me.setting.header[args.col].dataCode,
  658. lastDataCode = me.setting.header[me.lastCell.col].dataCode;
  659. if (thisDataCode === 'unit' || lastDataCode === 'unit' || thisDataCode === 'gljType' || lastDataCode === 'gljType') {
  660. let rects = [];
  661. rects.push(args.sheet.getCellRect(args.row, args.col));
  662. if (me.lastCell) {
  663. rects.push(args.sheet.getCellRect(me.lastCell.row, me.lastCell.col));
  664. }
  665. for (let rect of rects) {
  666. args.sheet.repaint(rect);
  667. }
  668. //args.sheet.repaint();
  669. }
  670. me.cellRowIdx = args.row;
  671. let isHasData = false;
  672. if (me.addGljObj) {
  673. for (let i = 0; i < me.setting.header.length; i++) {
  674. if (me.addGljObj[me.setting.header[i].dataCode]) {
  675. isHasData = true;
  676. break;
  677. }
  678. }
  679. }
  680. if (isHasData) {
  681. if (me.editingRowIdx !== me.cellRowIdx) {
  682. let focusToCol;
  683. function getFocusToCol(me) {
  684. if (!me.addGljObj.code) {
  685. $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
  686. return me.colMapping.fieldToCol['code'];
  687. }
  688. else if (!me.addGljObj.name) {
  689. $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
  690. return me.colMapping.fieldToCol['name'];
  691. }
  692. else if (!me.addGljObj.gljType) {
  693. $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
  694. return me.colMapping.fieldToCol['gljType'];
  695. }
  696. else {
  697. return -1;
  698. }
  699. }
  700. focusToCol = getFocusToCol(me);
  701. if (focusToCol !== -1) {
  702. $('#gljAlertBtn').click();
  703. $('#aleConfBtn').unbind('click');
  704. $('#aleConfBtn').bind('click', function () {
  705. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  706. me.workBook.focus(true);
  707. });
  708. $('#gljAleClose').click(function () {
  709. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  710. me.workBook.focus(true);
  711. });
  712. $('#aleCanceBtn').unbind('click');
  713. $('#aleCanceBtn').bind('click', function () {
  714. me.addGljObj = null;
  715. args.sheet.suspendEvent();
  716. args.sheet.suspendPaint();
  717. for (let col = 0; col < me.setting.header.length; col++) {
  718. if (col === 0) {
  719. me.workBook.getSheet(0).getCell(me.editingRowIdx, 0).formatter("@");
  720. }
  721. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value('');
  722. }
  723. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  724. me.workBook.focus(true);
  725. args.sheet.resumeEvent();
  726. args.sheet.resumePaint();
  727. });
  728. }
  729. }
  730. }
  731. },
  732. onCellEditStart: function (sender, args) {
  733. let me = repositoryGljObj;
  734. me.orgCode = me.workBook.getSheet(0).getValue(args.row, me.colMapping.fieldToCol['code']);
  735. let rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me);
  736. if (me.prevent) {
  737. args.cancel = true;
  738. return;
  739. }
  740. me.currentEditingGlj = rObj;
  741. if (args.row < me.currentCache.length) {
  742. let dataCode = me.setting.header[args.col].dataCode;
  743. me.currentGlj = me.currentCache[args.row];
  744. if (dataCode === 'code'
  745. || (me.feeDataCode.includes(dataCode) && me.getParentType(me.currentGlj.gljType) !== 2)) {//费率数据列只有材料能用
  746. args.cancel = true;
  747. }
  748. else {
  749. rObj.ID = me.currentGlj.ID;
  750. rObj.gljClass = me.currentGlj.gljClass;
  751. }
  752. }
  753. else {
  754. me.currentGlj = null;
  755. }
  756. },
  757. dataChanged: function (objA, objB, col) {
  758. let me = repositoryGljObj;
  759. if (me.priceCols.includes(col)) {
  760. if (!priceProperties || priceProperties.length === 0) {
  761. return objA.basePrice !== objB.basePrice;
  762. }
  763. else {
  764. return objA.priceProperty[me.colMapping.colToField[col]] !== objB.priceProperty[me.colMapping.colToField[col]]
  765. }
  766. }
  767. return objA[me.colMapping.colToField[col]] !== objB[[me.colMapping.colToField[col]]];
  768. },
  769. onCellEditEnd: function (sender, args) {
  770. let me = repositoryGljObj, that = gljComponentOprObj,
  771. updateArr = [], addArr = [], updateBasePrcArr = [];
  772. // 输入编号、名称、规格时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  773. let deESCFields = ['code', 'name', 'specs'];
  774. let dataCode = me.setting.header[args.col].dataCode;
  775. if (deESCFields.includes(dataCode)) {
  776. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  777. args.sheet.setValue(args.row, args.col, args.editingText);
  778. }
  779. let rObj = sheetsOprObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me);
  780. me.editingRowIdx = args.row;
  781. //rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  782. me.initPrice(rObj);
  783. //更新
  784. if (me.currentEditingGlj["ID"] !== null && me.currentEditingGlj["ID"] !== undefined && me.currentGlj) {
  785. rObj["ID"] = me.currentEditingGlj["ID"];
  786. rObj.gljClass = me.currentEditingGlj.gljClass;
  787. if (me.dataChanged(me.currentEditingGlj, rObj, args.col)) {
  788. if (rObj.code && rObj.name && rObj.gljType &&
  789. rObj.code.toString().trim().length !== 0 && rObj.name.toString().trim().length !== 0 && rObj.gljType.toString().trim().length !== 0) {
  790. if (rObj.gljType !== me.currentEditingGlj.gljType) {//修改了工料机类型
  791. if (!$('#typeAlert').is(':visible')) {
  792. $('#typeAlert').modal('show');
  793. }
  794. $('#typeConfirm').unbind('click');
  795. $('#typeConfirm').bind('click', function () {
  796. $('#typeAlert').modal('hide');
  797. if (me.currentGlj) {
  798. me.currentGlj.component = [];
  799. }
  800. //工料机类型不为材料时,情况费率数据
  801. if (me.getParentType(me.currentEditingGlj.gljType) === 2 && me.getParentType(rObj.gljType) !== 2) {
  802. for (let feeCode of me.feeDataCode) {
  803. if (me.currentEditingGlj[feeCode]) {
  804. rObj[feeCode] = null;
  805. }
  806. }
  807. }
  808. if (componentType.includes(me.currentEditingGlj.gljType) &&
  809. !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType)) &&
  810. !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))) {//修改了原本是组成物的工料机
  811. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  812. let updateGljs = me.getUpdateGljs(rObj, true);
  813. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  814. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  815. updateArr.push(updateGljs.updateArr[i]);
  816. }
  817. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  818. updateArr.push(updateGljs.updateBasePrcArr[i]);
  819. }
  820. }
  821. }
  822. sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, 5);
  823. rObj.component = me.currentGlj.component;
  824. updateArr.push(rObj);
  825. me.mixUpdateRequest(updateArr, [], []);
  826. });
  827. $('.typeClose').unbind('click');
  828. $('.typeClose').bind('click', function () {
  829. args.sheet.setValue(args.row, args.col, _.find(me.distTypeTree.comboDatas, { value: me.currentGlj.gljType }).text);
  830. });
  831. return;
  832. } else if ((me.feeDataCode.includes(dataCode) || dataCode === 'lossRate') && rObj[dataCode] !== me.currentEditingGlj[dataCode]) {
  833. if (isNaN(rObj[dataCode])) {
  834. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[dataCode] ? me.currentEditingGlj[dataCode] : '');
  835. alert(`${me.setting.header[args.col].headerName}只能输入数值!`);
  836. return;
  837. }
  838. } else if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {//修改了单价,可修改单价的必为可成为组成物的
  839. let rObjPrice = me.getPrice(rObj, args.col),
  840. editingGljPrice = me.getPrice(me.currentEditingGlj, args.col);
  841. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  842. if (isNaN(parseFloat(rObjPrice))) {
  843. alert('单价只能输入数值!');
  844. args.sheet.setValue(args.row, args.col, editingGljPrice ? editingGljPrice : 0);
  845. return;
  846. }
  847. me.setGljPrice(rObj, scMathUtil.roundTo(parseFloat(rObjPrice), -2), args.col);
  848. let updateGljs = me.getUpdateGljs(rObj);
  849. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  850. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  851. updateArr.push(updateGljs.updateArr[i]);
  852. }
  853. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  854. updateArr.push(updateGljs.updateBasePrcArr[i]);
  855. }
  856. }
  857. }
  858. rObj.component = me.currentGlj.component;
  859. updateArr.push(rObj);
  860. } else {
  861. if (dataCode === 'gljType') {
  862. let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[dataCode]].data.fullName;
  863. args.sheet.setValue(args.row, args.col, distTypeVal);
  864. } else {
  865. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[dataCode]);
  866. }
  867. }
  868. }
  869. if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  870. //update basePrice of ration when editting basePrice of glj
  871. let gljType = -1;
  872. let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
  873. if (gljTypeParent && gljTypeParent.data.ID <= 3) {
  874. gljType = gljTypeParent.data.ID;
  875. }
  876. if (!gljTypeParent && me.currentEditingGlj.gljType <= 3) {
  877. gljType = me.currentEditingGlj.gljType;
  878. }
  879. let gljBasePrcObj = { gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: me.getRationGljPrice(rObj) };
  880. if (gljBasePrcObj.gljType !== -1) {
  881. updateBasePrcArr.push(gljBasePrcObj);
  882. if (me.rationLibs.length > 0) {//重算定额单价
  883. me.updateRationBasePrcRq(updateBasePrcArr);
  884. }
  885. }
  886. }
  887. } else { //新增
  888. if (typeof rObj.code !== 'undefined') {
  889. me.addGljObj = rObj;
  890. let isCanSav = true;
  891. if (!rObj.code || !rObj.name || !rObj.gljType) {
  892. isCanSav = false;
  893. }
  894. if (isCanSav) {
  895. me.addGljObj = null;
  896. rObj.component = [];
  897. me.initPrice(rObj);
  898. addArr.push(rObj);
  899. }
  900. }
  901. }
  902. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  903. rObj.gljClass = me.gljCurTypeId;
  904. }
  905. if (updateArr.length > 0 || addArr.length > 0) {
  906. me.currentEditingGlj = null;
  907. me.mixUpdateRequest(updateArr, addArr, []);
  908. }
  909. },
  910. delGljs: function (sels) {
  911. let me = repositoryGljObj;
  912. let sheet = me.workBook.getSheet(0),
  913. updateArr = [], removeArr = [],
  914. removeIDs = [],
  915. removeNames = [],
  916. updateBasePrcArr = [],//删除基价单位后重新计算
  917. canUpdate = false,
  918. cacheSection = me.currentCache,
  919. updateBackups = [];
  920. if (sels.length > 0 && cacheSection.length > 0) {
  921. for (let i = 0; i < sels.length; i++) {
  922. if (sels[i].colCount === me.setting.header.length) {
  923. for (let j = 0; j < sels[i].rowCount; j++) {
  924. if (sels[i].row + j < cacheSection.length) {
  925. removeArr.push(cacheSection[sels[i].row + j]);
  926. removeIDs.push(cacheSection[sels[i].row + j].ID);
  927. removeNames.push(cacheSection[sels[i].row + j].name);
  928. //删除后重新计算引用了此工料机的定额单价
  929. updateBasePrcArr.push({ gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1 });
  930. }
  931. }
  932. }
  933. else {
  934. let maxCol = sels[i].col + sels[i].colCount - 1;
  935. let cantNullDataCode = ['code', 'name', 'gljType'];
  936. for (let j = 0; j < sels[i].rowCount; j++) {
  937. if (sels[i].row + j < cacheSection.length) {
  938. let updateObj = cacheSection[sels[i].row + j];
  939. for (let col = sels[i].col; col <= maxCol; col++) {
  940. let dataCode = me.setting.header[col].dataCode;
  941. if (cantNullDataCode.includes(dataCode)) {
  942. $('#alertText').text(me.setting.header[col].headerName + "不可为空!");
  943. $('#codeAlert').modal('show');
  944. return false;
  945. }
  946. else {
  947. canUpdate = true;
  948. break;
  949. }
  950. }
  951. }
  952. }
  953. }
  954. }
  955. if (canUpdate) {
  956. //删除警告
  957. let upAlertText = '确认删除选中字段?';
  958. $('#alertGljTxt').text(upAlertText);
  959. $('#gljAlert').modal('show');
  960. $('#aleConfBtn').unbind('click');
  961. //确认
  962. $('#aleConfBtn').bind('click', function () {
  963. for (let i = 0; i < sels.length; i++) {
  964. let maxCol = sels[i].col + sels[i].colCount - 1;
  965. for (let j = 0; j < sels[i].rowCount; j++) {
  966. if (sels[i].row + j < cacheSection.length) {
  967. let updateObj = cacheSection[sels[i].row + j];
  968. for (let col = sels[i].col; col <= maxCol; col++) {
  969. let dataCode = me.setting.header[col].dataCode;
  970. if (me.priceCols.includes(col)) {
  971. me.setGljPrice(updateObj, 0, col);
  972. updateBasePrcArr.push({
  973. gljId: updateObj.ID,
  974. gljType: updateObj.gljType,
  975. basePrice: 0
  976. });
  977. }
  978. else {
  979. updateObj[dataCode] = '';
  980. }
  981. }
  982. updateArr.push(updateObj);
  983. }
  984. }
  985. }
  986. me.mixUpdateRequest(updateArr, [], []);
  987. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  988. me.updateRationBasePrcRq(updateBasePrcArr);
  989. }
  990. });
  991. }
  992. if (removeArr.length > 0) {
  993. $.bootstrapLoading.start();
  994. CommonAjax.post('/stdGljRepository/api/isUsed', { gljIds: removeIDs }, function (rstData) {
  995. $.bootstrapLoading.end();
  996. //存在被引用的人材机(标准/补充定额库)
  997. if (rstData.isUsed) {
  998. $('#gljAlert').find('.modal-body h5').text('已有定额引用了当前人材机,不可删除。');
  999. $('#gljAlert').modal('show');
  1000. $('#aleConfBtn').unbind('click');
  1001. $('#aleConfBtn').bind('click', function () {
  1002. $('#gljAlert').modal('hide');
  1003. me.workBook.focus(true)
  1004. });
  1005. }
  1006. else {
  1007. $('#gljAlert').find('.modal-body h5').text(`确定要删除人材机 “${removeNames.join(',')}” 吗? `);
  1008. setTimeout(function () {
  1009. $('#gljAlert').modal('show');
  1010. }, 200);
  1011. //确认
  1012. $('#aleConfBtn').unbind('click');
  1013. $('#aleConfBtn').bind('click', function () {
  1014. for (let removeD of removeArr) {
  1015. let updateGljs = me.getUpdateGljs(removeD, true);
  1016. if (updateGljs.updateArr.length > 0) {
  1017. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1018. updateArr.push(updateGljs.updateArr[i]);
  1019. }
  1020. }
  1021. }
  1022. me.mixUpdateRequest(updateArr, [], removeIDs);
  1023. /* if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1024. me.updateRationBasePrcRq(updateBasePrcArr);
  1025. me.workBook.focus(true);
  1026. }*/
  1027. });
  1028. }
  1029. }, function () {
  1030. $.bootstrapLoading.end();
  1031. $('#gljAlert').find('.modal-body h5').text('查询引用错误,不可删除。');
  1032. $('#gljAlert').modal('show');
  1033. $('#aleConfBtn').unbind('click');
  1034. $('#aleConfBtn').bind('click', function () {
  1035. $('#gljAlert').modal('hide');
  1036. me.workBook.focus(true);
  1037. });
  1038. });
  1039. }
  1040. }
  1041. },
  1042. //删除人材机前需要判断人材机是否有被引用,被引用了则不可删除
  1043. repositoryGljDelOpr: function () {
  1044. if (locked) {
  1045. return;
  1046. }
  1047. let me = repositoryGljObj;
  1048. me.workBook.commandManager().register('repositoryGljDel', function () {
  1049. let sels = me.workBook.getActiveSheet().getSelections();
  1050. me.delGljs(sels);
  1051. });
  1052. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  1053. me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
  1054. },
  1055. onContextmenuOpr: function () {
  1056. let me = repositoryGljObj;
  1057. $.contextMenu({
  1058. selector: '#GLJListSheet',
  1059. build: function ($triggerElement, e) {
  1060. //控制允许右键菜单在哪个位置出现
  1061. let sheet = me.workBook.getSheet(0);
  1062. let offset = $("#GLJListSheet").offset(),
  1063. x = e.pageX - offset.left,
  1064. y = e.pageY - offset.top;
  1065. let target = sheet.hitTest(x, y);
  1066. let sel = sheet.getSelections()[0];
  1067. if (sel.row === -1) {
  1068. sel.row = 0;
  1069. }
  1070. if (sel.col === -1) {
  1071. sel.col = 0;
  1072. }
  1073. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  1074. me.initSel(target.row);
  1075. if (sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
  1076. sel.col > target.col || sel.col + sel.colCount - 1 < target.col) {
  1077. sheet.setActiveCell(target.row, target.col);
  1078. }
  1079. return {
  1080. callback: function () { },
  1081. items: {
  1082. delete: {
  1083. name: "删除",
  1084. disabled: function () {
  1085. return locked || !(me.currentCache && me.currentCache[target.row]);
  1086. },
  1087. icon: "fa-remove",
  1088. callback: function (key, opt) {
  1089. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  1090. curSel.colCount = me.setting.header.length;
  1091. me.delGljs([curSel]);
  1092. }
  1093. },
  1094. getReference: {
  1095. name: '查找引用',
  1096. disabled: function () {
  1097. return !(me.currentCache && me.currentCache[target.row]);
  1098. },
  1099. icon: 'fa-search',
  1100. callback: function () {
  1101. const glj = me.currentCache[target.row];
  1102. me.getReference(glj);
  1103. }
  1104. },
  1105. getUsedInfo: {
  1106. name: '查找用户使用情况',
  1107. disabled: function () {
  1108. return !(me.currentCache && me.currentCache[target.row]);
  1109. },
  1110. icon: 'fa-search',
  1111. callback: function () {
  1112. const glj = me.currentCache[target.row];
  1113. me.getUsedInfo(glj);
  1114. }
  1115. }
  1116. }
  1117. };
  1118. }
  1119. else {
  1120. return false;
  1121. }
  1122. }
  1123. });
  1124. },
  1125. getReference: function (glj) {
  1126. const $info = $('#info');
  1127. const $infoBody = $('#infoBody');
  1128. $.bootstrapLoading.start();
  1129. CommonAjax.post('/stdGljRepository/api/getReference', { repositoryId: glj.repositoryId, gljId: glj.ID }, function (info) {
  1130. const htmlArr = [];
  1131. if (!info || !Object.keys(info).length) {
  1132. htmlArr.push('<li>无引用数据</li>');
  1133. }
  1134. for (let libName in info) {
  1135. htmlArr.push(`<li class="list-title">${libName}</li>`);
  1136. const rations = info[libName];
  1137. const rationList = rations.map(ration => {
  1138. if (ration.rationRepId) {
  1139. return `<li>
  1140. <span>${ration.code}</span>
  1141. <a target="_blank" href="/rationRepository/ration?repository=${ration.rationRepId}&locked=${locked}#${ration.code}">定位</a>
  1142. </li>`;
  1143. }
  1144. return `<li><span>${ration.code}</span></li>`;
  1145. });
  1146. htmlArr.push(...rationList);
  1147. }
  1148. $infoBody.html(htmlArr.join(''));
  1149. $info.modal('show');
  1150. $.bootstrapLoading.end();
  1151. }, function () {
  1152. $.bootstrapLoading.end();
  1153. });
  1154. },
  1155. getUsedInfo: function (glj) {
  1156. $.bootstrapLoading.start();
  1157. $("#usedInfo").modal('show');
  1158. CommonAjax.post('/stdGljRepository/api/getUsedInfo', { repositoryId: glj.repositoryId, gljId: glj.ID }, function (info) {
  1159. $("#usedTotal").html(`共${info.length}项记录`);
  1160. let htmlString = "";
  1161. for (let u of info) {
  1162. htmlString += `<tr><td>${u.ID}</td><td>${u.username}</td> <td>${u.mobile}</td></tr>`;
  1163. }
  1164. $("#userInfoShowArea").html(htmlString);
  1165. $.bootstrapLoading.end();
  1166. }, function () {
  1167. $.bootstrapLoading.end();
  1168. });
  1169. },
  1170. validUpdateObj: function (pasteObj, rowIdx) {
  1171. let rst = { updateGlj: [], updateBasePrcArr: [] }, backUpObj = {},
  1172. me = repositoryGljObj,
  1173. that = gljComponentOprObj,
  1174. tempObj = me.currentCache[rowIdx],
  1175. reCalBasePrc = false,
  1176. isValid = true;
  1177. //备份原始数据
  1178. for (let atr in tempObj) {
  1179. backUpObj[atr] = tempObj[atr];
  1180. }
  1181. if (typeof pasteObj.code !== 'undefined') {
  1182. if (pasteObj.code.trim().length !== 0) {
  1183. let isExist = false;
  1184. for (let i = 0; i < me.gljList.length; i++) {
  1185. if (me.gljList[i].code === pasteObj.code) {
  1186. isExist = true;
  1187. break;
  1188. }
  1189. }
  1190. if (!isExist) {
  1191. tempObj.code = pasteObj.code;
  1192. }
  1193. else isValid = false;
  1194. }
  1195. else isValid = false;
  1196. }
  1197. if (typeof pasteObj.name !== 'undefined') {
  1198. if (pasteObj.name.trim().length === 0) isValid = false;
  1199. else tempObj.name = pasteObj.name;
  1200. }
  1201. if (typeof pasteObj.specs !== 'undefined') {
  1202. tempObj.specs = pasteObj.specs;
  1203. }
  1204. if (typeof pasteObj.unit !== 'undefined') {
  1205. tempObj.unit = pasteObj.unit;
  1206. }
  1207. if (typeof pasteObj.lossRate !== 'undefined' && !isNaN(pasteObj.lossRate)) {
  1208. tempObj.lossRate = pasteObj.lossRate;
  1209. }
  1210. if (typeof pasteObj.gljType !== 'undefined') {
  1211. let isExsit = false;
  1212. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1213. if (pasteObj.gljType === me.distTypeTree.comboDatas[i].text) {
  1214. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1215. isExsit = true;
  1216. if (me.getParentType(pasteObj.gljType) !== 2 && me.getParentType(tempObj.gljType) === 2) {
  1217. for (let feeCode of me.feeDataCode) {
  1218. tempObj[feeCode] = null;
  1219. }
  1220. }
  1221. if (componentType.includes(tempObj.gljType) &&
  1222. !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
  1223. !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))) {//修改了原本是组成物的工料机
  1224. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1225. let updateGljs = me.getUpdateGljs(tempObj, true);
  1226. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1227. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1228. rst.updateGlj.push(updateGljs.updateArr[i]);
  1229. }
  1230. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1231. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1232. }
  1233. }
  1234. }
  1235. tempObj.component = tempObj.gljType === pasteObj.gljType ? tempObj.component : [];
  1236. tempObj.gljType = pasteObj.gljType;
  1237. tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
  1238. break;
  1239. }
  1240. }
  1241. if (!isExsit) {
  1242. isValid = false;
  1243. }
  1244. }
  1245. for (let feeCode of me.feeDataCode) {
  1246. if (typeof pasteObj[feeCode] !== 'undefined' && !isNaN(pasteObj[feeCode])) {
  1247. if ((typeof pasteObj.gljType !== 'undefined' && me.getParentType(pasteObj.gljType) === 2) ||
  1248. (tempObj.gljType && me.getParentType(tempObj.gljType) === 2)) {
  1249. tempObj[feeCode] = pasteObj[feeCode];
  1250. } else {
  1251. isValid = false;
  1252. }
  1253. }
  1254. }
  1255. //单价相关
  1256. if (me.pasteIncludesPrice(pasteObj)) {
  1257. if (!priceProperties || priceProperties.length === 0) {
  1258. pasteObj.basePrice = pasteObj.basePrice && !isNaN(parseFloat(pasteObj.basePrice)) ?
  1259. scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2) : me.currentCache[rowIdx].basePrice;
  1260. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1261. reCalBasePrc = true;
  1262. tempObj.basePrice = pasteObj.basePrice;
  1263. }
  1264. }
  1265. else {
  1266. //多单价粘贴
  1267. let pastePriceProperty = {};
  1268. let priceFields = me.getPriceFields();
  1269. for (let priceField of priceFields) {
  1270. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1271. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1272. }
  1273. }
  1274. if (!me.priceIsEqual(tempObj, pasteObj)) {
  1275. reCalBasePrc = true;
  1276. //更新人材机单价
  1277. for (let priceField in pastePriceProperty) {
  1278. tempObj.priceProperty[priceField] = pastePriceProperty[priceField];
  1279. }
  1280. }
  1281. }
  1282. let updateGljs = me.getUpdateGljs(tempObj, false);
  1283. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1284. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1285. rst.updateGlj.push(updateGljs.updateArr[i]);
  1286. }
  1287. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1288. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1289. }
  1290. }
  1291. }
  1292. if (isValid) {
  1293. rst.updateGlj.push(tempObj);
  1294. if (reCalBasePrc) {
  1295. //重新计算定额基价对象
  1296. let newReObj = { gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: me.getRationGljPrice(tempObj) };
  1297. rst.updateBasePrcArr.push(newReObj);
  1298. }
  1299. }
  1300. else {
  1301. for (let attr in backUpObj) {
  1302. tempObj[attr] = backUpObj[attr];
  1303. }
  1304. }
  1305. return rst;
  1306. },
  1307. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  1308. isValidObj: function (pasteObj) {
  1309. let me = repositoryGljObj;
  1310. if (!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
  1311. !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')) {
  1312. return false;
  1313. }
  1314. if (pasteObj.gljType && typeof pasteObj.gljType !== 'undefined') {
  1315. let isExist = false;
  1316. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1317. if (me.distTypeTree.comboDatas[i].text === pasteObj.gljType) {
  1318. isExist = true;
  1319. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1320. pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
  1321. break;
  1322. }
  1323. }
  1324. if (!isExist) {
  1325. return false;
  1326. }
  1327. }
  1328. if (pasteObj.code && typeof pasteObj.code !== 'undefined') {
  1329. for (let i = 0; i < me.gljList.length; i++) {
  1330. if (me.gljList[i].code === pasteObj.code) {
  1331. return false;
  1332. }
  1333. }
  1334. }
  1335. if (typeof pasteObj.lossRate !== 'undefined' && isNaN(pasteObj[feeCode])) {
  1336. return false;
  1337. }
  1338. for (let feeCode of me.feeDataCode) {
  1339. if (typeof pasteObj[feeCode] !== 'undefined' && (isNaN(pasteObj[feeCode]) || me.getParentType(pasteObj.gljType) !== 2)) {
  1340. return false;
  1341. }
  1342. }
  1343. if (!priceProperties || priceProperties.length === 0) {
  1344. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1345. }
  1346. else {
  1347. let pastePriceProperty = {};
  1348. let priceFields = me.getPriceFields();
  1349. for (let priceField of priceFields) {
  1350. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1351. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1352. }
  1353. else {
  1354. pastePriceProperty[priceField] = 0;
  1355. }
  1356. }
  1357. pasteObj.priceProperty = pastePriceProperty;
  1358. }
  1359. //pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1360. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1361. pasteObj.gljClass = me.gljCurTypeId;
  1362. }
  1363. return true;
  1364. },
  1365. canPasted: function (info) {
  1366. let rst = true;
  1367. let me = repositoryGljObj;
  1368. if (me.gljCurTypeId < 0) {
  1369. return false;
  1370. }
  1371. //粘贴的最大列下标不超过总列数
  1372. if (info.cellRange.col + info.cellRange.colCount - 1 > me.setting.header.length - 1) {
  1373. return false;
  1374. }
  1375. if (info.cellRange.row < me.currentCache.length) {
  1376. if (info.cellRange.col === 0) {
  1377. return false;
  1378. }
  1379. }
  1380. return rst;
  1381. },
  1382. onClipboardPasting: function (sender, args) {
  1383. let me = repositoryGljObj;
  1384. //复制的列数超过正确的列数,不可复制
  1385. if (me.prevent) {
  1386. args.cancel = true;
  1387. return;
  1388. }
  1389. if (!me.canPasted(args)) {
  1390. args.cancel = true;
  1391. }
  1392. },
  1393. onClipboardPasted: function (e, info) {
  1394. $.bootstrapLoading.start();
  1395. let me = repositoryGljObj;
  1396. let updateArr = [], addArr = [];
  1397. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1398. let beginRow = info.cellRange.row,
  1399. endRow = info.cellRange.row + info.cellRange.rowCount - 1,
  1400. maxRow = me.currentCache.length - 1,
  1401. updateBasePrcArr = [],
  1402. updateCount, resumeArr = [];
  1403. if (endRow <= maxRow) {
  1404. for (let i = 0; i < items.length; i++) {
  1405. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1406. if (updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0) {
  1407. updateArr = updateArr.concat(updateObj.updateGlj);
  1408. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1409. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1410. }
  1411. }
  1412. }
  1413. }
  1414. else if (beginRow <= maxRow && endRow > maxRow) {
  1415. updateCount = maxRow - beginRow + 1;
  1416. for (let i = 0; i < updateCount; i++) {
  1417. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1418. if (updateObj && typeof updateObj.updateGlj !== 'undefined') {
  1419. updateArr = updateArr.concat(updateObj.updateGlj);
  1420. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1421. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1422. }
  1423. }
  1424. }
  1425. //[code, ..., gljType]
  1426. if (info.cellRange.colCount >= 5 && info.cellRange.colCount <= me.setting.header.length) {
  1427. for (let i = updateCount; i < items.length; i++) {
  1428. if (me.isValidObj(items[i])) {
  1429. items[i].component = [];
  1430. addArr.push(items[i]);
  1431. }
  1432. }
  1433. }
  1434. }
  1435. else {
  1436. //粘贴的的最大列至少要等于工料机类型列,因为工料机类型必须有效才可新增
  1437. if (info.cellRange.colCount >= 5 && info.cellRange.colCount <= me.setting.header.length && info.cellRange.col + info.cellRange.colCount - 1 >= me.colMapping.fieldToCol['gljType']) {
  1438. for (let i = 0; i < items.length; i++) {
  1439. if (me.isValidObj(items[i])) {
  1440. items[i].component = [];
  1441. addArr.push(items[i]);
  1442. }
  1443. }
  1444. }
  1445. }
  1446. //repaint
  1447. for (let i = 0; i < info.cellRange.rowCount; i++) {
  1448. resumeArr.push(info.cellRange.row + i);
  1449. }
  1450. if (resumeArr.length > 0) {
  1451. info.sheet.suspendPaint();
  1452. for (let i = 0; i < resumeArr.length; i++) {
  1453. if (resumeArr[i] < me.currentCache.length) {
  1454. for (let col = 0; col < me.setting.header.length; col++) {
  1455. let dCode = me.setting.header[col].dataCode;
  1456. if (me.priceCols.includes(col)) {
  1457. let price = me.getPrice(me.currentCache[resumeArr[i]], col);
  1458. info.sheet.setValue(resumeArr[i], col, price ? price : 0);
  1459. }
  1460. else if (dCode === 'gljType') {
  1461. let gljType = me.currentCache[resumeArr[i]][dCode];
  1462. info.sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
  1463. }
  1464. else {
  1465. info.sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][dCode]);
  1466. }
  1467. }
  1468. }
  1469. else {
  1470. for (let col = 0; col < me.setting.header.length; col++) {
  1471. info.sheet.setValue(resumeArr[i], col, '');
  1472. }
  1473. }
  1474. }
  1475. info.sheet.resumePaint();
  1476. }
  1477. if (updateArr.length > 0 || addArr.length > 0) {
  1478. me.mixUpdateRequest(updateArr, addArr, []);
  1479. } else {
  1480. $.bootstrapLoading.end();
  1481. }
  1482. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1483. me.updateRationBasePrcRq(updateBasePrcArr);
  1484. }
  1485. },
  1486. updateRationBasePrcRq: function (basePrcArr, workBook, callback) {
  1487. let me = this;
  1488. me.prevent = true;
  1489. if (!$.bootstrapLoading.isLoading()) {
  1490. $.bootstrapLoading.start();
  1491. }
  1492. $.ajax({
  1493. type: 'post',
  1494. url: 'api/updateRationBasePrc',
  1495. data: { basePrcArr: JSON.stringify(basePrcArr) },
  1496. dataType: 'json',
  1497. success: function (result) {
  1498. if (result.error) {
  1499. alert("计算定额基价失败");
  1500. }
  1501. if (workBook) {
  1502. workBook.focus(true);
  1503. }
  1504. else {
  1505. me.workBook.focus(true);
  1506. }
  1507. me.prevent = false;
  1508. if (callback) {
  1509. callback();
  1510. }
  1511. if ($.bootstrapLoading.isLoading()) {
  1512. $.bootstrapLoading.end();
  1513. }
  1514. }
  1515. });
  1516. },
  1517. mixUpdateRequest: function (updateArr, addArr, removeIds) {
  1518. let me = repositoryGljObj;
  1519. if (updateArr.length > 0) {
  1520. me.saveInString(updateArr)
  1521. }
  1522. if (addArr.length > 0) {
  1523. const codeMap = {};
  1524. const uniqueCodeAddArr = [];
  1525. addArr.forEach(item => {
  1526. if (!codeMap[item.code]) {
  1527. codeMap[item.code] = 1;
  1528. uniqueCodeAddArr.push(item);
  1529. }
  1530. });
  1531. addArr = uniqueCodeAddArr;
  1532. me.saveInString(addArr);
  1533. }
  1534. $.ajax({
  1535. type: "POST",
  1536. url: "api/mixUpdateGljItems",
  1537. data: { "repositoryId": me.currentRepositoryId, "lastOpr": userAccount, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds) },
  1538. dataType: "json",
  1539. cache: false,
  1540. timeout: 50000,
  1541. success: function (result) {
  1542. if (result.error) {
  1543. alert(result.message);
  1544. } else {
  1545. const failCodes = result.data.failCode;
  1546. if (failCodes && failCodes.length) {
  1547. let failText = '';
  1548. failCodes.forEach(code => {
  1549. failText += `<p>编码“${code}”已存在</p>`;
  1550. });
  1551. $('#alertText').html(failText);
  1552. $('#codeAlert').modal('show');
  1553. }
  1554. const insertData = result.data.insertData;
  1555. me.updateCache(insertData, updateArr, removeIds);
  1556. //me.sortGlj();
  1557. if (me.currentOprParent === 1) {
  1558. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  1559. }
  1560. else {
  1561. me.currentCache = me.getCache();
  1562. }
  1563. me.showGljItems(me.currentCache, me.gljCurTypeId);
  1564. //getCurrentGlj
  1565. let row = me.workBook.getSheet(0).getSelections()[0].row;
  1566. me.currentGlj = row < me.currentCache.length ? me.currentCache[row] : null;
  1567. me.currentComponent = me.currentGlj ? me.getCurrentComponent(me.currentGlj.component) : [];
  1568. sheetCommonObj.cleanData(gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, -1);
  1569. sheetsOprObj.showData(gljComponentOprObj, gljComponentOprObj.workBook.getSheet(0), gljComponentOprObj.setting, me.currentComponent);
  1570. }
  1571. if ($.bootstrapLoading.isLoading()) {
  1572. $.bootstrapLoading.end();
  1573. }
  1574. },
  1575. error: function (err) {
  1576. if ($.bootstrapLoading.isLoading()) {
  1577. $.bootstrapLoading.end();
  1578. }
  1579. console.log(err);
  1580. alert("保存失败");
  1581. }
  1582. });
  1583. },
  1584. saveInString: function (datas) {
  1585. for (let i = 0, len = datas.length; i < len; i++) {
  1586. let data = datas[i];
  1587. if (_exist(data, 'basePrice')) {
  1588. data['basePrice'] = data['basePrice'].toString();
  1589. }
  1590. if (_exist(data, 'component')) {
  1591. for (let j = 0, jLen = data['component'].length; j < jLen; j++) {
  1592. let comGljObj = data['component'][j];
  1593. if (_exist(comGljObj, 'consumeAmt')) {
  1594. comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
  1595. }
  1596. }
  1597. }
  1598. }
  1599. function _exist(data, attr) {
  1600. return data && data[attr] !== undefined && data[attr];
  1601. }
  1602. },
  1603. getParentCache: function (nodes) {
  1604. let me = repositoryGljObj, rst = [];
  1605. for (let i = 0; i < me.gljList.length; i++) {
  1606. if (nodes.indexOf(me.gljList[i].gljClass) !== -1) {
  1607. rst.push(me.gljList[i]);
  1608. }
  1609. }
  1610. rst.sort(function (a, b) {
  1611. let rst = 0;
  1612. if (a.code > b.code) rst = 1;
  1613. else if (a.code < b.code) rst = -1;
  1614. return rst;
  1615. });
  1616. return rst;
  1617. },
  1618. getCache: function () {
  1619. let me = this, rst = [];
  1620. for (let i = 0; i < me.gljList.length; i++) {
  1621. if (me.gljList[i].gljClass == me.gljCurTypeId) {
  1622. rst.push(me.gljList[i]);
  1623. }
  1624. }
  1625. return rst;
  1626. },
  1627. updateCache: function (insertData, updateArr, removeIds) {
  1628. let me = this, cacheSection = me.gljList;
  1629. if (insertData && insertData.length > 0) {
  1630. me.gljList = me.gljList.concat(insertData);
  1631. cacheSection = me.gljList;
  1632. }
  1633. for (let i = removeIds.length - 1; i >= 0; i--) {
  1634. for (let j = cacheSection.length - 1; j >= 0; j--) {
  1635. if (cacheSection[j]["ID"] == removeIds[i]) {
  1636. cacheSection.splice(j, 1);
  1637. }
  1638. }
  1639. }
  1640. for (let i = 0; i < updateArr.length; i++) {
  1641. for (let j = 0; j < cacheSection.length; j++) {
  1642. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  1643. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  1644. cacheSection[j] = updateArr[i];
  1645. }
  1646. } else {
  1647. if (cacheSection[j]['code'] == updateArr[i]['code']) {
  1648. cacheSection[j] = updateArr[i];
  1649. }
  1650. }
  1651. }
  1652. }
  1653. },
  1654. updateParentNodeIds: function (nodes, caller) {
  1655. let private_build_parentNodeIds = function (pNodeId, nodesArr) {
  1656. let rst = [];
  1657. for (let i = 0; i < nodesArr.length; i++) {
  1658. if (nodesArr[i].children.length > 0) {
  1659. rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
  1660. } else {
  1661. rst.push(nodesArr[i].data.ID);
  1662. }
  1663. }
  1664. if (pNodeId && rst.length > 0) {
  1665. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  1666. }
  1667. return rst;
  1668. };
  1669. if (caller.parentNodeIds) {
  1670. private_build_parentNodeIds(null, nodes);
  1671. }
  1672. },
  1673. sortGljDeep: function (datas) {
  1674. function recurCompare(a, b, index) {
  1675. if (a[index] && !b[index]) {
  1676. return 1;
  1677. } else if (!a[index] && b[index]) {
  1678. return -1;
  1679. } else if (a[index] && b[index]) {
  1680. let aV = a[index],
  1681. bV = b[index];
  1682. if (!isNaN(aV) && !isNaN(bV)) {
  1683. aV = parseFloat(a[index]);
  1684. bV = parseFloat(b[index]);
  1685. }
  1686. if (aV > bV) {
  1687. return 1;
  1688. } else if (aV < bV) {
  1689. return -1;
  1690. } else {
  1691. return recurCompare(a, b, index + 1);
  1692. }
  1693. }
  1694. return 0;
  1695. }
  1696. //排序符号-
  1697. datas.sort(function (a, b) {
  1698. let aArr = a.code.split('-'),
  1699. bArr = b.code.split('-');
  1700. return recurCompare(aArr, bArr, 0);
  1701. });
  1702. },
  1703. //工料机排序
  1704. sortGlj: function () {
  1705. let me = this;
  1706. me.gljList.sort(function (a, b) {
  1707. let rst = 0;
  1708. if (a.code > b.code) rst = 1
  1709. else if (a.code < b.code) rst = -1;
  1710. return rst;
  1711. });
  1712. }
  1713. }
  1714. let gljTypeTreeOprObj = {
  1715. onClick: function (event, treeId, treeNode) {
  1716. let me = repositoryGljObj,
  1717. that = gljComponentOprObj,
  1718. gljTypeId = treeNode.ID;
  1719. me.gljCurTypeId = treeNode.ID;
  1720. me.addGljObj = null;
  1721. sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, 10);
  1722. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  1723. me.currentOprParent = 1;
  1724. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  1725. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  1726. } else {
  1727. me.currentOprParent = 0;
  1728. me.currentCache = me.getCache();
  1729. }
  1730. me.showGljItems(me.currentCache, gljTypeId);
  1731. },
  1732. beforeRename: function (treeId, treeNode, newName, isCancel) {
  1733. if (newName.length == 0) {
  1734. return false;
  1735. }
  1736. return true;
  1737. },
  1738. onRename: function (e, treeId, treeNode, isCancel) {
  1739. let nodes = [];
  1740. nodes.push(treeNode);
  1741. gljTypeTreeOprObj.updateNodes(nodes);
  1742. },
  1743. onBeforeRemove: function (treeId, treeNode) {
  1744. let me = this;
  1745. if (treeNode.ParentID == -1 && treeNode.isFirstNode) {
  1746. alert("不允许删除全部!");
  1747. return false;
  1748. }
  1749. if (!confirm("您确定要删除此节点及所有子节点的数据?删除后不可恢复!")) {
  1750. return false;
  1751. }
  1752. let nodeIds = [], preNode = treeNode.getPreNode(), preNodeId = -1;
  1753. if (preNode) {
  1754. preNodeId = preNode.ID;
  1755. }
  1756. private_fetchAllSubItems = function (pItem) {
  1757. nodeIds.push(pItem.ID);
  1758. if (pItem.items && pItem.items.length > 0) {
  1759. for (let i = 0; i < pItem.items.length; i++) {
  1760. private_fetchAllSubItems(pItem.items[i]);
  1761. }
  1762. }
  1763. };
  1764. nodeIds.push(treeNode.ID);
  1765. for (let i = 0; i < treeNode.items.length; i++) {
  1766. private_fetchAllSubItems(treeNode.items[i]);
  1767. }
  1768. $.ajax({
  1769. type: "POST",
  1770. url: "api/deleteGljNodes",
  1771. data: { "repId": pageOprObj.gljLibId, "lastOpr": userAccount, "nodes": JSON.stringify(nodeIds), "preNodeId": preNodeId, "preNodeNextId": treeNode.NextSiblingID },
  1772. dataType: "json",
  1773. cache: false,
  1774. timeout: 5000,
  1775. success: function (result, textStatus, status) {
  1776. let pNode = treeNode.getParentNode();
  1777. if (pNode && pNode.items && pNode.items.length == 1) {
  1778. pNode.isParent = false;
  1779. }
  1780. },
  1781. error: function () {
  1782. }
  1783. });
  1784. return true;
  1785. },
  1786. onRemove: function (e, treeId, treeNode) {
  1787. let me = repositoryGljObj, pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
  1788. if (pNode && pNode.items && pNode.items.length == 0) {
  1789. pNode.isParent = false;
  1790. me.treeObj.refresh();
  1791. }
  1792. },
  1793. updateNodes: function (nodes) {
  1794. if (nodes && nodes.length > 0) {
  1795. let reqData = []
  1796. for (let i = 0; i < nodes.length; i++) {
  1797. let node = {};
  1798. node.repositoryId = nodes[i].repositoryId;
  1799. node.ID = nodes[i].ID;
  1800. node.ParentID = nodes[i].ParentID;
  1801. node.NextSiblingID = nodes[i].NextSiblingID;
  1802. node.Name = nodes[i].Name;
  1803. reqData.push(node);
  1804. }
  1805. $.ajax({
  1806. type: "POST",
  1807. url: "api/updateGljNodes",
  1808. data: { "repId": pageOprObj.gljLibId, "lastOpr": userAccount, "nodes": JSON.stringify(reqData) },
  1809. dataType: "json",
  1810. cache: false,
  1811. timeout: 5000,
  1812. success: function (result, textStatus, status) {
  1813. console.log(status + ' : ' + result);
  1814. },
  1815. error: function () {
  1816. }
  1817. })
  1818. }
  1819. },
  1820. addRootNode: function () {
  1821. let me = repositoryGljObj, rawNode = { ParentID: -1, NextSiblingID: -1, Name: "所有" }, lastNodeId = -1;
  1822. if (me.treeObj) {
  1823. let rootNodes = me.treeObj.getNodes();
  1824. if (rootNodes.length == 0) {
  1825. gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function (err, rst) {
  1826. if (!(err)) {
  1827. let newNodes = [], isSilent = false;
  1828. newNodes.push({ repositoryId: rst.data.repositoryId, ID: rst.data.ID, ParentID: rst.data.ParentID, NextSiblingID: -1, Name: "所有", isParent: false, items: [] });
  1829. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  1830. }
  1831. });
  1832. }
  1833. }
  1834. },
  1835. addNewNode: function (rawNode, lastNodeId, callback) {
  1836. $.ajax({
  1837. type: "POST",
  1838. url: "api/createNewGljTypeNode",
  1839. data: { "lastOpr": userAccount, "repositoryId": repositoryGljObj.currentRepositoryId, "lastNodeId": lastNodeId, "rawNodeData": JSON.stringify(rawNode) },
  1840. dataType: "json",
  1841. cache: false,
  1842. timeout: 1000,
  1843. success: function (result, textStatus, status) {
  1844. callback(false, result);
  1845. },
  1846. error: function (err) {
  1847. callback(err);
  1848. }
  1849. })
  1850. },
  1851. addHoverDom: function (treeId, treeNode) {
  1852. if (typeof treeNode.doing !== 'undefined' && treeNode.doing) {
  1853. return false;
  1854. }
  1855. hoverOpr();
  1856. function hoverOpr() {
  1857. let me = repositoryGljObj, sObj = $("#" + treeNode.tId + "_span");
  1858. if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
  1859. let addStr = "<span class='button add' id='addBtn_" + treeNode.tId + "' title='新增子节点' onfocus='this.blur();'></span>";
  1860. sObj.after(addStr);
  1861. let btn = $("#addBtn_" + treeNode.tId);
  1862. if (btn) btn.bind("click", function () {
  1863. treeNode.doing = true;
  1864. let rawNode = { ParentID: treeNode.ID, NextSiblingID: -1, Name: "新增子节点" }, lastNodeId = -1;
  1865. if (treeNode.items.length > 0) {
  1866. lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
  1867. }
  1868. gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function (err, rst) {
  1869. if (!(err)) {
  1870. let newNodes = [], isSilent = false;
  1871. if (treeNode.items.length > 0) {
  1872. treeNode.items[treeNode.items.length - 1].NextSiblingID = rst.data.ID;
  1873. }
  1874. newNodes.push({ repositoryId: rst.data.repositoryId, ID: rst.data.ID, ParentID: rst.data.ParentID, NextSiblingID: -1, Name: "新增子节点", isParent: false, items: [] });
  1875. treeNode.isParent = true;
  1876. if (me.treeObj) {
  1877. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  1878. } else {
  1879. me.treeObj = $.fn.zTree.init($("#rationChapterTree"), gljSetting, newNodes);
  1880. }
  1881. treeNode.doing = false;
  1882. hoverOpr();
  1883. }
  1884. });
  1885. });
  1886. }
  1887. },
  1888. removeHoverDom: function (treeId, treeNode) {
  1889. $("#addBtn_" + treeNode.tId).unbind().remove();
  1890. }
  1891. };