ImportLisRecord.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="importDisWrapper clearfix">
  3. <crumbs
  4. title="检验关联维护-导入关联"
  5. class="topBack"
  6. :param="$route.params"
  7. linkTo="Lis"
  8. ></crumbs>
  9. <div class="importDisBox">
  10. <P>
  11. 数据导入后,
  12. <span :style="{color: '#D9001B'}">将删除原有数据,替换为导入的新数据。</span>请确保导入的内容为所需的全部关联。
  13. </P>
  14. <P>建议您先下载现有全部数据,在此基础上新增或修改数据。</P>
  15. <div>
  16. <img src="../../../images/excelIcon.png">
  17. <span>检验关联数据</span>
  18. <span class="down" @click="exportData">下载</span>
  19. </div>
  20. <div class="upload">
  21. <el-input
  22. placeholder="点击上传文件"
  23. suffix-icon="el-icon-folder-opened"
  24. @click.native="uploadClick"
  25. v-model="fileName"
  26. disabled
  27. ></el-input>
  28. <div>
  29. <el-button size="small" @click="handleUpload">{{uploadInfo}}</el-button>
  30. </div>
  31. <input
  32. type="file"
  33. name="uploadfile "
  34. id="upFile"
  35. @change="uploadFile($event)"
  36. accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  37. />
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import api from '@api/icss.js';
  44. import config from '@api/config.js';
  45. import utils from '@api/utils.js';
  46. export default {
  47. data() {
  48. return {
  49. fileName: '',
  50. formData: {},
  51. headers: {},
  52. uploadInfo: '开始导入'
  53. };
  54. },
  55. created() {},
  56. methods: {
  57. // 导出现有全部数据
  58. exportData() {
  59. api
  60. .exportLisRecord()
  61. .then(res => {
  62. if (res.status === 200) {
  63. utils.downloadExportedData(res.data, '检验关联数据.xls');
  64. this.$message({ message: '下载成功', type: 'success' });
  65. }
  66. })
  67. .catch(err => {
  68. this.$message({ message: '下载失败', type: 'waring' });
  69. });
  70. },
  71. uploadClick() {
  72. let inp = document.getElementById('upFile');
  73. inp.click();
  74. },
  75. uploadFile(e) {
  76. let fileInfo = e.target.files[0];
  77. this.fileName = e.target.files[0].name; // 表单同步显示
  78. e.preventDefault();
  79. let formData = new FormData();
  80. formData.append('file', fileInfo);
  81. const header = {
  82. headers: {
  83. 'Content-Type': 'multipart/form-data'
  84. }
  85. };
  86. this.formData = formData;
  87. this.header = header;
  88. //解决上传相同文件不触发change
  89. let inp = document.getElementById('upFile');
  90. inp.value = '';
  91. },
  92. // 上传文件
  93. handleUpload() {
  94. if (!this.fileName) {
  95. this.$message('请先选择上传文件');
  96. return;
  97. }
  98. this.uploadInfo = '导入中...';
  99. api.importLisRecord(this.formData, this.header).then(res => {
  100. if (res.status === 200) {
  101. this.fileName = '';
  102. this.formData = {};
  103. this.$message({
  104. message: '导入成功',
  105. type: 'success'
  106. });
  107. setTimeout(() => {
  108. this.uploadInfo = '开始导入';
  109. }, 300);
  110. } else {
  111. this.fileName = '';
  112. this.formData = {};
  113. this.$message({
  114. message: '导入失败',
  115. type: 'error'
  116. });
  117. setTimeout(() => {
  118. this.uploadInfo = '开始导入';
  119. }, 300);
  120. }
  121. });
  122. }
  123. }
  124. };
  125. </script>
  126. <style lang="less">
  127. .importDisWrapper {
  128. min-width: 940px;
  129. color: #606266;
  130. .topBack {
  131. top: 0;
  132. }
  133. .importDisBox {
  134. padding: 20px 60px 120px 60px;
  135. margin: 70px 20px 0 20px;
  136. background: #fff;
  137. img{
  138. width: 18px;
  139. height: 18px;
  140. position: relative;
  141. top: 3px;
  142. left: 0px;
  143. margin-right: 4px;
  144. }
  145. p,
  146. span {
  147. font-size: 14px;
  148. }
  149. .down {
  150. color: #85a7f1;
  151. margin-left: 48px;
  152. line-height: 48px;
  153. cursor: pointer;
  154. }
  155. }
  156. .upload {
  157. .el-input {
  158. width: 240px;
  159. }
  160. .el-button {
  161. margin-left: 170px;
  162. margin-top: 20px;
  163. }
  164. #upFile {
  165. display: none !important;
  166. }
  167. }
  168. }
  169. </style>