永康嘉持电器有限公司前端
小小儁爺
2024-12-25 c6da28cde9dc469ee1e2d4dba4b7234307d9bd5a
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<template>
  <el-dialog
    v-el-drag-dialog
    :visible.sync="visible"
    :title="title"
    :code="code"
    :close-on-click-modal="false"
    @close="$emit('update:shows', false)"
  >
    <div>
      <el-steps :active="num" align-center style="margin-bottom:10px;">
        <el-step title="上传Excel" />
        <el-step title="数据验证" />
        <el-step title="导入数据" />
        <el-step title="完成" />
      </el-steps>
 
      <div v-if="div1" style="margin-left: 85px;margin-top: 35px" class="mb40">
        <h3>导入提示</h3>
        <p>1. 导入文件支持类型:.xlsx,最大不能超10M</p>
        <p>2. 请勿调整导入模版中字段的左右顺序或新增sheet页</p>
      </div>
 
      <div v-if="div2 && div2_state === '301'" style="margin-left: 85px;margin-right: 85px">
        <p><span class="gth_icon">!</span>文件中有<span style="color:red">{{ error_list.length }}</span>条错误数据,请修改后重新导入</p>
        <el-table class="table" :data="error_list" :header-cell-style="{background:'#f5f5f5'}">
          <el-table-column label="序号" prop="Seq" width="50" />
          <!--          <el-table-column label="行号" prop="RoeNumber" />-->
          <el-table-column label="错误字段" prop="ErrorField" min-width="150" />
          <el-table-column label="错误详情" prop="ErrorCont" min-width="300" />
        </el-table>
      </div>
      <div v-if="div2 && div2_state === '200'" style="position:relative;margin:100px 85px;">
        <div class="progress_bar bar-color-a" />
        <div :class="{'progress_bar':true, 'bar-color-b':true,'position_div':true,'cg':cg4,}" />
        <div class="mt"><img src="@/assets/images/succ.png" class="img_position"> 校验数据 (成功)</div>
        <div class="mt">即将导入{{ total_num }}条数据</div>
      </div>
      <div v-if="div1" style="margin-left:85px" class="mb40">
        <h3>上传文件</h3>
        <el-upload
          style="display: inline-block;"
          :action="baseUrl==='/api/'?'/api/importexcel/ExcelModelCheck':'/apis/importexcel/ExcelModelCheck'"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeUpload"
          :data="{FileCode:code}"
        >
          <el-button v-waves class="but_style" icon="el-icon-upload2" size="small" :style="{color:$store.state.settings.theme}">{{ button_name }}</el-button>
        </el-upload>
        请点击
        <el-button v-waves type="text" style="font-size: 14px;cursor: pointer" icon="el-icon-download" @click="clickDown(code)">下载数据模版</el-button>
        , 并按照模版编辑导入数据
      </div>
      <p v-if="div1" style="margin:0 85px 5px">{{ file_name }}</p>
      <div v-show="div1 && getDataing" style="margin: 0 85px" class="yz">
        <ul>
          <li>
            <div class="progress_bar bar-color-a" />
            <div :class="{'progress_bar':true, 'bar-color-b':true,'position_div':true,'cg':cg1,'sb':sb1}" />
            <!--            <div v-if="json1 === '200'" class="mt"><img src="@/assets/images/succ.png" class="img_position">文件上传 (成功)</div>-->
            <div v-if="json1 === '200'" class="mt"><img src="@/assets/images/succ.png" class="img_position">{{ message1 }}</div>
            <!--            <div v-if="json1 === '300'" class="mt"><img src="@/assets/images/sbbbb_icon.png" class="img_position">文件上传 (失败)</div>-->
            <div v-if="json1 === '300'" class="mt"><img src="@/assets/images/sbbbb_icon.png" class="img_position">{{ message1 }}</div>
            <div v-if="json1=== null" class="mt">文件上传(待校验)</div>
          </li>
          <!-- <li >
              <div class='progress_bar bar-color-a'></div>
              <div class='progress_bar ba r-color-c position_div' style="width:80%"></div>
 
          </li> -->
 
          <li>
            <div class="progress_bar bar-color-a" />
            <div :class="{'progress_bar':true, 'bar-color-b':true,'position_div':true,'cg':cg2,'sb':sb2}" />
            <div v-if="json2 === '200'" class="mt"><img src="@/assets/images/succ.png" class="img_position">{{ message2 }}</div>
            <div v-if="json2 === '300'" class="mt"><img src="@/assets/images/sbbbb_icon.png" class="img_position">{{ message2 }}</div>
            <div v-if="json2 === null" class="mt">模版校验(待校验)</div>
          </li>
          <!-- <li v-if="json2 === 300">
              <div class='progress_bar bar-color-a'></div>
              <div class='progress_bar bar-color-c position_div' style="width:80%"></div>
 
          </li> -->
          <!-- <li v-if="json2 === null">
              <div class='progress_bar bar-color-a'></div>
              <div class='progress_bar position_div'></div>
              <div class='mt'>模版验证(待校验)</div>
          </li> -->
 
          <li>
            <div class="progress_bar bar-color-a" />
            <div :class="{'progress_bar':true, 'bar-color-b':true,'position_div':true,'cg':cg3,'sb':sb3}" />
            <div v-if="json3 === '200'" class="mt"><img src="@/assets/images/succ.png" class="img_position">{{ message3 }}</div>
            <div v-if="json3 === '300'" class="mt"><img src="@/assets/images/sbbbb_icon.png" class="img_position">{{ message3 }}</div>
            <div v-if="json3 === null" class="mt">数据量校验(待校验)</div>
          </li>
          <!-- <li v-if="json3 === 300">
              <div class='progress_bar bar-color-a'></div>
              <div class='progress_bar bar-color-c position_div' style="width:80%"></div>
 
          </li>
          <li v-if="json3 === null">
              <div class='progress_bar bar-color-a'></div>
              <div class='progress_bar position_div'></div>
 
          </li> -->
        </ul>
      </div>
      <div v-if="div3" class="div3_s">
        <img src="@/assets/images/ws_icon.png">
        <p>已成功导入数据{{ total_num }}条</p>
      </div>
      <div v-if="div3_sb" class="div3_s">
        <img src="@/assets/images/error_icon.png">
        <p>导入失败,失败的原因是{{ error_message }}!</p>
      </div>
    </div>
    <span slot="footer" class="dialog-footer" style="display: flex;">
      <el-button v-if="button_text !=&quot;完成&quot;" v-waves @click="colos()">取 消</el-button>
      <el-button
        v-waves
        type="primary"
        class="button_style"
        :disabled="disState"
        @click="nextStep(code)"
      >{{ button_text }}</el-button>
    </span>
  </el-dialog>
</template>
<script>
 
import { DownLoadExcel, ExcelCheckData, ExcelImportSubmit, ExcelModelCheck } from '@/api/Excel'
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
 
export default {
  directives: { elDragDialog, waves },
  props: {
    code: {
      type: String,
      default: null
    },
    shows: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: null
    },
    // num:{
    //     type:Number,
    //     default:0
    // },
    // nextStep:{
    //     type:Function,
    //     default:null
    // },
    colos: {
      type: Function,
      default: null
    }
    // mnList:{
    //     type:Array,
    //     default:[]
    // }
  },
  data() {
    return {
      message1: '',
      message2: '',
      message3: '',
      getDataing: false,
      cg1: false,
      sb1: false,
      cg2: false,
      sb2: false,
      cg3: false,
      sb3: false,
      cg4: false,
      background1: '',
      background2: '',
      background3: '',
      error_message: '',
      total_num: 0,
      file: '',
      div3_sb: false,
      div3: false,
      div2_state: '',
      num: 0,
      disState: true,
      visible: this.shows,
      file_name: '',
      div2: false,
      div1: true,
      button_name: '选择文件',
      json1: '',
      json2: '',
      json3: '',
      mnList: [],
      error_list: [],
      button_text: '下一步',
      baseUrl: ''
 
    }
  },
  watch: {
    shows() {
      this.visible = this.shows
    }
  },
  mounted() {
    this.baseUrl = process.env.VUE_APP_BASE_API
  },
  methods: {
    newDataFunc() {
      this.num = 0
      this.getDataing = false
      this.div1 = true
      this.div2 = false
      this.div3 = false
      this.div3_sb = false
      this.file_name = ''
      this.disState = true
      this.json1 = ''
      this.json2 = ''
      this.json3 = ''
      this.button_name = '选择文件'
      this.button_text = '下一步'
    },
    nextStep(code) {
      const data = {
        FileCode: code,
        FileName: this.file_name
      }
 
      if (this.num === 0) {
        this.div1 = false
        this.div2 = true
        this.ExcelCheckData(data)
        this.num += 1
        this.disState = true
      } else if (this.num === 1) {
        this.div2 = false
        this.ExcelImportSubmit(data)
      } else {
        this.colos()
      }
    },
    ExcelImportSubmit(data) {
      ExcelImportSubmit(data).then((res) => {
        if (res.code === '200') {
          this.div3 = true
          this.num += 2
          this.button_text = '完成'
          this.disState = false
        } else {
          this.num += 1
          this.div3_sb = true
          this.disState = true
          this.error_message = res.Message
        }
      })
    },
    ExcelCheckData(data) {
      ExcelCheckData(data).then((res) => {
        this.div2_state = res.code
        setTimeout(() => {
          this.cg4 = true
        }, 2000)
 
        this.error_list = res.list
 
        this.total_num = res.Count
        if (res.code === '200') {
          this.disState = false
        }
      })
    },
    beforeUpload(file) {
      this.file_name = file.name
      this.file = file
    },
    handleAvatarSuccess(res, file, fileList) {
      this.disState = true
      this.getDataing = true
      this.json1 = null
      this.json2 = null
      this.json3 = null
      this.cg1 = false
      this.sb1 = false
      this.cg2 = false
      this.sb2 = false
      this.cg3 = false
      this.sb3 = false
      setTimeout(() => {
        if (res.json1.code === '200') {
          this.cg1 = true
        } else {
          this.sb1 = true
          this.json2 = null
          this.json3 = null
          this.button_name = '更新文件'
        }
      }, 500)
      setTimeout(() => {
        this.json1 = res.json1.code
        this.message1 = res.json1.Message
        this.json2 = null
        this.json3 = null
        if (res.json2.code === '200') {
          this.cg2 = true
        } else {
          this.sb2 = true
          this.json3 = null
          this.button_name = '更新文件'
        }
      }, 2000)
      setTimeout(() => {
        this.json2 = res.json2.code
        this.message2 = res.json2.Message
        this.json3 = null
        if (res.json3 !== null) {
          if (res.json3.code === '200') {
            this.cg3 = true
          } else {
            this.sb3 = true
            this.json3 = null
            this.button_name = '更新文件'
          }
        }
      }, 4000)
      setTimeout(() => {
        if (res.json3 !== null) {
          this.json3 = res.json3.code
          this.message3 = res.json3.Message
        }
      }, 6000)
      // if(res.json1.code === 300){
      //     this.json2 = null
      //     this.json3 =null
      //     this.button_name = '更新文件'
      // }else{
      //     this.json2 = res.json2.code
 
      // }
      // if(res.json2.code === 300){
      //     this.json3 =null
      //     this.button_name = '更新文件'
      // }else{
      //     this.json3 = res.json3.code
      // }
      setTimeout(() => {
        if (this.json1 === '200' && this.json2 === '200' && this.json3 === '200') {
          this.disState = false
        }
      }, 7000)
    },
    clickDown(code) {
      const data = {
        FileCode: code
      }
      // all.DownLoadExcel(data).then((res) => {
      //   window.location.href = res
      // })
      DownLoadExcel(data).then(res => {
        // console.log(res.data)
        // console.log(process.env.VUE_APP_BASE_API, 8989899)
        // console.log(process.env.VUE_APP_BASE_API_FILE)
        // console.log(window.location.origin + res.data)
        // window.location.href = process.env.VUE_APP_BASE_API_FILE + res.data
        window.location.href = res.data
      })
    }
  }
 
}
</script>
<style scoped>
.yz ul {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
}
 
.yz ul li {
  list-style: none;
  width: 32%;
  position: relative;
}
 
.progress_bar {
  height: 12px;
  width: 100%;
  border-radius: 10px;
}
 
.bar-color-a {
  background: #F1F1F1
}
 
.bar-color-b {
  background: #28C689
}
 
.bar-color-c {
  background: #EB8383
}
 
.position_div {
  position: absolute;
  top: 0;
  left: 0;
  width: 0px;
  border-radius: 10px;
 
}
 
.mt {
  margin-top: 10px;
}
 
.mb40 {
  margin-bottom: 40px;
}
 
.mb20 {
  margin-bottom: 20px;
}
 
.div3_s {
  margin-top: 100px;
  text-align: center;
}
 
.img_position {
  vertical-align: -1px;
  margin-right: 5px;
}
 
.cg {
  width: 100%;
  background: #28C689;
  transition: width 2s ease 0.3s;
}
 
.sb {
  width: 80%;
  background: #EB8383;
  transition: width 2s ease 0.3s;
}
 
.but_style {
  color: #00a79d;
  background-color: #FFFFFF;
  border-color: #00a79d;
}
 
.gth_icon {
  height: 20px;
  display: inline-block;
  background: #F7B500;
  color: #FFFFFF;
  border-radius: 100%;
  width: 20px;
  text-align: center;
  line-height: 20px;
  margin-right: 6px;
}
</style>