123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /**
- * 聊天室相关
- *
- * @author CaiAoLin
- * @date 2017/6/15
- * @version
- */
- $(document).ready(function () {
- // excel
- let header = [
- {name: '编码', field: 'code', visible: true},
- {name: '名称', field: 'name', visible: true},
- {name: '规格型号', field: 'specs', visible: true},
- {name: '单位', field: 'unit', visible: true},
- {name: 'ID', field: 'id', visible: false},
- {name: '类型', field: 'type', visible: false},
- {name: '人工工种', field: 'type_of_work', visible: false},
- {name: '总消耗量', field: '', visible: true},
- {name: '基价单价', field: "unit_price.base_price", visible: true},
- {name: '调整基价', field: 'adjust_price', visible: true},
- {name: '市场单价', field: "unit_price.market_price", visible: true},
- {name: '是否暂估', field: 'is_evaluate', visible: true, cellType: new GC.Spread.Sheets.CellTypes.CheckBox()},
- {name: '供货方式', field: 'supply', visible: true},
- {name: '甲供数量', field: 'supply_quantity', visible: true},
- {name: '交货方式', field: 'delivery', visible: true},
- {name: '送达地点', field: 'delivery_address', visible: true},
- {name: '不调价', field: 'is_adjust_price', visible: true, cellType: new GC.Spread.Sheets.CellTypes.CheckBox()},
- ];
- let setting = {
- header: []
- };
- for(let tmp of header) {
- setting.header.push({headerName: tmp.name, headerWidth: 120});
- }
- let spread = sheetCommonObj.buildSheet(document.getElementById("test"), setting, 3);
- spread.options.scrollbarShowMax = true;
- spread.options.scrollbarMaxAlign = true;
- spread.options.showHorizontalScrollbar = true;
- let sheet = spread.getActiveSheet();
- // 设置表单不可编辑
- sheet.options.isProtected = true;
- // 居中样式
- let centerStyleSetting = {hAlign: 1};
- sheet.setStyle(-1, 11, getStyle(centerStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- sheet.setStyle(-1, 16, getStyle(centerStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- sheet.setStyle(-1, 3, getStyle(centerStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- // 向右对齐样式
- let rightStyleSetting = {hAlign: GC.Spread.Sheets.HorizontalAlign.right};
- sheet.setStyle(-1, 7, getStyle(rightStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- sheet.setStyle(-1, 8, getStyle(rightStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- sheet.setStyle(-1, 9, getStyle(rightStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- sheet.setStyle(-1, 10, getStyle(rightStyleSetting), GC.Spread.Sheets.SheetArea.viewport);
- // 设置可编辑列
- sheet.getRange(-1, 10, -1, 1).locked(false);
- sheet.getRange(-1, 11, -1, 1).locked(false);
- sheet.getRange(-1, 16, -1, 1).locked(false);
- // 设置json数据
- let sourceData = JSON.parse(jsonData);
- let rowCounter = 0;
- for(let data of sourceData) {
- let columnCounter = 0;
- for(let columnInfo of header) {
- // 设置是否显示
- sheet.setColumnVisible(columnCounter, columnInfo.visible);
- let dataString = columnInfo.field !== '' && columnInfo.field !== undefined ?
- "data." + columnInfo.field : '';
- let cellData = eval(dataString);
- // 设置复选框
- if (columnInfo.cellType !== undefined) {
- let checkbox = new GC.Spread.Sheets.CellTypes.CheckBox();
- sheet.setCellType(rowCounter, columnCounter, checkbox, GC.Spread.Sheets.SheetArea.viewport);
- }
- // 如果不为材料“是否暂估列”根据条件显示
- if (columnInfo.field === 'is_evaluate' && materialIdList.indexOf(data.type + '') < 0) {
- let string = new GC.Spread.Sheets.CellTypes.Text();
- sheet.setCellType(rowCounter, columnCounter, string, GC.Spread.Sheets.SheetArea.viewport);
- cellData = '';
- // 并且锁定该单元格
- sheet.getRange(rowCounter, columnCounter, 1, 1).locked(true);
- }
- sheet.setValue(rowCounter, columnCounter, cellData, GC.Spread.Sheets.SheetArea.viewport);
- columnCounter++;
- }
- rowCounter++;
- }
- /*
- let socket = io('http://notify.smartcost.com.cn:3300');
- socket.on('connect', function () {
- socket.emit('join', project);
- console.log('连接成功');
- });
- // 接受到改变
- let changeInfo = [];
- socket.on('dataChange', function(data) {
- data = JSON.parse(data);
- if (data.newValue === undefined) {
- return false;
- }
- changeInfo.push(data);
- $("#message").html('基价单位已被修改,<a href="javascript:void(0);" id="load-data">点击加载</a>');
- $("#notify").slideDown('fast');
- initiativeChange = false;
- });
- // 是否主动更改数据
- let initiativeChange = false;
- $("#message").on('click', '#load-data', function() {
- $("#notify").slideUp('fast');
- if (changeInfo.length > 0) {
- for (let index in changeInfo) {
- let cell = sheet.getCell(changeInfo[index].row, changeInfo[index].col, GC.Spread.Sheets.SheetArea.viewport);
- cell.value(changeInfo[index].newValue);
- }
- }
- changeInfo = [];
- });
- // 进入单元格后设置为主动设置数据
- sheet.bind(GC.Spread.Sheets.Events.EditEnding, function (element, info) {
- initiativeChange = true;
- });
- // 绑定事件
- sheet.bind(GC.Spread.Sheets.Events.CellChanged, function (element, info) {
- // 如果修改了数据且为主动修改,先存库再广播给其他页面
- if (info.newValue !== undefined && info.oldValue !== undefined && initiativeChange) {
- let id = sheet.getCell(info.row, 0).value();
- $.ajax({
- url: '/save',
- type: 'post',
- data: {priceValue: info.newValue, id: id},
- error: function() {
- // @todo 替换为更好地错误提示
- alert('error');
- },
- beforeSend: function() {
- },
- success: function(response) {
- if (response.err === 0) {
- socket.emit('dataNotify', JSON.stringify(info));
- } else {
- // @todo 替换为更好地错误提示
- alert(response.msg);
- }
- }
- });
- }
- });
- */
- });
- function getStyle(setting) {
- let style = new GC.Spread.Sheets.Style();
- style.locked = setting.readOnly === undefined ? true : setting.readOnly;
- style.hAlign = setting.hAlign === undefined ? GC.Spread.Sheets.HorizontalAlign.center : setting.hAlign;
- return style;
- }
|