123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- /**
- * Created by Tony on 2017/4/28.
- */
- $("#gongliao").click(function(){
- $(this).attr('href', "/rationRepository/lmm" + "?repository=" + getQueryString("repository"))
- });
- $("#fuzhu").click(function(){
- $(this).attr('href', "/rationRepository/coeList" + "?repository=" + getQueryString("repository"))
- });
- var rationOprObj = {
- workBook: null,
- currentRations: {},
- currentEditingRation: null,
- currentSectionId: -1,
- setting: {
- header:[
- {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@"},
- {headerName:"名称",headerWidth:300,dataCode:"name", dataType: "String"},
- {headerName:"单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center"},
- {headerName:"人工费",headerWidth:120,dataCode:"labourPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"材料费",headerWidth:120,dataCode:"materialPrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"机械费",headerWidth:120,dataCode:"machinePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"基价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right"},
- {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption", dataType: "String"},
- {headerName:"取费专业",headerWidth:120,dataCode:"feeType", dataType: "Number", hAlign: "center"}
- ],
- view:{
- comboBox:[
- {row:-1,col:2,rowCount:-1,colCount:1}
- ],
- lockedCells:[
- {row:-1,col:3,rowCount:-1, colCount:1}
- ],
- lockColumns: [
- 3, 4, 5, 6
- ]
- }
- },
- buildSheet: function(container) {
- var me = rationOprObj;
- me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
- me.rationDelOpr();
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditStarting, me.onCellEditStart);
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
- //me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
- me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- },
- onCellClick: function(sender, args) {
- var me = rationOprObj,
- sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
- sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
- sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
- sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
- sheetCommonObj.shieldAllCells(sheetGLJ);
- sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
- sheetCommonObj.shieldAllCells(sheetCoe);
- sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
- sheetCommonObj.shieldAllCells(sheetAss);
- if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
- var cacheSection = me.getCache();
- if (cacheSection && args.row < cacheSection.length) {
- rationGLJOprObj.getGljItems(cacheSection[args.row]);
- rationCoeOprObj.getCoeItems(cacheSection[args.row]);
- rationAssistOprObj.getAssItems(cacheSection[args.row]);
- }
- };
- me.workBook.focus(true);
- },
- getCache: function() {
- var me = this, rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
- if (!(rst)) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
- rst = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- return rst;
- },
- updateCache: function(addArr, updateArr, removeIds, result) {
- var me = this, cacheSection = me.getCache();
- if (addArr.length > 0) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- for (var i = removeIds.length - 1; i >= 0; i--) {
- for (var j = cacheSection.length - 1; j >= 0 ; j--) {
- if (cacheSection[j]["ID"] == removeIds[i]) {
- cacheSection.splice(j,1);
- }
- }
- }
- if (result && result.data.ops && result.data.ops.length > 0) {
- for (var i = 0; i < result.data.ops.length; i++) {
- for (var j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == result.data.ops[i][me.setting.header[0].dataCode]) {
- cacheSection[j]["ID"] = result.data.ops[i]["ID"];
- cacheSection[j]["rationGljList"] = result.data.ops[i]["rationGljList"];
- }
- }
- }
- }
- for (var i = 0; i < updateArr.length; i++) {
- for (var j = 0; j < cacheSection.length; j++) {
- if (updateArr[i]["ID"] && cacheSection[j]["ID"]) {
- if (cacheSection[j]["ID"] == updateArr[i]["ID"]) {
- cacheSection[j] = updateArr[i];
- }
- } else {
- if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
- cacheSection[j] = updateArr[i];
- }
- }
- }
- }
- return cacheSection;
- },
- rationDelOpr: function () {
- let me = rationOprObj;
- me.workBook.commandManager().register('rationDelete', function () {
- let rationSheet = me.workBook.getActiveSheet();
- let sels = rationSheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
- let cacheSection = me.getCache();
- console.log(`sels`);
- console.log(sels);
- console.log(`cache`);
- console.log(cacheSection);
- if(sels.length > 0){
- for(let sel = 0; sel < sels.length; sel++){
- if(sels[sel].colCount === me.setting.header.length){
- if(cacheSection){
- for(let i = 0; i < sels[sel].rowCount; i++){
- if(sels[sel].row + i < cacheSection.length){
- removeArr.push(cacheSection[sels[sel].row + i].ID);
- }
- }
- }
- }
- else{
- if(sels[sel].col === 0){
- $('#alertText').text("编号不能为空,修改失败!");
- $('#alertModalBtn').click();
- rationSheet.options.isProtected = true;
- $('#alertModalCls').click(function () {
- rationSheet.options.isProtected = false;
- });
- $('#alertModalCof').click(function () {
- rationSheet.options.isProtected = false;
- })
- }
- else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
- if(cacheSection){
- for(let i =0; i < sels[sel].rowCount; i++){
- if(sels[sel].row + i < cacheSection.length){
- for(let col = sels[sel].col; col < sels[sel].col + sels[sel].colCount - 1; col++){
- if(lockCols.indexOf(col) === -1){
- cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = '';
- }
- }
- }
- updateArr.push(cacheSection[sels[sel].row + i]);
- }
- }
- }
- }
- }
- }
- console.log(`updateArr`);
- console.log(updateArr);
- console.log(`removeArr`);
- console.log(removeArr);
- if(updateArr.length > 0 || removeArr.length > 0){
- //me.mixUpdateRequest(updateArr, [], removeArr);
- }
- });
- me.workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
- me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
- },
- onRangeChanged: function(sender, args) {
- console.log(`sdad`);
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
- var me = rationOprObj, updateArr = [], removeArr = [];
- var cacheSection = me.getCache();
- console.log(`cacheSection`);
- console.log(cacheSection);
- console.log(`args`);
- console.log(args);
- if (cacheSection) {
- for (var i = 0; i < args.rowCount; i++) {
- //var hasUpdate = false, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row + i),
- var hasUpdate = false, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row + i),
- isEmpty = sheetCommonObj.chkIfEmpty(rObj, me.setting);
- for (var j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
- rObj["ID"] = cacheSection[j]["ID"];
- hasUpdate = true;
- break;
- }
- }
- if(isEmpty){
- if(args.row + i < cacheSection.length){
- rObj.ID = cacheSection[args.row + i].ID;
- removeArr.push(rObj.ID);
- }
- }
- else{
- }
- if (hasUpdate) {
- if (isEmpty) {
- removeArr.push(rObj);
- } else updateArr.push(rObj);
- } else if (isEmpty) {
- if (args.row + i < cacheSection.length) {
- rObj["ID"] = cacheSection[args.row + i]["ID"];
- removeArr.push(rObj["ID"]);
- }
- }
- }
- // me.mixUpdateRequest(updateArr, [], removeArr);
- //removeRationItems
- }
- }
- },
- onCellEditStart: function(sender, args) {
- var me = rationOprObj;
- //var rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row);
- var rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row);
- me.currentEditingRation = rObj;
- console.log(`currentEditingRation`);
- console.log(me.currentEditingRation);
- var cacheSection = me.getCache();
- if (cacheSection) {
- for (var j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == rObj[me.setting.header[0].dataCode]) {
- rObj["ID"] = cacheSection[j]["ID"];
- break;
- }
- }
- }
- },
- onCellEditEnd: function(sender, args) {
- //var me = rationOprObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row),
- var me = rationOprObj, rObj = sheetCommonObj.combineRationRowData(me.workBook.getSheet(0), me.setting, args.row),
- updateArr = [], addArr = [];
- let dataCode = me.setting.header[args.col].dataCode;
- if (me.currentEditingRation["ID"] && me.currentEditingRation[dataCode] !== args.editingText) {
- rObj["ID"] = me.currentEditingRation["ID"];
- updateArr.push(rObj);
- } else if(!me.currentEditingRation["ID"]) {
- if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
- addArr.push(rObj);
- }
- }
- me.currentEditingRation = null;
- if (updateArr.length > 0 || addArr.length > 0) {
- me.mixUpdateRequest(updateArr, addArr, []);
- }
- },
- onClipboardPasting: function(sender, args) {
- var me = rationOprObj;
- console.log(`args`);
- console.log(args);
- /* if (args.cellRange.colCount != me.setting.header.length) {
- args.cancel = true;
- }*/
- },
- onClipboardPasted: function(e, info) {
- console.log(`info`);
- console.log(info);
- var me = rationOprObj;
- var cacheSection = me.getCache();
- console.log(`cache`);
- console.log(cacheSection);
- var updateArr = [], addArr = [];
- var items = sheetCommonObj.analyzePasteData(me.setting, info);
- console.log(`items`);
- console.log(items);
- for (var i = 0; i < items.length; i++) {
- if (cacheSection) {
- var hasCacheItem = false;
- for (var j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
- hasCacheItem = true;
- items[i]["ID"] = cacheSection[j]["ID"];
- break;
- }
- }
- if (!hasCacheItem && info.cellRange.col === 0) {
- addArr.push(items[i]);
- } else if(hasCacheItem){
- updateArr.push(items[i]);
- }
- } else {
- //add
- if(info.cellRange.col === 0){
- addArr.push(items[i])
- }
- }
- };
- console.log(`updateArr`);
- console.log(updateArr);
- console.log(addArr);
- if (updateArr.length > 0 || addArr.length > 0) {
- //me.mixUpdateRequest(updateArr, addArr, []);
- }
- },
- mixUpdateRequest: function(updateArr, addArr, removeIds) {
- var me = rationOprObj;
- $.ajax({
- type:"POST",
- url:"api/mixUpdateRationItems",
- data:{"rationLibId": getQueryString("repository"), "sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr), "removeIds": JSON.stringify(removeIds)},
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result){
- if (result.err) {
- alert(err);
- me.getRationItems(me.currentSectionId);
- } else {
- var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
- cacheSection.sort(function(a, b){
- var rst = 0;
- if (a.code > b.code) rst = 1
- else if (a.code < b.code) rst = -1;
- return rst;
- });
- me.showRationItems(me.currentSectionId);
- }
- },
- error:function(){
- }
- });
- },
- getRationItems: function(sectionID){
- if (sectionID != -1) {
- var me = rationOprObj;
- me.currentSectionId = sectionID;
- if (me.currentRations["_SEC_ID_" + sectionID]) {
- me.showRationItems(sectionID);
- ///sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
- sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
- sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
- sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
- sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
- } else {
- $.ajax({
- type:"POST",
- url:"api/getRationItems",
- data:{"sectionID": sectionID},
- dataType:"json",
- cache:false,
- timeout:1000,
- success:function(result){
- if (result) {
- me.currentRations["_SEC_ID_" + sectionID] = result.data;
- me.sortByCode(me.currentRations["_SEC_ID_" + sectionID]);
- me.showRationItems(sectionID);
- //sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
- sheetCommonObj.lockCells(me.workBook.getSheet(0), rationOprObj.setting);
- sheetCommonObj.lockCells(rationGLJOprObj.sheet, rationGLJOprObj.setting);
- sheetCommonObj.lockCells(rationCoeOprObj.sheet, rationCoeOprObj.setting);
- sheetCommonObj.unShieldAllCells(rationAssistOprObj.sheet);
- } else {
- sheetCommonObj.shieldAllCells(me.workBook.getSheet(0));
- sheetCommonObj.shieldAllCells(rationGLJOprObj.sheet);
- sheetCommonObj.shieldAllCells(rationCoeOprObj.sheet);
- sheetCommonObj.shieldAllCells(rationAssistOprObj.sheet);
- }
- },
- error:function(err){
- alert(err);
- }
- })
- }
- }
- },
- showRationItems: function(sectionID){
- var me = rationOprObj;
- if (me.workBook) {
- if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
- var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
- sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
- sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
- } else {
- //清除ration数据及工料机数据
- sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
- }
- }
- },
- sortByCode: function(arr){
- function compare(){
- return function (a, b) {
- let rst = 0;
- if (a.code > b.code) {
- rst = 1;
- }
- else if (a.code < b.code) {
- rst = -1;
- }
- return rst;
- }
- }
- arr.sort(compare());
- }
- }
|