12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 'use strict';
- /**
- * 变更令详细页js
- *
- * @author EllisRan.
- * @date 2018/11/22
- * @version
- */
- $(document).ready(() => {
- // tab切换
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- const tab = $(this).attr('aria-controls');
- $('.show_title').hide();
- $('#'+ tab +'_title').show();
- });
- // 上传附件
- $('#upload-file-btn').click(function () {
- const file = $('#upload-file')[0];
- if (file.files[0] === undefined) {
- toastr.error('未选择上传文件!');
- return false;
- }
- const filesize = file.files[0].size;
- if (filesize > 30 * 1024 * 1024) {
- toastr.error('文件大小过大!');
- return false;
- }
- const fileext = '.' + file.files[0].name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('只能上传指定格式的附件!');
- return false;
- }
- const formData = new FormData();
- formData.append('cid', $('#changeId').val());
- formData.append('tid', $('#tenderId').val());
- formData.append('size', filesize);
- formData.append('file', file.files[0]);
- postDataWithFile('/change/upload/file', formData, function (data) {
- $('#addfujian').modal('hide');
- console.log(data);
- const fileInfo = data;
- let index = $('#attList tr').length;
- let html = '<tr> ' +
- '<td>' + (index+1) + '</td> ' +
- '<td><a href="/change/download/file/' + fileInfo.id + '">' + fileInfo.filename + fileInfo.fileext + '</a></td> ' +
- '<td>' + fileInfo.filesize + '</td> ' +
- '<td>' + fileInfo.in_time + '</td> ' +
- '<td> <a class="btn btn-light btn-sm delete-file" data-attid="' + fileInfo.id + '" title="删除附件"><span class="fa fa-trash text-danger"></span></a> </td> ' +
- '</tr>';
- $('#attList').append(html);
- }, function () {
- });
- $('#upload-file').val('');
- });
- $('body').on('click', '.delete-file', function () {
- let attid = $(this).data('attid');
- console.log(attid);
- let self = $(this);
- const data = {id: attid};
- postData('/change/delete/file', data, function (result) {
- self.parents('tr').remove();
- // 重新排序
- let newsort = 1;
- $('#attList tr').each(function(){
- $(this).children('td').eq(0).text(newsort);
- newsort++;
- });
- });
- })
- });
|