11fde8934e8d2bb6a97bb2c5ec446631098a666e.svn-base 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <el-dialog class="customs_dialog" :visible.sync="dialogVisible" :before-close="handleClose" :title="dialogTitle">
  3. <div class="upload_div">
  4. <el-upload
  5. ref="upload"
  6. class="upload-demo"
  7. drag
  8. :action="actionUrl"
  9. :on-preview="handlePreview"
  10. :on-remove="handleRemove"
  11. :before-remove="beforeRemove"
  12. :before-upload="beforeAvatarUpload"
  13. :on-success="handleSuccess"
  14. multiple
  15. :limit="1"
  16. :on-exceed="handleExceed"
  17. :auto-upload="false"
  18. :file-list="fileList">
  19. <i class="el-icon-upload"></i>
  20. <div class="el-upload__text">将模板文件拖到此处,或<em>点击选取模板文件</em></div>
  21. </el-upload>
  22. <el-button type="primary" @click="submitUpload" :loading="uploadLoading" >点击上传</el-button>
  23. </div>
  24. <div ref="messageDiv" id="messageDiv" style="width: 100%;margin-top: 10px">
  25. </div>
  26. <!-- 验证数据的弹出框 -->
  27. <shuiKuTianbaoPlVer v-if="showShuiKuTianBaoPlVer"
  28. @closePlVerDialog="closePlVerDialog"
  29. :tableData="tableData"
  30. :uuid="uuid"
  31. :id='id'
  32. ></shuiKuTianbaoPlVer>
  33. <a type="primary" @click="openPlVerDialog" href="javascript:void(0)" v-show="showButton">点击弹框</a>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import request from '@util/gw_ajax_request.js'
  38. import shuiKuTianbaoPlVer from './shuiKuTianbao_piliang_verify'
  39. export default {
  40. props: ['showtianBaoPiLiangCom','id','preUrl','dialogTitle'],
  41. components: {
  42. shuiKuTianbaoPlVer:shuiKuTianbaoPlVer,
  43. },
  44. data(){
  45. return{
  46. dialogVisible:true,
  47. fileList:[],
  48. uuid:1,
  49. socket:null,
  50. showShuiKuTianBaoPlVer:false,
  51. filePath:'',
  52. tableData:[],
  53. showButton:false,
  54. uploadLoading: false,
  55. }
  56. },
  57. mounted(){
  58. },
  59. computed: {
  60. persId() {
  61. return localStorage.getItem("userid")
  62. ? localStorage.getItem("userid")
  63. : "1098101939614724096";
  64. },
  65. baseUrl() {
  66. return window.location.href.indexOf('localhost') > -1 || window.location.href.indexOf("10.1.102.136") > -1 ? '10.1.102.136:8100' : `${window.location.host}/api`
  67. },
  68. actionUrl(){
  69. console.log(this.preUrl)
  70. return '/api' + this.preUrl + '/uploadTemplate'
  71. }
  72. },
  73. methods:{
  74. handleClose(done) {
  75. this.$parent.getDfDataList();
  76. this.$emit("closePlDialog");
  77. },
  78. handleRemove(file, fileList) {
  79. console.log(file, fileList);
  80. },
  81. handlePreview(file) {
  82. console.log(file);
  83. },
  84. handleExceed(files, fileList) {
  85. this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  86. },
  87. beforeRemove(file, fileList) {
  88. //return this.$confirm(`确定移除 ${ file.name }?`);
  89. },
  90. beforeAvatarUpload(file) {
  91. let Xls = file.name.split('.');
  92. if(Xls[1] === 'xls'){
  93. return file;
  94. }else {
  95. this.$message.error('请上传编辑后的模板文件!')
  96. return false;
  97. }
  98. },
  99. handleSuccess(res,file,fileList){
  100. let filePath = res.data.key;
  101. this.filePath = filePath;
  102. // 调用解析的接口
  103. request.post(`${this.preUrl}/parseUpload?path=${this.filePath}&startRow=2`).then(res => {
  104. request.post(`${this.preUrl}/insertIntoData?dataId=${res.data.dataId}&persId=${this.persId}&groupId=${this.id}`).then(res => {
  105. this.$message.success('批量填报成功')
  106. this.uploadLoading = false;
  107. this.$emit("closePlDialog");
  108. })
  109. });
  110. },
  111. submitUpload() {
  112. this.uploadLoading = true;
  113. this.$refs.upload.submit();
  114. },
  115. closePlVerDialog(){
  116. this.showShuiKuTianBaoPlVer = false;
  117. },
  118. openPlVerDialog(){
  119. this.showShuiKuTianBaoPlVer = true;
  120. }
  121. },
  122. watch:{
  123. showShuiKuTianBaoPl(n,o){
  124. // 想用监听得使用v-show,因为v-if会重新渲染DOM,子组件已关闭
  125. // alert("进入监听")
  126. // if(!n){
  127. // alert(this.showShuiKuTianBaoPl)
  128. // this.closeSocket();
  129. // }
  130. },
  131. },
  132. }
  133. </script>
  134. <style>
  135. .title{
  136. font-size: 16px;
  137. }
  138. .customs_dialog .el-icon-edit{
  139. margin-right: 10px;
  140. }
  141. .customs_dialog .el-dialog{
  142. width: 40% !important;
  143. }
  144. .customs_dialog .el-dialog__body {
  145. padding: 30px 20px;
  146. color: #606266;
  147. font-size: 14px;
  148. height: 60vh;
  149. overflow: auto;
  150. }
  151. .upload_div {
  152. text-align: center;
  153. }
  154. .upload_div_left {
  155. border:1px solid red;
  156. width:50%;
  157. height:100px;
  158. float:left;
  159. }
  160. .upload_div_right {
  161. border:1px solid red;
  162. width:50%;
  163. height:100%;
  164. float:right;
  165. }
  166. </style>