ration_glj.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /**
  2. * Created by Tony on 2017/4/28.
  3. */
  4. var rationGLJOprObj = {
  5. processDecimal: -6,
  6. sheet: null,
  7. currentRationItem: null,
  8. distTypeTree: null,
  9. activeCell: null,
  10. tempCacheArr: [],//被更新的工料机,若更新的工料机不存在,则恢复
  11. cache: {},
  12. setting: {
  13. header: [
  14. { headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@" },
  15. { headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String" },
  16. { headerName: "规格型号", headerWidth: 100, dataCode: "specs", dataType: "String" },
  17. { headerName: "单位", headerWidth: 60, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center" },
  18. { headerName: "定额价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", precision: 2 },
  19. { headerName: "定额消耗", headerWidth: 80, dataCode: "consumeAmt", dataType: "Number", formatter: "0.000", precision: 3 },
  20. { headerName: "类型", headerWidth: 70, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center" },
  21. { headerName: "配合比", headerWidth: 70, dataCode: "proportion", dataType: "Number", formatter: "0.00", precision: 2 },
  22. { headerName: "损耗编号", headerWidth: 80, dataCode: "lossRateNo", dataType: "Number" },
  23. { headerName: "损耗率", headerWidth: 80, dataCode: "lossRate", dataType: "Number", hAlign: "right", vAlign: "center" },
  24. ],
  25. view: {
  26. comboBox: [],
  27. lockColumns: [1, 2, 3, 4, 6, 8, 9]
  28. }
  29. },
  30. getDistTypeTree: function (gljDistType) {
  31. let distType;
  32. let distTypeTree = {
  33. prefix: 'gljDistType',
  34. distTypes: {},
  35. comboDatas: [],
  36. distTypesArr: []
  37. };
  38. gljDistType.forEach(function (typeData) {
  39. let typeObj = {
  40. data: typeData,
  41. children: [],
  42. parent: null
  43. }
  44. distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
  45. distTypeTree.distTypesArr.push(typeObj);
  46. });
  47. gljDistType.forEach(function (typeData) {
  48. distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
  49. let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
  50. if (parent) {
  51. distType.parent = parent;
  52. parent.children.push(distType);
  53. }
  54. });
  55. distTypeTree.distTypesArr.forEach(function (distTypeObj) {
  56. if (distTypeObj.children.length === 0 && distTypeObj.data.fullName !== '普通机械' && distTypeObj.data.fullName !== '机械组成物'
  57. && distTypeObj.data.fullName !== '机上人工') {
  58. distTypeTree.comboDatas.push({ text: distTypeObj.data.fullName, value: distTypeObj.data.ID });
  59. }
  60. if (distTypeObj.data.fullName === '机械') {
  61. distTypeTree.comboDatas.push({ text: distTypeObj.data.fullName, value: distTypeObj.data.ID });
  62. }
  63. });
  64. return distTypeTree;
  65. },
  66. initGljDistType: function (gljDistTypeList) {
  67. this.distTypeTree = this.getDistTypeTree(gljDistTypeList);
  68. },
  69. buildSheet: function (sheet) {
  70. this.sheet = sheet;
  71. sheetCommonObj.initSheet(this.sheet, this.setting, 30);
  72. this.onContextmenuOpr();
  73. this.bindRationGljDelOpr();
  74. this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, this.onClipboardPasting);
  75. this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, this.onClipboardPasted);
  76. this.sheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onEditStarting);
  77. this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onCellEditEnd);
  78. },
  79. bindRationGljDelOpr: function () {
  80. if (locked) {
  81. return;
  82. }
  83. const me = rationGLJOprObj;
  84. const spreadBook = me.sheet.getParent();
  85. spreadBook.commandManager().register('rationGljDelete', function () {
  86. const cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID];
  87. const sels = me.sheet.getSelections();
  88. if (!cacheSection || !sels.length) {
  89. return;
  90. }
  91. let isUpdate = false;
  92. for (const sel of sels) {
  93. const deleteRow = sel.colCount === me.setting.header.length && sel.row < cacheSection.length;
  94. if (deleteRow) {
  95. isUpdate = true;
  96. cacheSection.splice(sel.row, sel.rowCount);
  97. }
  98. }
  99. if (isUpdate) {
  100. me.updateRationItem(function () {
  101. me.sheet.getParent().focus(true);
  102. });
  103. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  104. me.showGljItems(me.currentRationItem.ID);
  105. }
  106. });
  107. spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
  108. spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
  109. },
  110. onClipboardPasting: function (sender, args) {
  111. const me = rationGLJOprObj;
  112. const rationCache = rationOprObj.getCache();
  113. const rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  114. me.currentRationItem = rationRow < rationCache.length ? rationCache[rationRow] : null;
  115. if (me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined') {
  116. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  117. }
  118. const field = me.setting.header[args.cellRange.col].dataCode;
  119. const canPasteFields = ['code', 'consumeAmt', 'proportion', 'lossRateNo'];
  120. if (!me.currentRationItem || !(canPasteFields.includes(field) && args.cellRange.colCount === 1)) {
  121. args.cancel = true;
  122. }
  123. },
  124. onClipboardPasted: async function (e, info) {
  125. const me = rationGLJOprObj;
  126. me.tempCacheArr = [];
  127. const gljCache = me.cache["_GLJ_" + me.currentRationItem.ID];
  128. const field = me.setting.header[info.cellRange.col].dataCode;
  129. debugger;
  130. if (field === 'code') {
  131. const pasteList = sheetCommonObj.analyzePasteData({ header: [{ dataCode: "code" }] }, info);
  132. const codes = [];
  133. for (let i = 0; i < pasteList.length; i++) {
  134. let rowIdx = info.cellRange.row + i;
  135. if (rowIdx < gljCache.length) {//更新
  136. me.tempCacheArr.push({ org: gljCache[rowIdx], newCode: pasteList[i].code });
  137. gljCache.splice(rowIdx--, 1);
  138. }
  139. codes.push(pasteList[i].code);
  140. }
  141. me.addGljItems(codes, pageOprObj.gljLibId, info.cellRange);
  142. } else if (gljCache && info.cellRange.row < gljCache.length) {
  143. const pasteList = sheetCommonObj.analyzePasteData(me.setting, info);
  144. const maxCount = info.cellRange.row + info.cellRange.rowCount - 1 > gljCache.length - 1 ?
  145. gljCache.length - info.cellRange.row : info.cellRange.rowCount;
  146. const precision = me.setting.header[info.cellRange.col].precision;
  147. if (field === 'lossRateNo') {
  148. const lossRateNos = pasteList.map(item => item.lossRateNo);
  149. const lossMap = await rationGLJOprObj.getLossMap(lossRateNos);
  150. for (let i = 0; i < maxCount; i++) {
  151. const curGLJ = gljCache[info.cellRange.row + i]
  152. const serialNo = pasteList[i][field];
  153. const loss = lossMap[serialNo];
  154. if (loss) {
  155. curGLJ.lossRateID = loss.ID;
  156. curGLJ.lossRateNo = loss.serialNo;
  157. curGLJ.lossRateName = loss.name;
  158. curGLJ.lossRate = loss.rate;
  159. } else {
  160. delete curGLJ.lossRateID;
  161. delete curGLJ.lossRateNo;
  162. delete curGLJ.lossRateName;
  163. delete curGLJ.lossRate;
  164. }
  165. }
  166. } else {
  167. for (let i = 0; i < maxCount; i++) {
  168. const pasteVal = precision ? scMathUtil.roundTo(pasteList[i][field], -precision) : pasteList[i][field];
  169. gljCache[info.cellRange.row + i][field] = pasteVal;
  170. }
  171. }
  172. me.updateRationItem(function () {
  173. me.sheet.getParent().focus(true);
  174. });
  175. if (info.cellRange.row + info.cellRange.rowCount - 1 >= gljCache.length - 1) {
  176. me.sheet.suspendPaint();
  177. for (let rowIdx = gljCache.length; rowIdx <= info.cellRange.row + info.cellRange.rowCount - 1; rowIdx++) {
  178. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  179. }
  180. me.sheet.resumePaint();
  181. }
  182. } else if (info.cellRange.row >= gljCache.length) {
  183. me.sheet.suspendPaint();
  184. for (let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount - 1; rowIdx++) {
  185. me.sheet.setValue(rowIdx, info.cellRange.col, '');
  186. }
  187. me.sheet.resumePaint();
  188. }
  189. },
  190. onEditStarting: function (sender, args) {
  191. const me = rationGLJOprObj;
  192. const rationSection = rationOprObj.getCache();
  193. const rationRow = rationOprObj.workBook.getSheet(0).getSelections()[0].row;
  194. me.currentRationItem = rationRow < rationSection.length ? rationSection[rationRow] : null;
  195. if (me.currentRationItem && typeof me.cache["_GLJ_" + me.currentRationItem.ID] === 'undefined') {
  196. me.cache["_GLJ_" + me.currentRationItem.ID] = [];
  197. }
  198. const isEmptyRation = !me.currentRationItem;
  199. if (isEmptyRation) {
  200. return args.cancel = true;
  201. }
  202. const canEditFields = ['code', 'consumeAmt', 'proportion', 'lossRateNo'];
  203. const emptyGLJCanEditFields = ['code'];
  204. const isEmptyGLJ = args.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length;
  205. const editingField = me.setting.header[args.col].dataCode;
  206. const isValidField = isEmptyGLJ && emptyGLJCanEditFields.includes(editingField) || !isEmptyGLJ && canEditFields.includes(editingField);
  207. if (!isValidField) {
  208. return args.cancel = true;
  209. }
  210. },
  211. onCellEditEnd: async function (sender, args) {
  212. const me = rationGLJOprObj;
  213. me.tempCacheArr = [];
  214. const cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  215. const editingField = me.setting.header[args.col].dataCode;
  216. const trimText = args.editingText ? args.editingText.trim() : '';
  217. const curGLJ = cacheArr[args.row];
  218. const originText = curGLJ && !commonUtil.isEmptyVal(curGLJ[editingField]) ? String(curGLJ[editingField]) : '';
  219. if ((!trimText && editingField === 'code') || trimText === originText) {
  220. args.sheet.setValue(args.row, args.col, originText);
  221. return;
  222. }
  223. if (editingField === 'code') {
  224. const matchGLJ = cacheArr.find((item, index) => item.code === trimText && index !== args.row);
  225. if (matchGLJ) {
  226. alert("该人材机已存在!");
  227. args.sheet.setValue(args.row, args.col, originText);
  228. return;
  229. }
  230. if (args.row < cacheArr.length) { // 替换人材机
  231. me.tempCacheArr.push({ org: cacheArr[args.row], newCode: args.editingText.toString().trim() });
  232. cacheArr.splice(args.row, 1);
  233. }
  234. me.addGljItems([trimText], pageOprObj.gljLibId)
  235. } else {
  236. const fieldName = me.setting.header[args.col].headerName;
  237. if (isNaN(trimText)) {
  238. $('#alertText').text(`${fieldName}只能输入数值。`);
  239. $('#alertModal').modal('show');
  240. args.sheet.setValue(args.row, args.col, originText);
  241. } else {
  242. if (editingField === 'lossRateNo') {
  243. const lossMap = await rationGLJOprObj.getLossMap([trimText]);
  244. const loss = lossMap[trimText];
  245. if (loss) {
  246. curGLJ.lossRateID = loss.ID;
  247. curGLJ.lossRateNo = loss.serialNo;
  248. curGLJ.lossRateName = loss.name;
  249. curGLJ.lossRate = loss.rate;
  250. } else {
  251. delete curGLJ.lossRateID;
  252. delete curGLJ.lossRateNo;
  253. delete curGLJ.lossRateName;
  254. delete curGLJ.lossRate;
  255. }
  256. } else {
  257. const precision = me.setting.header[args.col].precision;
  258. const roundText = scMathUtil.roundTo(trimText, -precision);
  259. curGLJ[editingField] = roundText;
  260. }
  261. me.updateRationItem(function () {
  262. me.sheet.getParent().focus(true);
  263. });
  264. }
  265. }
  266. },
  267. getLossMap: async function (serialNos) {
  268. const lossList = await rationGLJOprObj.getLossListByNos(serialNos);
  269. const map = {};
  270. lossList.forEach(item => {
  271. map[item.serialNo] = item;
  272. });
  273. return map;
  274. },
  275. getLossListByNos: async function (serialNos) {
  276. try {
  277. const res = await ajaxPost('/rationRepository/api/getItemsBySerialNos', { serialNos, libID: pageOprObj.rationLibId });
  278. return res;
  279. } catch (error) {
  280. return [];
  281. }
  282. },
  283. onContextmenuOpr: function () {//右键菜单
  284. let me = this;
  285. let raCoe = rationCoeOprObj;
  286. $.contextMenu({
  287. selector: '#rdSpread',
  288. build: function ($triggerElement, e) {
  289. //控制允许右键菜单在哪个位置出现
  290. let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.sheet.getParent());
  291. let sheet = me.sheet;
  292. if (me.sheet.getParent().getActiveSheetIndex() === 0 && target.hitTestType === 3) {//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
  293. //rationGlj表
  294. if (typeof target.row !== 'undefined') {
  295. //控制按钮是否可用
  296. sheet.setActiveCell(target.row, target.col);
  297. }
  298. return {
  299. callback: function () { },
  300. items: {
  301. "add": {
  302. name: "添加人材机",
  303. disabled: function () {
  304. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  305. if (locked || inValidCell || !me.currentRationItem) {
  306. return true;
  307. }
  308. return false;
  309. },
  310. icon: "fa-plus",
  311. callback: function (key, opt) {
  312. //默认radio所有工料机
  313. gljSelOprObj.initRadio();
  314. gljSelOprObj.gljCurTypeId = null;
  315. //默认点击树根节点
  316. if (gljSelOprObj.rootNode) {
  317. gljSelOprObj.treeObj.selectNode(gljSelOprObj.rootNode);
  318. gljSelTreeOprObj.setting.callback.onClick(null, 'componentTree', gljSelOprObj.rootNode);
  319. }
  320. //弹出窗口
  321. $('#selGlj').modal('show');
  322. }
  323. },
  324. "delete": {
  325. name: "删除人材机",
  326. disabled: function () {
  327. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  328. const rationGlj = me.cache['_GLJ_' + me.currentRationItem.ID];
  329. const inValidData = !rationGlj || target.row >= rationGlj.length;
  330. if (locked || inValidCell || !me.currentRationItem || inValidData) {
  331. return true;
  332. }
  333. return false;
  334. },
  335. icon: "fa-remove",
  336. callback: function (key, opt) {
  337. const rationGlj = me.cache['_GLJ_' + me.currentRationItem.ID];
  338. rationGlj.splice(target.row, 1);
  339. me.updateRationItem(function () {
  340. me.sheet.getParent().focus();
  341. });
  342. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  343. me.showGljItems(me.currentRationItem.ID);
  344. }
  345. },
  346. }
  347. };
  348. }
  349. //rationCoe表
  350. else if (me.sheet.getParent().getActiveSheetIndex() === 2 && target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined') {
  351. let currentCache = raCoe.curRation && raCoe.isDef(raCoe.cache["_Coe_" + raCoe.curRation.ID]) ? raCoe.cache["_Coe_" + raCoe.curRation.ID] : [];
  352. sheet.setActiveCell(target.row, target.col);
  353. return {
  354. callback: function () { },
  355. items: {
  356. "upMove": {
  357. name: "上移",
  358. disabled: function () {
  359. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  360. const inValidData = target.row >= currentCache.length || !raCoe.isDef(currentCache[target.row - 1]);
  361. return locked || inValidCell || inValidData
  362. },
  363. icon: "fa-arrow-up",
  364. callback: function (key, opt) {
  365. raCoe.upMove(currentCache[target.row], currentCache[target.row - 1], { row: target.row - 1, col: target.col });
  366. }
  367. },
  368. "downMove": {
  369. name: "下移",
  370. disabled: function () {
  371. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  372. const inValidData = target.row >= currentCache.length || !raCoe.isDef(currentCache[target.row + 1]);
  373. return locked || inValidCell || inValidData;
  374. },
  375. icon: "fa-arrow-down",
  376. callback: function (key, opt) {
  377. raCoe.downMove(currentCache[target.row], currentCache[target.row + 1], { row: target.row + 1, col: target.col });
  378. }
  379. },
  380. "ref": {
  381. name: "添加到本节其他定额",
  382. disabled: function () {
  383. const inValidCell = !commonUtil.isDef(target.row) || !commonUtil.isDef(target.col);
  384. const inValidData = target.row >= currentCache.length;
  385. return locked || inValidCell || inValidData;
  386. },
  387. icon: "fa-arrow-left",
  388. callback: function (key, opt) {
  389. raCoe.updateSectionRation(rationOprObj.currentRations["_SEC_ID_" + rationOprObj.currentSectionId], currentCache[target.row], function (updateArr) {
  390. for (let i = 0, len = updateArr.length; i < len; i++) {
  391. let ration = updateArr[i];
  392. let rationCoeList = updateArr[i].rationCoeList;
  393. let newNo = 1;
  394. for (let j = 0, jLen = rationCoeList.length; j < jLen; j++) {
  395. if (rationCoeList[j].no >= newNo) {
  396. newNo = rationCoeList[j].no + 1;
  397. }
  398. }
  399. let theCache = raCoe.cache["_Coe_" + ration.ID];
  400. if (theCache !== undefined && theCache !== null) {
  401. let newCoe = {};
  402. for (let attr in currentCache[target.row]) {
  403. newCoe[attr] = currentCache[target.row][attr];
  404. }
  405. newCoe.no = newNo;
  406. theCache.push(newCoe);
  407. }
  408. }
  409. });
  410. }
  411. }
  412. }
  413. };
  414. }
  415. else {
  416. return false;
  417. }
  418. }
  419. });
  420. },
  421. getRecoveryArr: function (tempDelArr, newArr) {//获得更新的code不存在,恢复删除的被更新数据
  422. let rst = [];
  423. for (let i = 0, len = tempDelArr.length; i < len; i++) {
  424. let isExist = false;
  425. for (let j = 0, jLen = newArr.length; j < jLen; j++) {
  426. if (tempDelArr[i].newCode == newArr[j].code) {
  427. isExist = true;
  428. break;
  429. }
  430. }
  431. if (!isExist) {
  432. rst.push(tempDelArr[i].org);
  433. }
  434. }
  435. return rst;
  436. },
  437. addGljItems: function (codes, repId) {
  438. var me = this;
  439. $.ajax({
  440. type: "POST",
  441. url: "api/getGljItemsByCodes",
  442. data: { "gljCodes": JSON.stringify(codes), repId: repId },
  443. dataType: "json",
  444. cache: false,
  445. timeout: 5000,
  446. success: function (result) {
  447. if (result) {
  448. if (result.data.length > 0) {
  449. if (priceProperties && priceProperties.length > 0) {
  450. let priceField = priceProperties[0].price.dataCode;
  451. for (let glj of result.data) {
  452. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  453. }
  454. }
  455. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  456. var rstArr = [], dummyR = { gljId: 0, consumeAmt: 0 },
  457. newAddArr = [],
  458. validGlj = [];
  459. for (var i = 0; i < result.data.length; i++) {
  460. dummyR.gljId = result.data[i].ID;
  461. rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
  462. }
  463. if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
  464. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  465. for (var i = 0; i < rstArr.length; i++) {
  466. var hasDup = false;
  467. for (var j = 0; j < cacheArr.length; j++) {
  468. if (cacheArr[j].gljId == rstArr[i].gljId) {
  469. hasDup = true;
  470. break;
  471. }
  472. }
  473. if (!hasDup) {
  474. newAddArr.push(rstArr[i]);
  475. }
  476. }
  477. //新增的定额人材机,按照输入的编码排序
  478. for (let code of codes) {
  479. let fGlj = _.find(newAddArr, function (glj) {
  480. return glj.code === code;
  481. });
  482. if (fGlj) {
  483. validGlj.push(fGlj);
  484. }
  485. }
  486. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(validGlj);
  487. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, result.data);
  488. if (recoveryArr.length > 0) {
  489. me.cache["_GLJ_" + me.currentRationItem.ID] = me.cache["_GLJ_" + me.currentRationItem.ID].concat(recoveryArr);
  490. }
  491. }
  492. me.showGljItems(me.currentRationItem.ID);
  493. if (validGlj.length > 0) {
  494. me.updateRationItem(function () {
  495. me.sheet.getParent().focus(true);
  496. });
  497. }
  498. }
  499. else {
  500. let cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID] ? me.cache["_GLJ_" + me.currentRationItem.ID] : [];
  501. let recoveryArr = me.getRecoveryArr(me.tempCacheArr, []);
  502. if (recoveryArr.length > 0) {
  503. me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(recoveryArr);
  504. }
  505. //更新的工料机不存在
  506. $('#alertModalBtn').click();
  507. $('#alertText').text("人材机" + codes + "不存在,请查找你所需要的人材机,或新增人材机");
  508. $('#alertModalCls').click(function () {
  509. me.showGljItems(me.currentRationItem.ID);
  510. });
  511. $('#alertModalCof').click(function () {
  512. me.showGljItems(me.currentRationItem.ID);
  513. })
  514. }
  515. }
  516. },
  517. error: function (err) {
  518. alert(err);
  519. }
  520. })
  521. },
  522. round(v, e) {
  523. var t = 1;
  524. for (; e > 0; t *= 10, e--);
  525. for (; e < 0; t /= 10, e++);
  526. return Math.round(v * t) / t;
  527. },
  528. rationCal: function () {
  529. let me = rationGLJOprObj;
  530. let rationBasePrc = 0;
  531. if (me.currentRationItem && me.cache['_GLJ_' + me.currentRationItem.ID]) {
  532. let cacheArr = me.cache['_GLJ_' + me.currentRationItem.ID];
  533. cacheArr.forEach(function (gljData) {
  534. if (gljData.gljType && gljData.basePrice && gljData.consumeAmt) {
  535. rationBasePrc += gljData.basePrice * gljData.consumeAmt;
  536. }
  537. });
  538. rationBasePrc = scMathUtil.roundTo(rationBasePrc, 0);
  539. }
  540. return rationBasePrc;
  541. },
  542. updateRationItem: function (callback) {
  543. var me = this, updateArr = [];
  544. if (me.currentRationItem) {
  545. me.currentRationItem.rationGljList = me.buildRationItemGlj();
  546. //recalculate ration basePrice
  547. let price = me.rationCal();
  548. me.currentRationItem.basePrice = price;
  549. updateArr.push(me.currentRationItem);
  550. rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
  551. if (callback) callback();
  552. });
  553. }
  554. },
  555. buildRationItemGlj: function () {
  556. var me = this, rst = [];
  557. if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
  558. var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
  559. for (var i = 0; i < cacheArr.length; i++) {
  560. const rGlj = {
  561. gljId: cacheArr[i].gljId,
  562. consumeAmt: cacheArr[i].consumeAmt,
  563. proportion: cacheArr[i].proportion,
  564. lossRateID: cacheArr[i].lossRateID,
  565. lossRateNo: cacheArr[i].lossRateNo,
  566. lossRateName: cacheArr[i].lossRateName,
  567. lossRate: cacheArr[i].lossRate
  568. };
  569. rst.push(rGlj);
  570. }
  571. }
  572. return rst;
  573. },
  574. createRationGljDisplayItem: function (rItem, repGlj) {
  575. var rst = {};
  576. rst.gljId = rItem.gljId;
  577. rst.consumeAmt = rItem.consumeAmt;
  578. rst.proportion = rItem.proportion;
  579. rst.code = repGlj.code;
  580. rst.name = repGlj.name;
  581. rst.specs = repGlj.specs;
  582. rst.unit = repGlj.unit;
  583. rst.basePrice = repGlj.basePrice;
  584. rst.gljType = repGlj.gljType;
  585. rst.lossRateID = rItem.lossRateID;
  586. rst.lossRateNo = rItem.lossRateNo;
  587. rst.lossRateName = rItem.lossRateName;
  588. rst.lossRate = rItem.lossRate;
  589. return rst;
  590. },
  591. getGljItems: function (rationItem, callback) {
  592. var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList ? rationItem.rationGljList : [];
  593. me.currentRationItem = rationItem;
  594. if (me.cache["_GLJ_" + rationID]) {
  595. me.showGljItems(rationID);
  596. } else {
  597. var gljIds = [];
  598. for (var i = 0; i < rationGljList.length; i++) {
  599. gljIds.push(rationGljList[i].gljId);
  600. }
  601. $.ajax({
  602. type: "POST",
  603. url: "api/getGljItemsByIds",
  604. data: { "gljIds": JSON.stringify(gljIds) },
  605. dataType: "json",
  606. cache: false,
  607. timeout: 5000,
  608. success: function (result) {
  609. sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
  610. if (result) {
  611. if (priceProperties && priceProperties.length > 0) {
  612. let priceField = priceProperties[0].price.dataCode;
  613. for (let glj of result.data) {
  614. glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
  615. }
  616. }
  617. var cacheArr = [];
  618. for (var j = 0; j < rationGljList.length; j++) {
  619. for (var i = 0; i < result.data.length; i++) {
  620. if (rationGljList[j].gljId == result.data[i].ID) {
  621. cacheArr.push(me.createRationGljDisplayItem(rationGljList[j], result.data[i]));
  622. break;
  623. }
  624. }
  625. }
  626. me.cache["_GLJ_" + rationID] = cacheArr;
  627. me.showGljItems(rationID);
  628. }
  629. if (callback) callback();
  630. },
  631. error: function (err) {
  632. alert(err);
  633. }
  634. })
  635. }
  636. },
  637. showGljItems: function (rationID) {
  638. var me = this;
  639. if (me.cache["_GLJ_" + rationID]) {
  640. sheetCommonObj.cleanData(me.sheet, me.setting, -1);
  641. sheetsOprObj.showData(me.sheet, me.setting, me.cache["_GLJ_" + rationID], me.distTypeTree);
  642. }
  643. }
  644. }