3d077e99
wuxw
开发完成采购物品功能
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<el-upload class="upload-demo" action="" :auto-upload="false" :on-change="handleFileChange"
:show-file-list="false">
<el-button size="small" type="primary">
{{ $t('resourceStoreManage.browse') }}
</el-button>
<div slot="tip" class="el-upload__tip">
{{ fileName || $t('resourceStoreManage.selectDataFile') }}
</div>
</el-upload>
</el-form-item>
<el-form-item :label="$t('resourceStoreManage.downloadTemplate')">
<div>
{{ $t('resourceStoreManage.downloadTemplateTip1') }}
<a href="/import/importResourceStore.xlsx" target="_blank">
{{ $t('resourceStoreManage.resourceTemplate') }}
</a>
{{ $t('resourceStoreManage.downloadTemplateTip2') }}
</div>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="importData" :loading="importing">
{{ $t('resourceStoreManage.import') }}
</el-button>
</div>
</el-dialog>
</template>
<script>
|
3d077e99
wuxw
开发完成采购物品功能
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'ImportResourceStore',
data() {
return {
dialogVisible: false,
formData: {
shId: '',
file: null,
communityId: getCommunityId()
},
storehouses: [],
fileName: '',
importing: false,
rules: {
shId: [
{ required: true, message: this.$t('resourceStoreManage.storehouseRequired'), trigger: 'change' }
],
file: [
{ required: true, message: this.$t('resourceStoreManage.fileRequired'), trigger: 'change' }
]
}
}
},
methods: {
open() {
this.dialogVisible = true
this.listStorehouses()
},
async listStorehouses() {
try {
const params = {
page: 1,
row: 100,
communityId: getCommunityId()
}
const response = await listStorehouses(params)
this.storehouses = response.data || []
} catch (error) {
console.error('加载仓库列表失败:', error)
}
},
handleFileChange(file) {
this.formData.file = file.raw
this.fileName = file.name
this.$refs.importForm.validateField('file')
},
async importData() {
this.$refs.importForm.validate(async valid => {
if (!valid) return
// 检查文件类型
const ext = this.fileName.split('.').pop().toLowerCase()
if (!['xls', 'xlsx'].includes(ext)) {
this.$message.error(this.$t('resourceStoreManage.invalidExcelFormat'))
return
}
// 检查文件大小 (2MB)
if (this.formData.file.size > 2 * 1024 * 1024) {
this.$message.error(this.$t('resourceStoreManage.fileSizeLimit'))
return
}
try {
this.importing = true
const formData = new FormData()
formData.append('uploadFile', this.formData.file)
formData.append('shId', this.formData.shId)
formData.append('communityId', this.formData.communityId)
|
3d077e99
wuxw
开发完成采购物品功能
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
} finally {
this.importing = false
}
})
},
handleClosed() {
this.$refs.importForm.resetFields()
this.formData = {
shId: '',
file: null,
communityId: getCommunityId()
}
this.fileName = ''
}
}
}
</script>
<style scoped>
.upload-demo {
display: flex;
align-items: center;
}
.el-upload__tip {
margin-left: 10px;
color: #606266;
}
</style>
|