Blame view

src/views/system/historyFeeDetailImportList.vue 5.89 KB
ce5e1a2a   wuxw   系统模块开发中
1
2
3
  <template>
    <div class="history-fee-detail-import-container">
      <el-card class="box-card">
27dcfde5   wuxw   系统全面测试完成
4
        <div slot="header" class="flex justify-between">
ce5e1a2a   wuxw   系统模块开发中
5
6
7
8
9
10
11
12
13
14
15
16
17
          <span>{{ $t('historyFeeDetailImport.assetInfo') }}</span>
          <div class="card-header-right">
            <el-button type="primary" size="small" @click="_openDownloadHcExcelTemplate">
              <i class="el-icon-download"></i>{{ $t('historyFeeDetailImport.houseTemplate') }}
            </el-button>
            <el-button type="primary" size="small" @click="_openDownloadHcCarExcelTemplate">
              <i class="el-icon-download"></i>{{ $t('historyFeeDetailImport.carTemplate') }}
            </el-button>
          </div>
        </div>
  
        <el-row :gutter="20">
          <el-col :span="24">
27dcfde5   wuxw   系统全面测试完成
18
            <el-form label-position="left" label-width="120px" class="text-left">
ce5e1a2a   wuxw   系统模块开发中
19
              <el-form-item :label="$t('historyFeeDetailImport.feeObject')">
27dcfde5   wuxw   系统全面测试完成
20
                <el-select v-model="historyFeeDetailImportInfo.objType" style="width:100%"
ce5e1a2a   wuxw   系统模块开发中
21
                  :placeholder="$t('historyFeeDetailImport.selectFeeObject')">
27dcfde5   wuxw   系统全面测试完成
22
                  <el-option disabled value="" :label="$t('historyFeeDetailImport.requiredSelect')">
ce5e1a2a   wuxw   系统模块开发中
23
                  </el-option>
27dcfde5   wuxw   系统全面测试完成
24
                  <el-option value="3333" :label="$t('historyFeeDetailImport.house')">
ce5e1a2a   wuxw   系统模块开发中
25
                  </el-option>
27dcfde5   wuxw   系统全面测试完成
26
                  <el-option value="6666" :label="$t('historyFeeDetailImport.car')">
ce5e1a2a   wuxw   系统模块开发中
27
28
29
30
31
                  </el-option>
                </el-select>
              </el-form-item>
  
              <el-form-item :label="$t('historyFeeDetailImport.selectFile')">
27dcfde5   wuxw   系统全面测试完成
32
                <el-upload class="upload-demo" action="" :auto-upload="false" :on-change="getExcelTemplate"
ce5e1a2a   wuxw   系统模块开发中
33
34
35
36
37
                  :show-file-list="false">
                  <el-button size="small" type="primary">
                    {{ $t('historyFeeDetailImport.clickUpload') }}
                  </el-button>
                  <div slot="tip" class="el-upload__tip">
27dcfde5   wuxw   系统全面测试完成
38
39
40
                    {{ historyFeeDetailImportInfo.excelTemplate ?
                      historyFeeDetailImportInfo.excelTemplate.name :
                      $t('historyFeeDetailImport.requiredFile') }}
ce5e1a2a   wuxw   系统模块开发中
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
                  </div>
                </el-upload>
              </el-form-item>
  
              <el-form-item :label="$t('historyFeeDetailImport.description')">
                <div class="description-text">
                  {{ $t('historyFeeDetailImport.importTip') }}
                </div>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
  
        <el-row>
          <el-col :span="24" class="text-right">
27dcfde5   wuxw   系统全面测试完成
56
            <el-button type="primary" @click="_importData"
ce5e1a2a   wuxw   系统模块开发中
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
              :disabled="!historyFeeDetailImportInfo.excelTemplate || !historyFeeDetailImportInfo.objType">
              {{ $t('historyFeeDetailImport.import') }}
            </el-button>
          </el-col>
        </el-row>
      </el-card>
    </div>
  </template>
  
  <script>
  import { importData } from '@/api/system/historyFeeDetailImportApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'HistoryFeeDetailImportList',
    data() {
      return {
        historyFeeDetailImportInfo: {
          communityId: '',
          excelTemplate: null,
          objType: ''
        }
      }
    },
    created() {
      this.historyFeeDetailImportInfo.communityId = getCommunityId()
    },
    methods: {
      _openDownloadHcExcelTemplate() {
        window.open('/import/importFeeDetail.xlsx')
      },
      _openDownloadHcCarExcelTemplate() {
        window.open('/import/importCarFeeDetail.xlsx')
      },
      getExcelTemplate(file) {
        this.historyFeeDetailImportInfo.excelTemplate = file.raw
      },
      async _importData() {
        if (!this.validateForm()) {
          return
        }
  
        const param = new FormData()
        param.append('uploadFile', this.historyFeeDetailImportInfo.excelTemplate)
        param.append('communityId', this.historyFeeDetailImportInfo.communityId)
        param.append('objType', this.historyFeeDetailImportInfo.objType)
27dcfde5   wuxw   系统全面测试完成
103
104
  
        const _importAdapt = this.historyFeeDetailImportInfo.objType === '6666' ?
ce5e1a2a   wuxw   系统模块开发中
105
106
107
108
109
110
111
112
113
          'importCarHistoryFeeDetail' : 'importRoomHistoryFeeDetail'
        param.append('importAdapt', _importAdapt)
  
        try {
          const res = await importData(param)
          if (res.code === 0) {
            this.$message.success(this.$t('historyFeeDetailImport.importSuccess'))
            this.historyFeeDetailImportInfo.excelTemplate = null
            this.$router.push({
27dcfde5   wuxw   系统全面测试完成
114
              path: '/views/system/assetImportLogDetail',
ce5e1a2a   wuxw   系统模块开发中
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
              query: {
                logId: res.data.logId,
                logType: _importAdapt
              }
            })
          } else {
            this.$message.error(res.msg)
          }
        } catch (error) {
          this.$message.error(this.$t('historyFeeDetailImport.importError'))
        }
      },
      validateForm() {
        if (!this.historyFeeDetailImportInfo.excelTemplate) {
          this.$message.error(this.$t('historyFeeDetailImport.fileRequired'))
          return false
        }
  
        if (!this.checkFileType(this.historyFeeDetailImportInfo.excelTemplate.name)) {
          this.$message.error(this.$t('historyFeeDetailImport.invalidFileType'))
          return false
        }
  
        if (!this.checkFileSize(this.historyFeeDetailImportInfo.excelTemplate.size)) {
          this.$message.error(this.$t('historyFeeDetailImport.fileSizeLimit'))
          return false
        }
  
        return true
      },
      checkFileType(fileName) {
        const fileExt = fileName.split('.').pop().toLowerCase()
        return ['xls', 'xlsx'].includes(fileExt)
      },
      checkFileSize(fileSize) {
        return fileSize <= 2 * 1024 * 1024 // 2MB
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .history-fee-detail-import-container {
    padding: 20px;
  
    .box-card {
      margin-bottom: 20px;
    }
  
    .card-header-right {
      float: right;
    }
  
    .description-text {
      color: #606266;
      font-size: 14px;
      line-height: 1.5;
    }
  
    .text-right {
      text-align: right;
      margin-top: 20px;
    }
  
    .el-upload__tip {
      margin-left: 10px;
      display: inline-block;
      vertical-align: middle;
    }
  }
  </style>