hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
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
46
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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
  <!--导入-->
  <el-dialog
    class="height-auto"
    title="导入"
    :visible="value"
    width=""
    :modal="false"
    :show-close="false"
    :before-close="onCancel"
  >
    <div class="loading-box" v-loading="loading">
      <span class="import-btn" v-for="(text, index) in importData" :key="index">
        <el-upload
          name="file"
          accept=".xls, .xlsx"
          :headers="{ Authorization: Authorization }"
          class="upload-demo"
          :show-file-list="false"
          :action="text.url"
          :on-success="success"
          :on-error="error"
          :before-upload="beforeUpload"
          multiple
        >
          <el-button type="primary" plain class="m_btn bgc_primary"
            >{{ text.name }}
          </el-button>
        </el-upload>
      </span>
    </div>
    <span slot="footer" class="dialog-footer">
      <!-- 导入错误按钮 -->
      <el-button type="text" class="danger-text" v-if="errUrl" @click="dowErr"
        >下载错误表格</el-button
      >
      <el-button @click="onCancel">取 消</el-button>
      <el-button type="primary" @click="onOk('ruleForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
export default {
  props: {
    value: { type: Boolean },
  },
 
  data() {
    return {
      Authorization: "",
      loading: false,
      errUrl: "", //导入失败地址
      errpostUrl: "", //导入失败请求接口
      importData: [
        {
          name: "实有人口",
          url: this.$js.api.http + "common/data/population/serve/import",
          error: "population",
        },
        {
          name: "吸毒人员",
          url: this.$js.api.http + "common/data/population/serve/importDrug",
          error: "populationDrug",
        },
        {
          name: "社区矫正人员",
          url: this.$js.api.http + "common/data/population/serve/importCorrect",
        },
        {
          name: "邪教人员",
          url: this.$js.api.http + "common/data/population/serve/importCult",
        },
        {
          name: "残疾人",
          url:
            this.$js.api.http + "common/data/population/serve/importDisability",
        },
        {
          name: "重点上访人员",
          url: this.$js.api.http + "common/data/population/serve/importKey",
        },
        {
          name: "低保户",
          url:
            this.$js.api.http +
            "common/data/population/serve/importLowSecurity",
        },
        {
          name: "重精人员",
          url: this.$js.api.http + "common/data/population/serve/importMajor",
        },
        {
          name: "刑释人员",
          url:
            this.$js.api.http +
            "common/data/population/serve/importRehabilitation",
        },
        //  {
        //   name:'服刑人员',
        //   url:this.$js.api.http + "common/data/population/serve/importSentence"
        // },
        {
          name: "退役军人",
          url:
            this.$js.api.http + "common/data/population/serve/importVeterans",
        },
        {
          name: "高龄老人",
          url: this.$js.api.http + "common/data/population/serve/importElder",
        },
        {
          name: "养老人员",
          url: this.$js.api.http + "common/data/population/serve/importPension",
        },
      ],
    };
  },
 
  created() {
    this.Authorization = "Bearer " + demo.$session.get("token") || "";
  },
 
  // computed: {
  //   syupl() {
  //     return this.$js.api.http + "common/data/population/serve/import";
  //   },
  // },
 
  methods: {
    /** 取消 */
    onCancel() {
      this.$emit("change", false);
    },
 
    /** 确认 */
    onOk(formName) {},
 
    //导入前
    beforeUpload() {
      console.log("1111");
      this.errUrl = "";
      this.loading = true;
      this.msg = "导入中,请勿退出系统和关闭网络";
    },
 
    success(e, file, fileList) {
      // console.log(fileList)
      //导入成功
      this.loading = false;
      if (e.msg === "导入数据为空!") {
        demo.toast("导入模板为空");
        return;
      }
      if (e.code !== 200) {
        this.errUrl = e.msg;
        switch (this.errUrl) {
          case "DRUG_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationDrug";
            break;
 
          case "POPULATION_ERROR_LIST_":
            this.errpostUrl = "population";
            break;
 
          case "CORRECT_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationCorrect";
            break;
 
          case "CULT_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationCult";
            break;
          case "KEY_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationKey";
            break;
 
          case "MAJOR_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationMajor";
            break;
          case "NumberFormatException":
            demo.toast("表格中数据格式有误,请修改后重新导入");
            break;
 
          case "REHABILITATION_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationRehabilitation";
            break;
 
          case "SENTENCE_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationSentence";
            break;
 
          case "VETERANS_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationVeterans";
            break;
 
          case "DISABILITY_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationDisability";
            break;
 
          case "LOWSECURITY_POPULATION_ERROR_LIST_":
            this.errpostUrl = "populationLowSecurity";
            break;
          default:
            if (this.errUrl.search("ELDER_POPULATION_ERROR_LIST") !== -1) {
              this.errpostUrl = "populationElder";
            } else if (
              this.errUrl.search("PENSION_POPULATION_ERROR_LIST") !== -1
            ) {
              this.errpostUrl = "populationPension";
            }
            // this.errpostUrl = '';
            break;
        }
        this.$emit("success");
        // demo.toast("导入模板错误");
      } else {
        demo.toast("导入成功");
        this.errUrl = "";
        this.$emit("success");
        this.onCancel();
      }
    },
 
    error(err) {
      this.loading = false;
      demo.toast("导入失败!请检查内容是否正确");
      // console.log(err)
    },
 
    dowErr() {
      //下载错误i
      let data = {
        key: this.errUrl,
      };
      this.$api.post(
        "common/data/population/download/error/" +
          this.errpostUrl +
          "?key=" +
          this.errUrl,
        "",
        (e) => {
          // console.log(e)
          location.href = e;
        }
      );
    },
  },
};
</script>
 
<style lang="less" scoped>
/deep/.el-dialog__body {
  height: 150px;
}
/deep/.el-button--text {
  color: #f56c6c;
  text-decoration: underline;
}
.loading-box {
  width: 100%;
  height: 100%;
}
.import-btn {
  float: left;
  margin-right: 15px;
  margin-bottom: 15px;
}
</style>