Files
number_zj/20220313_Excel/TempTask.WebEntry/Views/Home/Index.cshtml
2022-03-14 00:29:01 +08:00

123 lines
5.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="http://lib.baomitu.com/qs/6.10.3/qs.min.js"></script>
</head>
<body>
<div id="app">
<div>
<el-input-number v-model="year" :min="1970" :max="2100" label="选择年"></el-input-number>年
<el-input-number v-model="month" :min="1" :max="12" label="选择月"></el-input-number>月 第
<el-input-number v-model="week" :min="1" :max="5" label="选择周"></el-input-number>周
</div>
<div style="margin-top:15px;">
<el-button @@click="downloadfile_zongbiao" :loading="loading_zongbiao">下载文件-总表</el-button>
<el-button @@click="downloadfile_chengshigengxin" :loading="loading_chengshigengxin">下载文件-城市更新</el-button>
<el-button @@click="downloadfile_fangdichan" :loading="loading_fangdichan">下载文件-房地产业</el-button>
</div>
</div>
</body>
<script>
new Vue({
el: '#app',
data: function () {
return {
loading_zongbiao: false,
loading_chengshigengxin: false,
loading_fangdichan: false,
year: '',
month: '',
week: ''
}
},
created: function () {
var now = new Date();
this.year = now.getFullYear();
this.month = now.getMonth() + 1;
this.week = this.getMonthWeek(now);
},
methods: {
//总表
loading_zongbiao_false() { this.loading_zongbiao = false },
downloadfile_zongbiao() {
this.loading_zongbiao = true;
let url = '/api/num-zj/download';
this.download(url, 1, "总表.xlsx", this.loading_zongbiao_false);
},
//城市更新
loading_chengshigengxin_false() { this.loading_chengshigengxin = false },
downloadfile_chengshigengxin() {
this.loading_chengshigengxin = true;
let url = '/api/num-zj/download';
this.download(url, 2, "住建系统抓投资情况通报(城市更新).xlsx", this.loading_chengshigengxin_false);
},
//房地产业
loading_fangdichan_false() { this.loading_fangdichan = false },
downloadfile_fangdichan() {
this.loading_fangdichan = true;
let url = '/api/num-zj/download';
this.download(url, 3, "住建系统抓投资情况通报(房地产业+GDP支撑性指标.xlsx", this.loading_fangdichan_false);
},
download(url, type, filename, callback) {
let _this = this;
axios({
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
method: 'post',
url: url,
data: { type: type, year: _this.year, month: _this.month, week: _this.week },
responseType: "blob",
}).then(function (response) {
console.log(response);
//解析文件充blod中解析
const url = window.URL.createObjectURL(
new Blob([response.data], { type: "application/vnd.ms-excel" })
);
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.setAttribute("download", filename);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
callback();
}).catch(function (error) {
callback();
console.log(error)
_this.$message({
type: 'error',
message: error.message
})
})
},
getMonthWeek(now) {
var a = now.getYear();
var b = now.getMonth() + 1;
var c = now.getDate();
/*
a = d = 当前日期
b = 6 - w = 当前周的还有几天过完(不算今天)
a + b 的和在除以7 就是当天是当前月份的第几周
*/
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math.ceil(
(d + 6 - w) / 7
);
}
}
})
</script>
</html>