|
@@ -12,6 +12,31 @@ $(document).ready(() => {
|
|
|
let gsSpread, gsTree;
|
|
|
stageIm.init(stage, imType);
|
|
|
|
|
|
+ function getSelectDetailData() {
|
|
|
+ const rowIndex = parseInt($('#im-list').attr('rowIndex'));
|
|
|
+ const data = stageIm.getImData()[rowIndex];
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ function reLoadDetailData() {
|
|
|
+ const data = getSelectDetailData();
|
|
|
+ $('#edit-detail').show();
|
|
|
+ $('#save-detail').hide();
|
|
|
+ $('#cancel-detail').hide();
|
|
|
+ $('#bgl-code').val(data.bgl_code ? data.bgl_code : '');
|
|
|
+ $('#bw-name').val(data.bw ? data.bw : '');
|
|
|
+ $('#start-peg').val(data.start_peg ? data.start_peg : '');
|
|
|
+ $('#end-peg').val(data.end_peg ? data.end_peg : '');
|
|
|
+ $('#unit-name').val(data.jldy ? data.jldy : '');
|
|
|
+ $('#drawing-code').val(data.drawing_code ? data.drawing_code : '');
|
|
|
+ $('#calc-memo').val(data.calc_memo ? data.calc_memo : '');
|
|
|
+ if (data.calc_img) {
|
|
|
+ $('#calc-img').html('<img src="/' + data.calc_img + '" class="d-100" width="100%">');
|
|
|
+ } else {
|
|
|
+ $('#calc-img').html('');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function reBuildImData() {
|
|
|
const imData = stageIm.buildImData();
|
|
|
const html = [];
|
|
@@ -35,6 +60,15 @@ $(document).ready(() => {
|
|
|
html.push('</tr>');
|
|
|
}
|
|
|
$('#im-list').html(html.join(''));
|
|
|
+ $('tr:first', '#im-list').addClass('table-warning');
|
|
|
+ $('#im-list').attr('rowIndex', 0);
|
|
|
+ reLoadDetailData();
|
|
|
+ $('tr', '#im-list').click(function () {
|
|
|
+ $('tr.table-warning').removeClass('table-warning');
|
|
|
+ $(this).addClass('table-warning');
|
|
|
+ $('#im-list').attr('rowIndex', this.rowIndex - 1);
|
|
|
+ reLoadDetailData();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
postData(window.location.pathname + '/load', { loadType: 'all' }, function (data) {
|
|
@@ -42,23 +76,23 @@ $(document).ready(() => {
|
|
|
reBuildImData();
|
|
|
});
|
|
|
|
|
|
- let gatherComfirmPopover = {
|
|
|
+ let gatherConfirmPopover = {
|
|
|
reBind: function (obj, eventName, fun) {
|
|
|
obj.unbind(eventName);
|
|
|
obj.bind(eventName, fun);
|
|
|
},
|
|
|
check: function (pos, hint, okCallback) {
|
|
|
- const comfirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
|
|
|
+ const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
|
|
|
const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
|
|
|
this.reBind(cancelObj, 'click', function () {
|
|
|
- comfirmObj.hide();
|
|
|
+ confirmObj.hide();
|
|
|
});
|
|
|
this.reBind(okObj, 'click', function () {
|
|
|
okCallback();
|
|
|
- comfirmObj.hide();
|
|
|
+ confirmObj.hide();
|
|
|
});
|
|
|
hintObj.text(hint);
|
|
|
- comfirmObj.css("top", pos.y).css("left", pos.x).show();
|
|
|
+ confirmObj.css("top", pos.y).css("left", pos.x).show();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -159,7 +193,7 @@ $(document).ready(() => {
|
|
|
if (!node.check) {
|
|
|
if (checkParent(node)) {
|
|
|
const rect = info.sheet.getCellRect(info.row, info.col);
|
|
|
- gatherComfirmPopover.check({
|
|
|
+ gatherConfirmPopover.check({
|
|
|
x: rect.x + rect.width / 2 + 25,
|
|
|
y: rect.y + rect.height / 2 + 3,
|
|
|
}, '父项已勾选,继续将取消父项勾选。', function () {
|
|
@@ -176,7 +210,7 @@ $(document).ready(() => {
|
|
|
});
|
|
|
} else if (checkChildren(node)) {
|
|
|
const rect = info.sheet.getCellRect(info.row, info.col);
|
|
|
- gatherComfirmPopover.check({
|
|
|
+ gatherConfirmPopover.check({
|
|
|
x: rect.x + rect.width / 2 + 25,
|
|
|
y: rect.y + rect.height / 2 + 3,
|
|
|
}, '子项已勾选,继续将取消子项勾选。', function () {
|
|
@@ -201,31 +235,21 @@ $(document).ready(() => {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- if (!gsTree) {
|
|
|
- postData(window.location.pathname + '/load', { loadType: 'ledger' }, function (data) {
|
|
|
- gsTree = createNewPathTree('base', {
|
|
|
- id: 'ledger_id',
|
|
|
- pid: 'ledger_pid',
|
|
|
- order: 'order',
|
|
|
- level: 'level',
|
|
|
- rootId: -1,
|
|
|
- keys: ['id', 'tender_id', 'ledger_id'],
|
|
|
- });
|
|
|
- const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(','), _.toNumber) : [];
|
|
|
- for (const node of data) {
|
|
|
- node.check = gatherNodes.indexOf(node.id) !== -1;
|
|
|
- }
|
|
|
- gsTree.loadDatas(data);
|
|
|
- SpreadJsObj.loadSheetData(gsSpread.getActiveSheet(), 'tree', gsTree);
|
|
|
- SpreadJsObj.resetFieldReadOnly(gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
|
|
|
- });
|
|
|
+ const gsTree = stageIm.getGsTree();
|
|
|
+ const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(','), _.toNumber) : [];
|
|
|
+ for (const node of gsTree.datas) {
|
|
|
+ node.check = gatherNodes.indexOf(node.id) !== -1;
|
|
|
+ }
|
|
|
+ gsTree.expandByLevel(4);
|
|
|
+ SpreadJsObj.loadSheetData(gsSpread.getActiveSheet(), 'tree', gsTree);
|
|
|
+ SpreadJsObj.resetFieldReadOnly(gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
|
|
|
} else {
|
|
|
+ const gsTree = stageIm.getGsTree();
|
|
|
const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(','), _.toNumber) : [];
|
|
|
for (const node of gsTree.datas) {
|
|
|
node.check = gatherNodes.indexOf(node.id) !== -1;
|
|
|
}
|
|
|
- SpreadJsObj.resetFieldReadOnly(gsSpread.getActiveSheet(), 'check', !$('#im-gather-check')[0].checked);
|
|
|
+ SpreadJsObj.reLoadColsData(gsSpread.getActiveSheet(), [0]);
|
|
|
}
|
|
|
});
|
|
|
// 提交 高级设置
|
|
@@ -247,4 +271,208 @@ $(document).ready(() => {
|
|
|
$('#choose2').modal('hide');
|
|
|
});
|
|
|
});
|
|
|
+ // 编辑
|
|
|
+ $('#edit-detail').click(function () {
|
|
|
+ $(this).hide();
|
|
|
+ $('#save-detail').show();
|
|
|
+ $('#cancel-detail').show();
|
|
|
+ $('#bgl-code').removeAttr('readonly');
|
|
|
+ $('#bw-name').removeAttr('readonly');
|
|
|
+ $('#start-peg').removeAttr('readonly');
|
|
|
+ $('#end-peg').removeAttr('readonly');
|
|
|
+ $('#unit-name').removeAttr('readonly');
|
|
|
+ $('#drawing-code').removeAttr('readonly');
|
|
|
+ $('#calc-memo').removeAttr('readonly');
|
|
|
+ });
|
|
|
+ // 保存
|
|
|
+ $('#save-detail').click(() => {
|
|
|
+ function check(field, obj, org, update) {
|
|
|
+ const newValue = obj.val();
|
|
|
+ if (!org[field]) {
|
|
|
+ if (newValue !== '') {
|
|
|
+ update[field] = newValue;
|
|
|
+ }
|
|
|
+ } else if (newValue !== org[field]){
|
|
|
+ update[field] = newValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const data = getSelectDetailData();
|
|
|
+ const updateData = {lid: data.lid};
|
|
|
+ if (data.uuid) {
|
|
|
+ updateData.uuid = data.uuid;
|
|
|
+ } else {
|
|
|
+ updateData.code = data.code;
|
|
|
+ updateData.name = data.name;
|
|
|
+ updateData.unit = data.unit;
|
|
|
+ updateData.unit_price = data.unit_price;
|
|
|
+ }
|
|
|
+ check('bgl_code', $('#bgl-code'), data, updateData);
|
|
|
+ check('bw', $('#bw-name'), data, updateData);
|
|
|
+ check('start_peg', $('#start-peg'), data, updateData);
|
|
|
+ check('end_peg', $('#end-peg'), data, updateData);
|
|
|
+ check('jldy', $('#unit-name'), data, updateData);
|
|
|
+ check('drawing_code', $('#drawing-code'), data, updateData);
|
|
|
+ check('calc_memo', $('#calc-memo'), data, updateData);
|
|
|
+ postData(window.location.pathname + '/save', updateData, function (result) {
|
|
|
+ _.assign(data, result);
|
|
|
+ $('#edit-detail').show();
|
|
|
+ $('#save-detail').hide();
|
|
|
+ $('#cancel-detail').hide();
|
|
|
+ $('#bgl-code').attr('readonly', '');
|
|
|
+ $('#bw-name').attr('readonly', '');
|
|
|
+ $('#start-peg').attr('readonly', '');
|
|
|
+ $('#end-peg').attr('readonly', '');
|
|
|
+ $('#unit-name').attr('readonly', '');
|
|
|
+ $('#drawing-code').attr('readonly', '');
|
|
|
+ $('#calc-memo').attr('readonly', '');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ // 取消
|
|
|
+ $('#cancel-detail').click(() => {
|
|
|
+ $('#edit-detail').show();
|
|
|
+ $(this).hide();
|
|
|
+ $('#save-detail').hide();
|
|
|
+ $('#bgl-code').attr('readonly', '');
|
|
|
+ $('#bw-name').attr('readonly', '');
|
|
|
+ $('#start-peg').attr('readonly', '');
|
|
|
+ $('#end-peg').attr('readonly', '');
|
|
|
+ $('#unit-name').attr('readonly', '');
|
|
|
+ $('#drawing-code').attr('readonly', '');
|
|
|
+ $('#calc-memo').attr('readonly', '');
|
|
|
+ reLoadDetailData();
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 草图相关
|
|
|
+ // 移动图片
|
|
|
+ const moveImageItem = function (ev) {
|
|
|
+ const item = this;
|
|
|
+ const view = $('.img-view')[0];
|
|
|
+ let oEvent = ev;
|
|
|
+ // 浏览器有一些图片的默认事件,这里要阻止
|
|
|
+ oEvent.preventDefault();
|
|
|
+ let disX = oEvent.clientX - item.offsetLeft;
|
|
|
+ let disY = oEvent.clientY - item.offsetTop;
|
|
|
+ view.onmousemove = function (ev) {
|
|
|
+ oEvent = ev;
|
|
|
+ oEvent.preventDefault();
|
|
|
+ let x = oEvent.clientX -disX;
|
|
|
+ let y = oEvent.clientY -disY;
|
|
|
+
|
|
|
+ // 图形移动的边界判断
|
|
|
+ x = x <= 0 ? 0 : x;
|
|
|
+ x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
|
|
|
+ y = y <= 0 ? 0 : y;
|
|
|
+ y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
|
|
|
+ item.style.left = x + 'px';
|
|
|
+ item.style.top = y + 'px';
|
|
|
+ };
|
|
|
+ // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
|
|
|
+ view.onmouseleave = function () {
|
|
|
+ view.onmousemove = null;
|
|
|
+ view.onmouseup = null;
|
|
|
+ };
|
|
|
+ // 鼠标弹起后停止移动
|
|
|
+ view.onmouseup=function() {
|
|
|
+ view.onmousemove = null;
|
|
|
+ view.onmouseup = null;
|
|
|
+ };
|
|
|
+ };
|
|
|
+ const removeImageItem = function () {
|
|
|
+ $(this).parent().remove();
|
|
|
+ };
|
|
|
+ // 加载草图组成
|
|
|
+ $('#edit-img').on('show.bs.modal', function () {
|
|
|
+ const data = getSelectDetailData();
|
|
|
+ const items = JSON.parse(data.calc_img_org) || [];
|
|
|
+ const html = [];
|
|
|
+ for (const item of items) {
|
|
|
+ const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';';
|
|
|
+ html.push('<div class="img-item" style="' + itemStyle + '">');
|
|
|
+ html.push('<div class="img-bar">');
|
|
|
+ html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove"></i></a>');
|
|
|
+ html.push('</div>');
|
|
|
+ html.push('<img src="', item.src, '" id="draggable">');
|
|
|
+ html.push('</div>');
|
|
|
+ }
|
|
|
+ $('.img-view').html(html.join(''));
|
|
|
+ $('.img-item').mousedown(moveImageItem);
|
|
|
+ $('.img-bar').click(removeImageItem);
|
|
|
+ });
|
|
|
+ // 上传图片
|
|
|
+ $('#upload-img').click(function () {
|
|
|
+ $('#upload-img-file').trigger('click');
|
|
|
+ });
|
|
|
+ $('#upload-img-file').change(function () {
|
|
|
+ if ($(this).val()) {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', this.files[0]);
|
|
|
+ postDataWithFile(window.location.pathname + '/add-img', formData, function (result) {
|
|
|
+ const html = [];
|
|
|
+ html.push('<div class="img-item">');
|
|
|
+ html.push('<div class="img-bar">');
|
|
|
+ html.push('<a href="" class="text-danger" title="删除"><i class="fa fa-remove"></i></a>');
|
|
|
+ html.push('</div>');
|
|
|
+ html.push('<img src="', '/' + result, '" id="draggable">');
|
|
|
+ html.push('</div>');
|
|
|
+ $('.img-view').append(html.join(''));
|
|
|
+ $('.img-item').mousedown(moveImageItem);
|
|
|
+ $('.img-bar').click(removeImageItem);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 保存草图修改结果
|
|
|
+ $('#edit-img-ok').click(function () {
|
|
|
+ // 记录上传的图片的信息
|
|
|
+ const items = $('.img-item');
|
|
|
+ const data = getSelectDetailData();
|
|
|
+ if (items.length > 0) {
|
|
|
+ const itemInfo = [];
|
|
|
+ for (const item of items) {
|
|
|
+ const itemData = {
|
|
|
+ src: $('img', item).attr('src'),
|
|
|
+ left: item.style.left,
|
|
|
+ top: item.style.top,
|
|
|
+ };
|
|
|
+ itemInfo.push(itemData);
|
|
|
+ }
|
|
|
+ // 获取合并好的图片数据
|
|
|
+ const canvas = document.createElement('canvas');
|
|
|
+ const view = $('.img-view')[0];
|
|
|
+ canvas.height = view.clientHeight;
|
|
|
+ canvas.width = view.clientWidth;
|
|
|
+ const ctx = canvas.getContext('2d');
|
|
|
+ ctx.fillStyle = '#ffffff';
|
|
|
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
+ for (const b of $('.img-item')) {
|
|
|
+ const pos = $(b).position();
|
|
|
+ const img = $('img', b)[0];
|
|
|
+ ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
|
|
|
+ }
|
|
|
+ // 生成上传数据
|
|
|
+ const updateData = {updateType: 'update', lid: data.lid};
|
|
|
+ if (data.uuid) {
|
|
|
+ updateData.uuid = data.uuid;
|
|
|
+ } else {
|
|
|
+ updateData.code = data.code;
|
|
|
+ updateData.name = data.name;
|
|
|
+ updateData.unit = data.unit;
|
|
|
+ updateData.unit_price = data.unit_price;
|
|
|
+ }
|
|
|
+ updateData.img = canvas.toDataURL('image/jpeg');
|
|
|
+ updateData.imgInfo = itemInfo;
|
|
|
+ postData(window.location.pathname + '/merge-img', updateData, function (result) {
|
|
|
+ _.assign(data, result);
|
|
|
+ $('#calc-img').html('<img src="/' + data.calc_img + '" class="d-100" width="100%">');
|
|
|
+ $('#edit-img').modal('hide');
|
|
|
+ });
|
|
|
+ } else if (data.calc_img) {
|
|
|
+ postData(window.location.pathname + '/merge-img', {updateType: 'clear', lid: data.lid, uuid: data.uuid}, function (result) {
|
|
|
+ _.assign(data, result);
|
|
|
+ $('#calc-img').html('');
|
|
|
+ $('#edit-img').modal('hide');
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|