$(document).ready(() => { autoFlashHeight(); const xmjSpread = SpreadJsObj.createNewSpread($('#xmj-spread')[0]); const xmjSheet = xmjSpread.getActiveSheet(); const xmjSpreadSetting = { cols: [ { title: '工程编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 135, formatter: '@', cellType: 'tree' }, { title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 195, formatter: '@' }, ], emptyRows: 0, headRows: 1, headRowHeight: [32], headColWidth: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', readOnly: true, }; SpreadJsObj.initSheet(xmjSheet, xmjSpreadSetting); const xmjTree = createNewPathTree('gather', { id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1 }); postData('load', { filter: 'xmj;pos1', spec: { loadStatus: 1 } }, function(result) { result.xmj.forEach(x => { x.rela_type = 'xmj'; }); xmjTree.loadDatas(result.xmj); const posIndex = {}; for (const p of result.pos1) { if (!posIndex[p.lid]) posIndex[p.lid] = []; posIndex[p.lid].push(p); } for (const pi in posIndex) { const xmj = xmjTree.nodes.find(x => { return x.id === pi; }); if (!xmj || (xmj.children && xmj.children.length > 0)) continue; const posRange = posIndex[pi]; posRange.sort((a, b) => { return a.order - b.order; }); for (const p of posRange) { if (p.b_code) continue; xmjTree.addNode({ id: p.id, code: p.code, name: p.name, rela_type: 'pos' }, xmj); } } xmjTree.sortTreeNode(false); SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Tree, xmjTree); }); class BaseBlock { constructor(qualityObj, objKey, blockType) { this.qualityObj = qualityObj; this.objKey = objKey; this.obj = $(`#${objKey}`); this.blockType = blockType; this.saveUrl = 'save/' + this.blockType; } getFilterData() { if (!this.node) return null; const result = { rela_type: this.node.rela_type, rela_id: this.node.id }; if (this.node.quality) result.quality_id = this.node.quality.id; return result; } getBwName(){ if (!this.node) return ''; const parents = xmjTree.getAllParents(this.node); parents.shift(); parents.push(this.node); return parents.map(x => { return x.name; }).join('/'); } getFileHtml(file) { if (!file) return ''; const html = []; html.push(''); html.push(``); const qaMark = file.spec_type === 'qa' ? '' : ''; html.push(`${file.filename} ${qaMark}`); html.push(`${file.user_name}`); html.push(`${moment(file.create_time).format('YYYY-MM-DD')}`); // const editHtml = file.canEdit ? `` : ''; const editHtml = ''; const viewHtml = file.viewpath ? `` : ''; const downHtml = ``; const delHtml = file.canEdit || canDelete ? `` : ''; //''; html.push(`${editHtml}${viewHtml}${downHtml}${delHtml}`); html.push(''); return html.join(''); } getFilesTableHtml(files, key) { if (!files) return ''; const html = []; html.push(''); html.push(``); for (const f of files) { html.push(this.getFileHtml(f)); } html.push(''); html.push('
选择名称上传人上传时间操作
'); return html.join(''); } async uploadFiles(files, blockId = '', specType = ''){ const formData = new FormData(); formData.append('quality_id', this.node.quality.id); formData.append('block_type', this.blockType); formData.append('block_id', blockId); formData.append('spec_type', specType); let count = 0; for (const file of files) { if (file === undefined) { toastr.error('未选择上传文件。'); return false; } if (file.size > 50 * 1024 * 1024) { toastr.error('上传文件大小超过50MB。'); return false; } const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0]; if (whiteList.indexOf(fileext) === -1) { toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。'); return false; } formData.append('size', file.size); formData.append('file[]', file); count++; } if (count === 0) { toastr.warning('没有可上传的文件'); return false; } return await postDataWithFileAsync('file/upload', formData); } delFiles(files, callback) { postData('file/del', { del: files}, function(result) { callback(result); }); } selectUploadFiles(setting){ if (!setting) return; $('#upload-file').val(''); $('#add-file-ok').off('click'); $('#add-file').modal('show'); $('.spec-type-detail').hide(); if (setting.specType) { $('.spec-type').show(); for (const st of setting.specType) { $(`.spec-type-${st}`).show(); } } else { $('.spec-type').hide(); } $('#add-file-ok').on("click", function () { const specType = setting.specType ? $('[name=specType]:checked').val() : ''; setting.select(document.getElementById('upload-file').files, specType); $('#add-file').modal('hide'); }); } getControlHtml() { throw '请在子类中定义'; } getContentHtml() { throw '请在子类中定义'; } showQuality() { const html = []; html.push('
', this.getControlHtml(), '
'); html.push('
', this.getContentHtml(), '
'); html.push(''); this.obj.html(html.join('')); } showSum() { this.obj.html(''); } show(node) { this.node = node; this.refresh(); } refresh(data){ if (data) this.node.quality[this.blockType] = data; if (!this.node.children || this.node.children.length === 0) { this.showQuality(); } else { this.showSum(); } } } class Kaigong extends BaseBlock { constructor(objKey, qualityObj) { super(qualityObj, objKey, 'kaigong'); this.filesTable = objKey + '_files'; this.yyFilesTable = objKey + '_yy_files'; this.fileCountKey = objKey + '_filecount'; const self = this; $('#add-kaigong-ok').click(function() { const data = self.getFilterData(); data.add = { name: $('[name=kaigong-name]').val(), date: $('[name=kaigong-date]').val() }; postData(self.saveUrl, data, function(result) { if (self.node.quality) { self.node.quality.kaigong = result.kaigong } else { self.node.quality = result; } self.showQuality(); self.qualityObj.jiaogong.refresh(result.jiaogong); self.qualityObj.pingding.refresh(result.pingding); $('#add-kaigong').modal('hide'); autoFlashHeight(); }); }); $('body').on('click', '#del-kaigong', function() { const data = self.getFilterData(); data.del = data.quality_id; postData(self.saveUrl, data, function(result) { delete self.node.quality.kaigong; self.showQuality(); self.qualityObj.jiaogong.refresh(result.jiaogong); self.qualityObj.pingding.refresh(result.pingding); autoFlashHeight(); }) }); $('body').on('click', '[name=upload-kg]', function() { self.selectUploadFiles({ select: async function(files) { const result = await self.uploadFiles(files); self.node.quality.kaigong.files.push(...result); for (const r of result) { $(`#${self.filesTable}`).append(self.getFileHtml(r)); } self.refreshFileCountHtml(); self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', `#${this.filesTable} [name=del-file]`, function() { const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); const fi = self.node.quality.kaigong.files.findIndex(x => { return x.id === r; }); if (fi >= 0) self.node.quality.kaigong.files.splice(fi, 1); } self.refreshFileCountHtml(); self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); } _getAddHtml() { if (!permission.add) return ''; return !this.node.quality || !this.node.quality.kaigong ? '新增开工' : ''; } getControlHtml() { const html = []; html.push('
', this._getAddHtml(), '
'); return html.join(''); } _getCardHtml() { if (!this.node.quality.kaigong) return ''; const html = []; html.push('
'); html.push('
', this.getBwName(), ``, '
'); html.push(`
计划开工日期:${this.node.quality.kaigong.kaigong_date}资料个数:${this.node.quality.kaigong.files.length}
`); html.push('
'); html.push(''); html.push('
'); html.push('
', this.getFilesTableHtml(this.node.quality.kaigong.files, this.filesTable), '
'); html.push('
', this.getFilesTableHtml(this.node.quality.kaigong.qa_files, this.yyFilesTable), '
'); html.push('
'); html.push('
'); return html.join(''); } getContentHtml() { const html = []; if (this.node.quality && this.node.quality.kaigong) html.push(this._getCardHtml()); return html.join(''); } refreshFileCountHtml() { $(`#${this.fileCountKey}`).html(this.node.quality.kaigong.files.length); } } class Gongxu extends BaseBlock { constructor (objKey, qualityObj) { super(qualityObj, objKey, 'gongxu'); this.fileTablesPre = objKey + 'Files'; this.fileCountPre = objKey + 'Filecount'; this.pingding = this.qualityObj.pingding; const self = this; $('#add-gongxu-ok').click(function() { const name = $('[name=gongxu-name]').val(); if (!name) return; if (name.length > 100) { $('[name=gongxu-name]').addClass('is-invalid'); $('#gongxu-name-hint').show(); return; } else { $('[name=gongxu-name]').removeClass('is-invalid'); $('#gongxu-name-hint').hide(); } const data = self.getFilterData(); const gxid = $('#gongxu-id').val(); if (gxid) { data.update = { id: gxid, name }; } else { data.add = { name }; } postData(self.saveUrl, data, function(result) { if (data.add) { if (self.node.quality) { self.node.quality.gongxu = result.gongxu } else { self.node.quality = result; } self.qualityObj.jiaogong.refresh(result.jiaogong); self.qualityObj.pingding.refresh(result.pingding); self.showQuality(); } else { const gx = self.node.quality.gongxu.list.find(x => { return x.id === gxid; }); gx.name = name; $('[name=gx-name]', `.gongxu-card[gxid=${gxid}]`).html(name); } $('#add-gongxu').modal('hide'); autoFlashHeight(); }); }); $('body').on('click', '[name=add-gx]', function() { $('[name=gongxu-name]').val(''); $('#gongxu-id').val(''); $('#add-gongxu').modal('show'); }); $('body').on('click', '[name=del-gx]', function() { const gxid = this.getAttribute('gxid'); const data = self.getFilterData(); data.del = gxid; postData(self.saveUrl, data, function(result) { const gxIndex = self.node.quality.gongxu.list.findIndex(x => { return x.id === gxid; }); self.node.quality.gongxu.list.splice(gxIndex, 1); self.qualityObj.jiaogong.refresh(result.jiaogong); self.qualityObj.pingding.refresh(result.pingding); $(`.gongxu-card[gxid=${gxid}]`).remove(); autoFlashHeight(); }); }); $('body').on('click', '[name=edit-gx]', function() { const gxid = this.getAttribute('gxid'); const gx = self.node.quality.gongxu.list.find(x =>{ return x.id === gxid; }); $('[name=gongxu-name]').val(gx.name); $('#gongxu-id').val(gx.id); $('#add-gongxu').modal('show'); }); $('body').on('click', '[name=upload-gx]', function() { const gxid = this.getAttribute('gxid'); self.selectUploadFiles({ specType: ['qa'], select: async function(files, specType) { const gx = self.node.quality.gongxu.list.find(x => { return x.id === gxid }); const result = await self.uploadFiles(files, gxid, specType); gx.files.push(...result); for (const r of result) { $(`#${self.fileTablesPre}-${gx.id}`).append(self.getFileHtml(r)); } self.refreshFileCountHtml(gx); if (specType === 'qa') { self.pingding.addQaFiles(result); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', '.gongxu-card [name=del-file]', function(){ const gxid = $(this).closest('.gongxu-card').attr('gxid'); const gx = self.node.quality.gongxu.list.find(x => { return x.id === gxid; }); const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { const pdRemoveFiles = []; for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); const fi = gx.files.findIndex(x => { return x.id === r; }); const file = gx.files[fi]; if (file.spec_type === 'qa') pdRemoveFiles.push(file); if (fi >= 0) gx.files.splice(fi, 1); } if (pdRemoveFiles.length > 0) self.pingding.removeQaFiles(pdRemoveFiles); self.refreshFileCountHtml(gx); self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); } _getAddHtml() { return permission.add ? '新增工序' : ''; } getControlHtml() { const html = []; html.push('
', this._getAddHtml(), '
'); return html.join(''); } _getCardHtml(gx) { if (!gx) return ''; const html = []; html.push(`
`); html.push('
'); const editHtml = gx.canEdit ? `` : ''; const delHtml = gx.canEdit ? `` : ''; html.push(`${gx.name}${editHtml}${delHtml}上传文件`); html.push(`
资料个数:${gx.files.length}
`); html.push('
'); html.push('
', this.getFilesTableHtml(gx.files, this.fileTablesPre + '-' + gx.id),'
'); html.push('
'); return html.join(''); } getContentHtml() { const html = []; if (this.node.quality && this.node.quality.gongxu) { for (const gx of this.node.quality.gongxu.list) { html.push(this._getCardHtml(gx)); } } return html.join(''); } refreshFileCountHtml(gx) { $(`#${this.fileCountPre}-${gx.id}`).html(gx.files.length); } } class Pingding extends BaseBlock { constructor(objKey, qualityObj) { super(qualityObj, objKey, 'pingding'); this.filesTable = objKey + '_files'; this.sourceFilesTable = objKey + '_source_files'; const self = this; $('body').on('click', '[name=upload-pd]', function() { self.selectUploadFiles({ select: async function(files) { const result = await self.uploadFiles(files); self.node.quality.pingding.files.push(...result); for (const r of result) { $(`#${self.filesTable}`).append(self.getFileHtml(r)); } autoFlashHeight(); self.qualityObj.refreshFileCountHtml(); } }); }); $('body').on('click', `#${this.filesTable} [name=del-file]`, function() { const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); const fi = self.node.quality.pingding.files.findIndex(x => { return x.id === r; }); if (fi >= 0) self.node.quality.pingding.files.splice(fi, 1); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); $('body').on('click', '[name=upload-pd-source]', function() { self.selectUploadFiles({ select: async function(files) { const result = await self.uploadFiles(files, '', 'add'); self.node.quality.pingding.files.push(...result); for (const r of result) { $(`#${self.sourceFilesTable}`).append(self.getFileHtml(r)); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', `#${this.sourceFilesTable} [name=del-file]`, function() { const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); const fi = self.node.quality.pingding.source_files.findIndex(x => { return x.id === r; }); if (fi >= 0) self.node.quality.pingding.source_files.splice(fi, 1); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); } getControlHtml() { const html = []; return html.join(''); } _getCardHtml() { if (!this.node.quality.pingding) return ''; const html = []; html.push('
'); html.push('
', this.getBwName(), '
上传文件
', '
'); html.push('
'); html.push('
', this.getFilesTableHtml(this.node.quality.pingding.files, this.filesTable), '
'); html.push(''); html.push('
'); html.push('
', this.getFilesTableHtml(this.node.quality.pingding.source_files, this.sourceFilesTable), '
'); html.push('
'); html.push('
'); html.push('
'); return html.join(''); } getContentHtml() { const html = []; if (this.node.quality && this.node.quality.pingding) html.push(this._getCardHtml()); return html.join(''); } addQaFiles(files) { for (const f of files) { const qaF = JSON.parse(JSON.stringify(f)); qaF.canEdit = false; this.node.quality.pingding.files.push(qaF); $(`#${this.sourceFilesTable}`).append(this.getFileHtml(qaF)); } } removeQaFiles(files) { for (const f of files) { const qaFi = this.node.quality.pingding.source_files.findIndex(x => { return x.id === f.id; }); $(`input[fid=${f.id}]`, this.sourceFilesTable).parent().parent().remove(); this.node.quality.pingding.source_files.splice(qaFi, 1); } } } class Jiaogong extends BaseBlock { constructor(objKey, qualityObj) { super(qualityObj, objKey, 'jiaogong'); this.filesTable = objKey + '_files'; const self = this; $('body').on('click', '[name=upload-jg]', function() { self.selectUploadFiles({ select: async function(files) { const result = await self.uploadFiles(files); self.node.quality.jiaogong.files.push(...result); for (const r of result) { $(`#${self.filesTable}`).append(self.getFileHtml(r)); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', `#${this.filesTable} [name=del-file]`, function() { const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); const fi = self.node.quality.jiaogong.files.findIndex(x => { return x.id === r; }); if (fi >= 0) self.node.quality.jiaogong.files.splice(fi, 1); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); } getControlHtml() { const html = []; return html.join(''); } _getCardHtml() { if (!this.node.quality.jiaogong) return ''; const html = []; html.push('
'); html.push('
', this.getBwName(), '
'); html.push('
'); html.push('
', '
', '交工工序', '', '
'); html.push('
', this.getFilesTableHtml(this.node.quality.jiaogong.files, this.filesTable), '
'); html.push('
'); html.push('
'); return html.join(''); } getContentHtml() { const html = []; if (this.node.quality && this.node.quality.jiaogong) html.push(this._getCardHtml()); return html.join(''); } } class Yinbi extends BaseBlock { constructor (objKey, qualityObj) { super(qualityObj, objKey, 'yinbi'); this.beforeFilesPre = objKey + 'BeforeFiles'; this.afterFilesPre = objKey + 'AfterFiles'; const self = this; $('#add-yinbi-ok').click(function() { const name = $('[name=yinbi-name]').val(); if (!name) { toastr.warning('请输入名称'); return; } if (name.length > 100) { toastr.warning('名称超过100,请缩短'); return; } const gongxu_id = $('[name=yinbi-gongxu-id]').val(); const gcbw = $('[name=yinbi-gcbw]').val(); const content = $('[name=yinbi-content]').val(); if (gcbw.length > 1000) { toastr.warning('工程部位超过1000,请缩短'); return; } if (content.length > 1000) { toastr.warning('隐蔽工程说明超过1000,请缩短'); return; } const data = self.getFilterData(); const ybid = $('#yinbi-id').val(); if (ybid) { data.update = { id: ybid, name, gongxu_id, gcbw, content }; } else { data.add = { name, gongxu_id, gcbw, content }; } postData(self.saveUrl, data, function(result) { if (data.add) { if (self.node.quality) { self.node.quality.yinbi = result.yinbi } else { self.node.quality = result; } self.showQuality(); } else { const yb = self.node.quality.yinbi.list.find(x => { return x.id === ybid; }); yb.name = name; yb.gongxu_id = gongxu_id; yb.gcbw = gcbw; yb.content = content; self.afterEdit(yb); } $('#add-yinbi').modal('hide'); autoFlashHeight(); }); }); $('body').on('click', '[name=add-yb]', function() { $('[name=yinbi-name]').val(''); $('[name=yinbi-gongxu-id]').html(self._getSelectGongxuHtml()); $('[name=yinbi-gongxu-id]').val(''); $('[name=yinbi-gcbw]').val(''); $('[name=yinbi-content]').val(''); $('#yinbi-id').val(''); $('#add-yinbi').modal('show'); }); $('body').on('click', '[name=del-yb]', function() { const ybid = this.getAttribute('ybid'); const data = self.getFilterData(); data.del = ybid; postData(self.saveUrl, data, function(result) { const ybIndex = self.node.quality.yinbi.list.findIndex(x => { return x.id === ybid; }); self.node.quality.yinbi.list.splice(ybIndex, 1); $(`.yinbi-card[ybid=${ybid}]`).remove(); autoFlashHeight(); }); }); $('body').on('click', '[name=edit-yb]', function() { const ybid = this.getAttribute('ybid'); const yb = self.node.quality.yinbi.list.find(x =>{ return x.id === ybid; }); $('[name=yinbi-name]').val(yb.name); $('[name=yinbi-gongxu-id]').html(self._getSelectGongxuHtml()); $('[name=yinbi-gongxu-id]').val(yb.gongxu_id); $('[name=yinbi-gcbw]').val(yb.gcbw); $('[name=yinbi-content]').val(yb.content); $('#yinbi-id').val(yb.id); $('#add-yinbi').modal('show'); }); $('body').on('click', '[name=upload-yb-before]', function() { const ybid = $(this).closest('.yinbi-card').attr('ybid'); self.selectUploadFiles({ select: async function(files, specType) { const yb = self.node.quality.yinbi.list.find(x => { return x.id === ybid }); const result = await self.uploadFiles(files, ybid, 'before'); yb.before_files.push(...result); for (const r of result) { $(`#${self.beforeFilesPre}-${yb.id}`).append(self.getFileHtml(r)); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', '[name=upload-yb-after]', function() { const ybid = $(this).closest('.yinbi-card').attr('ybid'); self.selectUploadFiles({ select: async function(files, specType) { const yb = self.node.quality.yinbi.list.find(x => { return x.id === ybid }); const result = await self.uploadFiles(files, ybid, 'after'); yb.after_files.push(...result); for (const r of result) { $(`#${self.afterFilesPre}-${yb.id}`).append(self.getFileHtml(r)); } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); } }); }); $('body').on('click', `#${self.objKey} [name=del-file]`, function(){ const tableKey = $(this).closest('tbody').attr('id'); const ybid = $(this).closest('.yinbi-card').attr('ybid'); const yb = self.node.quality.yinbi.list.find(x => { return x.id === ybid; }); const del = [this.getAttribute('fid')]; self.delFiles(del, function(result) { for (const r of result) { $(`input[fid=${r}]`).parent().parent().remove(); if (tableKey.indexOf(self.beforeFilesPre) === 0) { const fi = yb.before_files.findIndex(x => { return x.id === r; }); if (fi >= 0) yb.before_files.splice(fi, 1); } else if (tableKey.indexOf(self.afterFilesPre) === 0) { const fi = yb.after_files.findIndex(x => { return x.id === r; }); if (fi >= 0) yb.after_files.splice(fi, 1); } } self.qualityObj.refreshFileCountHtml(); autoFlashHeight(); }); }); } _getSelectGongxuHtml(){ const html = ['']; this.node.quality.gongxu.list.forEach(x => { html.push(``)}); return html.join(''); } _getAddHtml() { return permission.add ? '新增隐蔽工程' : ''; } getControlHtml() { const html = []; html.push('
', this._getAddHtml(), '
'); return html.join(''); } _getCardHeaderHtml(yb){ const html = []; const editHtml = yb.canEdit ? `` : ''; const delHtml = yb.canEdit ? `` : ''; html.push(`
${yb.name}${editHtml}${delHtml}
`); const gongxu = yb.gongxu_id ? this.node.quality.gongxu.list.find(x => { return x.id === yb.gongxu_id; }) : null; html.push(`
${gongxu ? gongxu.name : ''}
`); html.push(`
创建日期:${moment(yb.create_time).format('YYYY-MM-DD')}
`); return html.join(''); } _getCardHtml(yb) { if (!yb) return ''; const html = []; html.push(`
`); html.push('
', this._getCardHeaderHtml(yb), '
'); html.push('
'); html.push(`
工程部位及桩号:${yb.gcbw || ''}
`); html.push(`
隐蔽工程说明:${yb.content || ''}
`); html.push('
', '
', '施工前:', '', '
'); html.push('
', this.getFilesTableHtml(yb.before_files, this.beforeFilesPre + '-' + yb.id ), '
'); html.push('
'); html.push('
', '
', '施工后:', '', '
'); html.push('
', this.getFilesTableHtml(yb.after_files, this.afterFilesPre + '-' + yb.id ), '
'); html.push('
'); html.push('
'); html.push('
'); return html.join(''); } getContentHtml() { const html = []; if (this.node.quality && this.node.quality.yinbi) { for (const yb of this.node.quality.yinbi.list) { html.push(this._getCardHtml(yb)); } } return html.join(''); } afterEdit(yb) { $(`.yinbi-card[ybid=${yb.id}] .yinbi-card-header`).html(this._getCardHeaderHtml(yb)); $(`.yinbi-card[ybid=${yb.id}] .yinbi-gcbw`).html(`工程部位及桩号:${yb.gcbw || ''}`); $(`.yinbi-card[ybid=${yb.id}] .yinbi-content`).html(`隐蔽工程说明:${yb.content || ''}`); } } class Quality { constructor () { this.kaigong = new Kaigong('kaigong', this); this.pingding = new Pingding('pingding', this); this.gongxu = new Gongxu('gongxu', this); this.jiaogong = new Jiaogong('jiaogong', this); this.yinbi = new Yinbi('yinbi', this); } getStatusText(type, status) { const def = thirdParty[type].find(function (x) { return x.value === status; }); return def ? def.name : ''; } getGxbyText(data) { return this.getStatusText('gxby', data.gxby_status); } getDaglText(data) { return this.getStatusText('dagl', data.dagl_status); } getFileCount() { if (!this.node || !this.node.quality) return 0; let result = this.node.quality.kaigong ? this.node.quality.kaigong.files.length : 0; this.node.quality.gongxu.list.forEach(gx => { result = result + gx.files.length; }); if (this.node.quality.pingding) { result = result + this.node.quality.pingding.files.length + this.node.quality.pingding.source_files.filter(x => {return x.spec_type !== 'qa'; }).length; } if (this.node.quality.jiaogong) result = result + this.node.quality.jiaogong.files.length; return result; } getYinbiFileCount() { if (!this.node || !this.node.quality) return 0; let result = 0; this.node.quality.yinbi.list.forEach(x => { result = result + x.before_files.length + x.after_files.length; }); return result; } refreshFileCountHtml() { const fileCount = this.getFileCount(); const yinbiFileCount = this.getYinbiFileCount(); $('#file-count').html('合计:' + (fileCount + yinbiFileCount)); $('#file-count-wo-yinbi').html('不含隐蔽:' + (fileCount)); $('#file-count-yinbi').html('隐蔽工程:' + (yinbiFileCount)); } refreshGaikuang() { let gxbyText = this.getGxbyText(this.node); if (this.node.gxby_date) gxbyText = gxbyText + `(${moment(this.node.gxby_date).format('YYYY-MM-DD')})`; if (gxbyText) { $('#gxby-info').html('完工:' + gxbyText).show(); } else { $('#gxby-info').hide(); } const daglText = this.getDaglText(this.node); if (daglText) { $('#dagl-info').html('资料:' + daglText).show(); } else { $('#dagl-info').hide(); } this.refreshFileCountHtml(); } refreshQuality() { this.refreshGaikuang(); this.kaigong.show(this.node); this.gongxu.show(this.node); this.pingding.show(this.node); this.jiaogong.show(this.node); this.yinbi.show(this.node); autoFlashHeight(); } async showQuality(node, force = 1) { this.node = node; this.isChild = !this.node.children || this.node.children.length === 0; if (!this.isChild) { $('#quality-detail').hide(); return; } else { $('#quality-detail').show(); } if (!node.quality || force) { node.quality = (await postDataAsync('load', { filter: 'detail', id: node.id })).detail; if (node.quality) { node.gxby_status = node.quality.gxby_status; node.gxby_date = node.quality.gxby_date; node.dagl_status = node.quality.dagl_status; } } this.refreshQuality(); } } const qualityObj = new Quality(); xmjSpread.bind(spreadNS.Events.SelectionChanged, function(e, info) { if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) { qualityObj.showQuality(SpreadJsObj.getSelectObject(info.sheet)); } }); $('#reload-quality').click(function() { qualityObj.showQuality(SpreadJsObj.getSelectObject(xmjSheet), true); }); $.contextMenu({ selector: '#xmj-spread', build: function ($trigger, e) { const target = SpreadJsObj.safeRightClickSelection($trigger, e, xmjSpread); return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader; }, items: { pushInc: { name: '推送状态', callback: function (key, opt, menu, e) { const select = []; const node = SpreadJsObj.getSelectObject(xmjSheet); if (node.children && node.children.length > 0) { const posterity = xmjTree.getPosterity(node); for (const p of posterity) { if (!node.children || node.children.length === 0) select.push(node.id); } } else { select.push(node.id); } postData('push', {push_type: 'inc', select}, function(result) { if (!result) { toastr.warning('暂无状态推送'); } else { toastr.success(`成功推送${result}条状态`); } }) }, }, pushAll: { name: '推送全部状态', callback: function (key, opt, menu, e) { postData('push', {push_type: 'all'}, function(result) { if (!result) { toastr.warning('暂无状态推送'); } else { toastr.success('推送成功'); } }); }, }, } }); // 显示层次 (function (select, sheet) { $(select).click(function () { const tag = $(this).attr('tag'); setTimeout(() => { showWaitingView(); const tree = sheet.zh_tree; if (!tree) return; switch (tag) { case "1": case "2": case "3": case "4": case "5": tree.expandByLevel(parseInt(tag)); SpreadJsObj.refreshTreeRowVisible(sheet); break; case "last": tree.expandByCustom(() => { return true; }); SpreadJsObj.refreshTreeRowVisible(sheet); break; } closeWaitingView(); }, 100); }); })('a[name=showLevel]', xmjSheet); const xmjSearch = $.posSearch({selector: '#xmj-search', searchSpread: xmjSpread, hint: '请输入 编号/名称 查询', specClass: 'mt-1'}); });