123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- 'use strict';
- /**
- *
- *
- * @author EllisRan
- * @date 2022/01/21
- * @version
- */
- $(document).ready(() => {
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'menu.1.0.0',
- miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
- callback: function (info) {
- if (info.mini) {
- $('.panel-title').addClass('fluid');
- $('#sub-menu').removeClass('panel-sidebar');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- }
- autoFlashHeight();
- }
- });
- handleFileList(fileList);
- $('#file-ok').click(function () {
- const files = Array.from($('#file-modal')[0].files)
- const valiData = files.map(v => {
- const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
- return {
- size: v.size,
- ext
- }
- })
- if (validateFiles(valiData)) {
- if (files.length) {
- const formData = new FormData()
- files.forEach(file => {
- formData.append('name', file.name)
- formData.append('size', file.size)
- formData.append('file', file)
- })
- postDataWithFile(preUrl + '/file/upload', formData, function (result) {
- handleFileList(result);
- $('#file-cancel').click()
- });
- }
- }
- })
- function handleFileList(files = []) {
- $('#file-content').empty();
- // const { uncheck, checkNo } = auditConst.status
- const newFiles = files.map(file => {
- let showDel = false;
- if (file.uid === cur_uid) {
- // if (!curAuditor) {
- // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
- // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
- // } else {
- // curAuditor.audit_id === cur_uid && (showDel = true)
- // }
- if (change.status === auditConst.status.checked) {
- showDel = Boolean(file.extra_upload )
- } else {
- showDel = true
- }
- }
- return {...file, showDel}
- })
- let html = change.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
- newFiles.forEach((file, idx) => {
- if (file.showDel) {
- html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
- } else {
- html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td></td></tr>`
- }
- })
- $('#file-content').append(html);
- }
- $('#file-content').on('click', 'a', function () {
- if ($(this).hasClass('file-del')) {
- const id = $(this).data('id');
- postData(preUrl + '/file/delete', {id}, (result) => {
- handleFileList(result);
- })
- }
- });
- // 回车提交
- $('#project-table input').on('keypress', function () {
- if(window.event.keyCode === 13) {
- $(this).blur();
- }
- });
- $('#project-table input').blur(function () {
- const val_name = $(this).data('name');
- let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
- switch(val_name) {
- case 'code':
- if(!val) {
- toastr.error('立项书编号不能为空');
- $(this).val(change[val_name]);
- return false;
- }
- break;
- case 'name':
- if(!val) {
- toastr.error('工程名称不能为空');
- $(this).val(change[val_name]);
- return false;
- } else if(val.length > 100) {
- toastr.error('名称超过100个字,请缩减名称');
- $(this).val(change[val_name]);
- return false;
- }
- break;
- case 'org_price':
- case 'change_price':
- case 'crease_price':
- val = val ? parseFloat(val) : null;
- if(val && !_.isNumber(val)) {
- toastr.error('请输入数字');
- $(this).val(change[val_name]);
- return false;
- }
- break;
- default:
- if(val && val.length > 255) {
- toastr.error('超出字段范围,请缩减');
- $(this).val(change[val_name]);
- return false;
- }
- break;
- }
- if(change[val_name] !== val) {
- const _self = $(this);
- postData(preUrl + '/save', { name: val_name, val}, function (result) {
- change[val_name] = val;
- _self.val(change[val_name]);
- if (val_name === 'code') {
- $('#change-project-code').text(change[val_name]);
- }
- }, function () {
- _self.val(change[val_name]);
- })
- } else {
- $(this).val(change[val_name]);
- }
- })
- $('#project-table textarea').blur(function () {
- const val_name = $(this).data('name');
- let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
- if(change[val_name] !== val) {
- const _self = $(this);
- postData(preUrl + '/save', { name: val_name, val}, function (result) {
- change[val_name] = val;
- _self.val(change[val_name]);
- }, function () {
- _self.val(change[val_name]);
- })
- } else {
- $(this).val(change[val_name]);
- }
- })
- });
- /**
- * 校验文件大小、格式
- * @param {Array} files 文件数组
- */
- function validateFiles(files) {
- if (files.length > 10) {
- toastr.error('至多同时上传10个文件');
- return false
- }
- return files.every(file => {
- if (file.size > 1024 * 1024 * 30) {
- toastr.error('文件大小限制为30MB');
- return false
- }
- if (whiteList.indexOf('.' + file.ext) === -1) {
- toastr.error('请上传正确的格式文件');
- return false
- }
- return true
- })
- }
|