|
|
@@ -0,0 +1,115 @@
|
|
|
+<template>
|
|
|
+ <a-modal
|
|
|
+ title="批量导入保养标准"
|
|
|
+ :width="720"
|
|
|
+ :visible="visible"
|
|
|
+ :confirmLoading="confirmLoading"
|
|
|
+ @cancel="handleCancel"
|
|
|
+ >
|
|
|
+ <a-form :form="form">
|
|
|
+ <a-form-item
|
|
|
+ label="上传文件"
|
|
|
+ :labelCol="BaseTool.Constant.labelCol"
|
|
|
+ :wrapperCol="BaseTool.Constant.wrapperCol"
|
|
|
+ >
|
|
|
+ <a-upload
|
|
|
+ :fileList="fileList"
|
|
|
+ :multiple="false"
|
|
|
+ :remove="handleRemove"
|
|
|
+ :beforeUpload="beforeUpload"
|
|
|
+ >
|
|
|
+ <a-button><a-icon type="upload" />选择 Excel 文件</a-button>
|
|
|
+ </a-upload>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item
|
|
|
+ :wrapperCol="BaseTool.Constant.wrapperCol"
|
|
|
+ :labelCol="{ span: 0 }"
|
|
|
+ >
|
|
|
+ <a-button type="link" icon="download" @click="doDownloadTemplate">下载导入模板</a-button>
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ <p style="color: red">
|
|
|
+ 注意事项:<br />
|
|
|
+ 1:一行对应一条保养标准,一台设备一个保养项类别需填一行<br />
|
|
|
+ 2:设备编号(新号/旧号)、保养项类别名称必须已存在于系统中<br />
|
|
|
+ 3:保养项类别下必须已配置保养项,执行人方式为“班组”时需填写执行班组名称<br />
|
|
|
+ 4:只要有一行填写错误,将整批拒绝并提示错误行,不会导入任何数据<br />
|
|
|
+ 5:示例行仅供参照,导入前请删除
|
|
|
+ </p>
|
|
|
+ <template slot="footer">
|
|
|
+ <a-button @click="handleCancel">关闭</a-button>
|
|
|
+ <a-button :loading="confirmLoading" type="primary" @click="save()">确定导入</a-button>
|
|
|
+ </template>
|
|
|
+ </a-modal>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { importCheckStandardBatch, downloadCheckStandardImportTemplate } from '@/api/check/checkstandard'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'BatchImportStandard',
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ visible: false,
|
|
|
+ confirmLoading: false,
|
|
|
+ form: this.$form.createForm(this),
|
|
|
+ fileList: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ base () {
|
|
|
+ this.visible = true
|
|
|
+ this.fileList = []
|
|
|
+ this.confirmLoading = false
|
|
|
+ },
|
|
|
+ beforeUpload (file) {
|
|
|
+ const reg = /\.(xls|xlsx)(\?.*)?$/
|
|
|
+ if (!reg.test(file.name)) {
|
|
|
+ this.$message.error('请上传正确的 Excel 文件')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 单文件:始终只保留最新选择的一个
|
|
|
+ this.fileList = [file]
|
|
|
+ return false
|
|
|
+ },
|
|
|
+ handleRemove (file) {
|
|
|
+ const index = this.fileList.indexOf(file)
|
|
|
+ const newFileList = this.fileList.slice()
|
|
|
+ newFileList.splice(index, 1)
|
|
|
+ this.fileList = newFileList
|
|
|
+ },
|
|
|
+ doDownloadTemplate () {
|
|
|
+ downloadCheckStandardImportTemplate().then((file) => {
|
|
|
+ this.BaseTool.UPLOAD.downLoadExportExcel(file)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ save () {
|
|
|
+ if (this.fileList.length === 0) {
|
|
|
+ this.$message.info('请先选择要导入的文件')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', this.fileList[0], this.fileList[0].name)
|
|
|
+ this.confirmLoading = true
|
|
|
+ importCheckStandardBatch(formData)
|
|
|
+ .then((res) => {
|
|
|
+ this.confirmLoading = false
|
|
|
+ this.$message.success(res.data || '导入成功')
|
|
|
+ this.$emit('ok')
|
|
|
+ this.visible = false
|
|
|
+ this.fileList = []
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ // 整批拒绝:后端返回的错误提示由全局拦截器展示,此处仅复位按钮状态
|
|
|
+ this.confirmLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleCancel () {
|
|
|
+ this.visible = false
|
|
|
+ this.confirmLoading = false
|
|
|
+ this.fileList = []
|
|
|
+ this.form.resetFields()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|