glj.js 79 KB

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