glj.js 74 KB

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