glj.js 80 KB

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