whj 2 жил өмнө
parent
commit
58627494a0

+ 3 - 3
src/views/check/checkstandard/CheckStandard.vue

@@ -163,7 +163,7 @@
     <detail-standard-check-job ref="detailSbCheckJobModal" @ok="handleOk"/>
     <base-form ref="baseModal" :check-type="checkType" @ok="handleOk"/>
     <detail ref="detailModal"/>
-    <import-form-add ref="importModal" @ok="handleOk"/>
+    <import-form-update ref="importModal" @ok="handleOk"/>
   </a-card>
 </template>
 
@@ -171,7 +171,7 @@
 import { STable, Ellipsis } from '@/components'
 import BaseForm from './modules/BaseForm'
 import Detail from './modules/Detail'
-import ImportFormAdd from './modules/ImportFormAdd'
+import ImportFormUpdate from './modules/ImportFormUpdate'
 import {
   getCheckStandardPage,
   deleteCheckStandards,
@@ -189,7 +189,7 @@ export default {
     Ellipsis,
     BaseForm,
     Detail,
-    ImportFormAdd,
+    ImportFormUpdate,
     DetailStandardCheckJob
   },
   props: {

+ 101 - 0
src/views/check/checkstandard/modules/ImportFormUpdate.vue

@@ -0,0 +1,101 @@
+<template>
+  <a-modal
+    :title="modalTitle"
+    :width="640"
+    :visible="visible"
+    :confirmLoading="confirmLoading"
+    @cancel="handleCancel"
+  >
+    <a-form>
+      <a-form-item
+        label="上传文件"
+        :labelCol="BaseTool.Constant.labelCol"
+        :wrapperCol="BaseTool.Constant.wrapperCol"
+      >
+        <a-upload :fileList="fileList" @change="handleChange" :remove="handleRemove" :beforeUpload="beforeUpload">
+          <a-button> <a-icon type="upload" />选择上传文件</a-button>
+        </a-upload>
+      </a-form-item>
+    </a-form>
+    <p style="color: red">注意事项:<br/>
+      1:请确保文件从系统中导出,并未修改格式,重新导入成功的数据将覆盖原有数据的属性<br/>
+      2:导入如出现问题,请及时联系<br/>
+    </p>
+    <template slot="footer">
+      <a-button :loading="confirmLoading" type="primary" @click="save()">确定</a-button>
+    </template>
+  </a-modal>
+</template>
+
+<script>
+import { importCheckStandardNew } from '@/api/check/checkstandard'
+
+export default {
+  name: 'SbModelBomImportForm',
+  data () {
+    return {
+      confirmLoading: false,
+      modalTitle: null,
+      visible: false,
+      fileList: []
+    }
+  },
+  methods: {
+    base () {
+      this.visible = true
+      this.modalTitle = '导入'
+    },
+    handleRemove (file) {
+      const index = this.fileList.indexOf(file)
+      const newFileList = this.fileList.slice()
+      newFileList.splice(index, 1)
+      this.fileList = newFileList
+    },
+    beforeUpload (file) {
+      const reg = /\.(xls|xlsx)(\?.*)?$/
+      return new Promise((resolve, reject) => {
+        if (reg.test(file.name)) {
+          this.fileList = [file]
+          return false
+        } else {
+          this.$message.error(`请上传正确的excel文件`)
+          reject(new Error('请上传正确的excel文件'))
+          return false
+        }
+      })
+    },
+    handleChange (info) {
+      if (info.file.status !== 'uploading') {
+        console.log(info.file, info.fileList)
+      }
+      if (info.file.status === 'done') {
+        this.$message.success(`${info.file.name} file uploaded successfully`)
+      } else if (info.file.status === 'error') {
+        this.$message.error(`${info.file.name} file upload failed.`)
+      }
+    },
+    save () {
+      this.confirmLoading = true
+      const formData = new FormData()
+      formData.append('file', this.fileList[0])
+
+      importCheckStandardNew(formData)
+        .then((res) => {
+          this.$message.success(res.data)
+          this.handleCancel()
+          this.BaseTool.ListForm.clearOneList(this)
+          this.BaseTool.ListForm.pushOneListAddMore(this, res.data)
+        }).catch(() => {
+          this.confirmLoading = false
+        })
+    },
+    handleCancel () {
+      this.visible = false
+      this.confirmLoading = false
+      this.fileList = []
+      this.$emit('ok')
+    }
+
+  }
+}
+</script>