glj.js 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. const locked = lockUtil.getLocked();
  5. const digital = {
  6. basePrice: -2,
  7. consumeAmt: -3,
  8. };
  9. let pageOprObj = {
  10. gljLibName: null,
  11. gljLibId: null,
  12. initPage: function (container, containerComponent, containerC) {
  13. let me = this,
  14. gljLibId = getQueryString("gljLibId"); //获取定额库参数
  15. me.gljLibId = gljLibId;
  16. //生成人材机表格列头
  17. repositoryGljObj.setting.header =
  18. repositoryGljObj.initHeaders(priceProperties);
  19. //生成列映射
  20. sheetCommonObj.initColMapping(
  21. repositoryGljObj,
  22. repositoryGljObj.setting.header
  23. );
  24. //生成单价列下标数组
  25. repositoryGljObj.initPriceCols(
  26. priceProperties,
  27. repositoryGljObj.colMapping
  28. );
  29. repositoryGljObj.getGljLib(gljLibId, function () {
  30. repositoryGljObj.buildSheet(container);
  31. gljComponentOprObj.buildSheet(containerComponent);
  32. componentOprObj.buildSheet(containerC);
  33. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  34. //repositoryGljObj.getRationGljIds(gljLibId);
  35. repositoryGljObj.getGljDistType(function () {
  36. repositoryGljObj.currentRepositoryId = parseInt(gljLibId);
  37. repositoryGljObj.getGljItems(gljLibId, function () {
  38. gljClassTreeObj.getGljClassTree(gljLibId, function () {
  39. const spreads = [
  40. gljClassTreeObj.workBook,
  41. repositoryGljObj.workBook,
  42. gljComponentOprObj.workBook,
  43. ];
  44. const $range = $(document.body);
  45. lockUtil.lockSpreadsAndTools(spreads, $range, locked);
  46. });
  47. });
  48. });
  49. });
  50. },
  51. };
  52. let repositoryGljObj = {
  53. colMapping: null,
  54. treeObj: null,
  55. workBook: null,
  56. gljCurTypeId: -1,
  57. gljCurClassSeq: 0,
  58. currentRepositoryId: -1,
  59. currentCache: null,
  60. parentNodeIds: {},
  61. gljList: [],
  62. feeDataCode: [
  63. "grossWeightCoe",
  64. "purchaseStorageRate",
  65. "offSiteTransportLossRate",
  66. "handlingLossRate",
  67. ],
  68. distTypeTree: null, //add
  69. setting: {
  70. owner: "glj",
  71. header: [
  72. {
  73. headerName: "编码",
  74. headerWidth: 80,
  75. dataCode: "code",
  76. dataType: "String",
  77. formatter: "@",
  78. hAlign: "left",
  79. vAlign: "center",
  80. },
  81. {
  82. headerName: "名称",
  83. headerWidth: 160,
  84. dataCode: "name",
  85. dataType: "String",
  86. formatter: "@",
  87. hAlign: "left",
  88. vAlign: "center",
  89. },
  90. {
  91. headerName: "规格型号",
  92. headerWidth: 120,
  93. dataCode: "specs",
  94. dataType: "String",
  95. formatter: "@",
  96. hAlign: "left",
  97. vAlign: "center",
  98. },
  99. {
  100. headerName: "单位",
  101. headerWidth: 60,
  102. dataCode: "unit",
  103. dataType: "String",
  104. hAlign: "center",
  105. vAlign: "center",
  106. },
  107. {
  108. headerName: "定额价",
  109. headerWidth: 80,
  110. dataCode: "basePrice",
  111. dataType: "Number",
  112. formatter: "0.00",
  113. hAlign: "right",
  114. vAlign: "center",
  115. },
  116. {
  117. headerName: "类型",
  118. headerWidth: 90,
  119. dataCode: "gljType",
  120. dataType: "String",
  121. hAlign: "center",
  122. vAlign: "center",
  123. },
  124. ],
  125. view: {
  126. comboBox: [{ row: -1, col: 3, rowCount: -1, colCount: 1 }],
  127. lockedCells: [],
  128. },
  129. },
  130. locateGlj: function (gljCode) {
  131. const glj = repositoryGljObj.gljList.find((glj) => glj.code === gljCode);
  132. if (!glj) {
  133. alert(`不存在人材机${gljCode}`);
  134. }
  135. const gljClassNode =
  136. gljClassTreeObj.cache.find((node) => node.data.ID === glj.gljClass) ||
  137. gljClassTreeObj.cache[0];
  138. if (!gljClassNode) {
  139. alert("无法定位到分类节点");
  140. }
  141. const gljClassRow = gljClassTreeObj.cache.indexOf(gljClassNode);
  142. const classSheet = gljClassTreeObj.workBook.getSheet(0);
  143. classSheet.showRow(gljClassRow, GC.Spread.Sheets.VerticalPosition.center);
  144. classSheet.setActiveCell(gljClassRow, 0);
  145. gljClassTreeObj.initSelection(gljClassNode);
  146. const theGlj = repositoryGljObj.currentCache.find(
  147. (item) => item.code === gljCode
  148. );
  149. if (!theGlj) {
  150. alert(`不存在人材机${gljCode}`);
  151. }
  152. const sheet = repositoryGljObj.workBook.getSheet(0);
  153. const gljRow = repositoryGljObj.currentCache.indexOf(theGlj);
  154. sheet.showRow(gljRow, GC.Spread.Sheets.VerticalPosition.center);
  155. sheet.setActiveCell(gljRow, 0);
  156. },
  157. //根据费用定额的单价属性获取人材机的单价属性
  158. getPriceProperty: function (priceProperties) {
  159. let priceProperty = {};
  160. for (let priceProp of priceProperties) {
  161. priceProperty[priceProp.price.dataCode] = 0;
  162. }
  163. return priceProperty;
  164. },
  165. //根据单价字段获取消耗量字段
  166. getConsumeAmtField: function (consumeAmtProperties, priceField) {
  167. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  168. return "consumeAmt";
  169. }
  170. for (let consumeAmtProp of consumeAmtProperties) {
  171. if (consumeAmtProp.consumeAmt.refPrice === priceField) {
  172. return consumeAmtProp.consumeAmt.dataCode;
  173. }
  174. }
  175. return "consumeAmt";
  176. },
  177. //初始单价相关的列(单价列、单价属性列)
  178. initPriceCols: function (priceProperties, colMapping) {
  179. let priceCols = [],
  180. pricePropertyCols = [];
  181. if (!priceProperties || priceProperties.length === 0) {
  182. priceCols.push(colMapping.fieldToCol["basePrice"]);
  183. }
  184. for (let priceProp of priceProperties) {
  185. pricePropertyCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  186. priceCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  187. }
  188. this.priceCols = priceCols;
  189. this.pricePropertyCols = pricePropertyCols;
  190. },
  191. getPriceFields: function () {
  192. let rst = [];
  193. for (let priceCol of this.priceCols) {
  194. rst.push(this.colMapping.colToField[priceCol]);
  195. }
  196. return rst;
  197. },
  198. //获取更新定额价的人材机价格(人材机只有一个单价取basePrice, 人材机有多个单价,取第一个单价)
  199. getRationGljPrice: function (glj) {
  200. if (glj.priceProperty) {
  201. let keys = Object.keys(glj.priceProperty);
  202. if (keys.length > 0) {
  203. return glj.priceProperty[keys[0]];
  204. }
  205. }
  206. return glj.basePrice;
  207. },
  208. //生成列头(多单价)
  209. initHeaders: function (priceProperties) {
  210. let headers = [
  211. {
  212. headerName: "编码",
  213. headerWidth: 80,
  214. dataCode: "code",
  215. dataType: "String",
  216. formatter: "@",
  217. hAlign: "left",
  218. vAlign: "center",
  219. },
  220. {
  221. headerName: "名称",
  222. headerWidth: 160,
  223. dataCode: "name",
  224. dataType: "String",
  225. formatter: "@",
  226. hAlign: "left",
  227. vAlign: "center",
  228. },
  229. {
  230. headerName: "规格型号",
  231. headerWidth: 120,
  232. dataCode: "specs",
  233. dataType: "String",
  234. formatter: "@",
  235. hAlign: "left",
  236. vAlign: "center",
  237. },
  238. {
  239. headerName: "单位",
  240. headerWidth: 60,
  241. dataCode: "unit",
  242. dataType: "String",
  243. hAlign: "center",
  244. vAlign: "center",
  245. },
  246. {
  247. headerName: "类型",
  248. headerWidth: 90,
  249. dataCode: "gljType",
  250. dataType: "String",
  251. hAlign: "center",
  252. vAlign: "center",
  253. },
  254. ];
  255. //生成单价列
  256. if (!priceProperties || priceProperties.length === 0) {
  257. headers.push({
  258. headerName: "定额价",
  259. headerWidth: 80,
  260. dataCode: "basePrice",
  261. dataType: "Number",
  262. formatter: "0.00",
  263. hAlign: "right",
  264. vAlign: "center",
  265. });
  266. } else {
  267. for (let priceProp of priceProperties) {
  268. let colData = {
  269. headerName: priceProp.price.dataName,
  270. headerWidth: 100,
  271. dataCode: priceProp.price.dataCode,
  272. dataType: "Number",
  273. formatter: "0.00",
  274. hAlign: "right",
  275. vAlign: "center",
  276. };
  277. headers.push(colData);
  278. }
  279. }
  280. let tailHeaders = [
  281. {
  282. headerName: "税率",
  283. headerWidth: 90,
  284. dataCode: "taxRate",
  285. dataType: "Number",
  286. hAlign: "center",
  287. vAlign: "center",
  288. },
  289. {
  290. headerName: "损耗率",
  291. headerWidth: 90,
  292. dataCode: "lossRate",
  293. dataType: "Number",
  294. hAlign: "center",
  295. vAlign: "center",
  296. },
  297. {
  298. headerName: "毛重系数",
  299. headerWidth: 90,
  300. dataCode: "grossWeightCoe",
  301. dataType: "Number",
  302. hAlign: "center",
  303. vAlign: "center",
  304. },
  305. {
  306. headerName: "采购保管费率",
  307. headerWidth: 90,
  308. dataCode: "purchaseStorageRate",
  309. dataType: "Number",
  310. hAlign: "center",
  311. vAlign: "center",
  312. },
  313. {
  314. headerName: "场外运输损耗率",
  315. headerWidth: 100,
  316. dataCode: "offSiteTransportLossRate",
  317. dataType: "Number",
  318. hAlign: "center",
  319. vAlign: "center",
  320. },
  321. {
  322. headerName: "每增一次装卸损耗率",
  323. headerWidth: 100,
  324. dataCode: "handlingLossRate",
  325. dataType: "Number",
  326. hAlign: "center",
  327. vAlign: "center",
  328. },
  329. ];
  330. headers = headers.concat(tailHeaders);
  331. return headers;
  332. },
  333. //工料机单价赋初始值(没有单价属性,则单价字段为basePrice,否则单价字段为单价属性对象中的属性)
  334. initPrice: function (glj) {
  335. if (!priceProperties || priceProperties.length === 0) {
  336. glj.basePrice =
  337. glj.basePrice && !isNaN(parseFloat(glj.basePrice))
  338. ? scMathUtil.roundTo(parseFloat(glj.basePrice), -2)
  339. : 0;
  340. } else {
  341. if (!glj.priceProperty) {
  342. glj.priceProperty = {};
  343. }
  344. for (let priceProp of priceProperties) {
  345. let gljPrice = glj["priceProperty"][priceProp.price.dataCode];
  346. gljPrice =
  347. gljPrice && !isNaN(parseFloat(gljPrice))
  348. ? scMathUtil.roundTo(parseFloat(gljPrice), -2)
  349. : 0;
  350. }
  351. }
  352. },
  353. //人材机单价是否变化
  354. isGljPriceChange: function (glj, newPrice) {
  355. //多单价,与人材机单价属性比较
  356. if (typeof newPrice === "object") {
  357. return !_.isEqual(glj.priceProperty, newPrice);
  358. }
  359. return !_.isEqual(glj.basePrice, newPrice);
  360. },
  361. //粘贴数据含有单价
  362. pasteIncludesPrice: function (pasteObj) {
  363. let me = repositoryGljObj;
  364. for (let priceCol of me.priceCols) {
  365. let priceField = me.colMapping.colToField[priceCol];
  366. if (typeof pasteObj[priceField] !== "undefined") {
  367. return true;
  368. }
  369. }
  370. return false;
  371. },
  372. //获取人材机价格
  373. getPrice: function (glj, col) {
  374. let me = repositoryGljObj;
  375. if (!priceProperties || priceProperties.length === 0) {
  376. return glj.basePrice;
  377. }
  378. return glj.priceProperty[me.colMapping.colToField[col]];
  379. },
  380. //工料机价格是否相同
  381. priceIsEqual: function (gljA, gljB) {
  382. if (!priceProperties || priceProperties.length === 0) {
  383. return gljA.basePrice === gljB.basePrice;
  384. }
  385. return _.isEqual(gljA.priceProperty, gljB.priceProperty);
  386. },
  387. setGljPrice: function (glj, newPrice, col) {
  388. if (!priceProperties || priceProperties.length === 0) {
  389. glj.basePrice = newPrice;
  390. } else {
  391. glj.priceProperty[this.colMapping.colToField[col]] = newPrice;
  392. }
  393. },
  394. setUnitCombo: function (sheet, headers) {
  395. let me = this;
  396. sheet.suspendPaint();
  397. sheet.suspendEvent();
  398. let combo = sheetCommonObj.getDynamicCombo();
  399. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  400. let unitCol = me.colMapping.fieldToCol["unit"];
  401. if (unitCol) {
  402. sheet.getRange(-1, unitCol, -1, 1).cellType(combo);
  403. }
  404. sheet.resumePaint();
  405. sheet.resumeEvent();
  406. },
  407. getComboData: function (gljDistType) {
  408. let me = this;
  409. let distType;
  410. let distTypeTree = {
  411. prefix: "gljType",
  412. distTypes: {},
  413. comboDatas: [],
  414. distTypesArr: [],
  415. };
  416. gljDistType.forEach(function (typeData) {
  417. let typeObj = {
  418. data: typeData,
  419. children: [],
  420. parent: null,
  421. };
  422. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  423. distTypeTree.distTypesArr.push(typeObj);
  424. });
  425. gljDistType.forEach(function (typeData) {
  426. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  427. let parent =
  428. distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  429. if (parent) {
  430. distType.parent = parent;
  431. parent.children.push(distType);
  432. }
  433. });
  434. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  435. if (allowGljType.includes(distTypeObj.data.ID)) {
  436. distTypeTree.comboDatas.push({
  437. text: distTypeObj.data.fullName,
  438. value: distTypeObj.data.ID,
  439. });
  440. }
  441. });
  442. return distTypeTree;
  443. },
  444. getGljDistType: function (callback) {
  445. let me = this;
  446. $.ajax({
  447. type: "post",
  448. url: "api/getGljDistType",
  449. dataType: "json",
  450. success: function (result) {
  451. if (!result.error && callback) {
  452. me.distTypeTree = me.getComboData(result.data);
  453. console.log(me.distTypeTree);
  454. callback();
  455. }
  456. },
  457. });
  458. },
  459. //获取工料机类型大类
  460. getParentType: function (type) {
  461. return parseInt(type.toString()[0]);
  462. },
  463. getGljLib: function (libId, callback) {
  464. let me = repositoryGljObj;
  465. $.ajax({
  466. type: "post",
  467. url: "api/getGljLib",
  468. data: { libId: libId },
  469. dataType: "json",
  470. success: function (result) {
  471. if (!result.error) {
  472. if (result.data.length > 0) {
  473. me.rationLibs = result.data[0].rationLibs;
  474. $(".navbar-text").append(
  475. "<a href='/stdGljRepository/main'>人材机库</a><i class='fa fa-angle-right fa-fw'></i>" +
  476. result.data[0].dispName
  477. );
  478. pageOprObj.gljLibName = result.data[0].dispName;
  479. }
  480. callback();
  481. }
  482. },
  483. });
  484. },
  485. getGljTree: function (gljLibId, callback) {
  486. let me = this;
  487. $.ajax({
  488. type: "POST",
  489. url: "api/getGljTree",
  490. data: { gljLibId: gljLibId },
  491. dataType: "json",
  492. cache: false,
  493. timeout: 20000,
  494. success: function (result, textStatus, status) {
  495. if (status.status == 200) {
  496. zTreeHelper.createTree(result.data, gljSetting, "repositoryTree", me);
  497. zTreeHelper.createTree(
  498. result.data,
  499. componentSetting,
  500. "componentTree",
  501. componentOprObj
  502. );
  503. if (result.data && result.data.length > 0) {
  504. me.gljCurTypeId = result.data[0].ID;
  505. me.gljCurClassSeq = result.data[0].classSeq;
  506. } else {
  507. //重新创建库?
  508. gljTypeTreeOprObj.addRootNode();
  509. }
  510. callback();
  511. }
  512. },
  513. error: function (err) {
  514. alert(err.responseJSON.error);
  515. },
  516. });
  517. },
  518. getGljItems: function (repId, callback) {
  519. let me = this;
  520. $.ajax({
  521. type: "POST",
  522. url: "api/getGljItems",
  523. data: { repositoryId: repId },
  524. dataType: "json",
  525. cache: false,
  526. timeout: 20000,
  527. success: function (result) {
  528. if (!result.error) {
  529. me.gljList = result.data;
  530. me.workBook.getSheet(0).setRowCount(result.data.length);
  531. me.sortGlj();
  532. me.currentGlj = me.gljList.length > 0 ? me.gljList[0] : null; //初始
  533. if (callback) {
  534. callback();
  535. }
  536. }
  537. },
  538. error: function (err) {
  539. alert(err.responseJSON.error);
  540. },
  541. });
  542. },
  543. showGljItems: function (data, type) {
  544. let me = repositoryGljObj;
  545. if (me.workBook) {
  546. let cacheSection = data;
  547. me.sortGljDeep(cacheSection);
  548. sheetCommonObj.cleanData(me.workBook.getSheet(0), me.setting, -1);
  549. sheetsOprObj.showData(
  550. me,
  551. me.workBook.getSheet(0),
  552. me.setting,
  553. cacheSection,
  554. me.distTypeTree
  555. );
  556. let gljTypeCol = me.colMapping.fieldToCol["gljType"];
  557. sheetCommonObj.setDynamicCombo(
  558. me.workBook.getActiveSheet(),
  559. 0,
  560. gljTypeCol,
  561. me.workBook.getActiveSheet().getRowCount(),
  562. me.distTypeTree.comboDatas,
  563. 10,
  564. "text"
  565. );
  566. cacheSection = null;
  567. let selRow = me.workBook.getActiveSheet().getSelections()[0].row;
  568. me.initSel(selRow);
  569. }
  570. },
  571. bindEnterKey: function () {
  572. let me = this;
  573. let sheet = me.workBook.getActiveSheet();
  574. me.workBook.commandManager().register("myEnter", function () {
  575. let orgRow = sheet.getActiveRowIndex();
  576. let orgCol = sheet.getActiveColumnIndex();
  577. if (sheet.isEditing()) {
  578. sheet.endEdit();
  579. }
  580. let codeCol = me.colMapping.fieldToCol["code"];
  581. let code = sheet.getValue(orgRow, codeCol);
  582. let newRow, newCol;
  583. if (
  584. !me.currentCache[orgRow] &&
  585. code !== undefined &&
  586. code !== null &&
  587. orgCol !== me.setting.header.length - 1
  588. ) {
  589. newRow = orgRow;
  590. newCol = orgCol + 1;
  591. sheet.setActiveCell(newRow, newCol);
  592. } else {
  593. newRow = orgRow + 1;
  594. newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
  595. sheet.setActiveCell(newRow, newCol);
  596. }
  597. //触发事件
  598. me.onLeaveCell(
  599. { type: "LeaveCell" },
  600. {
  601. sheet: sheet,
  602. sheetName: sheet.name(),
  603. cancel: false,
  604. row: orgRow,
  605. col: orgCol,
  606. }
  607. );
  608. me.onEnterCell(
  609. { type: "EnterCell" },
  610. {
  611. sheet: sheet,
  612. sheetName: sheet.name(),
  613. cancel: false,
  614. row: newRow,
  615. col: newCol,
  616. }
  617. );
  618. let newSels = [{ row: newRow, rowCount: 1, col: newCol, colCount: 1 }];
  619. let oldSels = [{ row: orgRow, rowCount: 1, col: orgRow, colCount: 1 }];
  620. me.onSelectionChanged(
  621. { type: "SelectionChanged" },
  622. {
  623. sheet: sheet,
  624. sheetName: sheet.name(),
  625. newSelections: newSels,
  626. oldSelections: oldSels,
  627. }
  628. );
  629. });
  630. me.workBook
  631. .commandManager()
  632. .setShortcutKey(
  633. null,
  634. GC.Spread.Commands.Key.enter,
  635. false,
  636. false,
  637. false,
  638. false
  639. );
  640. me.workBook
  641. .commandManager()
  642. .setShortcutKey(
  643. "myEnter",
  644. GC.Spread.Commands.Key.enter,
  645. false,
  646. false,
  647. false,
  648. false
  649. );
  650. },
  651. buildSheet: function (container) {
  652. let me = repositoryGljObj;
  653. me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30, me);
  654. sheetCommonObj.bindEscKey(me.workBook, [
  655. {
  656. sheet: me.workBook.getSheet(0),
  657. editStarting: me.onCellEditStart,
  658. editEnded: me.onCellEditEnd,
  659. },
  660. ]);
  661. me.bindEnterKey();
  662. me.repositoryGljDelOpr();
  663. me.onContextmenuOpr();
  664. me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
  665. me.workBook.bind(
  666. GC.Spread.Sheets.Events.ClipboardPasting,
  667. me.onClipboardPasting
  668. );
  669. me.workBook.bind(
  670. GC.Spread.Sheets.Events.ClipboardPasted,
  671. me.onClipboardPasted
  672. );
  673. if (priceProperties && priceProperties.length > 0) {
  674. me.workBook.getSheet(0).frozenColumnCount(5);
  675. }
  676. me.workBook
  677. .getSheet(0)
  678. .bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  679. me.workBook
  680. .getSheet(0)
  681. .bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  682. me.workBook
  683. .getSheet(0)
  684. .bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  685. me.workBook
  686. .getSheet(0)
  687. .bind(GC.Spread.Sheets.Events.LeaveCell, me.onLeaveCell);
  688. me.workBook
  689. .getSheet(0)
  690. .bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  691. },
  692. isDef: function (v) {
  693. return v !== undefined && v !== null;
  694. },
  695. //成为了组成物
  696. isComponent: function (gljId, gljList) {
  697. //暂时只需要判断主材(可成为主材的组成物)、机械组成物(可成为机械台班的组成物,但是机械组成物可能引用了普通材料)
  698. let gljTypes = [302, 4];
  699. for (let i = 0, len = gljList.length; i < len; i++) {
  700. let gljComponent = gljList[i].component;
  701. if (
  702. gljTypes.includes(gljList[i].gljType) &&
  703. this.isDef(gljComponent) &&
  704. gljComponent.length > 0
  705. ) {
  706. for (let j = 0, jLen = gljComponent.length; j < jLen; j++) {
  707. if (gljComponent[j].ID === gljId) {
  708. return true;
  709. }
  710. }
  711. }
  712. }
  713. return false;
  714. },
  715. getCurrentComponent: function (gljComponent, sort = false) {
  716. let me = repositoryGljObj,
  717. rst = [],
  718. IDCodeMapping = {};
  719. for (let i = 0; i < gljComponent.length; i++) {
  720. let obj = {};
  721. for (let j = 0; j < me.gljList.length; j++) {
  722. let specs = me.gljList[j].specs ? " " + me.gljList[j].specs : "";
  723. if (gljComponent[i].ID == me.gljList[j].ID) {
  724. obj.ID = me.gljList[j].ID;
  725. obj.code = me.gljList[j].code;
  726. obj.name = me.gljList[j].name + specs;
  727. obj.unit = me.gljList[j].unit;
  728. obj.basePrice = me.gljList[j].basePrice;
  729. obj.priceProperty = me.gljList[j].priceProperty
  730. ? me.gljList[j].priceProperty
  731. : {};
  732. obj.consumeAmt = gljComponent[i].consumeAmt;
  733. obj.consumeAmtProperty = gljComponent[i].consumeAmtProperty
  734. ? gljComponent[i].consumeAmtProperty
  735. : {};
  736. rst.push(obj);
  737. IDCodeMapping[obj.ID] = obj.code;
  738. }
  739. }
  740. }
  741. if (sort) {
  742. rst.sort(function (a, b) {
  743. let r = 0;
  744. if (a.code > b.code) r = 1;
  745. else if (a.code < b.code) r = -1;
  746. return r;
  747. });
  748. gljComponent.sort(function (a, b) {
  749. let aV = IDCodeMapping[a.ID],
  750. bV = IDCodeMapping[b.ID];
  751. if (aV > bV) {
  752. return 1;
  753. } else if (aV < bV) {
  754. return -1;
  755. }
  756. return 0;
  757. });
  758. }
  759. return rst;
  760. },
  761. //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
  762. getUpdateGljs: function (rObj, isDelete) {
  763. let me = repositoryGljObj,
  764. that = gljComponentOprObj,
  765. rst = { updateArr: [], updateBasePrcArr: [] };
  766. //改变单价,以便reCalGljBasePrc方法可行
  767. if (!isDelete) {
  768. for (let i = 0; i < me.gljList.length; i++) {
  769. if (me.gljList[i].ID === rObj.ID) {
  770. me.gljList[i].basePrice = rObj.basePrice;
  771. me.gljList[i].priceProperty = rObj.priceProperty
  772. ? rObj.priceProperty
  773. : {};
  774. break;
  775. }
  776. }
  777. }
  778. for (let i = 0; i < me.gljList.length; i++) {
  779. let thisComponent = me.gljList[i].component,
  780. isChange = false;
  781. for (let j = 0; j < thisComponent.length; j++) {
  782. if (thisComponent[j].ID === rObj.ID) {
  783. //删除
  784. isChange = true;
  785. if (isDelete) {
  786. thisComponent.splice(j--, 1);
  787. } else {
  788. break;
  789. }
  790. }
  791. }
  792. if (isChange) {
  793. //引用了此组成物
  794. rst.updateArr.push(me.gljList[i]);
  795. }
  796. }
  797. return rst;
  798. },
  799. reshowGljBasePrc: function (glj) {
  800. let me = repositoryGljObj;
  801. let cacheSection = me.currentCache;
  802. let sheet = me.workBook.getActiveSheet();
  803. let row = _.findIndex(cacheSection, { ID: glj.ID });
  804. sheet.suspendEvent();
  805. sheet.suspendPaint();
  806. for (let priceCol of me.priceCols) {
  807. sheet.setValue(row, priceCol, glj[me.colMapping.colToField[priceCol]]);
  808. }
  809. sheet.resumeEvent();
  810. sheet.resumePaint();
  811. },
  812. reSetGljBasePrc: function (gljs) {
  813. let me = repositoryGljObj;
  814. let cacheSection = me.currentCache;
  815. let sheet = me.workBook.getSheet(0);
  816. let basePriceCol = me.colMapping.fieldToCol["basePrice"];
  817. sheet.suspendPaint();
  818. sheet.suspendEvent();
  819. for (let i = 0; i < cacheSection.length; i++) {
  820. for (let glj of gljs) {
  821. if (glj.ID === cacheSection[i].ID) {
  822. for (let priceCol of me.priceCols) {
  823. sheet.setValue(
  824. i,
  825. priceCol,
  826. glj[me.colMapping.colToField[priceCol]]
  827. );
  828. }
  829. //sheet.setValue(i, basePriceCol, glj.basePrice);
  830. }
  831. }
  832. }
  833. sheet.resumePaint();
  834. sheet.resumeEvent();
  835. },
  836. initSel: function (row) {
  837. let me = repositoryGljObj,
  838. that = gljComponentOprObj;
  839. sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, -1);
  840. //sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, -1);
  841. me.workBook.focus(true);
  842. me.currentComponent = [];
  843. that.workBook.getSheet(0).setRowCount(10);
  844. if (row < me.currentCache.length) {
  845. //标记当前工料机
  846. me.currentGlj = me.currentCache[row];
  847. console.log(me.currentGlj);
  848. if (allowComponent.includes(me.currentCache[row].gljType)) {
  849. //展示数据
  850. if (me.currentGlj.component.length > 0) {
  851. me.currentComponent = me.getCurrentComponent(
  852. me.currentGlj.component,
  853. true
  854. );
  855. if (me.currentComponent.length > 0) {
  856. sheetsOprObj.showData(
  857. that,
  858. that.workBook.getSheet(0),
  859. that.setting,
  860. me.currentComponent
  861. );
  862. }
  863. }
  864. }
  865. } else {
  866. me.currentGlj = null;
  867. }
  868. },
  869. onSelectionChanged: function (sender, info) {
  870. let me = repositoryGljObj,
  871. that = gljComponentOprObj;
  872. //混凝土202、砂浆203、配合比204、机械3
  873. if (
  874. (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
  875. info.oldSelections[0].row !== info.newSelections[0].row
  876. ) {
  877. let row = info.newSelections[0].row;
  878. me.initSel(row);
  879. }
  880. },
  881. onLeaveCell: function (sender, args) {
  882. let me = repositoryGljObj;
  883. me.lastCell = { row: args.row, col: args.col };
  884. },
  885. onEnterCell: function (sender, args) {
  886. let me = repositoryGljObj;
  887. let thisDataCode = me.setting.header[args.col].dataCode,
  888. lastDataCode = me.setting.header[me.lastCell.col].dataCode;
  889. if (
  890. thisDataCode === "unit" ||
  891. lastDataCode === "unit" ||
  892. thisDataCode === "gljType" ||
  893. lastDataCode === "gljType"
  894. ) {
  895. let rects = [];
  896. rects.push(args.sheet.getCellRect(args.row, args.col));
  897. if (me.lastCell) {
  898. rects.push(args.sheet.getCellRect(me.lastCell.row, me.lastCell.col));
  899. }
  900. for (let rect of rects) {
  901. args.sheet.repaint(rect);
  902. }
  903. //args.sheet.repaint();
  904. }
  905. me.cellRowIdx = args.row;
  906. let isHasData = false;
  907. if (me.addGljObj) {
  908. for (let i = 0; i < me.setting.header.length; i++) {
  909. if (me.addGljObj[me.setting.header[i].dataCode]) {
  910. isHasData = true;
  911. break;
  912. }
  913. }
  914. }
  915. if (isHasData) {
  916. if (me.editingRowIdx !== me.cellRowIdx) {
  917. let focusToCol;
  918. function getFocusToCol(me) {
  919. if (!me.addGljObj.code) {
  920. $("#alertGljTxt").text("编号不能为空,继续增加人材机?");
  921. return me.colMapping.fieldToCol["code"];
  922. } else if (!me.addGljObj.name) {
  923. $("#alertGljTxt").text("名称不能为空,继续增加人材机?");
  924. return me.colMapping.fieldToCol["name"];
  925. } else if (!me.addGljObj.gljType) {
  926. $("#alertGljTxt").text("类型不能为空,继续增加人材机?");
  927. return me.colMapping.fieldToCol["gljType"];
  928. } else {
  929. return -1;
  930. }
  931. }
  932. focusToCol = getFocusToCol(me);
  933. if (focusToCol !== -1) {
  934. $("#gljAlertBtn").click();
  935. $("#aleConfBtn").unbind("click");
  936. $("#aleConfBtn").bind("click", function () {
  937. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  938. me.workBook.focus(true);
  939. });
  940. $("#gljAleClose").click(function () {
  941. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  942. me.workBook.focus(true);
  943. });
  944. $("#aleCanceBtn").unbind("click");
  945. $("#aleCanceBtn").bind("click", function () {
  946. me.addGljObj = null;
  947. args.sheet.suspendEvent();
  948. args.sheet.suspendPaint();
  949. for (let col = 0; col < me.setting.header.length; col++) {
  950. if (col === 0) {
  951. me.workBook
  952. .getSheet(0)
  953. .getCell(me.editingRowIdx, 0)
  954. .formatter("@");
  955. }
  956. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value("");
  957. }
  958. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  959. me.workBook.focus(true);
  960. args.sheet.resumeEvent();
  961. args.sheet.resumePaint();
  962. });
  963. }
  964. }
  965. }
  966. },
  967. onCellEditStart: function (sender, args) {
  968. let me = repositoryGljObj;
  969. me.orgCode = me.workBook
  970. .getSheet(0)
  971. .getValue(args.row, me.colMapping.fieldToCol["code"]);
  972. let rObj = sheetsOprObj.combineRowData(
  973. me.workBook.getSheet(0),
  974. me.setting,
  975. args.row,
  976. me
  977. );
  978. if (me.prevent) {
  979. args.cancel = true;
  980. return;
  981. }
  982. me.currentEditingGlj = rObj;
  983. if (args.row < me.currentCache.length) {
  984. let dataCode = me.setting.header[args.col].dataCode;
  985. me.currentGlj = me.currentCache[args.row];
  986. if (
  987. dataCode === "code" ||
  988. (me.feeDataCode.includes(dataCode) &&
  989. me.getParentType(me.currentGlj.gljType) !== 2)
  990. ) {
  991. //费率数据列只有材料能用
  992. args.cancel = true;
  993. } else {
  994. rObj.ID = me.currentGlj.ID;
  995. rObj.gljClass = me.currentGlj.gljClass;
  996. }
  997. } else {
  998. me.currentGlj = null;
  999. }
  1000. },
  1001. dataChanged: function (objA, objB, col) {
  1002. let me = repositoryGljObj;
  1003. if (me.priceCols.includes(col)) {
  1004. if (!priceProperties || priceProperties.length === 0) {
  1005. return objA.basePrice !== objB.basePrice;
  1006. } else {
  1007. return (
  1008. objA.priceProperty[me.colMapping.colToField[col]] !==
  1009. objB.priceProperty[me.colMapping.colToField[col]]
  1010. );
  1011. }
  1012. }
  1013. return (
  1014. objA[me.colMapping.colToField[col]] !==
  1015. objB[[me.colMapping.colToField[col]]]
  1016. );
  1017. },
  1018. onCellEditEnd: function (sender, args) {
  1019. let me = repositoryGljObj,
  1020. that = gljComponentOprObj,
  1021. updateArr = [],
  1022. addArr = [],
  1023. updateBasePrcArr = [];
  1024. // 输入编号、名称、规格时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  1025. let deESCFields = ["code", "name", "specs"];
  1026. let dataCode = me.setting.header[args.col].dataCode;
  1027. if (deESCFields.includes(dataCode)) {
  1028. args.editingText = me.isDef(args.editingText)
  1029. ? args.editingText.toString().replace(/[\r\n]/g, " ")
  1030. : "";
  1031. args.sheet.setValue(args.row, args.col, args.editingText);
  1032. }
  1033. let rObj = sheetsOprObj.combineRowData(
  1034. me.workBook.getSheet(0),
  1035. me.setting,
  1036. args.row,
  1037. me
  1038. );
  1039. me.editingRowIdx = args.row;
  1040. //rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  1041. me.initPrice(rObj);
  1042. //更新
  1043. if (
  1044. me.currentEditingGlj["ID"] !== null &&
  1045. me.currentEditingGlj["ID"] !== undefined &&
  1046. me.currentGlj
  1047. ) {
  1048. rObj["ID"] = me.currentEditingGlj["ID"];
  1049. rObj.gljClass = me.currentEditingGlj.gljClass;
  1050. if (me.dataChanged(me.currentEditingGlj, rObj, args.col)) {
  1051. if (
  1052. rObj.code &&
  1053. rObj.name &&
  1054. rObj.gljType &&
  1055. rObj.code.toString().trim().length !== 0 &&
  1056. rObj.name.toString().trim().length !== 0 &&
  1057. rObj.gljType.toString().trim().length !== 0
  1058. ) {
  1059. if (rObj.gljType !== me.currentEditingGlj.gljType) {
  1060. //修改了工料机类型
  1061. if (!$("#typeAlert").is(":visible")) {
  1062. $("#typeAlert").modal("show");
  1063. }
  1064. $("#typeConfirm").unbind("click");
  1065. $("#typeConfirm").bind("click", function () {
  1066. $("#typeAlert").modal("hide");
  1067. if (me.currentGlj) {
  1068. me.currentGlj.component = [];
  1069. }
  1070. //工料机类型不为材料时,情况费率数据
  1071. if (
  1072. me.getParentType(me.currentEditingGlj.gljType) === 2 &&
  1073. me.getParentType(rObj.gljType) !== 2
  1074. ) {
  1075. for (let feeCode of me.feeDataCode) {
  1076. if (me.currentEditingGlj[feeCode]) {
  1077. rObj[feeCode] = null;
  1078. }
  1079. }
  1080. }
  1081. if (
  1082. componentType.includes(me.currentEditingGlj.gljType) &&
  1083. !(
  1084. machineComponent.includes(me.currentEditingGlj.gljType) &&
  1085. machineComponent.includes(rObj.gljType)
  1086. ) &&
  1087. !(
  1088. materialComponent.includes(me.currentEditingGlj.gljType) &&
  1089. materialComponent.includes(rObj.gljType)
  1090. )
  1091. ) {
  1092. //修改了原本是组成物的工料机
  1093. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1094. let updateGljs = me.getUpdateGljs(rObj, true);
  1095. if (
  1096. updateGljs.updateArr.length > 0 ||
  1097. updateGljs.updateBasePrcArr.length > 0
  1098. ) {
  1099. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1100. updateArr.push(updateGljs.updateArr[i]);
  1101. }
  1102. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1103. updateArr.push(updateGljs.updateBasePrcArr[i]);
  1104. }
  1105. }
  1106. }
  1107. sheetCommonObj.cleanData(
  1108. that.workBook.getSheet(0),
  1109. that.setting,
  1110. 5
  1111. );
  1112. rObj.component = me.currentGlj.component;
  1113. updateArr.push(rObj);
  1114. me.mixUpdateRequest(updateArr, [], []);
  1115. });
  1116. $(".typeClose").unbind("click");
  1117. $(".typeClose").bind("click", function () {
  1118. args.sheet.setValue(
  1119. args.row,
  1120. args.col,
  1121. _.find(me.distTypeTree.comboDatas, {
  1122. value: me.currentGlj.gljType,
  1123. }).text
  1124. );
  1125. });
  1126. return;
  1127. } else if (
  1128. (me.feeDataCode.includes(dataCode) || dataCode === "lossRate") &&
  1129. rObj[dataCode] !== me.currentEditingGlj[dataCode]
  1130. ) {
  1131. if (isNaN(rObj[dataCode])) {
  1132. args.sheet.setValue(
  1133. args.row,
  1134. args.col,
  1135. me.currentEditingGlj[dataCode]
  1136. ? me.currentEditingGlj[dataCode]
  1137. : ""
  1138. );
  1139. alert(`${me.setting.header[args.col].headerName}只能输入数值!`);
  1140. return;
  1141. }
  1142. } else if (rObj.taxRate !== me.currentEditingGlj.taxRate) {
  1143. if (isNaN(rObj.taxRate)) {
  1144. args.sheet.setValue(
  1145. args.row,
  1146. args.col,
  1147. me.currentEditingGlj.taxRate || ""
  1148. );
  1149. alert("税率只能输入数值!");
  1150. return;
  1151. }
  1152. rObj.taxRate = scMathUtil.roundTo(parseFloat(rObj.taxRate), -2);
  1153. } else if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  1154. //修改了单价,可修改单价的必为可成为组成物的
  1155. let rObjPrice = me.getPrice(rObj, args.col),
  1156. editingGljPrice = me.getPrice(me.currentEditingGlj, args.col);
  1157. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1158. if (isNaN(parseFloat(rObjPrice))) {
  1159. alert("单价只能输入数值!");
  1160. args.sheet.setValue(
  1161. args.row,
  1162. args.col,
  1163. editingGljPrice ? editingGljPrice : 0
  1164. );
  1165. return;
  1166. }
  1167. me.setGljPrice(
  1168. rObj,
  1169. scMathUtil.roundTo(parseFloat(rObjPrice), -2),
  1170. args.col
  1171. );
  1172. let updateGljs = me.getUpdateGljs(rObj);
  1173. if (
  1174. updateGljs.updateArr.length > 0 ||
  1175. updateGljs.updateBasePrcArr.length > 0
  1176. ) {
  1177. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1178. updateArr.push(updateGljs.updateArr[i]);
  1179. }
  1180. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1181. updateArr.push(updateGljs.updateBasePrcArr[i]);
  1182. }
  1183. }
  1184. }
  1185. rObj.component = me.currentGlj.component;
  1186. updateArr.push(rObj);
  1187. } else {
  1188. if (dataCode === "gljType") {
  1189. let distTypeVal =
  1190. me.distTypeTree.distTypes[
  1191. me.distTypeTree.prefix + me.currentEditingGlj[dataCode]
  1192. ].data.fullName;
  1193. args.sheet.setValue(args.row, args.col, distTypeVal);
  1194. } else {
  1195. args.sheet.setValue(
  1196. args.row,
  1197. args.col,
  1198. me.currentEditingGlj[dataCode]
  1199. );
  1200. }
  1201. }
  1202. }
  1203. if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  1204. //update basePrice of ration when editting basePrice of glj
  1205. let gljType = -1;
  1206. let gljTypeParent =
  1207. me.distTypeTree.distTypes[
  1208. me.distTypeTree.prefix + me.currentEditingGlj.gljType
  1209. ].parent;
  1210. if (gljTypeParent && gljTypeParent.data.ID <= 3) {
  1211. gljType = gljTypeParent.data.ID;
  1212. }
  1213. if (!gljTypeParent && me.currentEditingGlj.gljType <= 3) {
  1214. gljType = me.currentEditingGlj.gljType;
  1215. }
  1216. let gljBasePrcObj = {
  1217. gljId: me.currentEditingGlj.ID,
  1218. gljType: gljType,
  1219. basePrice: me.getRationGljPrice(rObj),
  1220. };
  1221. if (gljBasePrcObj.gljType !== -1) {
  1222. updateBasePrcArr.push(gljBasePrcObj);
  1223. if (me.rationLibs.length > 0) {
  1224. //重算定额单价
  1225. me.updateRationBasePrcRq(updateBasePrcArr);
  1226. }
  1227. }
  1228. }
  1229. } else {
  1230. //新增
  1231. if (typeof rObj.code !== "undefined") {
  1232. me.addGljObj = rObj;
  1233. let isCanSav = true;
  1234. if (!rObj.code || !rObj.name || !rObj.gljType) {
  1235. isCanSav = false;
  1236. }
  1237. if (isCanSav) {
  1238. me.addGljObj = null;
  1239. rObj.component = [];
  1240. me.initPrice(rObj);
  1241. addArr.push(rObj);
  1242. }
  1243. }
  1244. }
  1245. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1246. rObj.gljClass = me.gljCurTypeId;
  1247. rObj.classSeq = me.gljCurClassSeq;
  1248. }
  1249. if (updateArr.length > 0 || addArr.length > 0) {
  1250. me.currentEditingGlj = null;
  1251. me.mixUpdateRequest(updateArr, addArr, []);
  1252. }
  1253. },
  1254. delGljs: function (sels) {
  1255. let me = repositoryGljObj;
  1256. let sheet = me.workBook.getSheet(0),
  1257. updateArr = [],
  1258. removeArr = [],
  1259. removeIDs = [],
  1260. removeNames = [],
  1261. updateBasePrcArr = [], //删除基价单位后重新计算
  1262. canUpdate = false,
  1263. cacheSection = me.currentCache,
  1264. updateBackups = [];
  1265. if (sels.length > 0 && cacheSection.length > 0) {
  1266. for (let i = 0; i < sels.length; i++) {
  1267. if (sels[i].colCount === me.setting.header.length) {
  1268. for (let j = 0; j < sels[i].rowCount; j++) {
  1269. if (sels[i].row + j < cacheSection.length) {
  1270. removeArr.push(cacheSection[sels[i].row + j]);
  1271. removeIDs.push(cacheSection[sels[i].row + j].ID);
  1272. removeNames.push(cacheSection[sels[i].row + j].name);
  1273. //删除后重新计算引用了此工料机的定额单价
  1274. updateBasePrcArr.push({
  1275. gljId: cacheSection[sels[i].row + j].ID,
  1276. gljType: cacheSection[sels[i].row + j].gljType,
  1277. basePrice: 0,
  1278. delete: 1,
  1279. });
  1280. }
  1281. }
  1282. } else {
  1283. let maxCol = sels[i].col + sels[i].colCount - 1;
  1284. let cantNullDataCode = ["code", "name", "gljType"];
  1285. for (let j = 0; j < sels[i].rowCount; j++) {
  1286. if (sels[i].row + j < cacheSection.length) {
  1287. let updateObj = cacheSection[sels[i].row + j];
  1288. for (let col = sels[i].col; col <= maxCol; col++) {
  1289. let dataCode = me.setting.header[col].dataCode;
  1290. if (cantNullDataCode.includes(dataCode)) {
  1291. $("#alertText").text(
  1292. me.setting.header[col].headerName + "不可为空!"
  1293. );
  1294. $("#codeAlert").modal("show");
  1295. return false;
  1296. } else {
  1297. canUpdate = true;
  1298. break;
  1299. }
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. if (canUpdate) {
  1306. //删除警告
  1307. let upAlertText = "确认删除选中字段?";
  1308. $("#alertGljTxt").text(upAlertText);
  1309. $("#gljAlert").modal("show");
  1310. $("#aleConfBtn").unbind("click");
  1311. //确认
  1312. $("#aleConfBtn").bind("click", function () {
  1313. for (let i = 0; i < sels.length; i++) {
  1314. let maxCol = sels[i].col + sels[i].colCount - 1;
  1315. for (let j = 0; j < sels[i].rowCount; j++) {
  1316. if (sels[i].row + j < cacheSection.length) {
  1317. let updateObj = cacheSection[sels[i].row + j];
  1318. for (let col = sels[i].col; col <= maxCol; col++) {
  1319. let dataCode = me.setting.header[col].dataCode;
  1320. if (me.priceCols.includes(col)) {
  1321. me.setGljPrice(updateObj, 0, col);
  1322. updateBasePrcArr.push({
  1323. gljId: updateObj.ID,
  1324. gljType: updateObj.gljType,
  1325. basePrice: 0,
  1326. });
  1327. } else {
  1328. updateObj[dataCode] = "";
  1329. }
  1330. }
  1331. updateArr.push(updateObj);
  1332. }
  1333. }
  1334. }
  1335. me.mixUpdateRequest(updateArr, [], []);
  1336. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1337. me.updateRationBasePrcRq(updateBasePrcArr);
  1338. }
  1339. });
  1340. }
  1341. if (removeArr.length > 0) {
  1342. $.bootstrapLoading.start();
  1343. CommonAjax.post(
  1344. "/stdGljRepository/api/isUsed",
  1345. { gljIds: removeIDs },
  1346. function (rstData) {
  1347. $.bootstrapLoading.end();
  1348. //存在被引用的人材机(标准/补充定额库)
  1349. if (rstData.isUsed) {
  1350. $("#gljAlert")
  1351. .find(".modal-body h5")
  1352. .text("已有定额引用了当前人材机,不可删除。");
  1353. $("#gljAlert").modal("show");
  1354. $("#aleConfBtn").unbind("click");
  1355. $("#aleConfBtn").bind("click", function () {
  1356. $("#gljAlert").modal("hide");
  1357. me.workBook.focus(true);
  1358. });
  1359. } else {
  1360. $("#gljAlert")
  1361. .find(".modal-body h5")
  1362. .text(`确定要删除人材机 “${removeNames.join(",")}” 吗? `);
  1363. setTimeout(function () {
  1364. $("#gljAlert").modal("show");
  1365. }, 200);
  1366. //确认
  1367. $("#aleConfBtn").unbind("click");
  1368. $("#aleConfBtn").bind("click", function () {
  1369. for (let removeD of removeArr) {
  1370. let updateGljs = me.getUpdateGljs(removeD, true);
  1371. if (updateGljs.updateArr.length > 0) {
  1372. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1373. updateArr.push(updateGljs.updateArr[i]);
  1374. }
  1375. }
  1376. }
  1377. me.mixUpdateRequest(updateArr, [], removeIDs);
  1378. /* if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1379. me.updateRationBasePrcRq(updateBasePrcArr);
  1380. me.workBook.focus(true);
  1381. }*/
  1382. });
  1383. }
  1384. },
  1385. function () {
  1386. $.bootstrapLoading.end();
  1387. $("#gljAlert")
  1388. .find(".modal-body h5")
  1389. .text("查询引用错误,不可删除。");
  1390. $("#gljAlert").modal("show");
  1391. $("#aleConfBtn").unbind("click");
  1392. $("#aleConfBtn").bind("click", function () {
  1393. $("#gljAlert").modal("hide");
  1394. me.workBook.focus(true);
  1395. });
  1396. }
  1397. );
  1398. }
  1399. }
  1400. },
  1401. //删除人材机前需要判断人材机是否有被引用,被引用了则不可删除
  1402. repositoryGljDelOpr: function () {
  1403. if (locked) {
  1404. return;
  1405. }
  1406. let me = repositoryGljObj;
  1407. me.workBook.commandManager().register("repositoryGljDel", function () {
  1408. let sels = me.workBook.getActiveSheet().getSelections();
  1409. me.delGljs(sels);
  1410. });
  1411. me.workBook
  1412. .commandManager()
  1413. .setShortcutKey(
  1414. null,
  1415. GC.Spread.Commands.Key.del,
  1416. false,
  1417. false,
  1418. false,
  1419. false
  1420. );
  1421. me.workBook
  1422. .commandManager()
  1423. .setShortcutKey(
  1424. "repositoryGljDel",
  1425. GC.Spread.Commands.Key.del,
  1426. false,
  1427. false,
  1428. false,
  1429. false
  1430. );
  1431. },
  1432. editCode: async function () {
  1433. const sheet = this.workBook.getSheet(0);
  1434. const row = sheet.getActiveRowIndex();
  1435. const glj = this.currentCache[row];
  1436. if (!glj) {
  1437. alert('请选中工料机!');
  1438. $('#edit-code').modal('hide');
  1439. return;
  1440. }
  1441. const newCode = $('#edit-code-text').val();
  1442. if (!newCode) {
  1443. alert('编号不可为空!');
  1444. $('#edit-code-text').focus();
  1445. return;
  1446. }
  1447. if (this.gljList.some(item => item.ID !== glj.ID && item.code === newCode)) {
  1448. alert('编号已存在!');
  1449. $('#edit-code-text').focus();
  1450. return;
  1451. }
  1452. if (newCode === glj.code) {
  1453. $('#edit-code').modal('hide');
  1454. return;
  1455. }
  1456. this.mixUpdateRequest([{ ...glj, code: newCode }], [], []);
  1457. $('#edit-code').modal('hide');
  1458. },
  1459. onContextmenuOpr: function () {
  1460. let me = repositoryGljObj;
  1461. $.contextMenu({
  1462. selector: "#GLJListSheet",
  1463. build: function ($triggerElement, e) {
  1464. //控制允许右键菜单在哪个位置出现
  1465. let sheet = me.workBook.getSheet(0);
  1466. let offset = $("#GLJListSheet").offset(),
  1467. x = e.pageX - offset.left,
  1468. y = e.pageY - offset.top;
  1469. let target = sheet.hitTest(x, y);
  1470. let sel = sheet.getSelections()[0];
  1471. if (sel.row === -1) {
  1472. sel.row = 0;
  1473. }
  1474. if (sel.col === -1) {
  1475. sel.col = 0;
  1476. }
  1477. if (
  1478. target.hitTestType === 3 &&
  1479. typeof target.row !== "undefined" &&
  1480. typeof target.col !== "undefined"
  1481. ) {
  1482. //在表格内
  1483. me.initSel(target.row);
  1484. if (
  1485. sel.row > target.row ||
  1486. sel.row + sel.rowCount - 1 < target.row ||
  1487. sel.col > target.col ||
  1488. sel.col + sel.colCount - 1 < target.col
  1489. ) {
  1490. sheet.setActiveCell(target.row, target.col);
  1491. }
  1492. return {
  1493. callback: function () { },
  1494. items: {
  1495. edit: {
  1496. name: "修改编号",
  1497. disabled: function () {
  1498. return (
  1499. locked || !(me.currentCache && me.currentCache[target.row])
  1500. );
  1501. },
  1502. icon: "fa-edit",
  1503. callback: function (key, opt) {
  1504. if (me.currentCache[target.row]) {
  1505. $('#edit-code').modal('show');
  1506. $('#edit-code-text').val(me.currentCache[target.row].code || '');
  1507. }
  1508. },
  1509. },
  1510. delete: {
  1511. name: "删除",
  1512. disabled: function () {
  1513. return (
  1514. locked || !(me.currentCache && me.currentCache[target.row])
  1515. );
  1516. },
  1517. icon: "fa-remove",
  1518. callback: function (key, opt) {
  1519. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  1520. curSel.colCount = me.setting.header.length;
  1521. me.delGljs([curSel]);
  1522. },
  1523. },
  1524. getReference: {
  1525. name: "查找引用",
  1526. disabled: function () {
  1527. return !(me.currentCache && me.currentCache[target.row]);
  1528. },
  1529. icon: "fa-search",
  1530. callback: function () {
  1531. const glj = me.currentCache[target.row];
  1532. me.getReference(glj);
  1533. },
  1534. },
  1535. getUsedInfo: {
  1536. name: "查找用户使用情况",
  1537. disabled: function () {
  1538. return !(me.currentCache && me.currentCache[target.row]);
  1539. },
  1540. icon: "fa-search",
  1541. callback: function () {
  1542. const glj = me.currentCache[target.row];
  1543. me.getUsedInfo(glj);
  1544. },
  1545. },
  1546. moveTo: {
  1547. name: "移动分类至…",
  1548. disabled: function () {
  1549. return (
  1550. locked || !(me.currentCache && me.currentCache[target.row])
  1551. );
  1552. },
  1553. icon: "fa-exchange",
  1554. callback: function (key, opt) {
  1555. me.moveTo([]);
  1556. },
  1557. },
  1558. },
  1559. };
  1560. } else {
  1561. return false;
  1562. }
  1563. },
  1564. });
  1565. },
  1566. getReference: function (glj) {
  1567. const $info = $("#info");
  1568. const $infoBody = $("#infoBody");
  1569. $.bootstrapLoading.start();
  1570. CommonAjax.post(
  1571. "/stdGljRepository/api/getReference",
  1572. { repositoryId: glj.repositoryId, gljId: glj.ID },
  1573. function (info) {
  1574. const htmlArr = [];
  1575. if (!info || !Object.keys(info).length) {
  1576. htmlArr.push("<li>无引用数据</li>");
  1577. }
  1578. for (let libName in info) {
  1579. htmlArr.push(`<li class="list-title">${libName}</li>`);
  1580. const rations = info[libName];
  1581. const rationList = rations.map((ration) => {
  1582. if (ration.rationRepId) {
  1583. return `<li>
  1584. <span>${ration.code}</span>
  1585. <a target="_blank" href="/rationRepository/ration?repository=${ration.rationRepId}&locked=${locked}#${ration.code}">定位</a>
  1586. </li>`;
  1587. }
  1588. return `<li><span>${ration.code}</span></li>`;
  1589. });
  1590. htmlArr.push(...rationList);
  1591. }
  1592. $infoBody.html(htmlArr.join(""));
  1593. $info.modal("show");
  1594. $.bootstrapLoading.end();
  1595. },
  1596. function () {
  1597. $.bootstrapLoading.end();
  1598. }
  1599. );
  1600. },
  1601. moveTo: function () {
  1602. $("#moveToConfirm").prop("disabled", true);
  1603. $("#moveTo").modal("show");
  1604. },
  1605. getUsedInfo: function (glj) {
  1606. $.bootstrapLoading.start();
  1607. $("#usedInfo").modal("show");
  1608. CommonAjax.post(
  1609. "/stdGljRepository/api/getUsedInfo",
  1610. { repositoryId: glj.repositoryId, gljId: glj.ID },
  1611. function (info) {
  1612. $("#usedTotal").html(`共${info.length}项记录`);
  1613. let htmlString = "";
  1614. for (let u of info) {
  1615. htmlString += `<tr><td>${u.ID}</td><td>${u.username}</td> <td>${u.mobile}</td></tr>`;
  1616. }
  1617. $("#userInfoShowArea").html(htmlString);
  1618. $.bootstrapLoading.end();
  1619. },
  1620. function () {
  1621. $.bootstrapLoading.end();
  1622. }
  1623. );
  1624. },
  1625. validUpdateObj: function (pasteObj, rowIdx) {
  1626. let rst = { updateGlj: [], updateBasePrcArr: [] },
  1627. backUpObj = {},
  1628. me = repositoryGljObj,
  1629. that = gljComponentOprObj,
  1630. tempObj = me.currentCache[rowIdx],
  1631. reCalBasePrc = false,
  1632. isValid = true;
  1633. //备份原始数据
  1634. for (let atr in tempObj) {
  1635. backUpObj[atr] = tempObj[atr];
  1636. }
  1637. if (typeof pasteObj.code !== "undefined") {
  1638. if (pasteObj.code.trim().length !== 0) {
  1639. let isExist = false;
  1640. for (let i = 0; i < me.gljList.length; i++) {
  1641. if (me.gljList[i].code === pasteObj.code) {
  1642. isExist = true;
  1643. break;
  1644. }
  1645. }
  1646. if (!isExist) {
  1647. tempObj.code = pasteObj.code;
  1648. } else isValid = false;
  1649. } else isValid = false;
  1650. }
  1651. if (typeof pasteObj.name !== "undefined") {
  1652. if (pasteObj.name.trim().length === 0) isValid = false;
  1653. else tempObj.name = pasteObj.name;
  1654. }
  1655. if (typeof pasteObj.specs !== "undefined") {
  1656. tempObj.specs = pasteObj.specs;
  1657. }
  1658. if (typeof pasteObj.unit !== "undefined") {
  1659. tempObj.unit = pasteObj.unit;
  1660. }
  1661. if (typeof pasteObj.lossRate !== "undefined" && !isNaN(pasteObj.lossRate)) {
  1662. tempObj.lossRate = pasteObj.lossRate;
  1663. }
  1664. if (typeof pasteObj.taxRate !== "undefined" && !isNaN(pasteObj.taxRate)) {
  1665. tempObj.taxRate = pasteObj.taxRate;
  1666. }
  1667. if (typeof pasteObj.gljType !== "undefined") {
  1668. let isExsit = false;
  1669. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1670. if (pasteObj.gljType === me.distTypeTree.comboDatas[i].text) {
  1671. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1672. isExsit = true;
  1673. if (
  1674. me.getParentType(pasteObj.gljType) !== 2 &&
  1675. me.getParentType(tempObj.gljType) === 2
  1676. ) {
  1677. for (let feeCode of me.feeDataCode) {
  1678. tempObj[feeCode] = null;
  1679. }
  1680. }
  1681. if (
  1682. componentType.includes(tempObj.gljType) &&
  1683. !(
  1684. machineComponent.includes(tempObj.gljType) &&
  1685. machineComponent.includes(pasteObj.gljType)
  1686. ) &&
  1687. !(
  1688. materialComponent.includes(tempObj.gljType) &&
  1689. materialComponent.includes(pasteObj.gljType)
  1690. )
  1691. ) {
  1692. //修改了原本是组成物的工料机
  1693. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1694. let updateGljs = me.getUpdateGljs(tempObj, true);
  1695. if (
  1696. updateGljs.updateArr.length > 0 ||
  1697. updateGljs.updateBasePrcArr.length > 0
  1698. ) {
  1699. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1700. rst.updateGlj.push(updateGljs.updateArr[i]);
  1701. }
  1702. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1703. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1704. }
  1705. }
  1706. }
  1707. tempObj.component =
  1708. tempObj.gljType === pasteObj.gljType ? tempObj.component : [];
  1709. tempObj.gljType = pasteObj.gljType;
  1710. tempObj.shortName =
  1711. me.distTypeTree.distTypes[
  1712. me.distTypeTree.prefix + tempObj.gljType
  1713. ].data.shortName;
  1714. break;
  1715. }
  1716. }
  1717. if (!isExsit) {
  1718. isValid = false;
  1719. }
  1720. }
  1721. for (let feeCode of me.feeDataCode) {
  1722. if (
  1723. typeof pasteObj[feeCode] !== "undefined" &&
  1724. !isNaN(pasteObj[feeCode])
  1725. ) {
  1726. if (
  1727. (typeof pasteObj.gljType !== "undefined" &&
  1728. me.getParentType(pasteObj.gljType) === 2) ||
  1729. (tempObj.gljType && me.getParentType(tempObj.gljType) === 2)
  1730. ) {
  1731. tempObj[feeCode] = pasteObj[feeCode];
  1732. } else {
  1733. isValid = false;
  1734. }
  1735. }
  1736. }
  1737. //单价相关
  1738. if (me.pasteIncludesPrice(pasteObj)) {
  1739. if (!priceProperties || priceProperties.length === 0) {
  1740. pasteObj.basePrice =
  1741. pasteObj.basePrice && !isNaN(parseFloat(pasteObj.basePrice))
  1742. ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2)
  1743. : me.currentCache[rowIdx].basePrice;
  1744. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1745. reCalBasePrc = true;
  1746. tempObj.basePrice = pasteObj.basePrice;
  1747. }
  1748. } else {
  1749. //多单价粘贴
  1750. let pastePriceProperty = {};
  1751. let priceFields = me.getPriceFields();
  1752. for (let priceField of priceFields) {
  1753. if (
  1754. typeof pasteObj[priceField] !== "undefined" &&
  1755. pasteObj[priceField] &&
  1756. !isNaN(parseFloat(pasteObj[priceField]))
  1757. ) {
  1758. pastePriceProperty[priceField] = scMathUtil.roundTo(
  1759. parseFloat(pasteObj[priceField]),
  1760. -2
  1761. );
  1762. }
  1763. }
  1764. if (!me.priceIsEqual(tempObj, pasteObj)) {
  1765. reCalBasePrc = true;
  1766. //更新人材机单价
  1767. for (let priceField in pastePriceProperty) {
  1768. tempObj.priceProperty[priceField] = pastePriceProperty[priceField];
  1769. }
  1770. }
  1771. }
  1772. let updateGljs = me.getUpdateGljs(tempObj, false);
  1773. if (
  1774. updateGljs.updateArr.length > 0 ||
  1775. updateGljs.updateBasePrcArr.length > 0
  1776. ) {
  1777. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1778. rst.updateGlj.push(updateGljs.updateArr[i]);
  1779. }
  1780. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1781. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1782. }
  1783. }
  1784. }
  1785. if (isValid) {
  1786. rst.updateGlj.push(tempObj);
  1787. if (reCalBasePrc) {
  1788. //重新计算定额基价对象
  1789. let newReObj = {
  1790. gljId: tempObj.ID,
  1791. gljType: tempObj.gljType,
  1792. basePrice: me.getRationGljPrice(tempObj),
  1793. };
  1794. rst.updateBasePrcArr.push(newReObj);
  1795. }
  1796. } else {
  1797. for (let attr in backUpObj) {
  1798. tempObj[attr] = backUpObj[attr];
  1799. }
  1800. }
  1801. return rst;
  1802. },
  1803. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  1804. isValidObj: function (pasteObj) {
  1805. let me = repositoryGljObj;
  1806. if (
  1807. !(pasteObj.code && typeof pasteObj.code !== "undefined") ||
  1808. !(pasteObj.name && typeof pasteObj.name !== "undefined") ||
  1809. !(pasteObj.gljType && typeof pasteObj.gljType !== "undefined")
  1810. ) {
  1811. return false;
  1812. }
  1813. if (pasteObj.gljType && typeof pasteObj.gljType !== "undefined") {
  1814. let isExist = false;
  1815. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1816. if (me.distTypeTree.comboDatas[i].text === pasteObj.gljType) {
  1817. isExist = true;
  1818. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1819. pasteObj.shortName =
  1820. me.distTypeTree.distTypes[
  1821. me.distTypeTree.prefix + pasteObj.gljType
  1822. ].data.shortName;
  1823. break;
  1824. }
  1825. }
  1826. if (!isExist) {
  1827. return false;
  1828. }
  1829. }
  1830. if (pasteObj.code && typeof pasteObj.code !== "undefined") {
  1831. for (let i = 0; i < me.gljList.length; i++) {
  1832. if (me.gljList[i].code === pasteObj.code) {
  1833. return false;
  1834. }
  1835. }
  1836. }
  1837. if (typeof pasteObj.lossRate !== "undefined" && isNaN(pasteObj[feeCode])) {
  1838. return false;
  1839. }
  1840. for (let feeCode of me.feeDataCode) {
  1841. if (
  1842. typeof pasteObj[feeCode] !== "undefined" &&
  1843. (isNaN(pasteObj[feeCode]) || me.getParentType(pasteObj.gljType) !== 2)
  1844. ) {
  1845. return false;
  1846. }
  1847. }
  1848. if (!priceProperties || priceProperties.length === 0) {
  1849. pasteObj.basePrice =
  1850. !isNaN(parseFloat(pasteObj.basePrice)) &&
  1851. pasteObj.basePrice &&
  1852. typeof pasteObj.basePrice !== "undefined"
  1853. ? parseFloat(pasteObj.basePrice)
  1854. : 0;
  1855. } else {
  1856. let pastePriceProperty = {};
  1857. let priceFields = me.getPriceFields();
  1858. for (let priceField of priceFields) {
  1859. if (
  1860. typeof pasteObj[priceField] !== "undefined" &&
  1861. pasteObj[priceField] &&
  1862. !isNaN(parseFloat(pasteObj[priceField]))
  1863. ) {
  1864. pastePriceProperty[priceField] = scMathUtil.roundTo(
  1865. parseFloat(pasteObj[priceField]),
  1866. -2
  1867. );
  1868. } else {
  1869. pastePriceProperty[priceField] = 0;
  1870. }
  1871. }
  1872. pasteObj.priceProperty = pastePriceProperty;
  1873. }
  1874. //pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1875. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1876. pasteObj.gljClass = me.gljCurTypeId;
  1877. pasteObj.classSeq = me.gljCurClassSeq;
  1878. }
  1879. return true;
  1880. },
  1881. canPasted: function (info) {
  1882. let rst = true;
  1883. let me = repositoryGljObj;
  1884. if (me.gljCurTypeId < 0) {
  1885. return false;
  1886. }
  1887. //粘贴的最大列下标不超过总列数
  1888. if (
  1889. info.cellRange.col + info.cellRange.colCount - 1 >
  1890. me.setting.header.length - 1
  1891. ) {
  1892. return false;
  1893. }
  1894. if (info.cellRange.row < me.currentCache.length) {
  1895. if (info.cellRange.col === 0) {
  1896. return false;
  1897. }
  1898. }
  1899. return rst;
  1900. },
  1901. onClipboardPasting: function (sender, args) {
  1902. let me = repositoryGljObj;
  1903. //复制的列数超过正确的列数,不可复制
  1904. if (me.prevent) {
  1905. args.cancel = true;
  1906. return;
  1907. }
  1908. if (!me.canPasted(args)) {
  1909. args.cancel = true;
  1910. }
  1911. },
  1912. onClipboardPasted: function (e, info) {
  1913. $.bootstrapLoading.start();
  1914. let me = repositoryGljObj;
  1915. let updateArr = [],
  1916. addArr = [];
  1917. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1918. let beginRow = info.cellRange.row,
  1919. endRow = info.cellRange.row + info.cellRange.rowCount - 1,
  1920. maxRow = me.currentCache.length - 1,
  1921. updateBasePrcArr = [],
  1922. updateCount,
  1923. resumeArr = [];
  1924. if (endRow <= maxRow) {
  1925. for (let i = 0; i < items.length; i++) {
  1926. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1927. if (
  1928. updateObj &&
  1929. typeof updateObj.updateGlj !== "undefined" &&
  1930. updateObj.updateGlj.length > 0
  1931. ) {
  1932. updateArr = updateArr.concat(updateObj.updateGlj);
  1933. if (typeof updateObj.updateBasePrcArr !== "undefined") {
  1934. updateBasePrcArr = updateBasePrcArr.concat(
  1935. updateObj.updateBasePrcArr
  1936. );
  1937. }
  1938. }
  1939. }
  1940. } else if (beginRow <= maxRow && endRow > maxRow) {
  1941. updateCount = maxRow - beginRow + 1;
  1942. for (let i = 0; i < updateCount; i++) {
  1943. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1944. if (updateObj && typeof updateObj.updateGlj !== "undefined") {
  1945. updateArr = updateArr.concat(updateObj.updateGlj);
  1946. if (typeof updateObj.updateBasePrcArr !== "undefined") {
  1947. updateBasePrcArr = updateBasePrcArr.concat(
  1948. updateObj.updateBasePrcArr
  1949. );
  1950. }
  1951. }
  1952. }
  1953. //[code, ..., gljType]
  1954. if (
  1955. info.cellRange.colCount >= 5 &&
  1956. info.cellRange.colCount <= me.setting.header.length
  1957. ) {
  1958. for (let i = updateCount; i < items.length; i++) {
  1959. if (me.isValidObj(items[i])) {
  1960. items[i].component = [];
  1961. addArr.push(items[i]);
  1962. }
  1963. }
  1964. }
  1965. } else {
  1966. //粘贴的的最大列至少要等于工料机类型列,因为工料机类型必须有效才可新增
  1967. if (
  1968. info.cellRange.colCount >= 5 &&
  1969. info.cellRange.colCount <= me.setting.header.length &&
  1970. info.cellRange.col + info.cellRange.colCount - 1 >=
  1971. me.colMapping.fieldToCol["gljType"]
  1972. ) {
  1973. for (let i = 0; i < items.length; i++) {
  1974. if (me.isValidObj(items[i])) {
  1975. items[i].component = [];
  1976. addArr.push(items[i]);
  1977. }
  1978. }
  1979. }
  1980. }
  1981. //repaint
  1982. for (let i = 0; i < info.cellRange.rowCount; i++) {
  1983. resumeArr.push(info.cellRange.row + i);
  1984. }
  1985. if (resumeArr.length > 0) {
  1986. info.sheet.suspendPaint();
  1987. for (let i = 0; i < resumeArr.length; i++) {
  1988. if (resumeArr[i] < me.currentCache.length) {
  1989. for (let col = 0; col < me.setting.header.length; col++) {
  1990. let dCode = me.setting.header[col].dataCode;
  1991. if (me.priceCols.includes(col)) {
  1992. let price = me.getPrice(me.currentCache[resumeArr[i]], col);
  1993. info.sheet.setValue(resumeArr[i], col, price ? price : 0);
  1994. } else if (dCode === "gljType") {
  1995. let gljType = me.currentCache[resumeArr[i]][dCode];
  1996. info.sheet.setValue(
  1997. resumeArr[i],
  1998. col,
  1999. me.distTypeTree.distTypes["gljType" + gljType].data.fullName
  2000. );
  2001. } else {
  2002. info.sheet.setValue(
  2003. resumeArr[i],
  2004. col,
  2005. me.currentCache[resumeArr[i]][dCode]
  2006. );
  2007. }
  2008. }
  2009. } else {
  2010. for (let col = 0; col < me.setting.header.length; col++) {
  2011. info.sheet.setValue(resumeArr[i], col, "");
  2012. }
  2013. }
  2014. }
  2015. info.sheet.resumePaint();
  2016. }
  2017. if (updateArr.length > 0 || addArr.length > 0) {
  2018. me.mixUpdateRequest(updateArr, addArr, []);
  2019. } else {
  2020. $.bootstrapLoading.end();
  2021. }
  2022. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  2023. me.updateRationBasePrcRq(updateBasePrcArr);
  2024. }
  2025. },
  2026. updateRationBasePrcRq: function (basePrcArr, workBook, callback) {
  2027. let me = this;
  2028. me.prevent = true;
  2029. if (!$.bootstrapLoading.isLoading()) {
  2030. $.bootstrapLoading.start();
  2031. }
  2032. $.ajax({
  2033. type: "post",
  2034. url: "api/updateRationBasePrc",
  2035. data: { basePrcArr: JSON.stringify(basePrcArr) },
  2036. dataType: "json",
  2037. success: function (result) {
  2038. if (result.error) {
  2039. alert("计算定额基价失败");
  2040. }
  2041. if (workBook) {
  2042. workBook.focus(true);
  2043. } else {
  2044. me.workBook.focus(true);
  2045. }
  2046. me.prevent = false;
  2047. if (callback) {
  2048. callback();
  2049. }
  2050. if ($.bootstrapLoading.isLoading()) {
  2051. $.bootstrapLoading.end();
  2052. }
  2053. },
  2054. });
  2055. },
  2056. mixUpdateRequest: function (updateArr, addArr, removeIds) {
  2057. let me = repositoryGljObj;
  2058. if (updateArr.length > 0) {
  2059. me.saveInString(updateArr);
  2060. }
  2061. if (addArr.length > 0) {
  2062. const codeMap = {};
  2063. const uniqueCodeAddArr = [];
  2064. addArr.forEach((item) => {
  2065. if (!codeMap[item.code]) {
  2066. codeMap[item.code] = 1;
  2067. uniqueCodeAddArr.push(item);
  2068. }
  2069. });
  2070. addArr = uniqueCodeAddArr;
  2071. me.saveInString(addArr);
  2072. }
  2073. $.ajax({
  2074. type: "POST",
  2075. url: "api/mixUpdateGljItems",
  2076. data: {
  2077. repositoryId: me.currentRepositoryId,
  2078. lastOpr: userAccount,
  2079. updateItems: JSON.stringify(updateArr),
  2080. addItems: JSON.stringify(addArr),
  2081. removeIds: JSON.stringify(removeIds),
  2082. },
  2083. dataType: "json",
  2084. cache: false,
  2085. timeout: 50000,
  2086. success: function (result) {
  2087. if (result.error) {
  2088. alert(result.message);
  2089. } else {
  2090. const failCodes = result.data.failCode;
  2091. if (failCodes && failCodes.length) {
  2092. let failText = "";
  2093. failCodes.forEach((code) => {
  2094. failText += `<p>编码“${code}”已存在</p>`;
  2095. });
  2096. $("#alertText").html(failText);
  2097. $("#codeAlert").modal("show");
  2098. }
  2099. const insertData = result.data.insertData;
  2100. me.updateCache(insertData, updateArr, removeIds);
  2101. //me.sortGlj();
  2102. if (me.currentOprParent === 1) {
  2103. me.currentCache = me.getParentCache(
  2104. me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]
  2105. );
  2106. } else {
  2107. me.currentCache = me.getCache();
  2108. }
  2109. me.showGljItems(me.currentCache, me.gljCurTypeId);
  2110. //getCurrentGlj
  2111. let row = me.workBook.getSheet(0).getSelections()[0].row;
  2112. me.currentGlj =
  2113. row < me.currentCache.length ? me.currentCache[row] : null;
  2114. me.currentComponent = me.currentGlj
  2115. ? me.getCurrentComponent(me.currentGlj.component)
  2116. : [];
  2117. sheetCommonObj.cleanData(
  2118. gljComponentOprObj.workBook.getSheet(0),
  2119. gljComponentOprObj.setting,
  2120. -1
  2121. );
  2122. sheetsOprObj.showData(
  2123. gljComponentOprObj,
  2124. gljComponentOprObj.workBook.getSheet(0),
  2125. gljComponentOprObj.setting,
  2126. me.currentComponent
  2127. );
  2128. }
  2129. if ($.bootstrapLoading.isLoading()) {
  2130. $.bootstrapLoading.end();
  2131. }
  2132. },
  2133. error: function (err) {
  2134. if ($.bootstrapLoading.isLoading()) {
  2135. $.bootstrapLoading.end();
  2136. }
  2137. console.log(err);
  2138. alert("保存失败");
  2139. },
  2140. });
  2141. },
  2142. saveInString: function (datas) {
  2143. for (let i = 0, len = datas.length; i < len; i++) {
  2144. let data = datas[i];
  2145. if (_exist(data, "basePrice")) {
  2146. data["basePrice"] = data["basePrice"].toString();
  2147. }
  2148. if (_exist(data, "component")) {
  2149. for (let j = 0, jLen = data["component"].length; j < jLen; j++) {
  2150. let comGljObj = data["component"][j];
  2151. if (_exist(comGljObj, "consumeAmt")) {
  2152. comGljObj["consumeAmt"] = comGljObj["consumeAmt"].toString();
  2153. }
  2154. }
  2155. }
  2156. }
  2157. function _exist(data, attr) {
  2158. return data && data[attr] !== undefined && data[attr];
  2159. }
  2160. },
  2161. getParentCache: function (nodes) {
  2162. let me = repositoryGljObj,
  2163. rst = [];
  2164. for (let i = 0; i < me.gljList.length; i++) {
  2165. if (nodes.indexOf(me.gljList[i].gljClass) !== -1) {
  2166. rst.push(me.gljList[i]);
  2167. }
  2168. }
  2169. rst.sort(function (a, b) {
  2170. let rst = 0;
  2171. if (a.code > b.code) rst = 1;
  2172. else if (a.code < b.code) rst = -1;
  2173. return rst;
  2174. });
  2175. return rst;
  2176. },
  2177. getCache: function () {
  2178. let me = this,
  2179. rst = [];
  2180. for (let i = 0; i < me.gljList.length; i++) {
  2181. if (me.gljList[i].gljClass == me.gljCurTypeId) {
  2182. rst.push(me.gljList[i]);
  2183. }
  2184. }
  2185. return rst;
  2186. },
  2187. updateCache: function (insertData, updateArr, removeIds) {
  2188. let me = this,
  2189. cacheSection = me.gljList;
  2190. if (insertData && insertData.length > 0) {
  2191. me.gljList = me.gljList.concat(insertData);
  2192. cacheSection = me.gljList;
  2193. }
  2194. for (let i = removeIds.length - 1; i >= 0; i--) {
  2195. for (let j = cacheSection.length - 1; j >= 0; j--) {
  2196. if (cacheSection[j]["ID"] == removeIds[i]) {
  2197. cacheSection.splice(j, 1);
  2198. }
  2199. }
  2200. }
  2201. for (let i = 0; i < updateArr.length; i++) {
  2202. for (let j = 0; j < cacheSection.length; j++) {
  2203. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  2204. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  2205. cacheSection[j] = updateArr[i];
  2206. }
  2207. } else {
  2208. if (cacheSection[j]["code"] == updateArr[i]["code"]) {
  2209. cacheSection[j] = updateArr[i];
  2210. }
  2211. }
  2212. }
  2213. }
  2214. },
  2215. updateParentNodeIds: function (nodes, caller) {
  2216. let private_build_parentNodeIds = function (pNodeId, nodesArr) {
  2217. let rst = [];
  2218. for (let i = 0; i < nodesArr.length; i++) {
  2219. if (nodesArr[i].children.length > 0) {
  2220. rst = rst.concat(
  2221. private_build_parentNodeIds(
  2222. nodesArr[i].data.ID,
  2223. nodesArr[i].children
  2224. )
  2225. );
  2226. } else {
  2227. rst.push(nodesArr[i].data.ID);
  2228. }
  2229. }
  2230. if (pNodeId && rst.length > 0) {
  2231. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  2232. }
  2233. return rst;
  2234. };
  2235. if (caller.parentNodeIds) {
  2236. private_build_parentNodeIds(null, nodes);
  2237. }
  2238. },
  2239. sortGljDeep: function (datas) {
  2240. function recurCompare(a, b, index) {
  2241. if (a[index] && !b[index]) {
  2242. return 1;
  2243. } else if (!a[index] && b[index]) {
  2244. return -1;
  2245. } else if (a[index] && b[index]) {
  2246. let aV = a[index],
  2247. bV = b[index];
  2248. if (!isNaN(aV) && !isNaN(bV)) {
  2249. aV = parseFloat(a[index]);
  2250. bV = parseFloat(b[index]);
  2251. }
  2252. if (aV > bV) {
  2253. return 1;
  2254. } else if (aV < bV) {
  2255. return -1;
  2256. } else {
  2257. return recurCompare(a, b, index + 1);
  2258. }
  2259. }
  2260. return 0;
  2261. }
  2262. //排序符号-
  2263. datas.sort(function (a, b) {
  2264. let aArr = a.code.split("-"),
  2265. bArr = b.code.split("-");
  2266. return recurCompare(aArr, bArr, 0);
  2267. });
  2268. },
  2269. //工料机排序
  2270. sortGlj: function () {
  2271. let me = this;
  2272. me.gljList.sort(function (a, b) {
  2273. let rst = 0;
  2274. if (a.code > b.code) rst = 1;
  2275. else if (a.code < b.code) rst = -1;
  2276. return rst;
  2277. });
  2278. },
  2279. };
  2280. let gljTypeTreeOprObj = {
  2281. onClick: function (event, treeId, treeNode) {
  2282. let me = repositoryGljObj,
  2283. that = gljComponentOprObj,
  2284. gljTypeId = treeNode.ID;
  2285. me.gljCurTypeId = treeNode.ID;
  2286. me.addGljObj = null;
  2287. sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, 10);
  2288. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  2289. me.currentOprParent = 1;
  2290. me.currentCache = me.getParentCache(
  2291. me.parentNodeIds["_pNodeId_" + treeNode.ID]
  2292. );
  2293. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  2294. } else {
  2295. me.currentOprParent = 0;
  2296. me.currentCache = me.getCache();
  2297. }
  2298. me.showGljItems(me.currentCache, gljTypeId);
  2299. },
  2300. beforeRename: function (treeId, treeNode, newName, isCancel) {
  2301. if (newName.length == 0) {
  2302. return false;
  2303. }
  2304. return true;
  2305. },
  2306. onRename: function (e, treeId, treeNode, isCancel) {
  2307. let nodes = [];
  2308. nodes.push(treeNode);
  2309. gljTypeTreeOprObj.updateNodes(nodes);
  2310. },
  2311. onBeforeRemove: function (treeId, treeNode) {
  2312. let me = this;
  2313. if (treeNode.ParentID == -1 && treeNode.isFirstNode) {
  2314. alert("不允许删除全部!");
  2315. return false;
  2316. }
  2317. if (!confirm("您确定要删除此节点及所有子节点的数据?删除后不可恢复!")) {
  2318. return false;
  2319. }
  2320. let nodeIds = [],
  2321. preNode = treeNode.getPreNode(),
  2322. preNodeId = -1;
  2323. if (preNode) {
  2324. preNodeId = preNode.ID;
  2325. }
  2326. private_fetchAllSubItems = function (pItem) {
  2327. nodeIds.push(pItem.ID);
  2328. if (pItem.items && pItem.items.length > 0) {
  2329. for (let i = 0; i < pItem.items.length; i++) {
  2330. private_fetchAllSubItems(pItem.items[i]);
  2331. }
  2332. }
  2333. };
  2334. nodeIds.push(treeNode.ID);
  2335. for (let i = 0; i < treeNode.items.length; i++) {
  2336. private_fetchAllSubItems(treeNode.items[i]);
  2337. }
  2338. $.ajax({
  2339. type: "POST",
  2340. url: "api/deleteGljNodes",
  2341. data: {
  2342. repId: pageOprObj.gljLibId,
  2343. lastOpr: userAccount,
  2344. nodes: JSON.stringify(nodeIds),
  2345. preNodeId: preNodeId,
  2346. preNodeNextId: treeNode.NextSiblingID,
  2347. },
  2348. dataType: "json",
  2349. cache: false,
  2350. timeout: 5000,
  2351. success: function (result, textStatus, status) {
  2352. let pNode = treeNode.getParentNode();
  2353. if (pNode && pNode.items && pNode.items.length == 1) {
  2354. pNode.isParent = false;
  2355. }
  2356. },
  2357. error: function () { },
  2358. });
  2359. return true;
  2360. },
  2361. onRemove: function (e, treeId, treeNode) {
  2362. let me = repositoryGljObj,
  2363. pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
  2364. if (pNode && pNode.items && pNode.items.length == 0) {
  2365. pNode.isParent = false;
  2366. me.treeObj.refresh();
  2367. }
  2368. },
  2369. updateNodes: function (nodes) {
  2370. if (nodes && nodes.length > 0) {
  2371. let reqData = [];
  2372. for (let i = 0; i < nodes.length; i++) {
  2373. let node = {};
  2374. node.repositoryId = nodes[i].repositoryId;
  2375. node.ID = nodes[i].ID;
  2376. node.ParentID = nodes[i].ParentID;
  2377. node.NextSiblingID = nodes[i].NextSiblingID;
  2378. node.Name = nodes[i].Name;
  2379. reqData.push(node);
  2380. }
  2381. $.ajax({
  2382. type: "POST",
  2383. url: "api/updateGljNodes",
  2384. data: {
  2385. repId: pageOprObj.gljLibId,
  2386. lastOpr: userAccount,
  2387. nodes: JSON.stringify(reqData),
  2388. },
  2389. dataType: "json",
  2390. cache: false,
  2391. timeout: 5000,
  2392. success: function (result, textStatus, status) {
  2393. console.log(status + " : " + result);
  2394. },
  2395. error: function () { },
  2396. });
  2397. }
  2398. },
  2399. addRootNode: function () {
  2400. let me = repositoryGljObj,
  2401. rawNode = { ParentID: -1, NextSiblingID: -1, Name: "所有" },
  2402. lastNodeId = -1;
  2403. if (me.treeObj) {
  2404. let rootNodes = me.treeObj.getNodes();
  2405. if (rootNodes.length == 0) {
  2406. gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function (err, rst) {
  2407. if (!err) {
  2408. let newNodes = [],
  2409. isSilent = false;
  2410. newNodes.push({
  2411. repositoryId: rst.data.repositoryId,
  2412. ID: rst.data.ID,
  2413. ParentID: rst.data.ParentID,
  2414. NextSiblingID: -1,
  2415. Name: "所有",
  2416. isParent: false,
  2417. items: [],
  2418. });
  2419. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  2420. }
  2421. });
  2422. }
  2423. }
  2424. },
  2425. addNewNode: function (rawNode, lastNodeId, callback) {
  2426. $.ajax({
  2427. type: "POST",
  2428. url: "api/createNewGljTypeNode",
  2429. data: {
  2430. lastOpr: userAccount,
  2431. repositoryId: repositoryGljObj.currentRepositoryId,
  2432. lastNodeId: lastNodeId,
  2433. rawNodeData: JSON.stringify(rawNode),
  2434. },
  2435. dataType: "json",
  2436. cache: false,
  2437. timeout: 1000,
  2438. success: function (result, textStatus, status) {
  2439. callback(false, result);
  2440. },
  2441. error: function (err) {
  2442. callback(err);
  2443. },
  2444. });
  2445. },
  2446. addHoverDom: function (treeId, treeNode) {
  2447. if (typeof treeNode.doing !== "undefined" && treeNode.doing) {
  2448. return false;
  2449. }
  2450. hoverOpr();
  2451. function hoverOpr() {
  2452. let me = repositoryGljObj,
  2453. sObj = $("#" + treeNode.tId + "_span");
  2454. if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0)
  2455. return;
  2456. let addStr =
  2457. "<span class='button add' id='addBtn_" +
  2458. treeNode.tId +
  2459. "' title='新增子节点' onfocus='this.blur();'></span>";
  2460. sObj.after(addStr);
  2461. let btn = $("#addBtn_" + treeNode.tId);
  2462. if (btn)
  2463. btn.bind("click", function () {
  2464. treeNode.doing = true;
  2465. let rawNode = {
  2466. ParentID: treeNode.ID,
  2467. NextSiblingID: -1,
  2468. Name: "新增子节点",
  2469. },
  2470. lastNodeId = -1;
  2471. if (treeNode.items.length > 0) {
  2472. lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
  2473. }
  2474. gljTypeTreeOprObj.addNewNode(
  2475. rawNode,
  2476. lastNodeId,
  2477. function (err, rst) {
  2478. if (!err) {
  2479. let newNodes = [],
  2480. isSilent = false;
  2481. if (treeNode.items.length > 0) {
  2482. treeNode.items[treeNode.items.length - 1].NextSiblingID =
  2483. rst.data.ID;
  2484. }
  2485. newNodes.push({
  2486. repositoryId: rst.data.repositoryId,
  2487. ID: rst.data.ID,
  2488. ParentID: rst.data.ParentID,
  2489. NextSiblingID: -1,
  2490. Name: "新增子节点",
  2491. isParent: false,
  2492. items: [],
  2493. });
  2494. treeNode.isParent = true;
  2495. if (me.treeObj) {
  2496. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  2497. } else {
  2498. me.treeObj = $.fn.zTree.init(
  2499. $("#rationChapterTree"),
  2500. gljSetting,
  2501. newNodes
  2502. );
  2503. }
  2504. treeNode.doing = false;
  2505. hoverOpr();
  2506. }
  2507. }
  2508. );
  2509. });
  2510. }
  2511. },
  2512. removeHoverDom: function (treeId, treeNode) {
  2513. $("#addBtn_" + treeNode.tId)
  2514. .unbind()
  2515. .remove();
  2516. },
  2517. };
  2518. $(document).ready(function () {
  2519. let moduleName = "stdGLj";
  2520. function refreshALlWorkBook() {
  2521. if (gljClassTreeObj.workBook) {
  2522. gljClassTreeObj.workBook.refresh();
  2523. }
  2524. if (repositoryGljObj.workBook) {
  2525. repositoryGljObj.workBook.refresh();
  2526. }
  2527. if (gljComponentOprObj.workBook) {
  2528. gljComponentOprObj.workBook.refresh();
  2529. }
  2530. }
  2531. SlideResize.loadHorizonWidth(
  2532. moduleName,
  2533. [$("#slideResizeLeft"), $("#slideResizeRight")],
  2534. [$("#leftContent"), $("#midContent"), $("#rightContent")],
  2535. function () {
  2536. refreshALlWorkBook();
  2537. }
  2538. );
  2539. //章节树与人材机表
  2540. let leftElesObj = {};
  2541. leftElesObj.module = moduleName;
  2542. leftElesObj.resize = $("#slideResizeLeft");
  2543. leftElesObj.parent = $("#dataRow");
  2544. leftElesObj.left = $("#leftContent");
  2545. leftElesObj.right = $("#midContent");
  2546. SlideResize.horizontalSlide(
  2547. leftElesObj,
  2548. {
  2549. min: 375,
  2550. max: `$('#dataRow').width() - $('#rightContent').width() - 375`,
  2551. },
  2552. function () {
  2553. refreshALlWorkBook();
  2554. }
  2555. );
  2556. //人材机表与人材机组成物表
  2557. let rightElesObj = {};
  2558. rightElesObj.module = moduleName;
  2559. rightElesObj.resize = $("#slideResizeRight");
  2560. rightElesObj.parent = $("#dataRow");
  2561. rightElesObj.left = $("#midContent");
  2562. rightElesObj.right = $("#rightContent");
  2563. SlideResize.horizontalSlide(
  2564. rightElesObj,
  2565. {
  2566. min: 200,
  2567. max: `$('#dataRow').width() - $('#leftContent').width() - 200`,
  2568. },
  2569. function () {
  2570. let resizeRate =
  2571. (SlideResize.resizeWidth * 100) / $("#midContent").width(),
  2572. sheetRate = 100 - resizeRate;
  2573. $("#slideResizeLeft").css("width", `${resizeRate}%`);
  2574. $("#GLJListSheet").css("width", `${sheetRate}%`);
  2575. refreshALlWorkBook();
  2576. }
  2577. );
  2578. $("#gljSearch").keydown(function (event) {
  2579. if (event.keyCode === 13) {
  2580. $(this).blur();
  2581. const gljCode = $(this).val();
  2582. if (gljCode) {
  2583. repositoryGljObj.locateGlj(gljCode);
  2584. // sectionTreeObj.locateToSection(rationCode);
  2585. }
  2586. }
  2587. });
  2588. $("#moveToConfirm").click(function () {
  2589. let sheet = repositoryGljObj.workBook.getSheet(0);
  2590. let sel = sheet.getSelections()[0];
  2591. let gljs = repositoryGljObj.currentCache.slice(
  2592. sel.row,
  2593. sel.row + sel.rowCount
  2594. );
  2595. let node = gljClassTreeObj.zTreeSetting.selected;
  2596. let updateArr = [];
  2597. for (let glj of gljs) {
  2598. const data = _.cloneDeep(glj);
  2599. data.gljClass = node.ID;
  2600. updateArr.push(data);
  2601. }
  2602. repositoryGljObj.mixUpdateRequest(updateArr, [], []);
  2603. $("#moveTo").modal("hide");
  2604. });
  2605. // 修改编号弹窗
  2606. $('#edit-code').on('shown.bs.modal', function () {
  2607. $('#edit-code-text').focus();
  2608. });
  2609. $('#edit-code-confirm').click(async () => {
  2610. await repositoryGljObj.editCode();
  2611. });
  2612. });