importDialog.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <el-dialog title="参数导入"
  3. :visible.sync="importFormVisible"
  4. custom-class="flow-design-dialog"
  5. append-to-body
  6. destroy-on-close>
  7. <el-form :label-position="left" label-width="80px" :model="formLabelAlign">
  8. <el-form-item label="模板上传:">
  9. <!-- <el-input v-model="formLabelAlign.name"></el-input> -->
  10. <el-upload
  11. :auto-upload="false"
  12. ref="file3"
  13. class="upload-demo"
  14. action="#"
  15. accept=".xls,.xlsx"
  16. :on-preview="handlePreview"
  17. :on-remove="handleRemove"
  18. :before-remove="beforeRemove"
  19. :on-change="uploadImportData"
  20. :on-exceed="handleExceed"
  21. :limit="1"
  22. :file-list="fileList">
  23. <el-button size="small" type="primary">点击上传</el-button>
  24. <div slot="tip" class="el-upload__tip">只能上传.xls,.xlsx文件</div>
  25. </el-upload>
  26. </el-form-item>
  27. <el-form-item label="数据覆盖:" label-width="90px"
  28. :rules="[
  29. { required: true, message: '请选择数据是否覆盖', trigger: 'blur' },
  30. ]"
  31. >
  32. <el-switch
  33. v-model="formLabelAlign.isCovered"
  34. active-text="是"
  35. active-color="#13ce66"
  36. inactive-color="#ff4949"
  37. inactive-text="否"
  38. active-value="1"
  39. inactive-value="0"
  40. >
  41. </el-switch>
  42. </el-form-item>
  43. <el-form-item label="模板下载">
  44. <!-- <el-input v-model="formLabelAlign.type"></el-input> -->
  45. <el-button
  46. @click="downloadExcel()"
  47. type="primary"
  48. size="mini">点击下载
  49. </el-button>
  50. </el-form-item>
  51. </el-form>
  52. <div slot="footer" class="dialog-footer">
  53. <el-button @click="importFormVisible = false">取 消</el-button>
  54. <el-button type="primary" @click="importSubmit ">确 定</el-button>
  55. </div>
  56. </el-dialog>
  57. </template>
  58. <script>
  59. import {importParam} from "@/api/tentative/testpram";
  60. import {importTemperaturetParam} from "@/api/tentative/testtempreature";
  61. export default {
  62. props:{
  63. importDialogType:Number,
  64. temonLoad:Function,
  65. paramLoad:Function
  66. },
  67. data(){
  68. return{
  69. importFormVisible:false,
  70. formLabelAlign: {//表格数据
  71. name: '',
  72. region: '',
  73. type: '',
  74. isCovered:"1",
  75. },
  76. //文件上传
  77. fileList: [],
  78. formData:{}
  79. }
  80. },
  81. methods:{
  82. show(){
  83. this.importFormVisible=true;
  84. this.fileList=[]
  85. },
  86. handleExceed(files, fileList) {
  87. this.$message.warning(`当前限制选择 1个文件,请删除原文件后再选择文件上传`);
  88. },
  89. beforeRemove(file, fileList) {
  90. return this.$confirm(`确定移除 ${ file.name }?`);
  91. },
  92. uploadImportData(file){
  93. console.log(this.fileList,'fileList');
  94. console.log(file,'file');
  95. let formData = new FormData()
  96. formData.append('file', file.raw);
  97. let pictureList =[]
  98. pictureList.push(file.name)
  99. this.fileList=pictureList.map(item=>{
  100. return {
  101. name: item,
  102. url: item,
  103. raw:file.raw
  104. }
  105. })
  106. },
  107. downloadExcel () {//下载excel表
  108. console.log('下载');
  109. const link = document.createElement('a')
  110. // downExcelFile(this.from.id).then((res)=>{
  111. // // 创建Blob对象,设置文件类型
  112. // let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
  113. // let objectUrl = URL.createObjectURL(blob) // 创建URL
  114. // link.href = objectUrl
  115. // link.download = this.from.extension // 自定义文件名
  116. // link.click() // 下载文件
  117. // URL.revokeObjectURL(objectUrl); // 释放内存
  118. // })
  119. },
  120. //确定导入
  121. importSubmit(){
  122. if(this.fileList.length>0){
  123. const loading = this.$loading({
  124. lock: true,
  125. text: 'Loading',
  126. spinner: 'el-icon-loading',
  127. background: 'rgba(0, 0, 0, 0.7)'
  128. });
  129. let formData = new FormData()
  130. formData.append('file', this.fileList[0].raw);
  131. formData.append('isCovered', this.formLabelAlign.isCovered);
  132. if(this.importDialogType===1){
  133. importParam(formData).then(() => {
  134. this.$message({
  135. message: '上传文件成功',
  136. type: 'success'
  137. })
  138. loading.close();
  139. this.importFormVisible=false;
  140. this.temonLoad();
  141. }).catch(() => {
  142. loading.close();
  143. });
  144. }else{
  145. importTemperaturetParam(formData).then(() => {
  146. this.$message({
  147. message: '上传文件成功',
  148. type: 'success'
  149. })
  150. loading.close();
  151. this.importFormVisible=false;
  152. this.paramLoad();
  153. }).catch(() => {
  154. loading.close();
  155. })
  156. }
  157. }else{
  158. // console.log('上次文件');
  159. this.$message.warning('请上传模板')
  160. }
  161. this.$refs.file3.clearFiles();
  162. },
  163. }
  164. }
  165. </script>
  166. <style>
  167. </style>