|
@@ -0,0 +1,426 @@
|
|
|
|
+/**
|
|
|
|
+ * Created by Zhong on 2017/8/31.
|
|
|
|
+ * 特征及内容
|
|
|
|
+ */
|
|
|
|
+let contentOprObj = {
|
|
|
|
+ workBook: null,
|
|
|
|
+ currentCache: [],//按照serialNo排序
|
|
|
|
+ setting: {
|
|
|
|
+ header: [
|
|
|
|
+ {headerName:"工作内容",headerWidth:160,dataCode:"content", dataType: "String", hAlign: "center", vAlign: "center"},
|
|
|
|
+ {headerName:"输出",headerWidth:80,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ buildSheet: function(container) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
|
|
|
|
+ me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
|
+ me.onContextmenuOpr();//右键菜单
|
|
|
|
+ },
|
|
|
|
+ //显示在jobSpread的数据
|
|
|
|
+ showContentData: function (sheet, setting, datas) {
|
|
|
|
+ sheetCommonObj.showData(sheet, setting, datas);
|
|
|
|
+ sheet.suspendPaint();
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
+ for(let i = 0, len = datas.length; i < len; i++){
|
|
|
|
+ sheet.getCell(i, 0).locked(true);
|
|
|
|
+ }
|
|
|
|
+ sheet.resumePaint();
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
+ },
|
|
|
|
+ //显示到清单工作内容列的数据
|
|
|
|
+ getColData: function (jobsArr) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ let rstStr = "", count = 0;
|
|
|
|
+ for(let i = 0, len = jobsArr.length; i < len; i++){
|
|
|
|
+ if(jobsArr[i].isChecked === true){
|
|
|
|
+ count ++;
|
|
|
|
+ if(count === 1){
|
|
|
|
+ rstStr += "“";
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ rstStr += " ";
|
|
|
|
+ }
|
|
|
|
+ rstStr += count + " " + jobsArr[i].content + "\n";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(rstStr.trim().length > 0){
|
|
|
|
+ let reg = /\n+$/g;
|
|
|
|
+ let newStr = rstStr.replace(reg, "”");
|
|
|
|
+ return newStr;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ },
|
|
|
|
+ upMove: function (rowIdx) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ let thisObj = me.currentCache[rowIdx],
|
|
|
|
+ preObj = me.currentCache[rowIdx - 1],
|
|
|
|
+ temp, contentTxt;
|
|
|
|
+ temp = thisObj.serialNo;
|
|
|
|
+ thisObj.serialNo = preObj.serialNo;
|
|
|
|
+ preObj.serialNo = temp;
|
|
|
|
+ me.sortCache(me.currentCache);
|
|
|
|
+ if(thisObj.isChecked === true && preObj.isChecked === true){
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ contentTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateContent(me.currentCache, contentTxt);
|
|
|
|
+ },
|
|
|
|
+ downMove: function (rowIdx) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ let thisObj = me.currentCache[rowIdx],
|
|
|
|
+ nextObj = me.currentCache[rowIdx + 1],
|
|
|
|
+ temp, contentTxt;
|
|
|
|
+ temp = thisObj.serialNo;
|
|
|
|
+ thisObj.serialNo = nextObj.serialNo;
|
|
|
|
+ nextObj.serialNo = temp;
|
|
|
|
+ me.sortCache(me.currentCache);
|
|
|
|
+ if(thisObj.isChecked === true && nextObj.isChecked === true){
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ contentTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateContent(me.currentCache, contentTxt);
|
|
|
|
+ },
|
|
|
|
+ deleteContent: function (rowIdx) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ let deleteObj = me.currentCache[rowIdx];
|
|
|
|
+ let contentTxt;
|
|
|
|
+ me.currentCache.splice(rowIdx, 1);
|
|
|
|
+ if(deleteObj.isChecked === true){//需要刷新显示
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ contentTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateContent(me.currentCache, contentTxt);
|
|
|
|
+ },
|
|
|
|
+ //只有空行时才可以输入,即是新增时用,新增的空行只有输入了值,才保存
|
|
|
|
+ onEditEnded: function (sender, args) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
|
|
|
|
+ let contentTxt;
|
|
|
|
+ if(args.editingText.toString().trim().length > 0){
|
|
|
|
+ let newObj = {content: args.editingText, isChecked: args.sheet.getValue(args.row, 1)};
|
|
|
|
+ newObj.serialNo = preObj ? preObj.serialNo + 1 : 1;//得到新增对象的排序号
|
|
|
|
+ me.currentCache.push(newObj);
|
|
|
|
+ if(newObj.isChecked === true){//可能编辑内容前就打勾
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ contentTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateContent(me.currentCache, contentTxt);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ //复选框控制输出
|
|
|
|
+ onButtonClicked: function (sender, args) {
|
|
|
|
+ let me = contentOprObj, contentTxt;
|
|
|
|
+ if(args.sheet.isEditing()){
|
|
|
|
+ args.sheet.endEdit(true);
|
|
|
|
+ }
|
|
|
|
+ let isChecked = args.sheet.getValue(args.row, args.col);
|
|
|
|
+ if(me.currentCache.length > args.row){
|
|
|
|
+ me.currentCache[args.row].isChecked = isChecked;
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ contentTxt = me.getColData(me.currentCache);
|
|
|
|
+ me.updateContent(me.currentCache, contentTxt);
|
|
|
|
+ }
|
|
|
|
+ //else的情况就是新增
|
|
|
|
+ },
|
|
|
|
+ sortCache: function (cacheArr) {
|
|
|
|
+ cacheArr.sort(function (a, b) {
|
|
|
|
+ let rst = 0;
|
|
|
|
+ if(a.serialNo > b.serialNo){
|
|
|
|
+ rst = 1;
|
|
|
|
+ }
|
|
|
|
+ else if(a.serialNo < b.serialNo){
|
|
|
|
+ rst = -1;
|
|
|
|
+ }
|
|
|
|
+ return rst;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ updateContent: function (billId, updateArr, contentTxt) {
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ $.ajax({
|
|
|
|
+ type: 'post',
|
|
|
|
+ url: '',
|
|
|
|
+ dataType: 'json',
|
|
|
|
+ data: {billId: billId, updateArr: updateArr, contentTxt: contentTxt},
|
|
|
|
+ success: function (result) {
|
|
|
|
+ if(!result.error){
|
|
|
|
+ me.showContentData(me.workBook.getSheet(0), me.setting, me.currentCache);//刷新jobSpread
|
|
|
|
+ if(me.refreshColData){
|
|
|
|
+ // mainSheet.setvalue(contentTxt); //刷新输出显示
|
|
|
|
+ me.refreshColData = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onContextmenuOpr: function () {//右键菜单
|
|
|
|
+ let me = contentOprObj;
|
|
|
|
+ $.contextMenu({
|
|
|
|
+ selector: '#jobSpread',
|
|
|
|
+ build: function($triggerElement, e){
|
|
|
|
+ //控制允许右键菜单在哪个位置出现
|
|
|
|
+ let clientX = e.originalEvent.clientX,
|
|
|
|
+ clientY = e.originalEvent.clientY;
|
|
|
|
+ let sheet = me.workBook.getSheet(0);
|
|
|
|
+ let offset = $("#jobSpread").offset(),
|
|
|
|
+ x = clientX - offset.left,
|
|
|
|
+ y = clientY - offset.top;
|
|
|
|
+ let target = sheet.hitTest(x, y);
|
|
|
|
+ if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
|
|
|
|
+ sheet.setActiveCell(target.row, target.col);
|
|
|
|
+ //控制按钮是否可用
|
|
|
|
+ let insertDis = false, delDis = false, upDis = false, downDis = false;
|
|
|
|
+ if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
|
|
|
|
+ delDis = true;
|
|
|
|
+ downDis = true;
|
|
|
|
+ upDis = true;
|
|
|
|
+ }
|
|
|
|
+ else{//有数据
|
|
|
|
+ if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
|
|
|
|
+ downDis = true;
|
|
|
|
+ }
|
|
|
|
+ if(target.row === 0){//定位在第一行,不可上移
|
|
|
|
+ upDis = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ callback: function(){},
|
|
|
|
+ items: {
|
|
|
|
+ "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
|
|
|
|
+ }},
|
|
|
|
+ "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
|
|
|
|
+ //删除
|
|
|
|
+ let deleteObj = me.currentCache[target.row];
|
|
|
|
+ }},
|
|
|
|
+ "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
|
|
|
|
+
|
|
|
|
+ }},
|
|
|
|
+ "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
|
|
|
|
+
|
|
|
|
+ }}
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+let characterOprObj = {
|
|
|
|
+ workBook: null,
|
|
|
|
+ currentCache: [],
|
|
|
|
+ setting: {
|
|
|
|
+ header: [
|
|
|
|
+ {headerName:"项目特征",headerWidth:160,dataCode:"character", dataType: "String", hAlign: "center", vAlign: "center"},
|
|
|
|
+ {headerName:"特征值",headerWidth:160,dataCode:"eigenvalue", dataType: "String", hAlign: "center", vAlign: "center"},
|
|
|
|
+ {headerName:"输出",headerWidth:80,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ buildSheet: function(container) {
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
|
|
|
|
+ me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
|
+ me.onContextmenuOpr();
|
|
|
|
+ //me.workBook.getSheet(0).setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);
|
|
|
|
+ //me.workBook.getSheet(0).options.isProtected = true;
|
|
|
|
+ //sheetOpr.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
|
|
|
|
+ },
|
|
|
|
+ //显示在itemSpread的数据
|
|
|
|
+ showCharacterData: function (sheet, setting, datas) {
|
|
|
|
+ sheetCommonObj.showData(sheet, setting, datas);
|
|
|
|
+ sheet.suspendPaint();
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
+ for(let i = 0, len = datas.length; i < len; i++){
|
|
|
|
+ sheet.getCell(i, 0).locked(true);
|
|
|
|
+ }
|
|
|
|
+ sheet.resumePaint();
|
|
|
|
+ sheet.suspendEvent();
|
|
|
|
+ },
|
|
|
|
+ //显示到清单项目特征列的数据
|
|
|
|
+ getColData: function (itemsArr) {
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ let rstStr = "", count = 0;
|
|
|
|
+ for(let i = 0, len = itemsArr.length; i < len; i++){
|
|
|
|
+ if(itemsArr[i].isChecked === true){
|
|
|
|
+ //获取选中的特征值
|
|
|
|
+ let eigenvalueStr = "";
|
|
|
|
+ let eigenvalue = itemsArr[i].eigenvalue;
|
|
|
|
+ for(let j = 0, vLen = eigenvalue.length; j < vLen; j++){
|
|
|
|
+ if(eigenvalue[j].isSelected === true){
|
|
|
|
+ eigenvalueStr += eigenvalue[j].value;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ count ++;
|
|
|
|
+ if(count === 1){
|
|
|
|
+ rstStr += "“";
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ rstStr += " ";
|
|
|
|
+ }
|
|
|
|
+ rstStr += count + " " + itemsArr[i].content + ": " + eigenvalueStr + "\n";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(rstStr.trim().length > 0){
|
|
|
|
+ let reg = /\n+$/g;
|
|
|
|
+ let newStr = rstStr.replace(reg, "”");
|
|
|
|
+ return newStr;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ },
|
|
|
|
+ upMove: function (rowIdx) {
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ let thisObj = me.currentCache[rowIdx],
|
|
|
|
+ preObj = me.currentCache[rowIdx - 1],
|
|
|
|
+ temp, characterTxt;
|
|
|
|
+ temp = thisObj.serialNo;
|
|
|
|
+ thisObj.serialNo = preObj.serialNo;
|
|
|
|
+ preObj.serialNo = temp;
|
|
|
|
+ contentOprObj.sortCache(me.currentCache);
|
|
|
|
+ if(thisObj.isChecked === true && preObj.isChecked === true){
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ characterTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateCharacter(me.currentCache, characterTxt);
|
|
|
|
+ },
|
|
|
|
+ downMove: function (rowIdx) {
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ let thisObj = me.currentCache[rowIdx],
|
|
|
|
+ nextObj = me.currentCache[rowIdx + 1],
|
|
|
|
+ temp, characterTxt;
|
|
|
|
+ temp = thisObj.serialNo;
|
|
|
|
+ thisObj.serialNo = nextObj.serialNo;
|
|
|
|
+ nextObj.serialNo = temp;
|
|
|
|
+ contentOprObj.sortCache(me.currentCache);
|
|
|
|
+ if(thisObj.isChecked === true && nextObj.isChecked === true){
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ characterTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateCharacter(me.currentCache, characterTxt);
|
|
|
|
+ },
|
|
|
|
+ deleteContent: function (rowIdx) {
|
|
|
|
+ let me = characterOprObj, characterTxt;
|
|
|
|
+ let deleteObj = me.currentCache[rowIdx];
|
|
|
|
+ me.currentCache.splice(rowIdx, 1);
|
|
|
|
+ if(deleteObj.isChecked === true){//需要刷新显示
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ characterTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateCharacter(me.currentCache, characterTxt);
|
|
|
|
+ },
|
|
|
|
+ //只有空行时才可以输入,即是新增时用,新增的空行只有输入了值,才保存
|
|
|
|
+ onEditEnded: function (sender, args) {
|
|
|
|
+ let me = characterOprObj, characterTxt;
|
|
|
|
+ let preObj = me.currentCache.length > 0 ? me.currentCache[me.currentCache.length - 1] : null;
|
|
|
|
+ if(args.editingText.toString().trim().length > 0){
|
|
|
|
+ let newObj = {content: args.editingText, isChecked: args.sheet.getValue(args.row, 1)};
|
|
|
|
+ newObj.serialNo = preObj ? preObj.serialNo + 1 : 1;//得到新增对象的排序号
|
|
|
|
+ me.currentCache.push(newObj);
|
|
|
|
+ if(newObj.isChecked === true){//可能编辑内容前就打勾
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ characterTxt = me.getColData(me.currentCache);
|
|
|
|
+ }
|
|
|
|
+ me.updateCharacter(me.currentCache, characterTxt);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ //复选框控制输出
|
|
|
|
+ onButtonClicked: function (sender, args) {
|
|
|
|
+ let me = characterOprObj, characterTxt;
|
|
|
|
+ if(args.sheet.isEditing()){
|
|
|
|
+ args.sheet.endEdit(true);
|
|
|
|
+ }
|
|
|
|
+ let isChecked = args.sheet.getValue(args.row, args.col);
|
|
|
|
+ if(me.currentCache.length > args.row){
|
|
|
|
+ me.currentCache[args.row].isChecked = isChecked;
|
|
|
|
+ me.refreshColData = true;
|
|
|
|
+ characterTxt = me.getColData(me.currentCache);
|
|
|
|
+ me.updateCharacter(me.currentCache, characterTxt);
|
|
|
|
+ }
|
|
|
|
+ //else的情况就是新增
|
|
|
|
+ },
|
|
|
|
+ updateCharacter: function (billId, updateArr, characterTxt) {
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ $.ajax({
|
|
|
|
+ type: 'post',
|
|
|
|
+ url: '',
|
|
|
|
+ dataType: 'json',
|
|
|
|
+ data: {billId: billId, updateArr: updateArr, characterTxt: characterTxt},
|
|
|
|
+ success: function (result) {
|
|
|
|
+ if(!result.error){
|
|
|
|
+ /* me.currentCache.sort(function (a, b) {
|
|
|
|
+ let rst = 0;
|
|
|
|
+ if(a.serialNo > b.serialNo){
|
|
|
|
+ rst = 1;
|
|
|
|
+ }
|
|
|
|
+ else if(a.serialNo < b.serialNo){
|
|
|
|
+ rst = -1;
|
|
|
|
+ }
|
|
|
|
+ return rst;
|
|
|
|
+ });
|
|
|
|
+ me.showCharacterData(me.workBook.getSheet(0), me.setting, me.currentCache);//刷新jobSpread
|
|
|
|
+ if(me.refreshColData){
|
|
|
|
+ //me.showColData(me.currentCache);//刷新输出显示
|
|
|
|
+ me.refreshColData = false;
|
|
|
|
+ }*/
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ onContextmenuOpr: function () {//右键菜单
|
|
|
|
+ let me = characterOprObj;
|
|
|
|
+ $.contextMenu({
|
|
|
|
+ selector: '#itemSpread',
|
|
|
|
+ build: function($triggerElement, e){
|
|
|
|
+ //控制允许右键菜单在哪个位置出现
|
|
|
|
+ let clientX = e.originalEvent.clientX,
|
|
|
|
+ clientY = e.originalEvent.clientY;
|
|
|
|
+ let sheet = me.workBook.getSheet(0);
|
|
|
|
+ let offset = $("#itemSpread").offset(),
|
|
|
|
+ x = clientX - offset.left,
|
|
|
|
+ y = clientY - offset.top;
|
|
|
|
+ let target = sheet.hitTest(x, y);
|
|
|
|
+ if(target.hitTestType === 3 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'){//在表格内
|
|
|
|
+ sheet.setActiveCell(target.row, target.col);
|
|
|
|
+ //控制按钮是否可用
|
|
|
|
+ let insertDis = false, delDis = false, upDis = false, downDis = false;
|
|
|
|
+ if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行,删除键才显示可用
|
|
|
|
+ delDis = true;
|
|
|
|
+ downDis = true;
|
|
|
|
+ upDis = true;
|
|
|
|
+ }
|
|
|
|
+ else{//有数据
|
|
|
|
+ if(target.row === me.currentCache.length -1){//定位在最后一行,不可下移
|
|
|
|
+ downDis = true;
|
|
|
|
+ }
|
|
|
|
+ if(target.row === 0){//定位在第一行,不可上移
|
|
|
|
+ upDis = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ callback: function(){},
|
|
|
|
+ items: {
|
|
|
|
+ "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
|
|
|
|
+ }},
|
|
|
|
+ "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
|
|
|
|
+ //删除
|
|
|
|
+ }},
|
|
|
|
+ "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
|
|
|
|
+
|
|
|
|
+ }},
|
|
|
|
+ "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
|
|
|
|
+
|
|
|
|
+ }}
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+};
|