/** * Created by Tony on 2017/4/28. */ var params = {} $("#dinge").click(function(){ $(this).attr('href', "/rationRepository/ration" + "?params=" + JSON.stringify(params)) }) $("#gongliao").click(function(){ $(this).attr('href', "/rationRepository/gongliao" + "?params=" + JSON.stringify(params)) }); var rationOprObj = { workBook: null, currentRations: {}, currentSectionId: -1, setting: { header:[ {headerName:"编码",headerWidth:120,data:"code"}, {headerName:"名称",headerWidth:300,data:"name"}, {headerName:"单位",headerWidth:120,data:"unit"}, {headerName:"基价",headerWidth:120,data:"basePrice"}, {headerName:"显示名称(以%s表示参数)",headerWidth:350,data:"caption"}, {headerName:"取费专业",headerWidth:120,data:"feeType"} ], view:{ comboBox:[ {row:-1,col:2,rowCount:-1,colCount:1} ], lockedCells:[ {row:-1,col:3,rowCount:-1, colCount:1} ] } }, buildSheet: function(container) { var me = this; me.workBook = sheetCommonObj.buildSheet(container, me.setting); me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting); me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted); }, onClipboardPasting: function(sender, args) { var me = rationOprObj; if (args.cellRange.colCount != me.setting.header.length) { args.cancel = true; } }, onClipboardPasted: function(e, info) { var me = rationOprObj; var cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId]; var updateArr = [], addArr = []; var private_createRationItems = function() { var rst = [], propId = 0, preStrIdx = 0, itemObj = {}; for (var i = 0; i < info.pasteData.text.length; i++) { if (info.pasteData.text[i] === "\n") { propId = 0; preStrIdx = i + 1; rst.push(itemObj); if (i < info.pasteData.text.length - 1) { itemObj = {}; } } else if (info.pasteData.text[i] === "\t" || info.pasteData.text[i] === "\r") { itemObj[me.setting.header[propId].data] = info.pasteData.text.slice(preStrIdx, i); propId++; preStrIdx = i + 1; } else if (i == info.pasteData.text.length - 1) { itemObj[me.setting.header[propId].data] = info.pasteData.text.slice(preStrIdx); rst.push(itemObj); } } return rst; }; var items = private_createRationItems(); 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].data] == items[i][me.setting.header[0].data]) { hasCacheItem = true; break; } } if (hasCacheItem) addArr.push(items[i]) else updateArr.push(items[i]) } else { addArr.push(items[i]) } }; }, getRationItems: function(sectionID){ if (sectionID != -1) { var me = rationOprObj; me.currentSectionId = sectionID; if (me.currentRations["_SEC_ID_" + sectionID]) { me.showRationItems(sectionID); } 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.showRationItems(sectionID); } }, error:function(){ } }) } } }, showRationItems: function(sectionID){ var me = rationOprObj; if (me.workBook) { if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) { // } else { //清除ration数据及工料机数据 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, 3); } } } }