123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /**
- * 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,dataCode:"code"},
- {headerName:"名称",headerWidth:300,dataCode:"name"},
- {headerName:"单位",headerWidth:120,dataCode:"unit"},
- {headerName:"基价",headerWidth:120,dataCode:"basePrice"},
- {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption"},
- {headerName:"取费专业",headerWidth:120,dataCode:"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, 30);
- 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].dataCode] = info.pasteData.text.slice(preStrIdx, i);
- propId++;
- preStrIdx = i + 1;
- //if the last copied-cell were empty, should check whether the end of text
- if (i == info.pasteData.text.length - 1) {
- itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx);
- rst.push(itemObj);
- }
- } else if (i == info.pasteData.text.length - 1) {
- itemObj[me.setting.header[propId].dataCode] = 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].dataCode] == items[i][me.setting.header[0].dataCode]) {
- hasCacheItem = true;
- items[i]["ID"] = cacheSection[j]["ID"];
- break;
- }
- }
- if (!hasCacheItem) {
- addArr.push(items[i]);
- } else {
- updateArr.push(items[i]);
- }
- } else {
- addArr.push(items[i])
- }
- };
- if (updateArr.length > 0 || addArr.length > 0) {
- $.ajax({
- type:"POST",
- url:"api/mixUpdateRationItems",
- data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
- dataType:"json",
- cache:false,
- timeout:5000,
- success:function(result){
- if (result.err) {
- alert(err);
- me.getRationItems(me.currentSectionId);
- } else {
- if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- if (addArr.length > 0) {
- me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
- cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
- }
- for (var i = 0; i < updateArr.length; i++) {
- for (var j = 0; j < cacheSection.length; j++) {
- if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
- cacheSection[j] = updateArr[i];
- }
- }
- }
- 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);
- } 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(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);
- }
- }
- }
- }
|