glj.js 94 KB

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