af75fae02dcb3d9fa8585a5f8c59bf298569f1f8.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <el-dialog class="customs_dialog" :visible.sync="dialogVisible" :before-close="handleClose" title="特定飞检批量填报">
  3. <div class="upload_div">
  4. <el-upload
  5. ref="upload"
  6. class="upload-demo"
  7. drag
  8. action="/pdcApi/bis/insp/fsc/pblm/uploadTemplate"
  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. :file-list="fileList">
  18. <i class="el-icon-upload"></i>
  19. <div class="el-upload__text">将模板文件拖到此处,或<em>点击选取模板文件</em></div>
  20. </el-upload>
  21. </div>
  22. <div ref="messageDiv" id="messageDiv" style="width: 100%;margin-top: 10px">
  23. </div>
  24. <!-- 验证数据的弹出框 -->
  25. <!--<shuiKuTianbaoPlVer v-if="showShuiKuTianBaoPlVer"-->
  26. <!--@closePlVerDialog="closePlVerDialog"-->
  27. <!--:tableData="tableData"-->
  28. <!--:uuid="uuid"-->
  29. <!--:id='id'-->
  30. <!--&gt;</shuiKuTianbaoPlVer>-->
  31. <!--<a type="primary" @click="openPlVerDialog" href="javascript:void(0)" v-show="showButton">点击弹框</a>-->
  32. <span slot="footer" class="dialog-footer">
  33. <el-button @click="handleClose">取 消</el-button>
  34. <el-button type="primary" @click="submitUpload" :loading="uploadLoading" >点击上传</el-button>
  35. </span>
  36. </el-dialog>
  37. </template>
  38. <script>
  39. import request from '../../utils/gw_ajax_request.js'
  40. // import shuiKuTianbaoPlVer from './shuiKuTianbao_piliang_verify'
  41. export default {
  42. props: ['showShuiKuTianBaoPl','id'],
  43. components: {
  44. // shuiKuTianbaoPlVer:shuiKuTianbaoPlVer,
  45. },
  46. data(){
  47. return{
  48. dialogVisible:true,
  49. fileList:[],
  50. uuid:1,
  51. actionUrl:'',
  52. socket:null,
  53. showShuiKuTianBaoPlVer:false,
  54. filePath:'',
  55. tableData:[],
  56. showButton:false,
  57. uploadLoading: false,
  58. }
  59. },
  60. mounted:function(){
  61. },
  62. computed: {
  63. persId() {
  64. return localStorage.getItem("userid")
  65. ? localStorage.getItem("userid")
  66. : "1098101939614724096";
  67. }
  68. },
  69. methods:{
  70. handleClose(done) {
  71. // this.closeSocket();
  72. // this.$parent.getSkDataList();
  73. this.$emit("closePlDialog");
  74. },
  75. handleRemove(file, fileList) {
  76. console.log(file, fileList);
  77. },
  78. handlePreview(file) {
  79. console.log(file);
  80. },
  81. handleExceed(files, fileList) {
  82. this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  83. },
  84. beforeRemove(file, fileList) {
  85. //return this.$confirm(`确定移除 ${ file.name }?`);
  86. },
  87. beforeAvatarUpload(file) {
  88. let Xls = file.name.split('.');
  89. if(Xls[1] === 'xls' || Xls[1] === 'xlsx'){
  90. return file;
  91. }else {
  92. this.$message.error('请上传编辑后的模板文件!');
  93. return false;
  94. }
  95. },
  96. handleSuccess(res,file,fileList){
  97. let filePath = res.data.key;
  98. this.filePath = filePath;
  99. // 调用解析的接口
  100. // request.get(`/dc/impExcel/parseExcel/${this.persId}/${this.uuid}?filePath=${this.filePath}&tid=08&pid=${this.id}`).then(res => {
  101. //
  102. // this.tableData = res.data;
  103. // console.log("table:" + this.tableData)
  104. //
  105. // if(this.tableData.length > 0){
  106. // this.showButton = true;
  107. // this.showShuiKuTianBaoPlVer = true;
  108. // }else{
  109. // this.$alert('可填报数据条数为0或非本组数据,请确认!', '提示', {
  110. // confirmButtonText: '确定',
  111. // type: 'warning',
  112. // callback: action => {
  113. //
  114. // }
  115. // });
  116. // }
  117. // // 只展示错误数据的逻辑
  118. // // if(this.tableData[0].Message == undefined){
  119. // // this.showButton = true;
  120. // // this.showShuiKuTianBaoPlVer = true;
  121. // // }else{
  122. // // var message = this.tableData[0].Message;
  123. // // if(message == 'success'){
  124. // // this.showButton = true;
  125. // // this.showShuiKuTianBaoPlVer = true;
  126. // // }else {
  127. // // this.$alert('可填报数据条数为0或非本组数据,请确认!', '提示', {
  128. // // confirmButtonText: '确定',
  129. // // type: 'warning',
  130. // // callback: action => {
  131. //
  132. // // }
  133. // // });
  134. // // }
  135. // // }
  136. //
  137. // this.uploadLoading = false;
  138. // });
  139. },
  140. openSocket() {
  141. if (typeof(WebSocket) == "undefined") {
  142. console.log("您的浏览器不支持WebSocket");
  143. } else {
  144. this.closeSocket();
  145. console.log("您的浏览器支持WebSocket");
  146. console.log("sid:" + this.uuid);
  147. //实例化WebSocket对象,指定要连接的服务器地址与端口 建立连接
  148. // let baseUrl = "localhost:8101";
  149. // 测试服务器
  150. let baseUrl = "10.1.102.136:8100";
  151. // let baseUrl = "sv.goldenwater.com.cn";
  152. // let baseUrl = "localhost:8085/wsbackend";
  153. this.socket = new WebSocket(`ws://${baseUrl}/websocket/${this.uuid}`);
  154. // socket
  155. let socket = this.socket;
  156. //打开事件
  157. socket.onopen = function () {
  158. console.log("Socket 已打开");
  159. //socket.send("这是来自客户端的消息" + location.href + new Date());
  160. };
  161. //获得消息事件
  162. socket.onmessage = function (msg) {
  163. console.log(msg.data);
  164. document.getElementById('messageDiv').innerHTML = document.getElementById('messageDiv').innerHTML
  165. + msg.data + "<br/>"
  166. //发现消息进入 开始处理前端触发逻辑
  167. if(msg.data.indexOf('完成数据校验') > 0){
  168. }
  169. };
  170. //关闭事件
  171. socket.onclose = function () {
  172. console.log("Socket已关闭");
  173. };
  174. //发生了错误事件
  175. socket.onerror = function () {
  176. console.log("Socket发生了错误");
  177. //此时可以尝试刷新页面
  178. };
  179. // 路由跳转时结束websocket链接
  180. this.$router.afterEach(function () {
  181. socket.close()
  182. })
  183. }
  184. },
  185. // getUUID (){
  186. // request.get('/socket/uuid').then(res => {
  187. // if(res.success){
  188. // this.uuid = res.data.key;
  189. // this.actionUrl = `/pdcApi/dc/impExcel/imp/${this.persId}/${this.uuid}?tid=08`;
  190. // }else {
  191. // console.log("success不为true")
  192. // }
  193. // });
  194. // },
  195. closeSocket() {
  196. if (this.socket != null) {
  197. this.socket.close();
  198. }
  199. },
  200. submitUpload() {
  201. let filePath = this.filePath;
  202. if(filePath){
  203. this.uploadLoading = true;
  204. request.post(`/bis/insp/fsc/pblm/parseUpload?path=${filePath}&startRow=1`).then(res =>{
  205. if(res.success){
  206. this.uploadLoading = false;
  207. request.post(`/bis/insp/fsc/pblm/insertIntoData?dataId=${res.data.dataId}`).then(res1 =>{
  208. if(res1.success){
  209. this.$message.success('上传成功');
  210. this.$emit('uploadSuccess');
  211. }else{
  212. this.$message.warning(res1.message);
  213. }
  214. })
  215. }
  216. })
  217. }else{
  218. this.$message.warning('请选择要上传的文件模板');
  219. }
  220. },
  221. closePlVerDialog(){
  222. this.showShuiKuTianBaoPlVer = false;
  223. },
  224. openPlVerDialog(){
  225. this.showShuiKuTianBaoPlVer = true;
  226. }
  227. },
  228. watch:{
  229. showShuiKuTianBaoPl(n,o){
  230. // 想用监听得使用v-show,因为v-if会重新渲染DOM,子组件已关闭
  231. // alert("进入监听")
  232. // if(!n){
  233. // alert(this.showShuiKuTianBaoPl)
  234. // this.closeSocket();
  235. // }
  236. },
  237. },
  238. }
  239. </script>
  240. <style>
  241. .title{
  242. font-size: 16px;
  243. }
  244. .el-icon-edit{
  245. margin-right: 10px;
  246. }
  247. .customs_dialog .el-dialog{
  248. width: 40% !important;
  249. }
  250. .customs_dialog .el-dialog__body {
  251. padding: 30px 20px;
  252. color: #606266;
  253. font-size: 14px;
  254. height: 60vh;
  255. overflow: auto;
  256. }
  257. .upload_div {
  258. text-align: center;
  259. }
  260. .upload_div_left {
  261. border:1px solid red;
  262. width:50%;
  263. height:100px;
  264. float:left;
  265. }
  266. .upload_div_right {
  267. border:1px solid red;
  268. width:50%;
  269. height:100%;
  270. float:right;
  271. }
  272. </style>