<div id="uploadOrDownloadBillWin" class="modal fade" tabindex="-1" data-width="500" data-backdrop="static">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">下载模板/导入账单</h4>
</div>
<div class="modal-body form">
<form class="form-horizontal" role="form">
<div class="form-body">
<h5 class="block"> 第一步: 请按EXCEL格式填写数据 </h5>
<a href="javascript:;" target="_bank" download="bill-template.pdf" class="filter-down-excel">
<i class="fa fa-download"></i> 下载EXCEL模板
</a>
<h5 class="block"> 第二步: 请上传附件以验证数据格式是否正确 </h5>
<div id="filter-updown-excel">
<a class="dt-button btn blue dropdown-toggle upload-excel" title="上传账单模板并验证">
<i class="fa fa-upload"></i> 上传账单模板并验证
</a>
</div>
<h5 class="block">第三步: 确认以上导入账单信息</h5>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-outline dark">关闭</button>
</div>
</div>
/**
* 初始化上传下载
*/
function initUploadBill() {
$('.filter-down-excel', '#uploadOrDownloadBillWin').unbind('').bind('click', function() {
// 下载模板
// window.open(OSS.APISERVER.SHAREBILL + '/rest/bill/model/' + OssUtil.getApiToken() + '/download');
$(this).attr('href', OSS.APISERVER.SHAREBILL + '/rest/bill/model/' + OssUtil.getApiToken() + '/download');
});
// 上传
var templateUploader = WebUploader.create({
pick: '#filter-updown-excel',
auto: true,
swf: '/assets/global/plugins/webuploader-0.1.5/Uploader.swf',
server: OSS.APISERVER.FILE + '/rest/media/upload/' + OssUtil.getApiToken(),
method: 'POST',
fileVal: 'uploadExcel',
accept: {
title: 'Excel',
extensions: 'xls,xlsx,xlsm',
mimeTypes: 'application/vnd.ms-excel,application/x-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.xls,.xlsx'
},
});
templateUploader.on('fileQueued', function (file) {
// 重新修改token,处理token过期问题
this.options.server = OSS.APISERVER.FILE + '/rest/media/upload/' + OssUtil.getApiToken();
$('#modalAjax').modal('show');
});
templateUploader.on('uploadSuccess', function (file, response) {
$('#modalAjax').modal('hide');
if (response) {
}
templateUploader.removeFile(templateUploader.getFile(file.id));
});
templateUploader.on('uploadError', function (file, response) {
$('#modalAjax').modal('hide');
console.info(response);
OssUtil.bootboxAlert({message : '导入失败!'});
templateUploader.removeFile(templateUploader.getFile(file.id));
});
$('.upload-excel', '#filter-updown-excel').on('click', function() {
// 上传模板
$(':file', '#filter-updown-excel').click();
});
}