|
@@ -70,10 +70,10 @@ let coeOprObj = {
|
|
|
workSheet: null,
|
|
|
currentCoeList: [],
|
|
|
currentCoe: null,
|
|
|
- //currentMaxNo: null,
|
|
|
+ currentMaxNo: null,
|
|
|
setting: {
|
|
|
header: [
|
|
|
- {headerName:"编号", headerWidth:60, dataCode:"ID", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
|
|
|
+ {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
|
|
|
{headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
|
|
|
{headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
|
|
|
]
|
|
@@ -110,26 +110,64 @@ let coeOprObj = {
|
|
|
onEditEnded: function (sender, args) {
|
|
|
let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
|
|
|
if(args.editingText && args.editingText.toString().trim().length > 0){
|
|
|
+ let inputT = args.editingText.toString().trim();
|
|
|
//update
|
|
|
if(args.row < me.currentCoeList.length){
|
|
|
let updateObj = me.currentCoeList[args.row];
|
|
|
- if(updateObj[dataCode] !== args.editingText.toString().trim()){
|
|
|
- updateObj[dataCode] = args.editingText;
|
|
|
- updateArr.push(updateObj);
|
|
|
- me.save([], updateArr, [], true);
|
|
|
+ if(updateObj[dataCode] != inputT){
|
|
|
+ if(dataCode === 'serialNo'){
|
|
|
+ if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
|
|
|
+ me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
|
|
|
+ updateObj[dataCode] = inputT;
|
|
|
+ updateArr.push(updateObj);
|
|
|
+ me.save([], updateArr, [], true);
|
|
|
+ }
|
|
|
+ else if(!me.isInt(inputT)){
|
|
|
+ args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
|
|
|
+ alert('编号只能为整数!');
|
|
|
+ }
|
|
|
+ else if(me.hasTisNo(me.currentCoeList, inputT)){
|
|
|
+ args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
|
|
|
+ alert('该编号已存在!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ updateObj[dataCode] = inputT;
|
|
|
+ updateArr.push(updateObj);
|
|
|
+ me.save([], updateArr, [], true);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//insert
|
|
|
else{
|
|
|
let newCoe = {};
|
|
|
- //me.currentMaxNo ++;
|
|
|
newCoe.libID = pageObj.libID;
|
|
|
- //newCoe.serialNo = me.currentMaxNo;
|
|
|
- newCoe[dataCode] = args.editingText;
|
|
|
- addArr.push(newCoe);
|
|
|
- me.save(addArr, [], [], true, function (result) {
|
|
|
- me.updateCurrentCoeList(result);
|
|
|
- });
|
|
|
+ if(dataCode === 'serialNo'){
|
|
|
+ if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
|
|
|
+ me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
|
|
|
+ newCoe[dataCode] = inputT;
|
|
|
+ addArr.push(newCoe);
|
|
|
+ me.save(addArr, [], [], true, function (result) {
|
|
|
+ me.updateCurrentCoeList(result);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if(!me.isInt(inputT)){
|
|
|
+ args.sheet.setValue(args.row, args.col, '');
|
|
|
+ alert('编号只能为整数!');
|
|
|
+ }
|
|
|
+ else if(me.hasTisNo(me.currentCoeList, inputT)){
|
|
|
+ args.sheet.setValue(args.row, args.col, '');
|
|
|
+ alert('该编号已存在!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ newCoe.serialNo = ++me.currentMaxNo;
|
|
|
+ newCoe[dataCode] = inputT;
|
|
|
+ addArr.push(newCoe);
|
|
|
+ me.save(addArr, [], [], true, function (result) {
|
|
|
+ me.updateCurrentCoeList(result);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -142,26 +180,40 @@ let coeOprObj = {
|
|
|
onClipboardPasted: function (sender, info) {
|
|
|
let me = coeOprObj, addArr = [], updateArr = [];
|
|
|
let items = sheetCommonObj.analyzePasteData(me.setting, info);
|
|
|
- for(let i = 0, len = items.length; i < len; i++){
|
|
|
+ let uniqItems = me.makeUniqItems(items);
|
|
|
+ for(let i = 0, len = uniqItems.length; i < len; i++){
|
|
|
let row = i + info.cellRange.row;
|
|
|
//update
|
|
|
if(row < me.currentCoeList.length){
|
|
|
let updateObj = me.currentCoeList[row];
|
|
|
- for(let attr in items[i]){
|
|
|
- updateObj[attr] = items[i][attr];
|
|
|
+ for(let attr in uniqItems[i]){
|
|
|
+ if(attr === 'serialNo'){
|
|
|
+ if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
|
|
|
+ me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
|
|
|
+ updateObj[attr] = uniqItems[i][attr];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ updateObj[attr] = uniqItems[i][attr];
|
|
|
+ }
|
|
|
}
|
|
|
updateArr.push(updateObj);
|
|
|
}
|
|
|
//insert
|
|
|
else {
|
|
|
- //items[i].serialNo = ++ me.currentMaxNo;
|
|
|
- items[i].libID = pageObj.libID;
|
|
|
- addArr.push(items[i]);
|
|
|
+ if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
|
|
|
+ me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ uniqItems[i].serialNo = ++me.currentMaxNo;
|
|
|
+ }
|
|
|
+ uniqItems[i].libID = pageObj.libID;
|
|
|
+ addArr.push(uniqItems[i]);
|
|
|
}
|
|
|
}
|
|
|
if(addArr.length > 0 || updateArr.length > 0){
|
|
|
me.save(addArr, updateArr, [], true, function (result) {
|
|
|
- me.updateCurrentCoeList(result)
|
|
|
+ me.updateCurrentCoeList(result);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
@@ -197,16 +249,57 @@ let coeOprObj = {
|
|
|
workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
|
|
|
workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
|
|
|
},
|
|
|
+ //粘贴的数据,编号唯一化,去除编号重复的项
|
|
|
+ makeUniqItems: function (items) {
|
|
|
+ let rst = [];
|
|
|
+ for(let i = 0, len = items.length; i < len; i++){
|
|
|
+ if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
|
|
|
+ if(rst.length === 0){
|
|
|
+ rst.push(items[i]);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ let isExist = false;
|
|
|
+ for(let j = 0, jLen = rst.length; j < jLen; j++){
|
|
|
+ if(items[i].serialNo === rst[j].serialNo){
|
|
|
+ isExist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isExist){
|
|
|
+ rst.push(items[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ rst.push(items[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ },
|
|
|
+ isInt: function (num) {
|
|
|
+ return !isNaN(num) && num % 1 === 0;
|
|
|
+ },
|
|
|
+ hasTisNo: function (coeList, newSerialNo) {
|
|
|
+ let rst = false;
|
|
|
+ for(let i = 0, len = coeList.length; i < len; i++){
|
|
|
+ if(coeList[i].serialNo == newSerialNo){
|
|
|
+ rst = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+ },
|
|
|
updateCurrentCoeList: function (newCoeList) {
|
|
|
let me = coeOprObj;
|
|
|
- me.currentCoeList = me.currentCoeList.concat(newCoeList);
|
|
|
- me.sortCoeList(me.currentCoeList);
|
|
|
+ if(newCoeList){
|
|
|
+ me.currentCoeList = me.currentCoeList.concat(newCoeList);
|
|
|
+ }
|
|
|
},
|
|
|
sortCoeList: function (coeList) {
|
|
|
coeList.sort(function (a, b) {
|
|
|
let rst = 0;
|
|
|
- if(a.ID > b.ID) rst = 1;
|
|
|
- else if(a.ID < b.ID) rst = -1;
|
|
|
+ if(a.serialNo > b.serialNo) rst = 1;
|
|
|
+ else if(a.serialNo < b.serialNo) rst = -1;
|
|
|
return rst;
|
|
|
});
|
|
|
},
|
|
@@ -222,7 +315,7 @@ let coeOprObj = {
|
|
|
if(!result.error){
|
|
|
me.currentCoeList = result.data;
|
|
|
me.sortCoeList(me.currentCoeList);
|
|
|
- //me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
|
|
|
+ me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
|
|
|
pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
|
|
|
me.workSheet.clearSelection();
|
|
|
}
|
|
@@ -256,6 +349,8 @@ let coeOprObj = {
|
|
|
callback(result.data);
|
|
|
}
|
|
|
if(refresh){
|
|
|
+ me.sortCoeList(me.currentCoeList);
|
|
|
+ me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
|
|
|
pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
|
|
|
}
|
|
|
}
|