liuhj 4 months ago
parent
commit
4b5d69b692
1 changed files with 177 additions and 8 deletions
  1. 177 8
      src/components/Resource/InvitationOfficialActivityData.vue

+ 177 - 8
src/components/Resource/InvitationOfficialActivityData.vue

@@ -1,8 +1,37 @@
 <template>
     <div>
         <div class="communal-list">
+            <!-- 上传个税 -->
+            <el-dialog title="导入" width="400px" :visible.sync="UploadTaxes">
+                <div>
+                    <el-upload drag
+                         :limit=limitNum
+                         :auto-upload="false"
+                         accept=".xlsx,.xls"
+                         :action="UploadUrl()"
+                         :before-upload="beforeUploadFile"
+                         :on-change="fileChange"
+                         :on-exceed="exceedFile"
+                         :on-success="handleSuccess"
+                         :on-error="handleError"
+                         :on-remove="removelist"
+                         :file-list="fileList">
+                      <i class="el-icon-upload"></i>
+                      <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
+                      <div class="el-upload__tip" slot="tip">只能上传xlsx文件,且不超过10M</div>
+                    </el-upload>
+                    <br/>
+                    <el-button size="small" type="primary" @click="uploadFile('TaxesData')">立即上传</el-button>
+                    <el-button size="small">取消</el-button>
+                </div>
+            </el-dialog>
             <div class="communal-title">
                 <div>邀请/公务活动资料</div>
+                <div class="toleadinto-box">
+                    <el-button @click="TemplateDownload" type="primary">模板下载</el-button>
+                    <el-button @click="InvitationOfficialActivityExcelExport" type="primary">导出</el-button>
+                    <el-button @click="UploadTaxes=true" type="primary">导入</el-button>
+                </div>
             </div>
             <div>
                 <div class="communal-box" style="margin-top: 10px;">
@@ -201,6 +230,9 @@ export default {
                     }
                 }]
             },
+            UploadTaxes:false,
+            limitNum: 1,  // 上传excell时,同时允许上传的最大数
+            fileList: [],   // excel文件列表
         }
     },
     beforeRouteLeave(to,from,next) {
@@ -277,6 +309,148 @@ export default {
             // 调用 callback 返回建议列表的数据
             cb(results);
         },
+        //模版下载
+        TemplateDownload(){
+            var url = "/api/Resource/InvitationOfficialActivityExcelTemplateExport"
+            var that = this
+            this.$axios({
+                method: 'get',
+                url: url,
+                headers: {
+                    Authorization: 'Bearer ' + that.token
+                }
+            }).then(function (res) {
+                if (res.data.code == 200) {
+                    that.$message({
+                        message:res.data.msg,
+                        type: 'success'
+                    });
+                    window.open(res.data.data);
+                }else{
+                    that.$message.error(res.data.msg);
+                }
+            }).catch(function (error) {
+                that.$message.error(error);
+            });
+        },
+        //导出
+        InvitationOfficialActivityExcelExport(){
+            var CreateUser = 0;
+            if (this.CreateUserId == "" || this.CreateUserId == undefined || this.CreateUserId == null) {
+                CreateUser = 0
+            } else {
+                CreateUser = this.CreateUserId
+            }
+            var url = "/api/Resource/InvitationOfficialActivityExcelExport"
+            var that = this
+            this.$axios({
+                method: 'post',
+                url: url,
+                headers: {
+                    Authorization: 'Bearer ' + this.token
+                },
+                data: {
+                    portType: 1,
+                    pageIndex: that.currentPage,
+                    pageSize: that.pageSize,
+                    country: that.Country,
+                    unitName: that.UnitName,
+                    contact: that.Contact,
+                    delegation: that.Delegation.toString(),
+                    field: that.Field,
+                    createUserId: CreateUser,
+                    startCreateTime: that.StartCreateTime,
+                    endCreateTime: that.EndCreateTime
+                }
+            }).then(function (res) {
+                if (res.data.code == 200) {
+                    that.$message({
+                        message:res.data.msg,
+                        type: 'success'
+                    });
+                    window.open(res.data.data)
+                } else {
+                    that.$message.error(res.data.msg);
+                }
+            }).catch(function (error) {
+                that.$message.error(error);
+            });
+        },
+        //导入
+        uploadFile(){
+            if (this.fileList.length === 0) {
+                this.$message.warning('请上传文件');
+            } else {
+                var form = new FormData();
+                form.append('file', this.fileList[0]);
+                //form.append('currUserId', this.userId);
+                var that = this
+                this.$axios({
+                    method: "post",
+                    url: "/api/Resource/InvitationOfficialActivityExcelUpload?currUserId=" + this.userId,
+                    headers: {
+                        'Content-type': 'multipart/form-data',
+                        Authorization: 'Bearer ' + that.token,
+                    },
+                    data: form
+                }).then(function (res) {
+                    if (res.data.code == 200) {
+                        that.UploadTaxes = false;
+                        that.$message({
+                            message: res.data.msg,
+                            type: 'success'
+                        });
+                        that.QueryInvitationOfficialActivityData(); 
+                    } else {
+                        that.$message({
+                            message: '上传失败!原因:' + res.data.msg,
+                            type: 'warning'
+                        });
+                    }
+                }).catch(()=>{
+                    that.$message({
+                        message: '上传失败!请联系信息部',
+                        type: 'warning'
+                    });
+                })
+            }
+        },
+        UploadUrl:function(){
+        // 因为action参数是必填项,我们使用二次确认进行文件上传时,直接填上传文件的url会因为没有参数导致api报404,所以这里将action设置为一个返回为空的方法就行,避免抛错
+            return ""
+        },
+        // 上传文件之前的钩子, 参数为上传的文件,若返回 false 或者返回 Promise 且被 reject,则停止上传
+        beforeUploadFile(file) {
+            console.log('before upload');
+            console.log(file);
+            let extension = file.name.substring(file.name.lastIndexOf('.')+1);
+            let size = file.size / 1024 / 1024;
+            if(extension !== 'xlsx') {
+            this.$message.warning('只能上传后缀是.xlsx的文件');
+            }
+            if(size > 10) {
+            this.$message.warning('文件大小不得超过10M');
+            }
+        },
+        // 文件状态改变时的钩子
+        fileChange(file, fileList) {
+            this.fileList.push(file.raw) ;
+        },
+        // 文件超出个数限制时的钩子
+        exceedFile(files, fileList) {
+            this.$message.warning(`只能选择 ${this.limitNum} 个文件,当前共选择了 ${files.length + fileList.length} 个`);
+        },
+         // 文件上传成功时的钩子
+         handleSuccess(res, file, fileList) {
+            this.$message.success('文件上传成功');
+        },
+        // 文件上传失败时的钩子
+        handleError(err, file, fileList) {
+            this.$message.error('文件上传失败');
+        },
+        removelist(file, fileList){
+            this.fileList=[]
+        },
         //领域搜索框处理
         querySearchField(queryString, cb) {
             var arr = this.restaurantField;
@@ -373,7 +547,6 @@ export default {
             });
         },
         QueryInvitationOfficialActivityData() {
-            console.log(this.Delegation)
             var CreateUser = 0;
             if (this.CreateUserId == "" || this.CreateUserId == undefined || this.CreateUserId == null) {
                 CreateUser = 0
@@ -489,23 +662,19 @@ export default {
                 cancelButtonText: '取消',
                 type: 'warning'
             }).then(() => {
-                var url = "/api/Resource/DelInvitationOfficialActivity"
                 var that = this
                 this.$axios({
                     method: 'post',
-                    url: url,
+                    url: "/api/Resource/DelInvitationOfficialActivity",
                     headers: {
-                        Authorization: 'Bearer ' + this.token
+                        Authorization: 'Bearer ' + that.token
                     },
                     data: {
                         Id: row.id,
-                        DeleteUserId: this.userId
+                        DeleteUserId: that.userId
                     }
                 }).then(function (res) {
-                    console.log(res)
-
                     if (res.data.code == 200) {
-
                         that.$message({
                             message: '删除成功',
                             type: 'success'