Blame view

src/components/resource/importResourceStore.vue 4.86 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
3d077e99   wuxw   开发完成采购物品功能
2
3
    <el-dialog :title="$t('resourceStoreManage.importResource')" :visible.sync="dialogVisible" width="40%"
      :close-on-click-modal="false" @closed="handleClosed">
9bb8cd93   wuxw   优化采购模块
4
      <el-form ref="importForm" :model="formData" :rules="rules" label-width="120px" label-position="right" class="text-left">
3d077e99   wuxw   开发完成采购物品功能
5
6
7
8
9
10
11
12
        <el-form-item :label="$t('resourceStoreManage.storehouse')" prop="shId">
          <el-select v-model="formData.shId" style="width:100%">
            <el-option :label="$t('resourceStoreManage.selectStorehouse')" value="" disabled></el-option>
            <el-option v-for="(item, index) in storehouses" :key="index" :label="item.shName"
              :value="item.shId"></el-option>
          </el-select>
        </el-form-item>
  
9bb8cd93   wuxw   优化采购模块
13
        <el-form-item :label="$t('common.select')" prop="file">
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>
9bb8cd93   wuxw   优化采购模块
46
  import { importData, listStorehouses } from '@/api/resource/resourceStoreManageApi'
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)
  
9bb8cd93   wuxw   优化采购模块
123
124
125
126
           const res = await importData(formData).catch(error => {
              this.$message.error(error)
            })
            if (res && res.code === 0) {
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
127
              this.$message.success(this.$t('common.operationSuccess'))
9bb8cd93   wuxw   优化采购模块
128
129
130
              this.dialogVisible = false
              this.$emit('success')
            }
3d077e99   wuxw   开发完成采购物品功能
131
132
          } catch (error) {
            console.error('导入物品失败:', error)
35126b43   wuxw   v1.9 修复车辆导入 报错提示不...
133
            this.$message.error(error)
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>