ImportFormUpdate.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="640"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <a-form-item
  11. label="上传文件"
  12. :labelCol="BaseTool.Constant.labelCol"
  13. :wrapperCol="BaseTool.Constant.wrapperCol"
  14. >
  15. <a-upload :fileList="fileList" @change="handleChange" :remove="handleRemove" :beforeUpload="beforeUpload">
  16. <a-button> <a-icon type="upload" />选择上传文件</a-button>
  17. </a-upload>
  18. </a-form-item>
  19. </a-form>
  20. <p style="color: red">注意事项:<br/>
  21. 1:请确保设备编号、名称、型号的准确填写<br/>
  22. 2:请确保文件从系统中导出,并未修改格式,重新导入成功的数据将覆盖原有数据的属性<br/>
  23. 3:导入如出现问题,请及时联系<br/>
  24. </p>
  25. <template slot="footer">
  26. <a-button :loading="confirmLoading" type="primary" @click="save()">确定</a-button>
  27. </template>
  28. </a-modal>
  29. </template>
  30. <script>
  31. import { importSbInfo } from '@/api/sb/info'
  32. export default {
  33. name: 'SbModelBomImportForm',
  34. data () {
  35. return {
  36. confirmLoading: false,
  37. modalTitle: null,
  38. form: this.$form.createForm(this),
  39. visible: false,
  40. useCompany: null,
  41. useProject: null,
  42. type: null,
  43. fileList: []
  44. }
  45. },
  46. methods: {
  47. base (useCompany, type) {
  48. this.visible = true
  49. this.useCompany = useCompany
  50. if (type === 1) {
  51. this.modalTitle = '设备新增导入'
  52. } else {
  53. this.modalTitle = '设备修改导入'
  54. }
  55. this.type = type
  56. },
  57. handleRemove (file) {
  58. const index = this.fileList.indexOf(file)
  59. const newFileList = this.fileList.slice()
  60. newFileList.splice(index, 1)
  61. this.fileList = newFileList
  62. },
  63. beforeUpload (file) {
  64. const reg = /\.(xls|xlsx)(\?.*)?$/
  65. return new Promise((resolve, reject) => {
  66. if (reg.test(file.name)) {
  67. this.fileList = [file]
  68. return false
  69. } else {
  70. this.$message.error(`请上传正确的excel文件`)
  71. reject(new Error('请上传正确的excel文件'))
  72. return false
  73. }
  74. })
  75. },
  76. handleChange (info) {
  77. if (info.file.status !== 'uploading') {
  78. console.log(info.file, info.fileList)
  79. }
  80. if (info.file.status === 'done') {
  81. this.$message.success(`${info.file.name} file uploaded successfully`)
  82. } else if (info.file.status === 'error') {
  83. this.$message.error(`${info.file.name} file upload failed.`)
  84. }
  85. },
  86. save () {
  87. const { form: { validateFieldsAndScroll } } = this
  88. this.confirmLoading = true
  89. validateFieldsAndScroll((errors, values) => {
  90. if (errors) {
  91. this.confirmLoading = false
  92. return
  93. }
  94. const formData = new FormData()
  95. formData.append('type', this.type)
  96. formData.append('file', this.fileList[0])
  97. importSbInfo(formData)
  98. .then((res) => {
  99. this.$message.success(res.data)
  100. this.handleCancel(values)
  101. this.BaseTool.ListForm.clearOneList(this)
  102. this.BaseTool.ListForm.pushOneListAddMore(this, res.data)
  103. }).catch(() => {
  104. this.confirmLoading = false
  105. })
  106. })
  107. },
  108. handleCancel (values) {
  109. this.visible = false
  110. this.confirmLoading = false
  111. this.fileList = []
  112. this.form.resetFields()
  113. this.storeId = null
  114. this.$emit('ok', values)
  115. }
  116. }
  117. }
  118. </script>