glj.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. /**
  2. * Created by Zhong on 2017/8/14.
  3. */
  4. $(document).ready(function () {
  5. $('#component').on('shown.bs.modal', function () {
  6. if (componentOprObj.workBook) {
  7. componentOprObj.workBook.refresh();
  8. }
  9. });
  10. let moduleName = 'compleGLj';
  11. SlideResize.loadHorizonWidth(moduleName, [$('#rightResize'), $('#leftResize')], [$('#leftContent'), $('#midContent'), $('#rightContent')], function () {
  12. refreshALlWorkBook();
  13. });
  14. //章节树与人材机表
  15. let leftElesObj = {};
  16. leftElesObj.module = moduleName;
  17. leftElesObj.resize = $('#leftResize');
  18. leftElesObj.parent = $('#dataRow');
  19. leftElesObj.left = $('#leftContent');
  20. leftElesObj.right = $('#midContent');
  21. SlideResize.horizontalSlide(leftElesObj, { min: 200, max: `$('#dataRow').width() - $('#rightContent').width() - 200` }, function () {
  22. refreshALlWorkBook();
  23. });
  24. //人材机表与人材机组成物表
  25. let rightElesObj = {};
  26. rightElesObj.module = moduleName;
  27. rightElesObj.resize = $('#rightResize');
  28. rightElesObj.parent = $('#dataRow');
  29. rightElesObj.left = $('#midContent');
  30. rightElesObj.right = $('#rightContent');
  31. SlideResize.horizontalSlide(rightElesObj, { min: 200, max: `$('#dataRow').width() - $('#leftContent').width() - 200` }, function () {
  32. let resizeRate = 500 / $('#midContent').width(),
  33. sheetRate = 100 - resizeRate;
  34. $('#leftResize').css('width', `${resizeRate}%`);
  35. $('#GLJListSheet').css('width', `${sheetRate}%`);
  36. refreshALlWorkBook();
  37. });
  38. });
  39. function refreshALlWorkBook() {
  40. if (gljClassTreeObj.workBook) {
  41. gljClassTreeObj.workBook.refresh();
  42. }
  43. if (repositoryGljObj.workBook) {
  44. repositoryGljObj.workBook.refresh();
  45. }
  46. if (gljComponentOprObj.workBook) {
  47. gljComponentOprObj.workBook.refresh();
  48. }
  49. }
  50. let pageOprObj = {
  51. gljLibName: null,
  52. stdGljLibId: null,
  53. userId: null,
  54. compilationId: null,
  55. initPage: function (container, containerComponent, containerC) {
  56. let me = pageOprObj;
  57. me.stdGljLibId = stdGljLibId;
  58. me.userId = userId;
  59. me.compilationId = compilationId;
  60. //生成人材机表格列头
  61. repositoryGljObj.setting.header = repositoryGljObj.initHeaders(priceProperties);
  62. //生成列映射
  63. sheetCommonObj.initColMapping(repositoryGljObj, repositoryGljObj.setting.header);
  64. //生成单价列下标数组
  65. repositoryGljObj.initPriceCols(priceProperties, repositoryGljObj.colMapping);
  66. repositoryGljObj.buildSheet(container);
  67. gljComponentOprObj.buildSheet(containerComponent);
  68. componentOprObj.buildSheet(containerC);
  69. //获得定额库中引用此工料机库中的,所有被定额所套的工料机的ID
  70. //repositoryGljObj.getRationGljIds(gljLibId);
  71. repositoryGljObj.getGljDistType(function () {
  72. repositoryGljObj.currentRepositoryId = me.stdGljLibId;
  73. gljClassTreeObj.getGljClassTree(stdGljLibId, function () {
  74. repositoryGljObj.getGljItems(me.stdGljLibId, function () {
  75. gljClassTreeObj.initSelection(gljClassTreeObj.tree.selected);
  76. });
  77. });
  78. });
  79. }
  80. };
  81. let repositoryGljObj = {
  82. colMapping: null,
  83. treeObj: null,
  84. workBook: null,
  85. // 是否获取了完整的人材机数据
  86. // 第一次打开页面只加载补充人材机和标准人材机的编码
  87. // 第一次打开选择组成物的窗口才加载标准人材机剩余数据
  88. pullCompleteData: false,
  89. gljCurTypeId: -1,
  90. currentRepositoryId: -1,
  91. currentCache: null,
  92. parentNodeIds: {},
  93. gljList: [],
  94. stdGljList: [],
  95. complementaryGljList: [],
  96. machineModel: { textArr: ['特', '大', '中', '小'], comboItems: [{ text: '特', value: 1 }, { text: '大', value: 2 }, { text: '中', value: 3 }, { text: '小', value: 4 }] },
  97. machineModelIdx: { '1': '特', '2': '大', '3': '中', '4': '小' },
  98. taxRateTypes: [201, 205, 206, 302, 4, 5],
  99. distTypeTree: null,//add
  100. setting: {
  101. header: [
  102. { headerName: "机型", headerWidth: 60, dataCode: "model", dataType: "Number", hAlign: "center", vAlign: "center" },
  103. { headerName: "是否新增", headerWidth: 60, dataCode: "isComplementary", hAlign: "center", vAlign: "center" }
  104. ],
  105. view: {
  106. comboBox: [
  107. { row: -1, col: 3, rowCount: -1, colCount: 1 }
  108. ],
  109. lockedCells: [
  110. ]
  111. }
  112. },
  113. //根据费用定额的单价属性获取人材机的单价属性
  114. getPriceProperty: function (priceProperties) {
  115. let priceProperty = {};
  116. for (let priceProp of priceProperties) {
  117. priceProperty[priceProp.price.dataCode] = 0;
  118. }
  119. return priceProperty;
  120. },
  121. //根据单价字段获取消耗量字段
  122. getConsumeAmtField: function (consumeAmtProperties, priceField) {
  123. if (!consumeAmtProperties || consumeAmtProperties.length === 0) {
  124. return 'consumeAmt';
  125. }
  126. for (let consumeAmtProp of consumeAmtProperties) {
  127. if (consumeAmtProp.consumeAmt.refPrice === priceField) {
  128. return consumeAmtProp.consumeAmt.dataCode;
  129. }
  130. }
  131. return 'consumeAmt';
  132. },
  133. //初始单价相关的列(单价列、单价属性列)
  134. initPriceCols: function (priceProperties, colMapping) {
  135. let priceCols = [],
  136. pricePropertyCols = [];
  137. if (!priceProperties || priceProperties.length === 0) {
  138. priceCols.push(colMapping.fieldToCol['basePrice']);
  139. }
  140. for (let priceProp of priceProperties) {
  141. pricePropertyCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  142. priceCols.push(colMapping.fieldToCol[priceProp.price.dataCode]);
  143. }
  144. this.priceCols = priceCols;
  145. this.pricePropertyCols = pricePropertyCols;
  146. },
  147. getPriceFields: function () {
  148. let rst = [];
  149. for (let priceCol of this.priceCols) {
  150. rst.push(this.colMapping.colToField[priceCol]);
  151. }
  152. return rst;
  153. },
  154. //获取更新定额价的人材机价格(人材机只有一个单价取basePrice, 人材机有多个单价,取第一个单价)
  155. getRationGljPrice: function (glj) {
  156. if (glj.priceProperty) {
  157. let keys = Object.keys(glj.priceProperty);
  158. if (keys.length > 0) {
  159. return glj.priceProperty[keys[0]];
  160. }
  161. }
  162. return glj.basePrice;
  163. },
  164. //生成列头(多单价)
  165. initHeaders: function (priceProperties) {
  166. let headers = [
  167. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  168. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center" },
  169. { headerName: "规格型号", headerWidth: 120, dataCode: "specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center" },
  170. { headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  171. { headerName: "类型", headerWidth: 90, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" },
  172. ];
  173. //生成单价列
  174. if (!priceProperties || priceProperties.length === 0) {
  175. headers.push({ headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center" });
  176. }
  177. else {
  178. for (let priceProp of priceProperties) {
  179. let colData = {
  180. headerName: priceProp.price.dataName,
  181. headerWidth: 100,
  182. dataCode: priceProp.price.dataCode,
  183. dataType: 'Number',
  184. formatter: '0.00',
  185. hAlign: 'right',
  186. vAlign: 'center'
  187. };
  188. headers.push(colData);
  189. }
  190. }
  191. headers = headers.concat(this.setting.header);
  192. return headers;
  193. },
  194. //工料机单价赋初始值(没有单价属性,则单价字段为basePrice,否则单价字段为单价属性对象中的属性)
  195. initPrice: function (glj) {
  196. if (!priceProperties || priceProperties.length === 0) {
  197. glj.basePrice = glj.basePrice && !isNaN(parseFloat(glj.basePrice)) ? scMathUtil.roundTo(parseFloat(glj.basePrice), -2) : 0;
  198. }
  199. else {
  200. if (!glj.priceProperty) {
  201. glj.priceProperty = {};
  202. }
  203. for (let priceProp of priceProperties) {
  204. let gljPrice = glj['priceProperty'][priceProp.price.dataCode];
  205. gljPrice = gljPrice && !isNaN(parseFloat(gljPrice)) ? scMathUtil.roundTo(parseFloat(gljPrice), -2) : 0;
  206. }
  207. }
  208. },
  209. //人材机单价是否变化
  210. isGljPriceChange: function (glj, newPrice) {
  211. //多单价,与人材机单价属性比较
  212. if (typeof newPrice === 'object') {
  213. return !_.isEqual(glj.priceProperty, newPrice);
  214. }
  215. return !_.isEqual(glj.basePrice, newPrice);
  216. },
  217. //粘贴数据含有单价
  218. pasteIncludesPrice: function (pasteObj) {
  219. let me = repositoryGljObj;
  220. for (let priceCol of me.priceCols) {
  221. let priceField = me.colMapping.colToField[priceCol];
  222. if (typeof pasteObj[priceField] !== 'undefined') {
  223. return true;
  224. }
  225. }
  226. return false;
  227. },
  228. //获取人材机价格
  229. getPrice: function (glj, col) {
  230. let me = repositoryGljObj;
  231. if (!priceProperties || priceProperties.length === 0) {
  232. return glj.basePrice;
  233. }
  234. return glj.priceProperty[me.colMapping.colToField[col]];
  235. },
  236. //工料机价格是否相同
  237. priceIsEqual: function (gljA, gljB) {
  238. if (!priceProperties || priceProperties.length === 0) {
  239. return gljA.basePrice == gljB.basePrice;
  240. }
  241. return _.isEqual(gljA.priceProperty, gljB.priceProperty);
  242. },
  243. setPriceByCol: function (glj, newPrice, col) {
  244. if (!priceProperties || priceProperties.length === 0) {
  245. glj.basePrice = newPrice;
  246. }
  247. else {
  248. glj.priceProperty[this.colMapping.colToField[col]] = newPrice;
  249. }
  250. },
  251. setPrice: function (glj, price) {
  252. if (!priceProperties || priceProperties.length === 0) {
  253. glj.basePrice = price;
  254. } else {
  255. glj.priceProperty = price;
  256. }
  257. },
  258. setUnitCombo: function (sheet, headers) {
  259. let me = this;
  260. sheet.suspendPaint();
  261. sheet.suspendEvent();
  262. let combo = sheetCommonObj.getDynamicCombo();
  263. combo.items(rationAndGljUnits).itemHeight(10).editable(true);
  264. let unitCol = me.colMapping.fieldToCol.unit;
  265. if (unitCol) {
  266. sheet.getRange(-1, unitCol, -1, 1).cellType(combo);
  267. }
  268. sheet.resumePaint();
  269. sheet.resumeEvent();
  270. },
  271. getComboData: function (gljDistType) {
  272. let me = this;
  273. let distType;
  274. let distTypeTree = {
  275. prefix: 'gljType',
  276. distTypes: {},
  277. comboDatas: [],
  278. distTypesArr: []
  279. };
  280. gljDistType.forEach(function (typeData) {
  281. let typeObj = {
  282. data: typeData,
  283. children: [],
  284. parent: null
  285. }
  286. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  287. distTypeTree.distTypesArr.push(typeObj);
  288. });
  289. gljDistType.forEach(function (typeData) {
  290. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  291. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  292. if (parent) {
  293. distType.parent = parent;
  294. parent.children.push(distType);
  295. }
  296. });
  297. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  298. if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
  299. distTypeTree.comboDatas.push({ text: distTypeObj.data.fullName, value: distTypeObj.data.ID });
  300. }
  301. });
  302. return distTypeTree;
  303. },
  304. getGljDistType: function (callback) {
  305. let me = this;
  306. CommonAjax.post('complementartGlj/api/getGljDistType', {}, function (rstData) {
  307. if (callback) {
  308. me.distTypeTree = me.getComboData(rstData);
  309. console.log(me.distTypeTree);
  310. callback();
  311. }
  312. });
  313. },
  314. getGljTree: function (gljLibId, callback) {
  315. let me = this;
  316. CommonAjax.post('complementartGlj/api/getGljTree', { gljLibId: gljLibId }, function (rstData) {
  317. zTreeHelper.createTree(rstData, gljSetting, "repositoryTree", me);
  318. zTreeHelper.createTree(rstData, componentSetting, "componentTree", componentOprObj);
  319. if (rstData && rstData.length > 0) {
  320. me.gljCurTypeId = rstData[0].ID;
  321. } else {
  322. //重新创建库?
  323. // gljTypeTreeOprObj.addRootNode();
  324. }
  325. if (callback) {
  326. callback();
  327. }
  328. });
  329. },
  330. getGljItems: function (stdGljLibId, callback) {
  331. let me = this,
  332. // 一开始获取的标准人材机只包含code,提升打开页面速度
  333. projection = {
  334. _id: 0,
  335. ID: 1,
  336. code: 1,
  337. unit: 1,
  338. name: 1,
  339. priceProperty: 1,
  340. basePrice: 1
  341. };
  342. $.bootstrapLoading.start();
  343. CommonAjax.post('/complementartGlj/api/getGljItems', { stdGljLibId, projection }, function (rstData) {
  344. me.stdGljList = rstData.stdGljs;
  345. // TODO
  346. //兼容多单价情况
  347. for (let sGlj of me.stdGljList) {
  348. if (sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined') {
  349. sGlj.basePrice = sGlj.priceProperty.price1;
  350. }
  351. }
  352. me.sortGlj(me.stdGljList);
  353. me.setProp('isStd', true, me.stdGljList);
  354. me.complementaryGljList = rstData.complementaryGljs;
  355. me.sortGlj(me.complementaryGljList);
  356. if (callback) {
  357. callback();
  358. }
  359. $.bootstrapLoading.end();
  360. }, function () {
  361. $.bootstrapLoading.end();
  362. });
  363. },
  364. // 获取标准人材机数据
  365. getStdItems: function (stdGljLibId, callback) {
  366. $.bootstrapLoading.start();
  367. let me = this;
  368. let projection = {
  369. _id: 0,
  370. ID: 1,
  371. specs: 1,
  372. gljType: 1,
  373. shortName: 1,
  374. gljClass: 1
  375. };
  376. CommonAjax.post('/complementartGlj/api/getStdItems', { stdGljLibId, projection }, function (data) {
  377. me.pullCompleteData = true;
  378. // 更新标准人材机数据
  379. let IDMapping = {};
  380. for (let glj of data) {
  381. IDMapping[glj.ID] = glj;
  382. }
  383. for (let glj of me.stdGljList) {
  384. Object.assign(glj, IDMapping[glj.ID]);
  385. }
  386. callback();
  387. $.bootstrapLoading.end();
  388. }, function () {
  389. $.bootstrapLoading.end();
  390. });
  391. },
  392. showGljItems: function (data, type) {
  393. let me = repositoryGljObj;
  394. let sheet = me.workBook.getActiveSheet();
  395. if (me.workBook) {
  396. let cacheSection = [];
  397. let pArr = me.parentNodeIds["_pNodeId_" + type];
  398. for (let i = 0; i < data.length; i++) {
  399. if (pArr && pArr.indexOf(data[i].gljClass) >= 0) {
  400. cacheSection.push(data[i]);
  401. } else if (type == data[i].gljClass) {
  402. cacheSection.push(data[i]);
  403. }
  404. }
  405. sheetOpr.cleanData(sheet, me.setting, -1);
  406. //清除是否新增复选框
  407. gljClassTreeObj.renderFunc(sheet, function () {
  408. let isComplementaryCol = 0;
  409. for (let colData of me.setting.header) {
  410. if (colData.dataCode === 'isComplementary') {
  411. isComplementaryCol = me.setting.header.indexOf(colData);
  412. }
  413. }
  414. let baseCell = new GC.Spread.Sheets.CellTypes.Base();
  415. for (let row = 0; row < sheet.getRowCount(); row++) {
  416. sheet.setCellType(row, isComplementaryCol, baseCell);
  417. }
  418. });
  419. sheetOpr.showData(me, me.workBook.getSheet(0), me.setting, cacheSection, me.distTypeTree, me.materialTypeIdx, me.machineModelIdx);;
  420. let gljTypeCol = me.colMapping.fieldToCol['gljType'],
  421. modelCol = me.colMapping.fieldToCol['model'];
  422. sheetCommonObj.setDynamicCombo(sheet, 0, gljTypeCol, sheet.getRowCount(), me.distTypeTree.comboDatas, false, 'text');
  423. sheetCommonObj.setDynamicCombo(sheet, 0, modelCol, sheet.getRowCount(), me.machineModel.comboItems, false, 'text');
  424. cacheSection = null;
  425. }
  426. },
  427. bindEnterKey: function () {
  428. let me = this;
  429. let sheet = me.workBook.getActiveSheet();
  430. me.workBook.commandManager().register("myEnter", function () {
  431. let orgRow = sheet.getActiveRowIndex();
  432. let orgCol = sheet.getActiveColumnIndex();
  433. if (sheet.isEditing()) {
  434. sheet.endEdit();
  435. }
  436. let codeCol = me.colMapping.fieldToCol['code'];
  437. let code = sheet.getValue(orgRow, codeCol);
  438. let newRow, newCol;
  439. if (!me.currentCache[orgRow] && code !== undefined && code !== null && orgCol !== me.setting.header.length - 1) {
  440. newRow = orgRow;
  441. newCol = orgCol + 1;
  442. sheet.setActiveCell(newRow, newCol);
  443. }
  444. else {
  445. newRow = orgRow + 1;
  446. newCol = me.currentCache[orgRow + 1] ? orgCol : 0;
  447. sheet.setActiveCell(newRow, newCol);
  448. }
  449. //触发事件
  450. //me.onLeaveCell({type: 'LeaveCell'}, {sheet: sheet, sheetName: sheet.name(), cancel: false, row: orgRow, col: orgCol});
  451. me.onEnterCell({ type: 'EnterCell' }, { sheet: sheet, sheetName: sheet.name(), cancel: false, row: newRow, col: newCol });
  452. let newSels = [{ row: newRow, rowCount: 1, col: newCol, colCount: 1 }];
  453. let oldSels = [{ row: orgRow, rowCount: 1, col: orgRow, colCount: 1 }];
  454. me.onSelectionChanged({ type: 'SelectionChanged' }, { sheet: sheet, sheetName: sheet.name(), newSelections: newSels, oldSelections: oldSels });
  455. });
  456. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.enter, false, false, false, false);
  457. me.workBook.commandManager().setShortcutKey("myEnter", GC.Spread.Commands.Key.enter, false, false, false, false);
  458. },
  459. buildSheet: function (container) {
  460. let me = repositoryGljObj;
  461. me.workBook = sheetOpr.buildSheet(container, me.setting, 30);
  462. sheetCommonObj.spreadDefaultStyle(me.workBook);
  463. me.repositoryGljDelOpr();
  464. me.onContextmenuOpr();
  465. me.bindEnterKey();
  466. me.setUnitCombo(me.workBook.getActiveSheet(), me.setting.header);
  467. if (priceProperties && priceProperties.length > 0) {
  468. me.workBook.getSheet(0).frozenColumnCount(5);
  469. }
  470. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
  471. me.workBook.getActiveSheet().bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
  472. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
  473. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
  474. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EnterCell, me.onEnterCell);
  475. me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
  476. me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
  477. },
  478. isDef: function (v) {
  479. return v !== undefined && v !== null;
  480. },
  481. //成为了组成物,暂时只需要判断主材的
  482. isComponent: function (gljId, gljList) {
  483. for (let i = 0, len = gljList.length; i < len; i++) {
  484. let gljComponent = gljList[i].component;
  485. if (gljList[i].gljType === 4 && this.isDef(gljComponent) && gljComponent.length > 0) {
  486. for (let j = 0, jLen = gljComponent.length; j < jLen; j++) {
  487. if (gljComponent[j].ID === gljId) {
  488. return true;
  489. }
  490. }
  491. }
  492. }
  493. return false;
  494. },
  495. getCurrentComponent: function (gljComponent) {
  496. let me = repositoryGljObj,
  497. rst = [];
  498. for (let thisGlj of gljComponent) {
  499. let toFindGljList = thisGlj.isStd
  500. ? me.stdGljList
  501. : me.complementaryGljList;
  502. let matchGlj = toFindGljList.find(glj => glj.ID === thisGlj.ID);
  503. if (matchGlj) {
  504. rst.push({
  505. isStd: thisGlj.isStd ? true : false,
  506. ID: matchGlj.ID,
  507. code: matchGlj.code,
  508. name: matchGlj.name,
  509. unit: matchGlj.unit,
  510. basePrice: matchGlj.basePrice,
  511. priceProperty: matchGlj.priceProperty,
  512. consumeAmt: thisGlj.consumeAmt,
  513. consumeAmtProperty: thisGlj.consumeAmtProperty
  514. });
  515. }
  516. }
  517. rst.sort(function (a, b) {
  518. let r = 0;
  519. if (a.code > b.code) r = 1;
  520. else if (a.code < b.code) r = -1;
  521. return r;
  522. });
  523. return rst;
  524. },
  525. //获得引用了组成物id为componentId的工料机,和重新变化组成物数组、重新计算单价
  526. getUpdateGljs: function (rObj, isDelete) {
  527. let me = repositoryGljObj, that = gljComponentOprObj,
  528. rst = { updateArr: [], updateBasePrcArr: [] };
  529. //改变单价,以便reCalGljBasePrc方法可行
  530. if (!isDelete) {
  531. for (let i = 0; i < me.complementaryGljList.length; i++) {
  532. if (me.complementaryGljList[i].ID === rObj.ID) {
  533. me.complementaryGljList[i].basePrice = rObj.basePrice;
  534. me.complementaryGljList[i].priceProperty = rObj.priceProperty || {};
  535. break;
  536. }
  537. }
  538. }
  539. for (let i = 0; i < me.complementaryGljList.length; i++) {
  540. let thisComponent = me.complementaryGljList[i].component, isChange = false;
  541. for (let j = 0; j < thisComponent.length; j++) {
  542. if (thisComponent[j].ID === rObj.ID) {
  543. //删除
  544. isChange = true;
  545. if (isDelete) {
  546. thisComponent.splice(j--, 1);
  547. }
  548. else {
  549. break;
  550. }
  551. }
  552. }
  553. if (isChange) {//引用了此组成物
  554. let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
  555. if (me.isGljPriceChange(me.complementaryGljList[i], gljBasePrc)) {
  556. const orgPriceForRation = me.getRationGljPrice(me.complementaryGljList[i]);
  557. me.setPrice(me.complementaryGljList[i], gljBasePrc);
  558. const newPriceForRation = me.getRationGljPrice(me.complementaryGljList[i]);
  559. // 多单价的情况下只有price1发生变化,才重算定额价格
  560. if (orgPriceForRation !== newPriceForRation) {
  561. rst.updateBasePrcArr.push({ gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: newPriceForRation });
  562. }
  563. }
  564. rst.updateArr.push(me.complementaryGljList[i]);
  565. }
  566. /* if(isChange){//引用了此组成物
  567. let gljBasePrc = that.reCalGljBasePrc(me.getCurrentComponent(thisComponent));
  568. if(me.complementaryGljList[i].basePrice !== gljBasePrc){
  569. me.complementaryGljList[i].basePrice = gljBasePrc;
  570. rst.updateBasePrcArr.push({gljId: me.complementaryGljList[i].ID, gljType: me.complementaryGljList[i].gljType, basePrice: me.complementaryGljList[i].basePrice});
  571. }
  572. rst.updateArr.push(me.complementaryGljList[i]);
  573. } */
  574. }
  575. return rst;
  576. },
  577. reshowGljBasePrc: function (glj) {
  578. /* let me = repositoryGljObj;
  579. let cacheSection = me.currentCache;
  580. for(let i = 0; i < cacheSection.length; i++){
  581. if(glj.ID === cacheSection[i].ID){
  582. cacheSection[i].basePrice = glj.basePrice;
  583. me.workBook.getSheet(0).setValue(i, 4, glj.basePrice);
  584. break;
  585. }
  586. } */
  587. let me = repositoryGljObj;
  588. let cacheSection = me.currentCache;
  589. let sheet = me.workBook.getActiveSheet();
  590. let row = _.findIndex(cacheSection, { ID: glj.ID });
  591. sheet.suspendEvent();
  592. sheet.suspendPaint();
  593. for (let priceCol of me.priceCols) {
  594. const dataCode = me.colMapping.colToField[priceCol];
  595. const priceObj = dataCode === 'basePrice' ? glj : glj.priceProperty;
  596. sheet.setValue(row, priceCol, priceObj[dataCode]);
  597. }
  598. sheet.resumeEvent();
  599. sheet.resumePaint();
  600. },
  601. onSelectionChanged: function (sender, info) {
  602. let me = repositoryGljObj, that = gljComponentOprObj;
  603. //混凝土202、砂浆203、配合比204、机械3
  604. if (typeof info.oldSelections || info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row) {
  605. let row = info.newSelections[0].row;
  606. me.initSel(row);
  607. }
  608. },
  609. initSel: function (row) {
  610. let me = repositoryGljObj, that = gljComponentOprObj, componentCanEdit = false;
  611. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, -1);
  612. me.workBook.focus(true);
  613. me.currentComponent = [];
  614. that.workBook.getSheet(0).setRowCount(5);
  615. if (row < me.currentCache.length) {
  616. //标记当前工料机
  617. me.currentGlj = me.currentCache[row];
  618. if (allowComponent.includes(me.currentCache[row].gljType)) {
  619. componentCanEdit = true;
  620. //展示数据
  621. if (me.currentGlj.component.length > 0) {
  622. me.currentComponent = me.getCurrentComponent(me.currentGlj.component);
  623. if (me.currentComponent.length > 0) {
  624. //sheetOpr.showData(that.workBook.getSheet(0), that.setting, me.currentComponent);
  625. sheetOpr.showData(that, that.workBook.getSheet(0), that.setting, me.currentComponent);
  626. }
  627. }
  628. }
  629. }
  630. else {
  631. me.currentGlj = null;
  632. }
  633. //减少触发
  634. if (me.preComponentCanEdit !== componentCanEdit) {
  635. me.spreadControl(componentCanEdit);
  636. refreshALlWorkBook();
  637. }
  638. me.preComponentCanEdit = componentCanEdit;
  639. },
  640. //组成物表能编辑则显示,否则隐藏该工作表
  641. spreadControl: function (showComponent) {
  642. let leftWidth = getLocalCache('compleGLjleftContentWidth') || '28%',
  643. midWidth = getLocalCache('compleGLjmidContentWidth') || '47%',
  644. rightWidth = getLocalCache('compleGLjrightContentWidth') || '25%';
  645. [leftWidth, midWidth, rightWidth] = [leftWidth, midWidth, rightWidth].map((v) => parseFloat(v.replace('%', '')));
  646. let curMidWidth = parseFloat($('#midContent')[0].style.width.replace('%', '')),
  647. curRightWidth = parseFloat($('#rightContent')[0].style.width.replace('%', ''));
  648. if (showComponent) {
  649. if (leftWidth + midWidth + rightWidth > 100) {
  650. leftWidth = 50;
  651. midWidth = rightWidth = 25;
  652. }
  653. } else {
  654. midWidth = curMidWidth + curRightWidth;
  655. rightWidth = 0;
  656. leftWidth = 100 - midWidth;
  657. }
  658. $('#leftContent').css('width', `${leftWidth}%`);
  659. $('#midContent').css('width', `${midWidth}%`);
  660. $('#rightContent').css('width', `${rightWidth}%`);
  661. },
  662. onEnterCell: function (sender, args) {
  663. let me = repositoryGljObj;
  664. args.sheet.repaint();
  665. me.cellRowIdx = args.row;
  666. let isHasData = false;
  667. if (me.addGljObj) {
  668. for (let i = 0; i < me.setting.header.length; i++) {
  669. if (me.addGljObj[me.setting.header[i].dataCode]) {
  670. isHasData = true;
  671. break;
  672. }
  673. }
  674. }
  675. if (isHasData) {
  676. if (me.editingRowIdx !== me.cellRowIdx) {
  677. let isComple = true;
  678. let focusToCol;
  679. function getFocusToCol(me) {
  680. if (!me.addGljObj.code) {
  681. $('#alertGljTxt').text('编号不能为空,继续增加人材机?');
  682. return me.colMapping.fieldToCol.code;
  683. }
  684. else if (!me.addGljObj.name) {
  685. $('#alertGljTxt').text('名称不能为空,继续增加人材机?');
  686. return me.colMapping.fieldToCol.name;
  687. }
  688. else if (!me.addGljObj.unit) {
  689. $('#alertGljTxt').text('计量单位不能为空,继续增加人材机?');
  690. return me.colMapping.fieldToCol.unit;
  691. }
  692. else if (!me.addGljObj.gljType) {
  693. $('#alertGljTxt').text('类型不能为空,继续增加人材机?');
  694. return me.colMapping.fieldToCol.gljType;
  695. }
  696. else {
  697. return -1;
  698. }
  699. }
  700. focusToCol = getFocusToCol(me);
  701. if (focusToCol === -1) {
  702. }
  703. else {
  704. $('#gljAlertBtn').click();
  705. $('#aleConfBtn').unbind('click');
  706. $('#aleConfBtn').bind('click', function () {
  707. args.sheet.setActiveCell(me.editingRowIdx, focusToCol);
  708. });
  709. $('#gljAleClose').unbind('click');
  710. $('#gljAleClose').bind('click', function () {
  711. args.sheet.setActiveCell(me.editingRowIdx, focusToCol);
  712. });
  713. $('#aleCanceBtn').unbind('click');
  714. $('#aleCanceBtn').bind('click', function () {
  715. me.addGljObj = null;
  716. args.sheet.suspendPaint();
  717. args.sheet.suspendEvent();
  718. for (let col = 0; col < me.setting.header.length; col++) {
  719. if (col === 0) {
  720. args.sheet.getCell(me.editingRowIdx, 0).formatter("@");
  721. }
  722. args.sheet.getCell(me.editingRowIdx, col).value('');
  723. }
  724. args.sheet.setActiveCell(me.editingRowIdx, 0);
  725. args.sheet.resumePaint();
  726. args.sheet.resumeEvent();
  727. });
  728. }
  729. }
  730. }
  731. },
  732. onButtonClicked: function (sender, args) {
  733. let me = repositoryGljObj;
  734. if (me.setting.header[args.col].dataCode === 'isComplementary' && args.row < me.currentCache.length) {
  735. args.sheet.setValue(args.row, args.col, true);
  736. }
  737. },
  738. onCellEditStart: function (sender, args) {
  739. let me = repositoryGljObj;
  740. me.orgCode = args.sheet.getValue(args.row, me.colMapping.fieldToCol['code']);
  741. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me);
  742. me.currentEditingGlj = rObj;
  743. me.orgCode = me.workBook.getSheet(0).getValue(args.row, 0);
  744. if (args.row < me.currentCache.length) {
  745. let dataCode = me.setting.header[args.col].dataCode;
  746. me.currentGlj = me.currentCache[args.row];
  747. if (dataCode === 'code'
  748. || (dataCode === 'taxRate' && !me.taxRateTypes.includes(me.currentGlj.gljType))
  749. || (me.priceCols.includes(args.col) && allowComponent.includes(me.currentGlj.gljType) && me.currentGlj.component.length > 0)
  750. || (dataCode === 'model' && me.currentGlj.gljType !== 301)
  751. || dataCode === 'isComplementary') {
  752. args.cancel = true;
  753. } else {
  754. rObj.ID = me.currentGlj.ID;
  755. rObj.gljClass = me.currentGlj.gljClass;
  756. }
  757. } else {
  758. me.currentGlj = null;
  759. }
  760. },
  761. dataChanged: function (objA, objB, col) {
  762. let me = repositoryGljObj;
  763. if (me.priceCols.includes(col)) {
  764. if (!priceProperties || priceProperties.length === 0) {
  765. return objA.basePrice !== objB.basePrice;
  766. }
  767. else {
  768. return objA.priceProperty[me.colMapping.colToField[col]] !== objB.priceProperty[me.colMapping.colToField[col]]
  769. }
  770. }
  771. return objA[me.colMapping.colToField[col]] !== objB[[me.colMapping.colToField[col]]];
  772. },
  773. onCellEditEnd: function (sender, args) {
  774. let me = repositoryGljObj,
  775. that = gljComponentOprObj;
  776. // 输入编号、名称、规格时,如果输入回车符或粘贴回车符,提交时应转换为空格。
  777. let deESCFields = ['code', 'name', 'specs'];
  778. if (deESCFields.includes(me.setting.header[args.col]['dataCode'])) {
  779. args.editingText = me.isDef(args.editingText) ? args.editingText.toString().replace(/[\r\n]/g, ' ') : '';
  780. args.sheet.setValue(args.row, args.col, args.editingText);
  781. }
  782. let rObj = sheetOpr.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
  783. updateArr = [],
  784. addArr = [],
  785. updateBasePrcArr = [];
  786. me.editingRowIdx = args.row;
  787. //rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
  788. me.initPrice(rObj);
  789. //更新
  790. if (me.currentEditingGlj["ID"]) {
  791. rObj["ID"] = me.currentEditingGlj["ID"];
  792. rObj.gljClass = me.currentEditingGlj.gljClass;
  793. if (me.dataChanged(me.currentEditingGlj, rObj, args.col)) {
  794. //me.addGljObj = rObj;
  795. //编码、名称、单位、类型不可为空
  796. if (rObj.code && rObj.name && rObj.unit && rObj.gljType
  797. && rObj.code.toString().trim().length !== 0 && rObj.name.toString().trim().length !== 0 && rObj.unit.toString().trim().length !== 0 &&
  798. rObj.gljType.toString().trim().length !== 0) {
  799. if (rObj.gljType !== me.currentEditingGlj.gljType) {//修改了工料机类型
  800. if (me.currentGlj) {
  801. me.currentGlj.component = [];
  802. }
  803. // 工料机类型不为普通材料、商品混凝土、商品砂浆、机械组成物、主材、设备时,清空税率
  804. if (!me.taxRateTypes.includes(rObj.gljType)) {
  805. rObj.taxRate = null;
  806. }
  807. //工料机类型不为机械台班时,清空机型
  808. if (me.currentEditingGlj.gljType === 301 && rObj.gljType !== 301 && me.currentEditingGlj.model) {
  809. rObj.model = null;
  810. }
  811. if (componentType.includes(me.currentEditingGlj.gljType) &&
  812. !(machineComponent.includes(me.currentEditingGlj.gljType) && machineComponent.includes(rObj.gljType))
  813. && !(materialComponent.includes(me.currentEditingGlj.gljType) && materialComponent.includes(rObj.gljType))) {//修改了原本是组成物的工料机
  814. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  815. let updateGljs = me.getUpdateGljs(rObj, true);
  816. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  817. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  818. updateArr.push(updateGljs.updateArr[i]);
  819. }
  820. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  821. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  822. }
  823. }
  824. }
  825. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, me.colMapping.fieldToCol.gljType);
  826. }
  827. // 修改了税率
  828. else if (rObj.taxRate !== me.currentEditingGlj.taxRate) {
  829. if (isNaN(rObj.taxRate)) {
  830. args.sheet.setValue(args.row, args.col, me.currentEditingGlj.taxRate || '');
  831. alert('税率只能输入数值!');
  832. return;
  833. }
  834. rObj.taxRate = scMathUtil.roundTo(parseFloat(rObj.taxRate), -2);
  835. }
  836. else if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {//修改了单价,可修改单价的必为可成为组成物的
  837. let rObjPrice = me.getPrice(rObj, args.col),
  838. editingGljPrice = me.getPrice(me.currentEditingGlj, args.col);
  839. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  840. if (isNaN(parseFloat(rObjPrice))) {
  841. alert('单价只能输入数值!');
  842. args.sheet.setValue(args.row, args.col, editingGljPrice ? editingGljPrice : 0);
  843. return;
  844. }
  845. me.setPriceByCol(rObj, scMathUtil.roundTo(parseFloat(rObjPrice), -2), args.col);
  846. let updateGljs = me.getUpdateGljs(rObj);
  847. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  848. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  849. updateArr.push(updateGljs.updateArr[i]);
  850. }
  851. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  852. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  853. }
  854. }
  855. }
  856. rObj.component = me.currentGlj.component;
  857. updateArr.push(rObj);
  858. }
  859. else {
  860. if (me.setting.header[args.col].dataCode === 'gljType') {
  861. let distTypeVal = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj[me.setting.header[args.col].dataCode]].data.fullName;
  862. args.sheet.setValue(args.row, args.col, distTypeVal);
  863. }
  864. else {
  865. args.sheet.setValue(args.row, args.col, me.currentEditingGlj[me.setting.header[args.col].dataCode]);
  866. }
  867. }
  868. }
  869. // 价格发生变化,需要重算补充定额
  870. if (!me.priceIsEqual(rObj, me.currentEditingGlj)) {
  871. //update basePrice of ration when editting basePrice of glj
  872. let gljType = -1;
  873. let gljTypeParent = me.distTypeTree.distTypes[me.distTypeTree.prefix + me.currentEditingGlj.gljType].parent;
  874. if (gljTypeParent && gljTypeParent.data.ID <= 3) {
  875. gljType = gljTypeParent.data.ID;
  876. }
  877. if (!gljTypeParent && me.currentEditingGlj.gljType <= 3) {
  878. gljType = me.currentEditingGlj.gljType;
  879. }
  880. let gljBasePrcObj = { gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: me.getRationGljPrice(rObj) };
  881. if (gljBasePrcObj.gljType !== -1) {
  882. updateBasePrcArr.push(gljBasePrcObj);
  883. }
  884. }
  885. // 人材机类型发生变化,需要重算补充定额
  886. else if (me.currentEditingGlj.gljType !== rObj.gljType) {
  887. let gljTypeObj = { gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: me.getRationGljPrice(rObj) };
  888. updateBasePrcArr.push(gljTypeObj);
  889. }
  890. //-----------------------------------------------------------
  891. }
  892. //新增
  893. else {
  894. if (typeof rObj.code !== 'undefined') {
  895. me.addGljObj = rObj;
  896. let isCanSav = true;
  897. if (!rObj.code || !rObj.name || !rObj.unit || !rObj.gljType) {
  898. isCanSav = false;
  899. }
  900. if (isCanSav) {
  901. me.addGljObj = null;
  902. rObj.component = [];
  903. me.initPrice(rObj);
  904. addArr.push(rObj);
  905. }
  906. }
  907. }
  908. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  909. rObj.gljClass = me.gljCurTypeId;
  910. }
  911. /* if (updateBasePrcArr.length) {
  912. me.updateRationBasePrcRq(updateBasePrcArr);
  913. } */
  914. if (updateArr.length > 0 || addArr.length > 0) {
  915. me.currentEditingGlj = null;
  916. me.mixUpdateRequest(updateArr, addArr, []);
  917. }
  918. },
  919. delGljs: function (sels) {
  920. let me = repositoryGljObj;
  921. let sheet = me.workBook.getSheet(0),
  922. updateArr = [], removeArr = [],
  923. tempRemoveArr = [],
  924. refGljCodes = [], //已被引用的工料机
  925. updateBasePrcArr = [],//删除基价单位后重新计算
  926. canUpdate = false,
  927. cacheSection = me.currentCache;
  928. if (sels.length > 0 && cacheSection.length > 0) {
  929. for (let i = 0; i < sels.length; i++) {
  930. if (sels[i].colCount === me.setting.header.length) {
  931. for (let j = 0; j < sels[i].rowCount; j++) {
  932. if (sels[i].row + j < cacheSection.length) {
  933. //删除了已被引用成组成物的工料机,重新计算所有引用此组成物的工料机的单价、组成物数组
  934. let updateGljs = me.getUpdateGljs(cacheSection[sels[i].row + j], true);
  935. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  936. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  937. updateArr.push(updateGljs.updateArr[i]);
  938. }
  939. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  940. updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  941. }
  942. }
  943. removeArr.push(cacheSection[sels[i].row + j].ID);
  944. //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
  945. //删除后重新计算引用了此工料机的定额单价
  946. updateBasePrcArr.push({ gljId: cacheSection[sels[i].row + j].ID, gljType: cacheSection[sels[i].row + j].gljType, basePrice: 0, delete: 1 });
  947. }
  948. }
  949. }
  950. else {
  951. let maxCol = sels[i].col + sels[i].colCount - 1;
  952. if (sels[i].col >= 2 && maxCol <= 4) {
  953. for (let j = 0; j < sels[i].rowCount; j++) {
  954. if (sels[i].row + j < cacheSection.length) {
  955. let updateObj = cacheSection[sels[i].row + j];
  956. for (let col = sels[i].col; col <= maxCol; col++) {
  957. if (me.setting.header[col].dataCode === 'basePrice') {
  958. //如果类型不为混凝土、砂浆、配合比、机械,才可删除单价 basePrice = 0
  959. if (!allowComponent.includes(updateObj.gljType)) {
  960. canUpdate = true;
  961. updateObj[me.setting.header[col].dataCode] = 0;
  962. updateBasePrcArr.push({ gljId: updateObj.ID, gljType: updateObj.gljType, basePrice: 0 });
  963. }
  964. }
  965. else {
  966. canUpdate = true;
  967. updateObj[me.setting.header[col].dataCode] = '';
  968. }
  969. }
  970. if (canUpdate) {
  971. updateArr.push(updateObj);
  972. }
  973. }
  974. }
  975. }
  976. //编号、名称、单位、类型不可为空
  977. else {
  978. if (sels[i].row < cacheSection.length) {
  979. let text = '', cantNullStr = ['编码', '名称', '类型'];
  980. for (let col = sels[i].col; col <= sels[i].col + sels[i].colCount - 1; col++) {
  981. if (cantNullStr.indexOf(me.setting.header[col].headerName) !== -1) {
  982. text += me.setting.header[col].headerName + " ";
  983. }
  984. }
  985. $('#alertText').text(text + "不可为空!");
  986. $('#codeAlertBtn').click();
  987. $('#codAleConfBtn').click(function () {
  988. });
  989. $('#codAleClose').click(function () {
  990. });
  991. }
  992. }
  993. }
  994. }
  995. if (removeArr.length > 0 || updateArr.length > 0) {
  996. //删除警告
  997. $('#alertGljTxt').text('可能已有定额引用了当前工料机,导致定额查找不到此工料机。确定要删除吗?');
  998. $('#gljAlertBtn').click();
  999. //确认
  1000. $('#aleConfBtn').unbind('click');
  1001. $('#aleConfBtn').bind('click', function () {
  1002. me.mixUpdateRequest(updateArr, [], removeArr);
  1003. /*if(updateBasePrcArr.length > 0 && me.rationLibs.length > 0){
  1004. me.updateRationBasePrcRq(updateBasePrcArr);
  1005. }*/
  1006. });
  1007. }
  1008. }
  1009. },
  1010. repositoryGljDelOpr: function () {
  1011. let me = repositoryGljObj;
  1012. /* me.workBook.commandManager().register('repositoryGljDel', function () {
  1013. let sels = me.workBook.getActiveSheet().getSelections();
  1014. me.delGljs(sels);
  1015. }); */
  1016. me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  1017. me.workBook.commandManager().setShortcutKey('repositoryGljDel', GC.Spread.Commands.Key.del, false, false, false, false);
  1018. },
  1019. onContextmenuOpr: function () {
  1020. let me = repositoryGljObj;
  1021. $.contextMenu({
  1022. selector: '#GLJListSheet',
  1023. build: function ($triggerElement, e) {
  1024. //控制允许右键菜单在哪个位置出现
  1025. let sheet = me.workBook.getSheet(0);
  1026. let offset = $("#GLJListSheet").offset(),
  1027. x = e.pageX - offset.left,
  1028. y = e.pageY - offset.top;
  1029. let target = sheet.hitTest(x, y);
  1030. let sel = sheet.getSelections()[0];
  1031. if (sel.row === -1) {
  1032. sel.row = 0;
  1033. }
  1034. if (sel.col === -1) {
  1035. sel.col = 0;
  1036. }
  1037. if (target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {//在表格内
  1038. me.initSel(target.row);
  1039. if (sel.row > target.row || sel.row + sel.rowCount - 1 < target.row ||
  1040. sel.col > target.col || sel.col + sel.colCount - 1 < target.col) {
  1041. sheet.setActiveCell(target.row, target.col);
  1042. }
  1043. return {
  1044. callback: function () { },
  1045. items: {
  1046. "delete": {
  1047. name: "删除",
  1048. disabled: function () {
  1049. return !(me.currentCache && me.currentCache[target.row]);
  1050. },
  1051. icon: "fa-remove",
  1052. callback: function (key, opt) {
  1053. let curSel = _.cloneDeep(sheet.getSelections()[0]);
  1054. curSel.colCount = me.setting.header.length;
  1055. me.delGljs([curSel]);
  1056. }
  1057. }
  1058. }
  1059. };
  1060. }
  1061. else {
  1062. return false;
  1063. }
  1064. }
  1065. });
  1066. },
  1067. validUpdateObj: function (pasteObj, rowIdx) {
  1068. let rst = { updateGlj: [], updateBasePrcArr: [] }, backUpObj = {},
  1069. me = repositoryGljObj,
  1070. that = gljComponentOprObj,
  1071. tempObj = me.currentCache[rowIdx],
  1072. reCalBasePrc = false,
  1073. isValid = true;
  1074. //备份原始数据
  1075. for (let atr in tempObj) {
  1076. backUpObj[atr] = tempObj[atr];
  1077. }
  1078. if (typeof pasteObj.code !== 'undefined') {
  1079. if (pasteObj.code.trim().length !== 0) {
  1080. let isExist = false;
  1081. for (let i = 0; i < me.stdGljList.length; i++) {
  1082. if (me.stdGljList[i].code === pasteObj.code) {
  1083. isExist = true;
  1084. break;
  1085. }
  1086. }
  1087. if (!isExist) {
  1088. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1089. if (me.complementaryGljList[i].code === pasteObj.code) {
  1090. isExist = true;
  1091. break;
  1092. }
  1093. }
  1094. }
  1095. if (!isExist) {
  1096. tempObj.code = pasteObj.code;
  1097. }
  1098. else isValid = false;
  1099. }
  1100. else isValid = false;
  1101. }
  1102. if (typeof pasteObj.name !== 'undefined') {
  1103. if (pasteObj.name.trim().length === 0) isValid = false;
  1104. else tempObj.name = pasteObj.name;
  1105. }
  1106. if (typeof pasteObj.specs !== 'undefined') {
  1107. tempObj.specs = pasteObj.specs;
  1108. }
  1109. if (typeof pasteObj.unit !== 'undefined') {
  1110. tempObj.unit = pasteObj.unit;
  1111. }
  1112. if (typeof pasteObj.gljType !== 'undefined') {
  1113. let isExsit = false;
  1114. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1115. if (pasteObj.gljType === me.distTypeTree.comboDatas[i].text) {
  1116. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1117. isExsit = true;
  1118. reCalBasePrc = true;
  1119. if (!me.taxRateTypes.includes(pasteObj.taxRate) && me.taxRateTypes.includes(tempObj.taxRate)) {
  1120. tempObj.taxRate = null;
  1121. }
  1122. if (pasteObj.gljType !== 301 && tempObj.gljType === 301) {
  1123. tempObj.model = null;
  1124. }
  1125. if (componentType.includes(tempObj.gljType) &&
  1126. !(machineComponent.includes(tempObj.gljType) && machineComponent.includes(pasteObj.gljType)) &&
  1127. !(materialComponent.includes(tempObj.gljType) && materialComponent.includes(pasteObj.gljType))) {//修改了原本是组成物的工料机
  1128. //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
  1129. let updateGljs = me.getUpdateGljs(tempObj, true);
  1130. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1131. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1132. rst.updateGlj.push(updateGljs.updateArr[i]);
  1133. }
  1134. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1135. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1136. }
  1137. }
  1138. }
  1139. tempObj.component = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.component : [];
  1140. /*if(me.allowComponent.indexOf(tempObj.gljType) !== -1){
  1141. tempObj.basePrice = tempObj.gljType === me.distTypeTree.comboDatas[i].value ? tempObj.basePrice : 0;
  1142. }*/
  1143. tempObj.gljType = me.distTypeTree.comboDatas[i].value;
  1144. tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
  1145. break;
  1146. }
  1147. }
  1148. if (!isExsit) isValid = false;
  1149. }
  1150. if (typeof pasteObj.taxRate !== 'undefined'
  1151. && typeof pasteObj.gljType === 'undefined') {
  1152. if (me.taxRateTypes.includes(tempObj.gljType)) {
  1153. tempObj.taxRate = pasteObj.taxRate && !isNaN(pasteObj.taxRate) ? scMathUtil.roundTo(parseFloat(pasteObj.taxRate), -2) : null;
  1154. } else {
  1155. isValid = false;
  1156. }
  1157. }
  1158. //
  1159. /* pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? scMathUtil.roundTo(parseFloat(pasteObj.basePrice), 2) :
  1160. me.currentCache[rowIdx].basePrice;
  1161. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1162. reCalBasePrc = true;
  1163. tempObj.basePrice = pasteObj.basePrice;
  1164. let updateGljs = me.getUpdateGljs(tempObj, false);
  1165. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1166. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1167. rst.updateGlj.push(updateGljs.updateArr[i]);
  1168. }
  1169. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1170. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1171. }
  1172. }
  1173. } */
  1174. //单价相关
  1175. if (me.pasteIncludesPrice(pasteObj)) {
  1176. if (!priceProperties || priceProperties.length === 0) {
  1177. pasteObj.basePrice = pasteObj.basePrice && !isNaN(parseFloat(pasteObj.basePrice)) ?
  1178. scMathUtil.roundTo(parseFloat(pasteObj.basePrice), -2) : me.currentCache[rowIdx].basePrice;
  1179. if (pasteObj.basePrice !== me.currentCache[rowIdx].basePrice) {
  1180. reCalBasePrc = true;
  1181. tempObj.basePrice = pasteObj.basePrice;
  1182. }
  1183. }
  1184. else {
  1185. //多单价粘贴
  1186. let pastePriceProperty = {};
  1187. let priceFields = me.getPriceFields();
  1188. for (let priceField of priceFields) {
  1189. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1190. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1191. }
  1192. }
  1193. if (!me.priceIsEqual(tempObj, pasteObj)) {
  1194. reCalBasePrc = true;
  1195. //更新人材机单价
  1196. for (let priceField in pastePriceProperty) {
  1197. tempObj.priceProperty[priceField] = pastePriceProperty[priceField];
  1198. }
  1199. }
  1200. }
  1201. let updateGljs = me.getUpdateGljs(tempObj, false);
  1202. if (updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0) {
  1203. for (let i = 0; i < updateGljs.updateArr.length; i++) {
  1204. rst.updateGlj.push(updateGljs.updateArr[i]);
  1205. }
  1206. for (let i = 0; i < updateGljs.updateBasePrcArr.length; i++) {
  1207. rst.updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
  1208. }
  1209. }
  1210. }
  1211. if (typeof pasteObj.model !== 'undefined') {
  1212. if (!me.machineModel.textArr.includes(pasteObj.model)) {
  1213. isValid = false;
  1214. }
  1215. else {
  1216. let existsModel = false;
  1217. if ((typeof pasteObj.gljType !== 'undefined' && pasteObj.gljType === 301) ||
  1218. (tempObj.gljType && tempObj.gljType === 301)) {
  1219. me.machineModel.comboItems.forEach(function (item) {
  1220. if (item.text === pasteObj.model) {
  1221. tempObj.model = item.value;
  1222. existsModel = true;
  1223. }
  1224. });
  1225. if (!existsModel) {
  1226. isValid = false;
  1227. }
  1228. }
  1229. else {
  1230. isValid = false;
  1231. }
  1232. }
  1233. }
  1234. if (isValid) {
  1235. rst.updateGlj.push(tempObj);
  1236. if (reCalBasePrc) {
  1237. //重新计算定额基价对象
  1238. //rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
  1239. let newReObj = { gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: me.getRationGljPrice(tempObj) };
  1240. rst.updateBasePrcArr.push(newReObj);
  1241. }
  1242. }
  1243. else {
  1244. for (let attr in backUpObj) {
  1245. tempObj[attr] = backUpObj[attr];
  1246. }
  1247. }
  1248. return rst;
  1249. },
  1250. //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
  1251. isValidObj: function (pasteObj) {
  1252. let me = repositoryGljObj;
  1253. if (!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
  1254. !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')) {
  1255. return false;
  1256. }
  1257. if (pasteObj.gljType && typeof pasteObj.gljType !== 'undefined') {
  1258. let isExist = false;
  1259. for (let i = 0; i < me.distTypeTree.comboDatas.length; i++) {
  1260. if (me.distTypeTree.comboDatas[i].text === pasteObj.gljType) {
  1261. isExist = true;
  1262. pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
  1263. pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
  1264. break;
  1265. }
  1266. }
  1267. if (!isExist) {
  1268. return false;
  1269. }
  1270. }
  1271. if (pasteObj.code && typeof pasteObj.code !== 'undefined') {
  1272. for (let i = 0; i < me.stdGljList.length; i++) {
  1273. if (me.stdGljList[i].code === pasteObj.code) {
  1274. return false;
  1275. }
  1276. }
  1277. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1278. if (me.complementaryGljList[i].code === pasteObj.code) {
  1279. return false;
  1280. }
  1281. }
  1282. }
  1283. if (pasteObj.taxRate && (isNaN(pasteObj.taxRate) || !me.taxRateTypes.includes(pasteObj.gljType))) {
  1284. return false;
  1285. }
  1286. if (typeof pasteObj.model !== 'undefined' && pasteObj.model) {
  1287. if (!me.machineModel.textArr.includes(pasteObj.model) || pasteObj.gljType !== 301) {
  1288. return false;
  1289. }
  1290. me.machineModel.comboItems.forEach(function (item) {
  1291. if (item.text === pasteObj.model) {
  1292. pasteObj.model = item.value;
  1293. }
  1294. });
  1295. }
  1296. //pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1297. if (!priceProperties || priceProperties.length === 0) {
  1298. pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
  1299. } else {
  1300. let pastePriceProperty = {};
  1301. let priceFields = me.getPriceFields();
  1302. for (let priceField of priceFields) {
  1303. if (typeof pasteObj[priceField] !== 'undefined' && pasteObj[priceField] && !isNaN(parseFloat(pasteObj[priceField]))) {
  1304. pastePriceProperty[priceField] = scMathUtil.roundTo(parseFloat(pasteObj[priceField]), -2);
  1305. }
  1306. else {
  1307. pastePriceProperty[priceField] = 0;
  1308. }
  1309. }
  1310. pasteObj.priceProperty = pastePriceProperty;
  1311. }
  1312. if (!me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
  1313. pasteObj.gljClass = me.gljCurTypeId;
  1314. }
  1315. return true;
  1316. },
  1317. canPasted: function (info) {
  1318. let rst = true;
  1319. let me = repositoryGljObj;
  1320. if (me.gljCurTypeId < 0) {
  1321. return false;
  1322. }
  1323. const maxCol = info.cellRange.col + info.cellRange.colCount - 1;
  1324. if (maxCol > me.setting.header.length - 2) {
  1325. return false;
  1326. }
  1327. if (info.cellRange.row < me.currentCache.length) {
  1328. const minPriceCol = Math.min(...me.priceCols);
  1329. const maxPriceCol = Math.max(...me.priceCols)
  1330. if (info.cellRange.col === 0) {
  1331. return false;
  1332. }
  1333. for (let i = 0, len = info.cellRange.rowCount; i < len; i++) {
  1334. let row = i + info.cellRange.row;
  1335. if (row < me.currentCache.length
  1336. && allowComponent.includes(me.currentCache[row].gljType)
  1337. && me.currentCache[row].component.length
  1338. && !(maxCol < minPriceCol || info.cellRange.col > maxPriceCol)) {// 包含了价格列
  1339. return false;
  1340. } else {
  1341. break;
  1342. }
  1343. }
  1344. }
  1345. return rst;
  1346. },
  1347. onClipboardPasting: function (sender, args) {
  1348. let me = repositoryGljObj;
  1349. if (!me.canPasted(args)) {
  1350. args.cancel = true;
  1351. }
  1352. },
  1353. onClipboardPasted: function (e, info) {
  1354. // if(info.pasteData.text.trim().length > 0){
  1355. let me = repositoryGljObj;
  1356. let updateArr = [], addArr = [];
  1357. let items = sheetOpr.analyzePasteData(me.setting, info);
  1358. let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,//复制的起始行数和结束行数
  1359. maxRow = me.currentCache.length - 1,//当前数据最大行数
  1360. updateBasePrcArr = [],
  1361. updateCount, resumeArr = [];
  1362. if (endRow <= maxRow) {
  1363. for (let i = 0; i < items.length; i++) {
  1364. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1365. if (updateObj && typeof updateObj.updateGlj !== 'undefined' && updateObj.updateGlj.length > 0) {
  1366. updateArr = updateArr.concat(updateObj.updateGlj);
  1367. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1368. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1369. }
  1370. }
  1371. }
  1372. }
  1373. else if (beginRow <= maxRow && endRow > maxRow) {
  1374. updateCount = maxRow - beginRow + 1;
  1375. for (let i = 0; i < updateCount; i++) {
  1376. let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
  1377. if (updateObj && typeof updateObj.updateGlj !== 'undefined') {
  1378. updateArr = updateArr.concat(updateObj.updateGlj);
  1379. if (typeof updateObj.updateBasePrcArr !== 'undefined') {
  1380. updateBasePrcArr = updateBasePrcArr.concat(updateObj.updateBasePrcArr);
  1381. }
  1382. }
  1383. }
  1384. for (let i = updateCount; i < items.length; i++) {
  1385. if (me.isValidObj(items[i])) {
  1386. items[i].component = [];
  1387. addArr.push(items[i]);
  1388. }
  1389. }
  1390. }
  1391. else {
  1392. for (let i = 0; i < items.length; i++) {
  1393. if (me.isValidObj(items[i])) {
  1394. items[i].component = [];
  1395. addArr.push(items[i]);
  1396. }
  1397. }
  1398. }
  1399. //repaint
  1400. for (let i = 0; i < info.cellRange.rowCount; i++) {
  1401. resumeArr.push(info.cellRange.row + i);
  1402. }
  1403. if (resumeArr.length > 0) {
  1404. let sheet = me.workBook.getActiveSheet();
  1405. sheet.suspendPaint();
  1406. for (let i = 0; i < resumeArr.length; i++) {
  1407. if (resumeArr[i] < me.currentCache.length) {
  1408. for (let col = 0; col < me.setting.header.length - 1; col++) {
  1409. if (me.setting.header[col].dataCode === 'gljType') {
  1410. let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
  1411. sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
  1412. }
  1413. else if (me.setting.header[col].dataCode === 'model') {
  1414. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode] ? me.machineModelIdx[me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]] : '');
  1415. }
  1416. else {
  1417. sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
  1418. }
  1419. }
  1420. }
  1421. else {
  1422. for (let col = 0; col < me.setting.header.length - 1; col++) {
  1423. sheet.setValue(resumeArr[i], col, '', GC.Spread.Sheets.SheetArea.viewport);
  1424. }
  1425. }
  1426. }
  1427. sheet.resumePaint();
  1428. }
  1429. if (updateArr.length > 0 || addArr.length > 0) {
  1430. me.mixUpdateRequest(updateArr, addArr, []);
  1431. }
  1432. /* if (updateBasePrcArr.length > 0 && me.rationLibs.length > 0) {
  1433. me.updateRationBasePrcRq(updateBasePrcArr);
  1434. } */
  1435. // }
  1436. },
  1437. updateRationBasePrcRq: function (basePrcArr) {
  1438. CommonAjax.post('/complementartGlj/api/updateRationBasePrc', { basePrcArr: basePrcArr }, function (rstData) {
  1439. });
  1440. },
  1441. /* getRationGljIds: function (repId) {
  1442. let me = repositoryGljObj;
  1443. $.ajax({
  1444. type: 'post',
  1445. url: 'api/getRationGljIds',
  1446. data: {data: JSON.stringify({repId: repId})},
  1447. dataType: 'json',
  1448. success: function(result){
  1449. if(!result.error){
  1450. me.rationGljIds = result.data;
  1451. }
  1452. }
  1453. });
  1454. },*/
  1455. mixUpdateRequest: function (updateArr, addArr, removeIds) {
  1456. let me = repositoryGljObj;
  1457. if (updateArr.length > 0) {
  1458. me.saveInString(updateArr);
  1459. }
  1460. if (addArr.length > 0) {
  1461. me.saveInString(addArr);
  1462. }
  1463. let url = 'complementartGlj/api/mixUpdateGljItems';
  1464. let post = { updateItems: updateArr, addItems: addArr, removeIds: removeIds };
  1465. let scCaller = function (rstData) {
  1466. me.updateCache(addArr, updateArr, removeIds, rstData);
  1467. me.sortGlj(me.complementaryGljList);
  1468. if (me.currentOprParent === 1) {
  1469. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
  1470. }
  1471. else {
  1472. me.currentCache = me.getCache();
  1473. }
  1474. me.showGljItems(me.complementaryGljList, me.gljCurTypeId);
  1475. //getCurrentGlj
  1476. let row = me.workBook.getSheet(0).getSelections()[0].row;
  1477. me.initSel(row);
  1478. }
  1479. let errCaller = function (err) {
  1480. alert('保存失败');
  1481. };
  1482. CommonAjax.post(url, post, scCaller, errCaller);
  1483. },
  1484. saveInString: function (datas) {
  1485. for (let i = 0, len = datas.length; i < len; i++) {
  1486. let data = datas[i];
  1487. if (_exist(data, 'basePrice')) {
  1488. data['basePrice'] = data['basePrice'].toString();
  1489. }
  1490. if (_exist(data, 'component')) {
  1491. for (let j = 0, jLen = data['component'].length; j < jLen; j++) {
  1492. let comGljObj = data['component'][j];
  1493. if (_exist(comGljObj, 'consumeAmt')) {
  1494. comGljObj['consumeAmt'] = comGljObj['consumeAmt'].toString();
  1495. }
  1496. }
  1497. }
  1498. }
  1499. function _exist(data, attr) {
  1500. return data && data[attr] !== undefined && data[attr];
  1501. }
  1502. },
  1503. getParentCache: function (nodes) {
  1504. let me = repositoryGljObj, rst = [];
  1505. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1506. if (nodes.indexOf(me.complementaryGljList[i].gljClass) !== -1) {
  1507. rst.push(me.complementaryGljList[i]);
  1508. }
  1509. }
  1510. rst.sort(function (a, b) {
  1511. let rst = 0;
  1512. if (a.code > b.code) rst = 1;
  1513. else if (a.code < b.code) rst = -1;
  1514. return rst;
  1515. });
  1516. return rst;
  1517. },
  1518. getCache: function () {
  1519. let me = this, rst = [];
  1520. for (let i = 0; i < me.complementaryGljList.length; i++) {
  1521. if (me.complementaryGljList[i].gljClass == me.gljCurTypeId) {
  1522. rst.push(me.complementaryGljList[i]);
  1523. }
  1524. }
  1525. return rst;
  1526. },
  1527. updateCache: function (addArr, updateArr, removeIds, rstData) {
  1528. let me = this, cacheSection = me.complementaryGljList;
  1529. if (addArr.length > 0) {
  1530. me.complementaryGljList = me.complementaryGljList.concat(addArr);
  1531. cacheSection = me.complementaryGljList;
  1532. }
  1533. for (let i = removeIds.length - 1; i >= 0; i--) {
  1534. for (let j = cacheSection.length - 1; j >= 0; j--) {
  1535. if (cacheSection[j]["ID"] == removeIds[i]) {
  1536. cacheSection.splice(j, 1);
  1537. }
  1538. }
  1539. }
  1540. if (rstData && rstData.ops && rstData.ops.length > 0) {
  1541. for (let i = 0; i < rstData.ops.length; i++) {
  1542. for (let j = 0; j < cacheSection.length; j++) {
  1543. if (cacheSection[j][me.setting.header[0].dataCode] == rstData.ops[i][me.setting.header[0].dataCode]) {
  1544. cacheSection[j]["ID"] = rstData.ops[i]["ID"];
  1545. }
  1546. }
  1547. }
  1548. }
  1549. for (let i = 0; i < updateArr.length; i++) {
  1550. for (let j = 0; j < cacheSection.length; j++) {
  1551. if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
  1552. if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
  1553. cacheSection[j] = updateArr[i];
  1554. }
  1555. } else if (cacheSection[j].code === updateArr[i].code) {
  1556. cacheSection[j] = updateArr[i];
  1557. }
  1558. }
  1559. }
  1560. //allgljs
  1561. },
  1562. updateParentNodeIds: function (nodes, caller) {
  1563. let private_build_parentNodeIds = function (pNodeId, nodesArr) {
  1564. let rst = [];
  1565. for (let i = 0; i < nodesArr.length; i++) {
  1566. if (nodesArr[i].children.length > 0) {
  1567. rst = rst.concat(private_build_parentNodeIds(nodesArr[i].data.ID, nodesArr[i].children));
  1568. } else {
  1569. rst.push(nodesArr[i].data.ID);
  1570. }
  1571. }
  1572. if (pNodeId && rst.length > 0) {
  1573. caller.parentNodeIds["_pNodeId_" + pNodeId] = rst;
  1574. }
  1575. return rst;
  1576. };
  1577. if (caller.parentNodeIds) {
  1578. private_build_parentNodeIds(null, nodes);
  1579. }
  1580. },
  1581. setProp: function (prop, value, gljList) {
  1582. let me = this;
  1583. for (let i = 0, len = gljList.length; i < len; i++) {
  1584. gljList[i][prop] = value;
  1585. }
  1586. },
  1587. sortGlj: function (gljList) {
  1588. let me = this;
  1589. gljList.sort(function (a, b) {
  1590. let rst = 0;
  1591. if (a.code > b.code) rst = 1
  1592. else if (a.code < b.code) rst = -1;
  1593. return rst;
  1594. });
  1595. }
  1596. }
  1597. let gljTypeTreeOprObj = {
  1598. onClick: function (event, treeId, treeNode) {
  1599. let me = repositoryGljObj,
  1600. that = gljComponentOprObj,
  1601. gljTypeId = treeNode.ID;
  1602. me.gljCurTypeId = treeNode.ID;
  1603. //消除新增到一半的数据
  1604. me.addGljObj = null;
  1605. //me.currentCache = me.getCache();
  1606. sheetOpr.cleanData(that.workBook.getSheet(0), that.setting, 5);
  1607. if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
  1608. me.currentOprParent = 1;
  1609. me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
  1610. me.workBook.getSheet(0).setRowCount(me.currentCache.length);
  1611. } else {
  1612. me.currentOprParent = 0;
  1613. me.currentCache = me.getCache();
  1614. }
  1615. me.showGljItems(me.complementaryGljList, gljTypeId);
  1616. }
  1617. }