123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958 |
- $(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('<tr>');
- html.push(`<td class="text-center"><input fid="${file.id}" type="checkbox"></td>`);
- const qaMark = file.spec_type === 'qa' ? '<span class="badge badge-pill badge-success p-1 mr-2">质</span>' : '';
- html.push(`<td>${file.filename} ${qaMark}</td>`);
- html.push(`<td class="text-center">${file.user_name}</td>`);
- html.push(`<td class="text-center">${moment(file.create_time).format('YYYY-MM-DD')}</td>`);
- // const editHtml = file.canEdit ? `<a href="javascript: void(0);" class="mr-1" name="edit-file" fid="${file.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
- const editHtml = '';
- const viewHtml = file.viewpath ? `<a href="${file.viewpath}" class="mr-1" target="_blank"><i class="fa fa-eye fa-fw"></i></a>` : '';
- const downHtml = `<a href="javascript: void(0);" onclick="AliOss.downloadFile('${file.filepath}', '${file.filename + file.fileext}')" class="mr-1"><i class="fa fa-download fa-fw"></i></a>`;
- const delHtml = file.canEdit || canDelete
- ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-file" fid="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>`
- : ''; //'<a href="javascript: void(0);" class="mr-1 text-muted"><i class="fa fa-trash-o fa-fw"></i></a>';
- html.push(`<td class="text-center">${editHtml}${viewHtml}${downHtml}${delHtml}</td>`);
- html.push('</tr>');
- return html.join('');
- }
- getFilesTableHtml(files, key) {
- if (!files) return '';
- const html = [];
- html.push('<table class="table table-bordered"><thead><tr class="text-center"><th width="60px">选择</th><th width="">名称</th><th width="150px">上传人</th><th width="150px">上传时间</th><th width="100px">操作</th></tr></thead>');
- html.push(`<tbody id="${key}">`);
- for (const f of files) {
- html.push(this.getFileHtml(f));
- }
- html.push('<tbody>');
- html.push('</table>');
- 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('<div class="title-main d-flex justify-content-between sjs-bar">', this.getControlHtml(), '</div>');
- html.push('<div class="sjs-quality scroll-y">', this.getContentHtml(), '</div>');
- html.push('</div>');
- 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 ? '<a href="#add-kaigong" data-toggle="modal" data-target="#add-kaigong" class="btn btn-primary btn-sm" >新增开工</a>' : '';
- }
- getControlHtml() {
- const html = [];
- html.push('<div>', this._getAddHtml(), '</div>');
- return html.join('');
- }
- _getCardHtml() {
- if (!this.node.quality.kaigong) return '';
- const html = [];
- html.push('<div class="card mt-2">');
- html.push('<div class="card-header d-flex justify-content-between">', this.getBwName(),
- `<a href="javascript: void(0)" class="text-danger" id="del-kaigong"><i class="fa fa-trash-o fa-fw"></i></a>`, '</div>');
- html.push(`<div class="card-body pt-2"> <div class="my-2"><table class="col-12"><tbody><tr><td width="33%">计划开工日期:${this.node.quality.kaigong.kaigong_date}</td><td width="33%">资料个数:<span id="${this.fileCountKey}">${this.node.quality.kaigong.files.length}</span></td></tr></tbody></table></div>`);
- html.push('<hr/>');
- html.push('<nav class="nav nav-tabs"><a class="nav-link nav-item active" data-toggle="tab" href="#kg_files">开工资料</a><a class="nav-link nav-item" data-toggle="tab" href="#yy_files" style="display: none;">引用试验资料</a>',
- '<div class="ml-auto"><a href="javascript: void(0);" name="upload-kg" class="btn btn-outline-primary btn-sm">上传开工资料</a><a href="#" data-toggle="modal" data-target="#upload-kg" class="btn btn-outline-primary btn-sm ml-1" style="display: none;">引用试验资料</a></div>', '</nav>');
- html.push('<div class="tab-content my-2">');
- html.push('<div class="tab-pane fade show active" id="kg_files" role="tabpanel" aria-labelledby="home-tab">', this.getFilesTableHtml(this.node.quality.kaigong.files, this.filesTable), '</div>');
- html.push('<div class="tab-pane fade show" id="yy_files" role="tabpanel" aria-labelledby="home-tab">', this.getFilesTableHtml(this.node.quality.kaigong.qa_files, this.yyFilesTable), '</div>');
- html.push('</div>');
- html.push('</div>');
- 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 ? '<a href="javascript: void(0)" name="add-gx" class="btn btn-primary btn-sm" >新增工序</a>' : '';
- }
- getControlHtml() {
- const html = [];
- html.push('<div>', this._getAddHtml(), '</div>');
- return html.join('');
- }
- _getCardHtml(gx) {
- if (!gx) return '';
- const html = [];
- html.push(`<div class="card mt-2 gongxu-card" gxid="${gx.id}">`);
- html.push('<div class="card-header d-flex justify-content-between">');
- const editHtml = gx.canEdit ? `<a href="javascript: void(0);" class="ml-1" name="edit-gx" gxid="${gx.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
- const delHtml = gx.canEdit ? `<a href="javascript: void(0);" class="ml-1 text-danger" name="del-gx" gxid="${gx.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
- html.push(`<span style="width: 40%"><span name="gx-name">${gx.name}</span>${editHtml}${delHtml}<a href="javascript: void(0)" class="btn btn-sm btn-light text-primary" gxid="${gx.id}" name="upload-gx">上传文件</a></span>`);
- html.push(`<div class="" style="width:30%">资料个数:<span id="${this.fileCountPre}-${gx.id}">${gx.files.length}</span></div>`);
- html.push('<div style="width:30%"></div></div>');
- html.push('<div class="card-body pt-2">', this.getFilesTableHtml(gx.files, this.fileTablesPre + '-' + gx.id),'</div>');
- html.push('</div>');
- 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('<div class="card mt-2">');
- html.push('<div class="card-header d-flex justify-content-between">', this.getBwName(), '<div><a href="javascript: void(0)" class="btn btn-sm btn-light text-primary" name="upload-pd">上传文件</a></div>', '</div>');
- html.push('<div class="card-body pt-2">');
- html.push('<div class="mt-2">', this.getFilesTableHtml(this.node.quality.pingding.files, this.filesTable), '</div>');
- html.push('<nav class="nav nav-tabs mt-4"><a class="nav-link nav-item active" data-toggle="tab" href="#pd-source">评定资料来源</a>',
- '<div class="ml-auto"><a href="javascript: void(0)" name="upload-pd-source" class="btn btn-outline-primary btn-sm">补充资料</a></div></nav>');
- html.push('<div class="tab-content my-2">');
- html.push('<div class="tab-pane fade show active" id="pd_source" role="tabpanel" aria-labelledby="home-tab">', this.getFilesTableHtml(this.node.quality.pingding.source_files, this.sourceFilesTable), '</div>');
- html.push('</div>');
- html.push('</div>');
- html.push('</div>');
- 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('<div class="card mt-2">');
- html.push('<div class="card-header d-flex justify-content-between">', this.getBwName(), '</div>');
- html.push('<div class="card-body pt-2">');
- html.push('<div class="card">', '<div class="card-header d-flex justify-content-between">', '交工工序', '<div><a href="javascript: void(0)" class="btn btn-sm btn-light text-primary" name="upload-jg">上传文件</a></div>', '</div>');
- html.push('<div class="card-body pt-2">', this.getFilesTableHtml(this.node.quality.jiaogong.files, this.filesTable), '</div>');
- html.push('</div>');
- html.push('</div>');
- 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 = ['<option value=""></option>'];
- this.node.quality.gongxu.list.forEach(x => { html.push(`<option value="${x.id}">${x.name}</option>`)});
- return html.join('');
- }
- _getAddHtml() {
- return permission.add ? '<a href="javascript: void(0)" name="add-yb" class="btn btn-primary btn-sm" >新增隐蔽工程</a>' : '';
- }
- getControlHtml() {
- const html = [];
- html.push('<div>', this._getAddHtml(), '</div>');
- return html.join('');
- }
- _getCardHeaderHtml(yb){
- const html = [];
- const editHtml = yb.canEdit ? `<a href="javascript: void(0);" class="ml-1" name="edit-yb" ybid="${yb.id}"><i class="fa fa-pencil fa-fw"></i></a>` : '';
- const delHtml = yb.canEdit ? `<a href="javascript: void(0);" class="ml-1 text-danger" name="del-yb" ybid="${yb.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
- html.push(`<div class="d-inline-block col-6 pl-0"><span name="yb-name">${yb.name}</span>${editHtml}${delHtml}</div>`);
- const gongxu = yb.gongxu_id ? this.node.quality.gongxu.list.find(x => { return x.id === yb.gongxu_id; }) : null;
- html.push(`<div class="d-inline-block col-4">${gongxu ? gongxu.name : ''}</div>`);
- html.push(`<div class="d-inline-block pull-right"><span class="mr-3">创建日期:${moment(yb.create_time).format('YYYY-MM-DD')}</span></div>`);
- return html.join('');
- }
- _getCardHtml(yb) {
- if (!yb) return '';
- const html = [];
- html.push(`<div class="card mt-2 yinbi-card" ybid="${yb.id}">`);
- html.push('<div class="card-header d-flex justify-content-between yinbi-card-header">', this._getCardHeaderHtml(yb), '</div>');
- html.push('<div class="card-body pt-2">');
- html.push(`<div class="mb-2"><span class="yinbi-gcbw">工程部位及桩号:${yb.gcbw || ''}</span></div>`);
- html.push(`<div class="mb-2"><span class="yinbi-content">隐蔽工程说明:${yb.content || ''}</span></div>`);
- html.push('<div class="card mt-2">', '<div class="card-header d-flex justify-content-between">', '施工前:', '<div><a href="javascript: void(0)" class="btn btn-sm btn-light text-primary" name="upload-yb-before">上传文件</a></div>', '</div>');
- html.push('<div class="card-body pt-2">', this.getFilesTableHtml(yb.before_files, this.beforeFilesPre + '-' + yb.id ), '</div>');
- html.push('</div>');
- html.push('<div class="card mt-2">', '<div class="card-header d-flex justify-content-between">', '施工后:', '<div><a href="javascript: void(0)" class="btn btn-sm btn-light text-primary" name="upload-yb-after">上传文件</a></div>', '</div>');
- html.push('<div class="card-body pt-2">', this.getFilesTableHtml(yb.after_files, this.afterFilesPre + '-' + yb.id ), '</div>');
- html.push('</div>');
- html.push('</div>');
- html.push('</div>');
- 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'});
- });
|