ImportMobiel.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <el-dialog
  3. :title="modalTitle"
  4. :visible.sync="modalVisible"
  5. :width="formLabelWidth"
  6. top="2vh"
  7. @close="handleCancel">
  8. <div class="userMobile">
  9. <el-steps :active="3" simple>
  10. <el-step title="下载模板文件" icon="el-icon-edit"></el-step>
  11. <el-step title="按格式填写数据" icon="el-icon-upload"></el-step>
  12. <el-step title="上传模版" icon="el-icon-picture"></el-step>
  13. </el-steps>
  14. <div class="uploadfile">
  15. <div class="downloadFile">
  16. 模版文件: <a href="/htdata/areaData/downloadTemplate">点击下载</a>
  17. </div>
  18. <div class="upload">
  19. <span class="title">文件上传:</span>
  20. <el-upload
  21. class="upload-ele"
  22. ref="upload"
  23. :action="importFileUrl"
  24. :on-remove="handleRemove"
  25. :on-change="handleChange"
  26. :on-success="handleSuccess"
  27. :file-list="fileList"
  28. accept=".xlsx,.xls"
  29. :headers = "headers"
  30. :on-exceed="onExceed"
  31. :limit="1"
  32. :multiple="false"
  33. :auto-upload="false">
  34. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  35. <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">开始上传</el-button>
  36. <div slot="tip" class="el-upload__tip">注意: <span style="color:red">只能上传xlsx/xks文件</span></div>
  37. </el-upload>
  38. </div>
  39. </div>
  40. </div>
  41. <div slot="footer" class="dialog-footer">
  42. <el-button @click="handleCancel">取 消</el-button>
  43. </div>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import {globalReg,uploadFileAreaUrl} from '@/api/CONST'
  48. export default {
  49. name: 'userMobiel',
  50. props: {
  51. visible: {
  52. type: Boolean,
  53. default: false
  54. },
  55. title: {
  56. type: String,
  57. default: 'title'
  58. },
  59. },
  60. watch: {
  61. visible(newVal, oldVal) {
  62. this.modalVisible = newVal;
  63. },
  64. title(newVal, oldVal) {
  65. this.modalTitle = newVal;
  66. },
  67. },
  68. data() {
  69. return {
  70. modalTitle: this.title,
  71. modalVisible: this.visible,
  72. modalAction: this.action,
  73. modalSelectRow:this.selectRow,
  74. formLabelWidth: '920px',
  75. importFileUrl:uploadFileAreaUrl,
  76. headers: {
  77. accessToken:''
  78. },
  79. fileList: []
  80. };
  81. },
  82. created() {
  83. this.headers.accessToken = this.getAccessToken
  84. },
  85. methods: {
  86. submitUpload() {
  87. this.$refs.upload.submit();
  88. },
  89. handleRemove(file, fileList) {
  90. },
  91. handleChange(file){
  92. },
  93. onExceed(){
  94. this.$message({
  95. message: '当前限制选择 1 个文件,请删除后继续上传!',
  96. type: 'warning'
  97. });
  98. },
  99. handleSuccess(response, file, fileList){
  100. console.log(response,file,fileList)
  101. console.log(response.retHead.errCode)
  102. if(response.retHead.errCode === 0){
  103. this.$message({
  104. message: '文件上传成功!',
  105. type: 'success'
  106. });
  107. this.handleCancel()
  108. this.$emit('closeModal',true)
  109. }else{
  110. this.$message.error('数据上传出错,请检查环境!');
  111. }
  112. },
  113. handleCancel() {
  114. this.$emit('closeModal', false);
  115. }
  116. },
  117. computed:{
  118. getAccessToken(){
  119. return this.$store.state.accessToken
  120. }
  121. }
  122. };
  123. </script>
  124. <style scoped lang="less">
  125. .uploadfile{
  126. padding:15px 0;
  127. }
  128. .downloadFile,
  129. .upload{
  130. border-bottom:1px solid #EBEEF5;
  131. }
  132. .downloadFile{
  133. height:40px;
  134. line-height:40px;
  135. font-weight:bold;
  136. }
  137. .downloadFile a{
  138. margin-left:10px;
  139. }
  140. .upload{
  141. padding:20px 0;
  142. overflow:hidden;
  143. }
  144. .upload .title{
  145. display:block;
  146. font-weight:bold;
  147. margin-top:5px;
  148. margin-bottom:15px;
  149. float:left;
  150. }
  151. .upload-ele{
  152. padding-left:70px;
  153. }
  154. </style>