glj.js 85 KB

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