ImportFormAdd.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 { importCheckStandard } from '@/api/check/checkstandard'
  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. type: null,
  41. fileList: []
  42. }
  43. },
  44. methods: {
  45. base (useCompany, useProject) {
  46. this.visible = true
  47. this.modalTitle = '保养标准导入'
  48. this.type = 1
  49. },
  50. handleRemove (file) {
  51. const index = this.fileList.indexOf(file)
  52. const newFileList = this.fileList.slice()
  53. newFileList.splice(index, 1)
  54. this.fileList = newFileList
  55. },
  56. beforeUpload (file) {
  57. const reg = /\.(xls|xlsx)(\?.*)?$/
  58. return new Promise((resolve, reject) => {
  59. if (reg.test(file.name)) {
  60. this.fileList = [file]
  61. return false
  62. } else {
  63. this.$message.error(`请上传正确的excel文件`)
  64. reject(new Error('请上传正确的excel文件'))
  65. return false
  66. }
  67. })
  68. },
  69. handleChange (info) {
  70. if (info.file.status !== 'uploading') {
  71. console.log(info.file, info.fileList)
  72. }
  73. if (info.file.status === 'done') {
  74. this.$message.success(`${info.file.name} file uploaded successfully`)
  75. } else if (info.file.status === 'error') {
  76. this.$message.error(`${info.file.name} file upload failed.`)
  77. }
  78. },
  79. save () {
  80. const { form: { validateFieldsAndScroll } } = this
  81. this.confirmLoading = true
  82. validateFieldsAndScroll((errors, values) => {
  83. if (errors) {
  84. this.confirmLoading = false
  85. return
  86. }
  87. const formData = new FormData()
  88. // formData.append('type', this.type)
  89. formData.append('file', this.fileList[0])
  90. importCheckStandard(formData)
  91. .then((res) => {
  92. this.$message.success(res.data)
  93. this.handleCancel(values)
  94. this.BaseTool.ListForm.clearOneList(this)
  95. this.BaseTool.ListForm.pushOneListAddMore(this, res.data)
  96. }).catch(() => {
  97. this.confirmLoading = false
  98. })
  99. })
  100. },
  101. handleCancel (values) {
  102. this.visible = false
  103. this.confirmLoading = false
  104. this.fileList = []
  105. this.form.resetFields()
  106. this.storeId = null
  107. this.$emit('ok', values)
  108. }
  109. }
  110. }
  111. </script>