Explorar el Código

feat: 加油卡导入导出

TwoKe945 hace 1 año
padre
commit
2cd6649ea0

+ 9 - 1
src/api/clw/gas.js

@@ -48,4 +48,12 @@ export function plateNumberList () {
     url: '/clw/car/plateNumberList',
     method: 'get'
   })
-}
+}
+
+export function importData (data) {
+  return request({
+    url: '/clw/gas/importData',
+    method: 'post',
+    data: data
+  })
+}

+ 11 - 0
src/views/clw/gas/index.vue

@@ -38,6 +38,13 @@
         <a-button type="danger" :disabled="multiple" @click="handleDelete" v-hasPermi="['clw:gas:remove']">
           <a-icon type="delete" />删除
         </a-button>
+        <a-button
+              type="dashed"
+              @click="$refs.importExcel.importExcelHandleOpen()"
+              v-hasPermi="['system:user:import']"
+            >
+              <a-icon type="import" />导入
+            </a-button>
         <a-button type="primary" @click="handleExport" v-hasPermi="['clw:gas:export']">
           <a-icon type="download" />导出
         </a-button>
@@ -58,6 +65,8 @@
       />
       <!-- 注销原因 -->
       <singOut ref="singForm" @signCar="signCar" />
+      <!-- 上传文件 -->
+      <import-excel ref="importExcel" @ok="getList" />
       <!-- 删除弹窗 -->
       <OpenModul ref="modules" @handleDeletes="handleDeletes" />
       <!-- 数据展示 -->
@@ -116,12 +125,14 @@ import CreateForm from './modules/CreateForm'
 import { tableMixin } from '@/store/table-mixin'
 import singOut from './modules/singOut.vue'
 import OpenModul from '@/components/OpenModul.vue'
+import ImportExcel from './modules/ImportExcel.vue'
 export default {
   name: 'Gas',
   components: {
     CreateForm,
     singOut,
     OpenModul,
+    ImportExcel
   },
   mixins: [tableMixin],
   dicts: ['gas_car_type', 'gas_status'],

+ 112 - 0
src/views/clw/gas/modules/ImportExcel.vue

@@ -0,0 +1,112 @@
+<template>
+  <a-modal
+    :title="title"
+    :visible="open"
+    :confirm-loading="uploading"
+    @cancel="importExcelHandleCancel"
+    @ok="importExcelHandleChange"
+  >
+    <a-spin tip="上传中..." :spinning="uploading">
+      <a-upload-dragger
+        name="file"
+        accept=".xlsx, .xls"
+        :file-list="fileList"
+        :multiple="false"
+        :remove="handleRemove"
+        :before-upload="beforeUpload"
+      >
+        <p class="ant-upload-drag-icon">
+          <a-icon type="inbox" />
+        </p>
+        <p class="ant-upload-text">
+          请将文件拖拽到此处上传
+        </p>
+        <p class="ant-upload-hint">
+          支持单个上传,也可以点击后选择文件上传
+        </p>
+      </a-upload-dragger>
+      <a-checkbox @change="handleCheckedUpdateSupport" :checked="updateSupport != 0">
+        是否更新已经存在的油卡数据
+      </a-checkbox>
+      <a @click="importTemplate">下载模板</a>
+    </a-spin>
+  </a-modal>
+</template>
+
+<script>
+
+import { importData } from '@/api/clw/gas'
+
+export default {
+  name: 'ImportExcel',
+  props: {
+  },
+  components: {
+  },
+  data () {
+    return {
+      title: '油卡数据导入',
+      open: false,
+      uploadStatus: '',
+      fileList: [],
+      // 是否禁用上传
+      uploading: false,
+      updateSupport: 0
+    }
+  },
+  filters: {
+  },
+  created () {
+  },
+  computed: {
+  },
+  watch: {
+  },
+  methods: {
+    /** 导入excel窗体关闭 */
+    importExcelHandleCancel (e) {
+      this.open = false
+      this.fileList = []
+      // 关闭后刷新列表
+      this.$emit('ok')
+    },
+    /** 下载模板操作 */
+    importTemplate () {
+      this.download('clw/gas/importTemplate', {
+        ...this.queryParams
+      }, `油卡数据_${new Date().getTime()}.xlsx`)
+    },
+    /** 导入excel窗体开启 */
+    importExcelHandleOpen (e) {
+      this.open = true
+    },
+    beforeUpload (file) {
+      this.fileList = [file]
+      return false
+    },
+    /** 导入excel */
+    importExcelHandleChange () {
+      this.uploading = true
+      const { fileList } = this
+      const formData = new FormData()
+      formData.append('file', fileList[0])
+      formData.append('updateSupport', this.updateSupport)
+      importData(formData).then(response => {
+        this.fileList = []
+        this.$message.success(response.msg)
+        this.open = false
+        this.$emit('ok')
+      }).finally(() => {
+        this.uploading = false
+      })
+    },
+    handleCheckedUpdateSupport () {
+      this.updateSupport = this.updateSupport === 0 ? 1 : 0
+    },
+    handleRemove () {
+      this.fileList = []
+      this.uploading = false
+    }
+  }
+}
+</script>

+ 1 - 1
src/views/system/user/modules/ImportExcel.vue

@@ -19,7 +19,7 @@
           <a-icon type="inbox" />
         </p>
         <p class="ant-upload-text">
-          请将文件拖拽到此处上传❥(^_-)
+          请将文件拖拽到此处上传
         </p>
         <p class="ant-upload-hint">
           支持单个上传,也可以点击后选择文件上传