glj.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575
  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. if (allowComponent.includes(me.currentCache[row].gljType)) {
  848. //展示数据
  849. if (me.currentGlj.component.length > 0) {
  850. me.currentComponent = me.getCurrentComponent(
  851. me.currentGlj.component,
  852. true
  853. );
  854. if (me.currentComponent.length > 0) {
  855. sheetsOprObj.showData(
  856. that,
  857. that.workBook.getSheet(0),
  858. that.setting,
  859. me.currentComponent
  860. );
  861. }
  862. }
  863. }
  864. } else {
  865. me.currentGlj = null;
  866. }
  867. },
  868. onSelectionChanged: function (sender, info) {
  869. let me = repositoryGljObj,
  870. that = gljComponentOprObj;
  871. //混凝土202、砂浆203、配合比204、机械3
  872. if (
  873. (info.oldSelections.length === 0 && info.newSelections.length > 0) ||
  874. info.oldSelections[0].row !== info.newSelections[0].row
  875. ) {
  876. let row = info.newSelections[0].row;
  877. me.initSel(row);
  878. }
  879. },
  880. onLeaveCell: function (sender, args) {
  881. let me = repositoryGljObj;
  882. me.lastCell = { row: args.row, col: args.col };
  883. },
  884. onEnterCell: function (sender, args) {
  885. let me = repositoryGljObj;
  886. let thisDataCode = me.setting.header[args.col].dataCode,
  887. lastDataCode = me.setting.header[me.lastCell.col].dataCode;
  888. if (
  889. thisDataCode === "unit" ||
  890. lastDataCode === "unit" ||
  891. thisDataCode === "gljType" ||
  892. lastDataCode === "gljType"
  893. ) {
  894. let rects = [];
  895. rects.push(args.sheet.getCellRect(args.row, args.col));
  896. if (me.lastCell) {
  897. rects.push(args.sheet.getCellRect(me.lastCell.row, me.lastCell.col));
  898. }
  899. for (let rect of rects) {
  900. args.sheet.repaint(rect);
  901. }
  902. //args.sheet.repaint();
  903. }
  904. me.cellRowIdx = args.row;
  905. let isHasData = false;
  906. if (me.addGljObj) {
  907. for (let i = 0; i < me.setting.header.length; i++) {
  908. if (me.addGljObj[me.setting.header[i].dataCode]) {
  909. isHasData = true;
  910. break;
  911. }
  912. }
  913. }
  914. if (isHasData) {
  915. if (me.editingRowIdx !== me.cellRowIdx) {
  916. let focusToCol;
  917. function getFocusToCol(me) {
  918. if (!me.addGljObj.code) {
  919. $("#alertGljTxt").text("编号不能为空,继续增加人材机?");
  920. return me.colMapping.fieldToCol["code"];
  921. } else if (!me.addGljObj.name) {
  922. $("#alertGljTxt").text("名称不能为空,继续增加人材机?");
  923. return me.colMapping.fieldToCol["name"];
  924. } else if (!me.addGljObj.gljType) {
  925. $("#alertGljTxt").text("类型不能为空,继续增加人材机?");
  926. return me.colMapping.fieldToCol["gljType"];
  927. } else {
  928. return -1;
  929. }
  930. }
  931. focusToCol = getFocusToCol(me);
  932. if (focusToCol !== -1) {
  933. $("#gljAlertBtn").click();
  934. $("#aleConfBtn").unbind("click");
  935. $("#aleConfBtn").bind("click", function () {
  936. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  937. me.workBook.focus(true);
  938. });
  939. $("#gljAleClose").click(function () {
  940. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, focusToCol);
  941. me.workBook.focus(true);
  942. });
  943. $("#aleCanceBtn").unbind("click");
  944. $("#aleCanceBtn").bind("click", function () {
  945. me.addGljObj = null;
  946. args.sheet.suspendEvent();
  947. args.sheet.suspendPaint();
  948. for (let col = 0; col < me.setting.header.length; col++) {
  949. if (col === 0) {
  950. me.workBook
  951. .getSheet(0)
  952. .getCell(me.editingRowIdx, 0)
  953. .formatter("@");
  954. }
  955. me.workBook.getSheet(0).getCell(me.editingRowIdx, col).value("");
  956. }
  957. me.workBook.getSheet(0).setActiveCell(me.editingRowIdx, 0);
  958. me.workBook.focus(true);
  959. args.sheet.resumeEvent();
  960. args.sheet.resumePaint();
  961. });
  962. }
  963. }
  964. }
  965. },
  966. onCellEditStart: function (sender, args) {
  967. let me = repositoryGljObj;
  968. me.orgCode = me.workBook
  969. .getSheet(0)
  970. .getValue(args.row, me.colMapping.fieldToCol["code"]);
  971. let rObj = sheetsOprObj.combineRowData(
  972. me.workBook.getSheet(0),
  973. me.setting,
  974. args.row,
  975. me
  976. );
  977. if (me.prevent) {
  978. args.cancel = true;
  979. return;
  980. }
  981. me.currentEditingGlj = rObj;
  982. if (args.row < me.currentCache.length) {
  983. let dataCode = me.setting.header[args.col].dataCode;
  984. me.currentGlj = me.currentCache[args.row];
  985. if (
  986. dataCode === "code" ||
  987. (me.feeDataCode.includes(dataCode) &&
  988. me.getParentType(me.currentGlj.gljType) !== 2)
  989. ) {
  990. //费率数据列只有材料能用
  991. args.cancel = true;
  992. } else {
  993. rObj.ID = me.currentGlj.ID;
  994. rObj.gljClass = me.currentGlj.gljClass;
  995. }
  996. } else {
  997. me.currentGlj = null;
  998. }
  999. },
  1000. dataChanged: function (objA, objB, col) {
  1001. let me = repositoryGljObj;
  1002. if (me.priceCols.includes(col)) {
  1003. if (!priceProperties || priceProperties.length === 0) {
  1004. return objA.basePrice !== objB.basePrice;
  1005. } else {
  1006. return (
  1007. objA.priceProperty[me.colMapping.colToField[col]] !==
  1008. objB.priceProperty[me.colMapping.colToField[col]]
  1009. );
  1010. }
  1011. }
  1012. return (
  1013. objA[me.colMapping.colToField[col]] !==
  1014. objB[[me.colMapping.colToField[col]]]
  1015. );
  1016. },
  1017. onCellEditEnd: function (sender, args) {
  1018. let me = repositoryGljObj,
  1019. that = gljComponentOprObj,
  1020. updateArr = [],
  1021. addArr = [],
  1022. updateBasePrcArr = [];
  1023. // 输入编号、名称、规格时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  1024. let deESCFields = ["code", "name", "specs"];
  1025. let dataCode = me.setting.header[args.col].dataCode;
  1026. if (deESCFields.includes(dataCode)) {
  1027. args.editingText = me.isDef(args.editingText)
  1028. ? args.editingText.toString().replace(/[\r\n]/g, " ")
  1029. : "";
  1030. args.sheet.setValue(args.row, args.col, args.editingText);
  1031. }
  1032. let rObj = sheetsOprObj.combineRowData(
  1033. me.workBook.getSheet(0),
  1034. me.setting,
  1035. args.row,
  1036. me
  1037. );
  1038. me.editingRowIdx = args.row;
  1039. //rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  1040. me.initPrice(rObj);
  1041. //更新
  1042. if (
  1043. me.currentEditingGlj["ID"] !== null &&
  1044. me.currentEditingGlj["ID"] !== undefined &&
  1045. me.currentGlj
  1046. ) {
  1047. rObj["ID"] = me.currentEditingGlj["ID"];
  1048. rObj.gljClass = me.currentEditingGlj.gljClass;
  1049. if (me.dataChanged(me.currentEditingGlj, rObj, args.col)) {
  1050. if (
  1051. rObj.code &&
  1052. rObj.name &&
  1053. rObj.gljType &&
  1054. rObj.code.toString().trim().length !== 0 &&
  1055. rObj.name.toString().trim().length !== 0 &&
  1056. rObj.gljType.toString().trim().length !== 0
  1057. ) {
  1058. if (rObj.gljType !== me.currentEditingGlj.gljType) {
  1059. //修改了工料机类型
  1060. if (!$("#typeAlert").is(":visible")) {
  1061. $("#typeAlert").modal("show");
  1062. }
  1063. $("#typeConfirm").unbind("click");
  1064. $("#typeConfirm").bind("click", function () {
  1065. $("#typeAlert").modal("hide");
  1066. if (me.currentGlj) {
  1067. me.currentGlj.component = [];
  1068. }
  1069. //工料机类型不为材料时,情况费率数据
  1070. if (
  1071. me.getParentType(me.currentEditingGlj.gljType) === 2 &&
  1072. me.getParentType(rObj.gljType) !== 2
  1073. ) {
  1074. for (let feeCode of me.feeDataCode) {
  1075. if (me.currentEditingGlj[feeCode]) {
  1076. rObj[feeCode] = null;
  1077. }
  1078. }
  1079. }
  1080. if (
  1081. componentType.includes(me.currentEditingGlj.gljType) &&
  1082. !(
  1083. machineComponent.includes(me.currentEditingGlj.gljType) &&
  1084. machineComponent.includes(rObj.gljType)
  1085. ) &&
  1086. !(
  1087. materialComponent.includes(me.currentEditingGlj.gljType) &&
  1088. materialComponent.includes(rObj.gljType)
  1089. )
  1090. ) {
  1091. //修改了原本是组成物的工料机
  1092. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1093. let updateGljs = me.getUpdateGljs(rObj, true);
  1094. if (
  1095. updateGljs.updateArr.length > 0 ||
  1096. updateGljs.updateBasePrcArr.length > 0
  1097. ) {
  1098. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1099. updateArr.push(updateGljs.updateArr[i]);
  1100. }
  1101. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1102. updateArr.push(updateGljs.updateBasePrcArr[i]);
  1103. }
  1104. }
  1105. }
  1106. sheetCommonObj.cleanData(
  1107. that.workBook.getSheet(0),
  1108. that.setting,
  1109. 5
  1110. );
  1111. rObj.component = me.currentGlj.component;
  1112. updateArr.push(rObj);
  1113. me.mixUpdateRequest(updateArr, [], []);
  1114. });
  1115. $(".typeClose").unbind("click");
  1116. $(".typeClose").bind("click", function () {
  1117. args.sheet.setValue(
  1118. args.row,
  1119. args.col,
  1120. _.find(me.distTypeTree.comboDatas, {
  1121. value: me.currentGlj.gljType,
  1122. }).text
  1123. );
  1124. });
  1125. return;
  1126. } else if (
  1127. (me.feeDataCode.includes(dataCode) || dataCode === "lossRate") &&
  1128. rObj[dataCode] !== me.currentEditingGlj[dataCode]
  1129. ) {
  1130. if (isNaN(rObj[dataCode])) {
  1131. args.sheet.setValue(
  1132. args.row,
  1133. args.col,
  1134. me.currentEditingGlj[dataCode]
  1135. ? me.currentEditingGlj[dataCode]
  1136. : ""
  1137. );
  1138. alert(`${me.setting.header[args.col].headerName}只能输入数值!`);
  1139. return;
  1140. }
  1141. } else if (rObj.taxRate !== me.currentEditingGlj.taxRate) {
  1142. if (isNaN(rObj.taxRate)) {
  1143. args.sheet.setValue(
  1144. args.row,
  1145. args.col,
  1146. me.currentEditingGlj.taxRate || ""
  1147. );
  1148. alert("税率只能输入数值!");
  1149. return;
  1150. }
  1151. rObj.taxRate = scMathUtil.roundTo(parseFloat(rObj.taxRate), -2);
  1152. } else if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  1153. //修改了单价,可修改单价的必为可成为组成物的
  1154. let rObjPrice = me.getPrice(rObj, args.col),
  1155. editingGljPrice = me.getPrice(me.currentEditingGlj, args.col);
  1156. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1157. if (isNaN(parseFloat(rObjPrice))) {
  1158. alert("单价只能输入数值!");
  1159. args.sheet.setValue(
  1160. args.row,
  1161. args.col,
  1162. editingGljPrice ? editingGljPrice : 0
  1163. );
  1164. return;
  1165. }
  1166. me.setGljPrice(
  1167. rObj,
  1168. scMathUtil.roundTo(parseFloat(rObjPrice), -2),
  1169. args.col
  1170. );
  1171. let updateGljs = me.getUpdateGljs(rObj);
  1172. if (
  1173. updateGljs.updateArr.length > 0 ||
  1174. updateGljs.updateBasePrcArr.length > 0
  1175. ) {
  1176. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1177. updateArr.push(updateGljs.updateArr[i]);
  1178. }
  1179. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1180. updateArr.push(updateGljs.updateBasePrcArr[i]);
  1181. }
  1182. }
  1183. }
  1184. rObj.component = me.currentGlj.component;
  1185. updateArr.push(rObj);
  1186. } else {
  1187. if (dataCode === "gljType") {
  1188. let distTypeVal =
  1189. me.distTypeTree.distTypes[
  1190. me.distTypeTree.prefix + me.currentEditingGlj[dataCode]
  1191. ].data.fullName;
  1192. args.sheet.setValue(args.row, args.col, distTypeVal);
  1193. } else {
  1194. args.sheet.setValue(
  1195. args.row,
  1196. args.col,
  1197. me.currentEditingGlj[dataCode]
  1198. );
  1199. }
  1200. }
  1201. }
  1202. if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  1203. //update basePrice of ration when editting basePrice of glj
  1204. let gljType = -1;
  1205. let gljTypeParent =
  1206. me.distTypeTree.distTypes[
  1207. me.distTypeTree.prefix + me.currentEditingGlj.gljType
  1208. ].parent;
  1209. if (gljTypeParent && gljTypeParent.data.ID <= 3) {
  1210. gljType = gljTypeParent.data.ID;
  1211. }
  1212. if (!gljTypeParent && me.currentEditingGlj.gljType <= 3) {
  1213. gljType = me.currentEditingGlj.gljType;
  1214. }
  1215. let gljBasePrcObj = {
  1216. gljId: me.currentEditingGlj.ID,
  1217. gljType: gljType,
  1218. basePrice: me.getRationGljPrice(rObj),
  1219. };
  1220. if (gljBasePrcObj.gljType !== -1) {
  1221. updateBasePrcArr.push(gljBasePrcObj);
  1222. if (me.rationLibs.length > 0) {
  1223. //重算定额单价
  1224. me.updateRationBasePrcRq(updateBasePrcArr);
  1225. }
  1226. }
  1227. }
  1228. } else {
  1229. //新增
  1230. if (typeof rObj.code !== "undefined") {
  1231. me.addGljObj = rObj;
  1232. let isCanSav = true;
  1233. if (!rObj.code || !rObj.name || !rObj.gljType) {
  1234. isCanSav = false;
  1235. }
  1236. if (isCanSav) {
  1237. me.addGljObj = null;
  1238. rObj.component = [];
  1239. me.initPrice(rObj);
  1240. addArr.push(rObj);
  1241. }
  1242. }
  1243. }
  1244. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1245. rObj.gljClass = me.gljCurTypeId;
  1246. rObj.classSeq = me.gljCurClassSeq;
  1247. }
  1248. if (updateArr.length > 0 || addArr.length > 0) {
  1249. me.currentEditingGlj = null;
  1250. me.mixUpdateRequest(updateArr, addArr, []);
  1251. }
  1252. },
  1253. delGljs: function (sels) {
  1254. let me = repositoryGljObj;
  1255. let sheet = me.workBook.getSheet(0),
  1256. updateArr = [],
  1257. removeArr = [],
  1258. removeIDs = [],
  1259. removeNames = [],
  1260. updateBasePrcArr = [], //删除基价单位后重新计算
  1261. canUpdate = false,
  1262. cacheSection = me.currentCache,
  1263. updateBackups = [];
  1264. if (sels.length > 0 && cacheSection.length > 0) {
  1265. for (let i = 0; i < sels.length; i++) {
  1266. if (sels[i].colCount === me.setting.header.length) {
  1267. for (let j = 0; j < sels[i].rowCount; j++) {
  1268. if (sels[i].row + j < cacheSection.length) {
  1269. removeArr.push(cacheSection[sels[i].row + j]);
  1270. removeIDs.push(cacheSection[sels[i].row + j].ID);
  1271. removeNames.push(cacheSection[sels[i].row + j].name);
  1272. //删除后重新计算引用了此工料机的定额单价
  1273. updateBasePrcArr.push({
  1274. gljId: cacheSection[sels[i].row + j].ID,
  1275. gljType: cacheSection[sels[i].row + j].gljType,
  1276. basePrice: 0,
  1277. delete: 1,
  1278. });
  1279. }
  1280. }
  1281. } else {
  1282. let maxCol = sels[i].col + sels[i].colCount - 1;
  1283. let cantNullDataCode = ["code", "name", "gljType"];
  1284. for (let j = 0; j < sels[i].rowCount; j++) {
  1285. if (sels[i].row + j < cacheSection.length) {
  1286. let updateObj = cacheSection[sels[i].row + j];
  1287. for (let col = sels[i].col; col <= maxCol; col++) {
  1288. let dataCode = me.setting.header[col].dataCode;
  1289. if (cantNullDataCode.includes(dataCode)) {
  1290. $("#alertText").text(
  1291. me.setting.header[col].headerName + "不可为空!"
  1292. );
  1293. $("#codeAlert").modal("show");
  1294. return false;
  1295. } else {
  1296. canUpdate = true;
  1297. break;
  1298. }
  1299. }
  1300. }
  1301. }
  1302. }
  1303. }
  1304. if (canUpdate) {
  1305. //删除警告
  1306. let upAlertText = "确认删除选中字段?";
  1307. $("#alertGljTxt").text(upAlertText);
  1308. $("#gljAlert").modal("show");
  1309. $("#aleConfBtn").unbind("click");
  1310. //确认
  1311. $("#aleConfBtn").bind("click", function () {
  1312. for (let i = 0; i < sels.length; i++) {
  1313. let maxCol = sels[i].col + sels[i].colCount - 1;
  1314. for (let j = 0; j < sels[i].rowCount; j++) {
  1315. if (sels[i].row + j < cacheSection.length) {
  1316. let updateObj = cacheSection[sels[i].row + j];
  1317. for (let col = sels[i].col; col <= maxCol; col++) {
  1318. let dataCode = me.setting.header[col].dataCode;
  1319. if (me.priceCols.includes(col)) {
  1320. me.setGljPrice(updateObj, 0, col);
  1321. updateBasePrcArr.push({
  1322. gljId: updateObj.ID,
  1323. gljType: updateObj.gljType,
  1324. basePrice: 0,
  1325. });
  1326. } else {
  1327. updateObj[dataCode] = "";
  1328. }
  1329. }
  1330. updateArr.push(updateObj);
  1331. }
  1332. }
  1333. }
  1334. me.mixUpdateRequest(updateArr, [], []);
  1335. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1336. me.updateRationBasePrcRq(updateBasePrcArr);
  1337. }
  1338. });
  1339. }
  1340. if (removeArr.length > 0) {
  1341. $.bootstrapLoading.start();
  1342. CommonAjax.post(
  1343. "/stdGljRepository/api/isUsed",
  1344. { gljIds: removeIDs },
  1345. function (rstData) {
  1346. $.bootstrapLoading.end();
  1347. //存在被引用的人材机(标准/补充定额库)
  1348. if (rstData.isUsed) {
  1349. $("#gljAlert")
  1350. .find(".modal-body h5")
  1351. .text("已有定额引用了当前人材机,不可删除。");
  1352. $("#gljAlert").modal("show");
  1353. $("#aleConfBtn").unbind("click");
  1354. $("#aleConfBtn").bind("click", function () {
  1355. $("#gljAlert").modal("hide");
  1356. me.workBook.focus(true);
  1357. });
  1358. } else {
  1359. $("#gljAlert")
  1360. .find(".modal-body h5")
  1361. .text(`确定要删除人材机 “${removeNames.join(",")}” 吗? `);
  1362. setTimeout(function () {
  1363. $("#gljAlert").modal("show");
  1364. }, 200);
  1365. //确认
  1366. $("#aleConfBtn").unbind("click");
  1367. $("#aleConfBtn").bind("click", function () {
  1368. for (let removeD of removeArr) {
  1369. let updateGljs = me.getUpdateGljs(removeD, true);
  1370. if (updateGljs.updateArr.length > 0) {
  1371. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1372. updateArr.push(updateGljs.updateArr[i]);
  1373. }
  1374. }
  1375. }
  1376. me.mixUpdateRequest(updateArr, [], removeIDs);
  1377. /* if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1378. me.updateRationBasePrcRq(updateBasePrcArr);
  1379. me.workBook.focus(true);
  1380. }*/
  1381. });
  1382. }
  1383. },
  1384. function () {
  1385. $.bootstrapLoading.end();
  1386. $("#gljAlert")
  1387. .find(".modal-body h5")
  1388. .text("查询引用错误,不可删除。");
  1389. $("#gljAlert").modal("show");
  1390. $("#aleConfBtn").unbind("click");
  1391. $("#aleConfBtn").bind("click", function () {
  1392. $("#gljAlert").modal("hide");
  1393. me.workBook.focus(true);
  1394. });
  1395. }
  1396. );
  1397. }
  1398. }
  1399. },
  1400. //删除人材机前需要判断人材机是否有被引用,被引用了则不可删除
  1401. repositoryGljDelOpr: function () {
  1402. if (locked) {
  1403. return;
  1404. }
  1405. let me = repositoryGljObj;
  1406. me.workBook.commandManager().register("repositoryGljDel", function () {
  1407. let sels = me.workBook.getActiveSheet().getSelections();
  1408. me.delGljs(sels);
  1409. });
  1410. me.workBook
  1411. .commandManager()
  1412. .setShortcutKey(
  1413. null,
  1414. GC.Spread.Commands.Key.del,
  1415. false,
  1416. false,
  1417. false,
  1418. false
  1419. );
  1420. me.workBook
  1421. .commandManager()
  1422. .setShortcutKey(
  1423. "repositoryGljDel",
  1424. GC.Spread.Commands.Key.del,
  1425. false,
  1426. false,
  1427. false,
  1428. false
  1429. );
  1430. },
  1431. onContextmenuOpr: function () {
  1432. let me = repositoryGljObj;
  1433. $.contextMenu({
  1434. selector: "#GLJListSheet",
  1435. build: function ($triggerElement, e) {
  1436. //控制允许右键菜单在哪个位置出现
  1437. let sheet = me.workBook.getSheet(0);
  1438. let offset = $("#GLJListSheet").offset(),
  1439. x = e.pageX - offset.left,
  1440. y = e.pageY - offset.top;
  1441. let target = sheet.hitTest(x, y);
  1442. let sel = sheet.getSelections()[0];
  1443. if (sel.row === -1) {
  1444. sel.row = 0;
  1445. }
  1446. if (sel.col === -1) {
  1447. sel.col = 0;
  1448. }
  1449. if (
  1450. target.hitTestType === 3 &&
  1451. typeof target.row !== "undefined" &&
  1452. typeof target.col !== "undefined"
  1453. ) {
  1454. //在表格内
  1455. me.initSel(target.row);
  1456. if (
  1457. sel.row > target.row ||
  1458. sel.row + sel.rowCount - 1 < target.row ||
  1459. sel.col > target.col ||
  1460. sel.col + sel.colCount - 1 < target.col
  1461. ) {
  1462. sheet.setActiveCell(target.row, target.col);
  1463. }
  1464. return {
  1465. callback: function () {},
  1466. items: {
  1467. delete: {
  1468. name: "删除",
  1469. disabled: function () {
  1470. return (
  1471. locked || !(me.currentCache && me.currentCache[target.row])
  1472. );
  1473. },
  1474. icon: "fa-remove",
  1475. callback: function (key, opt) {
  1476. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  1477. curSel.colCount = me.setting.header.length;
  1478. me.delGljs([curSel]);
  1479. },
  1480. },
  1481. getReference: {
  1482. name: "查找引用",
  1483. disabled: function () {
  1484. return !(me.currentCache && me.currentCache[target.row]);
  1485. },
  1486. icon: "fa-search",
  1487. callback: function () {
  1488. const glj = me.currentCache[target.row];
  1489. me.getReference(glj);
  1490. },
  1491. },
  1492. getUsedInfo: {
  1493. name: "查找用户使用情况",
  1494. disabled: function () {
  1495. return !(me.currentCache && me.currentCache[target.row]);
  1496. },
  1497. icon: "fa-search",
  1498. callback: function () {
  1499. const glj = me.currentCache[target.row];
  1500. me.getUsedInfo(glj);
  1501. },
  1502. },
  1503. moveTo: {
  1504. name: "移动分类至…",
  1505. disabled: function () {
  1506. return (
  1507. locked || !(me.currentCache && me.currentCache[target.row])
  1508. );
  1509. },
  1510. icon: "fa-exchange",
  1511. callback: function (key, opt) {
  1512. me.moveTo([]);
  1513. },
  1514. },
  1515. },
  1516. };
  1517. } else {
  1518. return false;
  1519. }
  1520. },
  1521. });
  1522. },
  1523. getReference: function (glj) {
  1524. const $info = $("#info");
  1525. const $infoBody = $("#infoBody");
  1526. $.bootstrapLoading.start();
  1527. CommonAjax.post(
  1528. "/stdGljRepository/api/getReference",
  1529. { repositoryId: glj.repositoryId, gljId: glj.ID },
  1530. function (info) {
  1531. const htmlArr = [];
  1532. if (!info || !Object.keys(info).length) {
  1533. htmlArr.push("<li>无引用数据</li>");
  1534. }
  1535. for (let libName in info) {
  1536. htmlArr.push(`<li class="list-title">${libName}</li>`);
  1537. const rations = info[libName];
  1538. const rationList = rations.map((ration) => {
  1539. if (ration.rationRepId) {
  1540. return `<li>
  1541. <span>${ration.code}</span>
  1542. <a target="_blank" href="/rationRepository/ration?repository=${ration.rationRepId}&locked=${locked}#${ration.code}">定位</a>
  1543. </li>`;
  1544. }
  1545. return `<li><span>${ration.code}</span></li>`;
  1546. });
  1547. htmlArr.push(...rationList);
  1548. }
  1549. $infoBody.html(htmlArr.join(""));
  1550. $info.modal("show");
  1551. $.bootstrapLoading.end();
  1552. },
  1553. function () {
  1554. $.bootstrapLoading.end();
  1555. }
  1556. );
  1557. },
  1558. moveTo: function () {
  1559. $("#moveToConfirm").prop("disabled", true);
  1560. $("#moveTo").modal("show");
  1561. },
  1562. getUsedInfo: function (glj) {
  1563. $.bootstrapLoading.start();
  1564. $("#usedInfo").modal("show");
  1565. CommonAjax.post(
  1566. "/stdGljRepository/api/getUsedInfo",
  1567. { repositoryId: glj.repositoryId, gljId: glj.ID },
  1568. function (info) {
  1569. $("#usedTotal").html(`共${info.length}项记录`);
  1570. let htmlString = "";
  1571. for (let u of info) {
  1572. htmlString += `<tr><td>${u.ID}</td><td>${u.username}</td> <td>${u.mobile}</td></tr>`;
  1573. }
  1574. $("#userInfoShowArea").html(htmlString);
  1575. $.bootstrapLoading.end();
  1576. },
  1577. function () {
  1578. $.bootstrapLoading.end();
  1579. }
  1580. );
  1581. },
  1582. validUpdateObj: function (pasteObj, rowIdx) {
  1583. let rst = { updateGlj: [], updateBasePrcArr: [] },
  1584. backUpObj = {},
  1585. me = repositoryGljObj,
  1586. that = gljComponentOprObj,
  1587. tempObj = me.currentCache[rowIdx],
  1588. reCalBasePrc = false,
  1589. isValid = true;
  1590. //备份原始数据
  1591. for (let atr in tempObj) {
  1592. backUpObj[atr] = tempObj[atr];
  1593. }
  1594. if (typeof pasteObj.code !== "undefined") {
  1595. if (pasteObj.code.trim().length !== 0) {
  1596. let isExist = false;
  1597. for (let i = 0; i < me.gljList.length; i++) {
  1598. if (me.gljList[i].code === pasteObj.code) {
  1599. isExist = true;
  1600. break;
  1601. }
  1602. }
  1603. if (!isExist) {
  1604. tempObj.code = pasteObj.code;
  1605. } else isValid = false;
  1606. } else isValid = false;
  1607. }
  1608. if (typeof pasteObj.name !== "undefined") {
  1609. if (pasteObj.name.trim().length === 0) isValid = false;
  1610. else tempObj.name = pasteObj.name;
  1611. }
  1612. if (typeof pasteObj.specs !== "undefined") {
  1613. tempObj.specs = pasteObj.specs;
  1614. }
  1615. if (typeof pasteObj.unit !== "undefined") {
  1616. tempObj.unit = pasteObj.unit;
  1617. }
  1618. if (typeof pasteObj.lossRate !== "undefined" && !isNaN(pasteObj.lossRate)) {
  1619. tempObj.lossRate = pasteObj.lossRate;
  1620. }
  1621. if (typeof pasteObj.taxRate !== "undefined" && !isNaN(pasteObj.taxRate)) {
  1622. tempObj.taxRate = pasteObj.taxRate;
  1623. }
  1624. if (typeof pasteObj.gljType !== "undefined") {
  1625. let isExsit = false;
  1626. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1627. if (pasteObj.gljType === me.distTypeTree.comboDatas[i].text) {
  1628. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1629. isExsit = true;
  1630. if (
  1631. me.getParentType(pasteObj.gljType) !== 2 &&
  1632. me.getParentType(tempObj.gljType) === 2
  1633. ) {
  1634. for (let feeCode of me.feeDataCode) {
  1635. tempObj[feeCode] = null;
  1636. }
  1637. }
  1638. if (
  1639. componentType.includes(tempObj.gljType) &&
  1640. !(
  1641. machineComponent.includes(tempObj.gljType) &&
  1642. machineComponent.includes(pasteObj.gljType)
  1643. ) &&
  1644. !(
  1645. materialComponent.includes(tempObj.gljType) &&
  1646. materialComponent.includes(pasteObj.gljType)
  1647. )
  1648. ) {
  1649. //修改了原本是组成物的工料机
  1650. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1651. let updateGljs = me.getUpdateGljs(tempObj, true);
  1652. if (
  1653. updateGljs.updateArr.length > 0 ||
  1654. updateGljs.updateBasePrcArr.length > 0
  1655. ) {
  1656. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1657. rst.updateGlj.push(updateGljs.updateArr[i]);
  1658. }
  1659. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1660. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1661. }
  1662. }
  1663. }
  1664. tempObj.component =
  1665. tempObj.gljType === pasteObj.gljType ? tempObj.component : [];
  1666. tempObj.gljType = pasteObj.gljType;
  1667. tempObj.shortName =
  1668. me.distTypeTree.distTypes[
  1669. me.distTypeTree.prefix + tempObj.gljType
  1670. ].data.shortName;
  1671. break;
  1672. }
  1673. }
  1674. if (!isExsit) {
  1675. isValid = false;
  1676. }
  1677. }
  1678. for (let feeCode of me.feeDataCode) {
  1679. if (
  1680. typeof pasteObj[feeCode] !== "undefined" &&
  1681. !isNaN(pasteObj[feeCode])
  1682. ) {
  1683. if (
  1684. (typeof pasteObj.gljType !== "undefined" &&
  1685. me.getParentType(pasteObj.gljType) === 2) ||
  1686. (tempObj.gljType && me.getParentType(tempObj.gljType) === 2)
  1687. ) {
  1688. tempObj[feeCode] = pasteObj[feeCode];
  1689. } else {
  1690. isValid = false;
  1691. }
  1692. }
  1693. }
  1694. //单价相关
  1695. if (me.pasteIncludesPrice(pasteObj)) {
  1696. if (!priceProperties || priceProperties.length === 0) {
  1697. pasteObj.basePrice =
  1698. pasteObj.basePrice && !isNaN(parseFloat(pasteObj.basePrice))
  1699. ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2)
  1700. : me.currentCache[rowIdx].basePrice;
  1701. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1702. reCalBasePrc = true;
  1703. tempObj.basePrice = pasteObj.basePrice;
  1704. }
  1705. } else {
  1706. //多单价粘贴
  1707. let pastePriceProperty = {};
  1708. let priceFields = me.getPriceFields();
  1709. for (let priceField of priceFields) {
  1710. if (
  1711. typeof pasteObj[priceField] !== "undefined" &&
  1712. pasteObj[priceField] &&
  1713. !isNaN(parseFloat(pasteObj[priceField]))
  1714. ) {
  1715. pastePriceProperty[priceField] = scMathUtil.roundTo(
  1716. parseFloat(pasteObj[priceField]),
  1717. -2
  1718. );
  1719. }
  1720. }
  1721. if (!me.priceIsEqual(tempObj, pasteObj)) {
  1722. reCalBasePrc = true;
  1723. //更新人材机单价
  1724. for (let priceField in pastePriceProperty) {
  1725. tempObj.priceProperty[priceField] = pastePriceProperty[priceField];
  1726. }
  1727. }
  1728. }
  1729. let updateGljs = me.getUpdateGljs(tempObj, false);
  1730. if (
  1731. updateGljs.updateArr.length > 0 ||
  1732. updateGljs.updateBasePrcArr.length > 0
  1733. ) {
  1734. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1735. rst.updateGlj.push(updateGljs.updateArr[i]);
  1736. }
  1737. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1738. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1739. }
  1740. }
  1741. }
  1742. if (isValid) {
  1743. rst.updateGlj.push(tempObj);
  1744. if (reCalBasePrc) {
  1745. //重新计算定额基价对象
  1746. let newReObj = {
  1747. gljId: tempObj.ID,
  1748. gljType: tempObj.gljType,
  1749. basePrice: me.getRationGljPrice(tempObj),
  1750. };
  1751. rst.updateBasePrcArr.push(newReObj);
  1752. }
  1753. } else {
  1754. for (let attr in backUpObj) {
  1755. tempObj[attr] = backUpObj[attr];
  1756. }
  1757. }
  1758. return rst;
  1759. },
  1760. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  1761. isValidObj: function (pasteObj) {
  1762. let me = repositoryGljObj;
  1763. if (
  1764. !(pasteObj.code && typeof pasteObj.code !== "undefined") ||
  1765. !(pasteObj.name && typeof pasteObj.name !== "undefined") ||
  1766. !(pasteObj.gljType && typeof pasteObj.gljType !== "undefined")
  1767. ) {
  1768. return false;
  1769. }
  1770. if (pasteObj.gljType && typeof pasteObj.gljType !== "undefined") {
  1771. let isExist = false;
  1772. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1773. if (me.distTypeTree.comboDatas[i].text === pasteObj.gljType) {
  1774. isExist = true;
  1775. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1776. pasteObj.shortName =
  1777. me.distTypeTree.distTypes[
  1778. me.distTypeTree.prefix + pasteObj.gljType
  1779. ].data.shortName;
  1780. break;
  1781. }
  1782. }
  1783. if (!isExist) {
  1784. return false;
  1785. }
  1786. }
  1787. if (pasteObj.code && typeof pasteObj.code !== "undefined") {
  1788. for (let i = 0; i < me.gljList.length; i++) {
  1789. if (me.gljList[i].code === pasteObj.code) {
  1790. return false;
  1791. }
  1792. }
  1793. }
  1794. if (typeof pasteObj.lossRate !== "undefined" && isNaN(pasteObj[feeCode])) {
  1795. return false;
  1796. }
  1797. for (let feeCode of me.feeDataCode) {
  1798. if (
  1799. typeof pasteObj[feeCode] !== "undefined" &&
  1800. (isNaN(pasteObj[feeCode]) || me.getParentType(pasteObj.gljType) !== 2)
  1801. ) {
  1802. return false;
  1803. }
  1804. }
  1805. if (!priceProperties || priceProperties.length === 0) {
  1806. pasteObj.basePrice =
  1807. !isNaN(parseFloat(pasteObj.basePrice)) &&
  1808. pasteObj.basePrice &&
  1809. typeof pasteObj.basePrice !== "undefined"
  1810. ? parseFloat(pasteObj.basePrice)
  1811. : 0;
  1812. } else {
  1813. let pastePriceProperty = {};
  1814. let priceFields = me.getPriceFields();
  1815. for (let priceField of priceFields) {
  1816. if (
  1817. typeof pasteObj[priceField] !== "undefined" &&
  1818. pasteObj[priceField] &&
  1819. !isNaN(parseFloat(pasteObj[priceField]))
  1820. ) {
  1821. pastePriceProperty[priceField] = scMathUtil.roundTo(
  1822. parseFloat(pasteObj[priceField]),
  1823. -2
  1824. );
  1825. } else {
  1826. pastePriceProperty[priceField] = 0;
  1827. }
  1828. }
  1829. pasteObj.priceProperty = pastePriceProperty;
  1830. }
  1831. //pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1832. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1833. pasteObj.gljClass = me.gljCurTypeId;
  1834. pasteObj.classSeq = me.gljCurClassSeq;
  1835. }
  1836. return true;
  1837. },
  1838. canPasted: function (info) {
  1839. let rst = true;
  1840. let me = repositoryGljObj;
  1841. if (me.gljCurTypeId < 0) {
  1842. return false;
  1843. }
  1844. //粘贴的最大列下标不超过总列数
  1845. if (
  1846. info.cellRange.col + info.cellRange.colCount - 1 >
  1847. me.setting.header.length - 1
  1848. ) {
  1849. return false;
  1850. }
  1851. if (info.cellRange.row < me.currentCache.length) {
  1852. if (info.cellRange.col === 0) {
  1853. return false;
  1854. }
  1855. }
  1856. return rst;
  1857. },
  1858. onClipboardPasting: function (sender, args) {
  1859. let me = repositoryGljObj;
  1860. //复制的列数超过正确的列数,不可复制
  1861. if (me.prevent) {
  1862. args.cancel = true;
  1863. return;
  1864. }
  1865. if (!me.canPasted(args)) {
  1866. args.cancel = true;
  1867. }
  1868. },
  1869. onClipboardPasted: function (e, info) {
  1870. $.bootstrapLoading.start();
  1871. let me = repositoryGljObj;
  1872. let updateArr = [],
  1873. addArr = [];
  1874. let items = sheetCommonObj.analyzePasteData(me.setting, info);
  1875. let beginRow = info.cellRange.row,
  1876. endRow = info.cellRange.row + info.cellRange.rowCount - 1,
  1877. maxRow = me.currentCache.length - 1,
  1878. updateBasePrcArr = [],
  1879. updateCount,
  1880. resumeArr = [];
  1881. if (endRow <= maxRow) {
  1882. for (let i = 0; i < items.length; i++) {
  1883. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1884. if (
  1885. updateObj &&
  1886. typeof updateObj.updateGlj !== "undefined" &&
  1887. updateObj.updateGlj.length > 0
  1888. ) {
  1889. updateArr = updateArr.concat(updateObj.updateGlj);
  1890. if (typeof updateObj.updateBasePrcArr !== "undefined") {
  1891. updateBasePrcArr = updateBasePrcArr.concat(
  1892. updateObj.updateBasePrcArr
  1893. );
  1894. }
  1895. }
  1896. }
  1897. } else if (beginRow <= maxRow && endRow > maxRow) {
  1898. updateCount = maxRow - beginRow + 1;
  1899. for (let i = 0; i < updateCount; i++) {
  1900. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1901. if (updateObj && typeof updateObj.updateGlj !== "undefined") {
  1902. updateArr = updateArr.concat(updateObj.updateGlj);
  1903. if (typeof updateObj.updateBasePrcArr !== "undefined") {
  1904. updateBasePrcArr = updateBasePrcArr.concat(
  1905. updateObj.updateBasePrcArr
  1906. );
  1907. }
  1908. }
  1909. }
  1910. //[code, ..., gljType]
  1911. if (
  1912. info.cellRange.colCount >= 5 &&
  1913. info.cellRange.colCount <= me.setting.header.length
  1914. ) {
  1915. for (let i = updateCount; i < items.length; i++) {
  1916. if (me.isValidObj(items[i])) {
  1917. items[i].component = [];
  1918. addArr.push(items[i]);
  1919. }
  1920. }
  1921. }
  1922. } else {
  1923. //粘贴的的最大列至少要等于工料机类型列,因为工料机类型必须有效才可新增
  1924. if (
  1925. info.cellRange.colCount >= 5 &&
  1926. info.cellRange.colCount <= me.setting.header.length &&
  1927. info.cellRange.col + info.cellRange.colCount - 1 >=
  1928. me.colMapping.fieldToCol["gljType"]
  1929. ) {
  1930. for (let i = 0; i < items.length; i++) {
  1931. if (me.isValidObj(items[i])) {
  1932. items[i].component = [];
  1933. addArr.push(items[i]);
  1934. }
  1935. }
  1936. }
  1937. }
  1938. //repaint
  1939. for (let i = 0; i < info.cellRange.rowCount; i++) {
  1940. resumeArr.push(info.cellRange.row + i);
  1941. }
  1942. if (resumeArr.length > 0) {
  1943. info.sheet.suspendPaint();
  1944. for (let i = 0; i < resumeArr.length; i++) {
  1945. if (resumeArr[i] < me.currentCache.length) {
  1946. for (let col = 0; col < me.setting.header.length; col++) {
  1947. let dCode = me.setting.header[col].dataCode;
  1948. if (me.priceCols.includes(col)) {
  1949. let price = me.getPrice(me.currentCache[resumeArr[i]], col);
  1950. info.sheet.setValue(resumeArr[i], col, price ? price : 0);
  1951. } else if (dCode === "gljType") {
  1952. let gljType = me.currentCache[resumeArr[i]][dCode];
  1953. info.sheet.setValue(
  1954. resumeArr[i],
  1955. col,
  1956. me.distTypeTree.distTypes["gljType" + gljType].data.fullName
  1957. );
  1958. } else {
  1959. info.sheet.setValue(
  1960. resumeArr[i],
  1961. col,
  1962. me.currentCache[resumeArr[i]][dCode]
  1963. );
  1964. }
  1965. }
  1966. } else {
  1967. for (let col = 0; col < me.setting.header.length; col++) {
  1968. info.sheet.setValue(resumeArr[i], col, "");
  1969. }
  1970. }
  1971. }
  1972. info.sheet.resumePaint();
  1973. }
  1974. if (updateArr.length > 0 || addArr.length > 0) {
  1975. me.mixUpdateRequest(updateArr, addArr, []);
  1976. } else {
  1977. $.bootstrapLoading.end();
  1978. }
  1979. if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1980. me.updateRationBasePrcRq(updateBasePrcArr);
  1981. }
  1982. },
  1983. updateRationBasePrcRq: function (basePrcArr, workBook, callback) {
  1984. let me = this;
  1985. me.prevent = true;
  1986. if (!$.bootstrapLoading.isLoading()) {
  1987. $.bootstrapLoading.start();
  1988. }
  1989. $.ajax({
  1990. type: "post",
  1991. url: "api/updateRationBasePrc",
  1992. data: { basePrcArr: JSON.stringify(basePrcArr) },
  1993. dataType: "json",
  1994. success: function (result) {
  1995. if (result.error) {
  1996. alert("计算定额基价失败");
  1997. }
  1998. if (workBook) {
  1999. workBook.focus(true);
  2000. } else {
  2001. me.workBook.focus(true);
  2002. }
  2003. me.prevent = false;
  2004. if (callback) {
  2005. callback();
  2006. }
  2007. if ($.bootstrapLoading.isLoading()) {
  2008. $.bootstrapLoading.end();
  2009. }
  2010. },
  2011. });
  2012. },
  2013. mixUpdateRequest: function (updateArr, addArr, removeIds) {
  2014. let me = repositoryGljObj;
  2015. if (updateArr.length > 0) {
  2016. me.saveInString(updateArr);
  2017. }
  2018. if (addArr.length > 0) {
  2019. const codeMap = {};
  2020. const uniqueCodeAddArr = [];
  2021. addArr.forEach((item) => {
  2022. if (!codeMap[item.code]) {
  2023. codeMap[item.code] = 1;
  2024. uniqueCodeAddArr.push(item);
  2025. }
  2026. });
  2027. addArr = uniqueCodeAddArr;
  2028. me.saveInString(addArr);
  2029. }
  2030. $.ajax({
  2031. type: "POST",
  2032. url: "api/mixUpdateGljItems",
  2033. data: {
  2034. repositoryId: me.currentRepositoryId,
  2035. lastOpr: userAccount,
  2036. updateItems: JSON.stringify(updateArr),
  2037. addItems: JSON.stringify(addArr),
  2038. removeIds: JSON.stringify(removeIds),
  2039. },
  2040. dataType: "json",
  2041. cache: false,
  2042. timeout: 50000,
  2043. success: function (result) {
  2044. if (result.error) {
  2045. alert(result.message);
  2046. } else {
  2047. const failCodes = result.data.failCode;
  2048. if (failCodes && failCodes.length) {
  2049. let failText = "";
  2050. failCodes.forEach((code) => {
  2051. failText += `<p>编码“${code}”已存在</p>`;
  2052. });
  2053. $("#alertText").html(failText);
  2054. $("#codeAlert").modal("show");
  2055. }
  2056. const insertData = result.data.insertData;
  2057. me.updateCache(insertData, updateArr, removeIds);
  2058. //me.sortGlj();
  2059. if (me.currentOprParent === 1) {
  2060. me.currentCache = me.getParentCache(
  2061. me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]
  2062. );
  2063. } else {
  2064. me.currentCache = me.getCache();
  2065. }
  2066. me.showGljItems(me.currentCache, me.gljCurTypeId);
  2067. //getCurrentGlj
  2068. let row = me.workBook.getSheet(0).getSelections()[0].row;
  2069. me.currentGlj =
  2070. row < me.currentCache.length ? me.currentCache[row] : null;
  2071. me.currentComponent = me.currentGlj
  2072. ? me.getCurrentComponent(me.currentGlj.component)
  2073. : [];
  2074. sheetCommonObj.cleanData(
  2075. gljComponentOprObj.workBook.getSheet(0),
  2076. gljComponentOprObj.setting,
  2077. -1
  2078. );
  2079. sheetsOprObj.showData(
  2080. gljComponentOprObj,
  2081. gljComponentOprObj.workBook.getSheet(0),
  2082. gljComponentOprObj.setting,
  2083. me.currentComponent
  2084. );
  2085. }
  2086. if ($.bootstrapLoading.isLoading()) {
  2087. $.bootstrapLoading.end();
  2088. }
  2089. },
  2090. error: function (err) {
  2091. if ($.bootstrapLoading.isLoading()) {
  2092. $.bootstrapLoading.end();
  2093. }
  2094. console.log(err);
  2095. alert("保存失败");
  2096. },
  2097. });
  2098. },
  2099. saveInString: function (datas) {
  2100. for (let i = 0, len = datas.length; i < len; i++) {
  2101. let data = datas[i];
  2102. if (_exist(data, "basePrice")) {
  2103. data["basePrice"] = data["basePrice"].toString();
  2104. }
  2105. if (_exist(data, "component")) {
  2106. for (let j = 0, jLen = data["component"].length; j < jLen; j++) {
  2107. let comGljObj = data["component"][j];
  2108. if (_exist(comGljObj, "consumeAmt")) {
  2109. comGljObj["consumeAmt"] = comGljObj["consumeAmt"].toString();
  2110. }
  2111. }
  2112. }
  2113. }
  2114. function _exist(data, attr) {
  2115. return data && data[attr] !== undefined && data[attr];
  2116. }
  2117. },
  2118. getParentCache: function (nodes) {
  2119. let me = repositoryGljObj,
  2120. rst = [];
  2121. for (let i = 0; i < me.gljList.length; i++) {
  2122. if (nodes.indexOf(me.gljList[i].gljClass) !== -1) {
  2123. rst.push(me.gljList[i]);
  2124. }
  2125. }
  2126. rst.sort(function (a, b) {
  2127. let rst = 0;
  2128. if (a.code > b.code) rst = 1;
  2129. else if (a.code < b.code) rst = -1;
  2130. return rst;
  2131. });
  2132. return rst;
  2133. },
  2134. getCache: function () {
  2135. let me = this,
  2136. rst = [];
  2137. for (let i = 0; i < me.gljList.length; i++) {
  2138. if (me.gljList[i].gljClass == me.gljCurTypeId) {
  2139. rst.push(me.gljList[i]);
  2140. }
  2141. }
  2142. return rst;
  2143. },
  2144. updateCache: function (insertData, updateArr, removeIds) {
  2145. let me = this,
  2146. cacheSection = me.gljList;
  2147. if (insertData && insertData.length > 0) {
  2148. me.gljList = me.gljList.concat(insertData);
  2149. cacheSection = me.gljList;
  2150. }
  2151. for (let i = removeIds.length - 1; i >= 0; i--) {
  2152. for (let j = cacheSection.length - 1; j >= 0; j--) {
  2153. if (cacheSection[j]["ID"] == removeIds[i]) {
  2154. cacheSection.splice(j, 1);
  2155. }
  2156. }
  2157. }
  2158. for (let i = 0; i < updateArr.length; i++) {
  2159. for (let j = 0; j < cacheSection.length; j++) {
  2160. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  2161. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  2162. cacheSection[j] = updateArr[i];
  2163. }
  2164. } else {
  2165. if (cacheSection[j]["code"] == updateArr[i]["code"]) {
  2166. cacheSection[j] = updateArr[i];
  2167. }
  2168. }
  2169. }
  2170. }
  2171. },
  2172. updateParentNodeIds: function (nodes, caller) {
  2173. let private_build_parentNodeIds = function (pNodeId, nodesArr) {
  2174. let rst = [];
  2175. for (let i = 0; i < nodesArr.length; i++) {
  2176. if (nodesArr[i].children.length > 0) {
  2177. rst = rst.concat(
  2178. private_build_parentNodeIds(
  2179. nodesArr[i].data.ID,
  2180. nodesArr[i].children
  2181. )
  2182. );
  2183. } else {
  2184. rst.push(nodesArr[i].data.ID);
  2185. }
  2186. }
  2187. if (pNodeId && rst.length > 0) {
  2188. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  2189. }
  2190. return rst;
  2191. };
  2192. if (caller.parentNodeIds) {
  2193. private_build_parentNodeIds(null, nodes);
  2194. }
  2195. },
  2196. sortGljDeep: function (datas) {
  2197. function recurCompare(a, b, index) {
  2198. if (a[index] && !b[index]) {
  2199. return 1;
  2200. } else if (!a[index] && b[index]) {
  2201. return -1;
  2202. } else if (a[index] && b[index]) {
  2203. let aV = a[index],
  2204. bV = b[index];
  2205. if (!isNaN(aV) && !isNaN(bV)) {
  2206. aV = parseFloat(a[index]);
  2207. bV = parseFloat(b[index]);
  2208. }
  2209. if (aV > bV) {
  2210. return 1;
  2211. } else if (aV < bV) {
  2212. return -1;
  2213. } else {
  2214. return recurCompare(a, b, index + 1);
  2215. }
  2216. }
  2217. return 0;
  2218. }
  2219. //排序符号-
  2220. datas.sort(function (a, b) {
  2221. let aArr = a.code.split("-"),
  2222. bArr = b.code.split("-");
  2223. return recurCompare(aArr, bArr, 0);
  2224. });
  2225. },
  2226. //工料机排序
  2227. sortGlj: function () {
  2228. let me = this;
  2229. me.gljList.sort(function (a, b) {
  2230. let rst = 0;
  2231. if (a.code > b.code) rst = 1;
  2232. else if (a.code < b.code) rst = -1;
  2233. return rst;
  2234. });
  2235. },
  2236. };
  2237. let gljTypeTreeOprObj = {
  2238. onClick: function (event, treeId, treeNode) {
  2239. let me = repositoryGljObj,
  2240. that = gljComponentOprObj,
  2241. gljTypeId = treeNode.ID;
  2242. me.gljCurTypeId = treeNode.ID;
  2243. me.addGljObj = null;
  2244. sheetCommonObj.cleanSheet(that.workBook.getSheet(0), that.setting, 10);
  2245. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  2246. me.currentOprParent = 1;
  2247. me.currentCache = me.getParentCache(
  2248. me.parentNodeIds["_pNodeId_" + treeNode.ID]
  2249. );
  2250. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  2251. } else {
  2252. me.currentOprParent = 0;
  2253. me.currentCache = me.getCache();
  2254. }
  2255. me.showGljItems(me.currentCache, gljTypeId);
  2256. },
  2257. beforeRename: function (treeId, treeNode, newName, isCancel) {
  2258. if (newName.length == 0) {
  2259. return false;
  2260. }
  2261. return true;
  2262. },
  2263. onRename: function (e, treeId, treeNode, isCancel) {
  2264. let nodes = [];
  2265. nodes.push(treeNode);
  2266. gljTypeTreeOprObj.updateNodes(nodes);
  2267. },
  2268. onBeforeRemove: function (treeId, treeNode) {
  2269. let me = this;
  2270. if (treeNode.ParentID == -1 && treeNode.isFirstNode) {
  2271. alert("不允许删除全部!");
  2272. return false;
  2273. }
  2274. if (!confirm("您确定要删除此节点及所有子节点的数据?删除后不可恢复!")) {
  2275. return false;
  2276. }
  2277. let nodeIds = [],
  2278. preNode = treeNode.getPreNode(),
  2279. preNodeId = -1;
  2280. if (preNode) {
  2281. preNodeId = preNode.ID;
  2282. }
  2283. private_fetchAllSubItems = function (pItem) {
  2284. nodeIds.push(pItem.ID);
  2285. if (pItem.items && pItem.items.length > 0) {
  2286. for (let i = 0; i < pItem.items.length; i++) {
  2287. private_fetchAllSubItems(pItem.items[i]);
  2288. }
  2289. }
  2290. };
  2291. nodeIds.push(treeNode.ID);
  2292. for (let i = 0; i < treeNode.items.length; i++) {
  2293. private_fetchAllSubItems(treeNode.items[i]);
  2294. }
  2295. $.ajax({
  2296. type: "POST",
  2297. url: "api/deleteGljNodes",
  2298. data: {
  2299. repId: pageOprObj.gljLibId,
  2300. lastOpr: userAccount,
  2301. nodes: JSON.stringify(nodeIds),
  2302. preNodeId: preNodeId,
  2303. preNodeNextId: treeNode.NextSiblingID,
  2304. },
  2305. dataType: "json",
  2306. cache: false,
  2307. timeout: 5000,
  2308. success: function (result, textStatus, status) {
  2309. let pNode = treeNode.getParentNode();
  2310. if (pNode && pNode.items && pNode.items.length == 1) {
  2311. pNode.isParent = false;
  2312. }
  2313. },
  2314. error: function () {},
  2315. });
  2316. return true;
  2317. },
  2318. onRemove: function (e, treeId, treeNode) {
  2319. let me = repositoryGljObj,
  2320. pNode = me.treeObj.getNodeByTId(treeNode.parentTId);
  2321. if (pNode && pNode.items && pNode.items.length == 0) {
  2322. pNode.isParent = false;
  2323. me.treeObj.refresh();
  2324. }
  2325. },
  2326. updateNodes: function (nodes) {
  2327. if (nodes && nodes.length > 0) {
  2328. let reqData = [];
  2329. for (let i = 0; i < nodes.length; i++) {
  2330. let node = {};
  2331. node.repositoryId = nodes[i].repositoryId;
  2332. node.ID = nodes[i].ID;
  2333. node.ParentID = nodes[i].ParentID;
  2334. node.NextSiblingID = nodes[i].NextSiblingID;
  2335. node.Name = nodes[i].Name;
  2336. reqData.push(node);
  2337. }
  2338. $.ajax({
  2339. type: "POST",
  2340. url: "api/updateGljNodes",
  2341. data: {
  2342. repId: pageOprObj.gljLibId,
  2343. lastOpr: userAccount,
  2344. nodes: JSON.stringify(reqData),
  2345. },
  2346. dataType: "json",
  2347. cache: false,
  2348. timeout: 5000,
  2349. success: function (result, textStatus, status) {
  2350. console.log(status + " : " + result);
  2351. },
  2352. error: function () {},
  2353. });
  2354. }
  2355. },
  2356. addRootNode: function () {
  2357. let me = repositoryGljObj,
  2358. rawNode = { ParentID: -1, NextSiblingID: -1, Name: "所有" },
  2359. lastNodeId = -1;
  2360. if (me.treeObj) {
  2361. let rootNodes = me.treeObj.getNodes();
  2362. if (rootNodes.length == 0) {
  2363. gljTypeTreeOprObj.addNewNode(rawNode, lastNodeId, function (err, rst) {
  2364. if (!err) {
  2365. let newNodes = [],
  2366. isSilent = false;
  2367. newNodes.push({
  2368. repositoryId: rst.data.repositoryId,
  2369. ID: rst.data.ID,
  2370. ParentID: rst.data.ParentID,
  2371. NextSiblingID: -1,
  2372. Name: "所有",
  2373. isParent: false,
  2374. items: [],
  2375. });
  2376. me.treeObj.addNodes(null, -1, newNodes, isSilent);
  2377. }
  2378. });
  2379. }
  2380. }
  2381. },
  2382. addNewNode: function (rawNode, lastNodeId, callback) {
  2383. $.ajax({
  2384. type: "POST",
  2385. url: "api/createNewGljTypeNode",
  2386. data: {
  2387. lastOpr: userAccount,
  2388. repositoryId: repositoryGljObj.currentRepositoryId,
  2389. lastNodeId: lastNodeId,
  2390. rawNodeData: JSON.stringify(rawNode),
  2391. },
  2392. dataType: "json",
  2393. cache: false,
  2394. timeout: 1000,
  2395. success: function (result, textStatus, status) {
  2396. callback(false, result);
  2397. },
  2398. error: function (err) {
  2399. callback(err);
  2400. },
  2401. });
  2402. },
  2403. addHoverDom: function (treeId, treeNode) {
  2404. if (typeof treeNode.doing !== "undefined" && treeNode.doing) {
  2405. return false;
  2406. }
  2407. hoverOpr();
  2408. function hoverOpr() {
  2409. let me = repositoryGljObj,
  2410. sObj = $("#" + treeNode.tId + "_span");
  2411. if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0)
  2412. return;
  2413. let addStr =
  2414. "<span class='button add' id='addBtn_" +
  2415. treeNode.tId +
  2416. "' title='新增子节点' onfocus='this.blur();'></span>";
  2417. sObj.after(addStr);
  2418. let btn = $("#addBtn_" + treeNode.tId);
  2419. if (btn)
  2420. btn.bind("click", function () {
  2421. treeNode.doing = true;
  2422. let rawNode = {
  2423. ParentID: treeNode.ID,
  2424. NextSiblingID: -1,
  2425. Name: "新增子节点",
  2426. },
  2427. lastNodeId = -1;
  2428. if (treeNode.items.length > 0) {
  2429. lastNodeId = treeNode.items[treeNode.items.length - 1].ID;
  2430. }
  2431. gljTypeTreeOprObj.addNewNode(
  2432. rawNode,
  2433. lastNodeId,
  2434. function (err, rst) {
  2435. if (!err) {
  2436. let newNodes = [],
  2437. isSilent = false;
  2438. if (treeNode.items.length > 0) {
  2439. treeNode.items[treeNode.items.length - 1].NextSiblingID =
  2440. rst.data.ID;
  2441. }
  2442. newNodes.push({
  2443. repositoryId: rst.data.repositoryId,
  2444. ID: rst.data.ID,
  2445. ParentID: rst.data.ParentID,
  2446. NextSiblingID: -1,
  2447. Name: "新增子节点",
  2448. isParent: false,
  2449. items: [],
  2450. });
  2451. treeNode.isParent = true;
  2452. if (me.treeObj) {
  2453. me.treeObj.addNodes(treeNode, -1, newNodes, isSilent);
  2454. } else {
  2455. me.treeObj = $.fn.zTree.init(
  2456. $("#rationChapterTree"),
  2457. gljSetting,
  2458. newNodes
  2459. );
  2460. }
  2461. treeNode.doing = false;
  2462. hoverOpr();
  2463. }
  2464. }
  2465. );
  2466. });
  2467. }
  2468. },
  2469. removeHoverDom: function (treeId, treeNode) {
  2470. $("#addBtn_" + treeNode.tId)
  2471. .unbind()
  2472. .remove();
  2473. },
  2474. };
  2475. $(document).ready(function () {
  2476. let moduleName = "stdGLj";
  2477. function refreshALlWorkBook() {
  2478. if (gljClassTreeObj.workBook) {
  2479. gljClassTreeObj.workBook.refresh();
  2480. }
  2481. if (repositoryGljObj.workBook) {
  2482. repositoryGljObj.workBook.refresh();
  2483. }
  2484. if (gljComponentOprObj.workBook) {
  2485. gljComponentOprObj.workBook.refresh();
  2486. }
  2487. }
  2488. SlideResize.loadHorizonWidth(
  2489. moduleName,
  2490. [$("#slideResizeLeft"), $("#slideResizeRight")],
  2491. [$("#leftContent"), $("#midContent"), $("#rightContent")],
  2492. function () {
  2493. refreshALlWorkBook();
  2494. }
  2495. );
  2496. //章节树与人材机表
  2497. let leftElesObj = {};
  2498. leftElesObj.module = moduleName;
  2499. leftElesObj.resize = $("#slideResizeLeft");
  2500. leftElesObj.parent = $("#dataRow");
  2501. leftElesObj.left = $("#leftContent");
  2502. leftElesObj.right = $("#midContent");
  2503. SlideResize.horizontalSlide(
  2504. leftElesObj,
  2505. {
  2506. min: 375,
  2507. max: `$('#dataRow').width() - $('#rightContent').width() - 375`,
  2508. },
  2509. function () {
  2510. refreshALlWorkBook();
  2511. }
  2512. );
  2513. //人材机表与人材机组成物表
  2514. let rightElesObj = {};
  2515. rightElesObj.module = moduleName;
  2516. rightElesObj.resize = $("#slideResizeRight");
  2517. rightElesObj.parent = $("#dataRow");
  2518. rightElesObj.left = $("#midContent");
  2519. rightElesObj.right = $("#rightContent");
  2520. SlideResize.horizontalSlide(
  2521. rightElesObj,
  2522. {
  2523. min: 200,
  2524. max: `$('#dataRow').width() - $('#leftContent').width() - 200`,
  2525. },
  2526. function () {
  2527. let resizeRate =
  2528. (SlideResize.resizeWidth * 100) / $("#midContent").width(),
  2529. sheetRate = 100 - resizeRate;
  2530. $("#slideResizeLeft").css("width", `${resizeRate}%`);
  2531. $("#GLJListSheet").css("width", `${sheetRate}%`);
  2532. refreshALlWorkBook();
  2533. }
  2534. );
  2535. $("#gljSearch").keydown(function (event) {
  2536. if (event.keyCode === 13) {
  2537. $(this).blur();
  2538. const gljCode = $(this).val();
  2539. if (gljCode) {
  2540. repositoryGljObj.locateGlj(gljCode);
  2541. // sectionTreeObj.locateToSection(rationCode);
  2542. }
  2543. }
  2544. });
  2545. $("#moveToConfirm").click(function () {
  2546. let sheet = repositoryGljObj.workBook.getSheet(0);
  2547. let sel = sheet.getSelections()[0];
  2548. let gljs = repositoryGljObj.currentCache.slice(
  2549. sel.row,
  2550. sel.row + sel.rowCount
  2551. );
  2552. let node = gljClassTreeObj.zTreeSetting.selected;
  2553. let updateArr = [];
  2554. for (let glj of gljs) {
  2555. const data = _.cloneDeep(glj);
  2556. data.gljClass = node.ID;
  2557. updateArr.push(data);
  2558. }
  2559. repositoryGljObj.mixUpdateRequest(updateArr, [], []);
  2560. $("#moveTo").modal("hide");
  2561. });
  2562. });