ImportForm.vue 13.6 KB
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
<template>
  <el-dialog title="批量导入" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center"
    lock-scroll width="1000px">
    <el-steps :active="active" align-center>
      <el-step title="上传文件"></el-step>
      <el-step title="数据预览"></el-step>
      <el-step title="导入数据"></el-step>
    </el-steps>
    <div class="import-main" v-show="active==1">
      <div class="upload">
        <div class="up_left">
          <img src="@/assets/images/upload.png">
        </div>
        <div class="up_right">
          <p class="title">上传填好的数据表</p>
          <p class="tip">文件后缀名必须是xls或xlsx,文件大小不超过500KB,最多支持导入1000条数据
            <br/>
            导入内容的分类直接填写分类名称即可(完全匹配) 如 绞车 ,未填写分类 按照列表页选择分类进行导入
<br/>
<br/> 
   <span v-if="orgId" style="padding:10px;">当前分类ID:
    <el-tag type="success">{{type}}</el-tag>
      当前分类:
    <el-tag type="success">{{orgId}}</el-tag>
    </span>

          </p>
          <el-upload :action="define.comUrl+'/api/file/Uploader/imp'" :headers="{ Authorization: $store.getters.token}"
            :on-success="handleSuccess" :on-remove="handleRemove" :before-remove="beforeRemove"
            :on-change="handleChange" :file-list="fileList" accept=".xls,.xlsx" :before-upload="beforeUpload"
            class="upload-area">
            <el-button type="text">上传文件</el-button>
          </el-upload>
        </div>
      </div>
      <div class="upload">
        <div class="up_left">
          <img src="@/assets/images/import.png">
        </div>
        <div class="up_right">
          <p class="title">填写导入数据信息</p>
          <p class="tip">请按照数据模板的格式准备导入数据,模板中的表头名称不可更改,表头行不能删除</p>
          <el-button type="text" @click="templateDownload">下载模板</el-button>
        </div>
      </div>
    </div>
    <div class="import-main" v-show="active==2">
      <NCC-table v-loading="listLoading" :data="list">
        <el-table-column v-for="item in fileds" :prop="item.value" :key="item" :label="item.key" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row[item.value]" />
          </template>
        </el-table-column> 
        <!-- <el-table-column prop="fullName" label="姓名" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.fullName" />
          </template>
        </el-table-column>
        <el-table-column prop="gender" label="性别" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.gender" />
          </template>
        </el-table-column>
        <el-table-column prop="departmentName" label="部门" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.departmentName" />
          </template>
        </el-table-column>
        <el-table-column prop="positionName" label="岗位" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.positionName" />
          </template>
        </el-table-column>
        <el-table-column prop="workingNature" label="用工性质" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.workingNature" />
          </template>
        </el-table-column>
        <el-table-column prop="idNumber" label="身份证号" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.idNumber" />
          </template>
        </el-table-column>
        <el-table-column prop="telephone" label="联系电话" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.telephone" />
          </template>
        </el-table-column>
        <el-table-column prop="birthday" label="出生年月" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.birthday" />
          </template>
        </el-table-column>
        <el-table-column prop="attendWorkTime" label="参加工作" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.attendWorkTime" />
          </template>
        </el-table-column>
        <el-table-column prop="education" label="最高学历" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.education" />
          </template>
        </el-table-column>
        <el-table-column prop="major" label="所学专业" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.major" />
          </template>
        </el-table-column>
        <el-table-column prop="graduationAcademy" label="毕业院校" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.graduationAcademy" />
          </template>
        </el-table-column>
        <el-table-column prop="graduationTime" label="毕业时间" width="150">
          <template slot-scope="scope">
            <el-input v-model="scope.row.graduationTime" />
          </template>
        </el-table-column> -->
        <el-table-column label="操作" fixed="right" width="50">
          <template slot-scope="scope">
            <el-button size="mini" type="text" class="NCC-table-delBtn" @click="handleDel(scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </NCC-table>
    </div>
    <div class="import-main" v-show="active==3">
      <div class="success" v-if="!result.resultType">
        <img src="@/assets/images/success.png" alt="">
        <p class="success-title">批量导入成功</p>
        <p class="success-tip">您已成功导入{{result.snum}}条数据</p>
      </div>
      <div class="unsuccess" v-if="result.resultType">
        <el-alert title="错误提醒:导入失败数据展示" type="warning" show-icon :closable="false" />
        <div class="upload error-show">
          <div class="up_left">
            <img class="" src="@/assets/images/tip.png">
          </div>
          <div class="up_right">
            <p class="tip">正常数量条数:<el-link type="success" :underline="false">{{result.snum}}条
              </el-link>
            </p>
            <p class="tip">异常数量条数:<el-link type="danger" :underline="false">{{result.fnum}}条
              </el-link>
            </p>
          </div>
        </div>
        <p class="contips">以下为导入异常数据(含错误字段与错误信息)</p>
        <NCC-table :data="resultList" height="280px">
          <el-table-column v-for="item in fileds" :prop="item.value" :key="item.value" :label="item.key" width="100" />
          <el-table-column prop="_errorField" label="错误字段" width="100" />
          <el-table-column prop="_errorMessage" label="错误信息" min-width="160" show-overflow-tooltip />
          <!-- <el-table-column prop="fullName" label="姓名" width="100" />
          <el-table-column prop="gender" label="性别" width="80" />
          <el-table-column prop="departmentName" label="部门" width="120" />
          <el-table-column prop="positionName" label="岗位" width="120" />
          <el-table-column prop="workingNature" label="用工性质" width="100" />
          <el-table-column prop="idNumber" label="身份证号" width="150" />
          <el-table-column prop="telephone" label="联系电话" width="100" />
          <el-table-column prop="birthday" label="出生年月" width="100" />
          <el-table-column prop="attendWorkTime" label="参加工作" width="100" />
          <el-table-column prop="education" label="最高学历" width="100" />
          <el-table-column prop="major" label="所学专业" width="120" />
          <el-table-column prop="graduationAcademy" label="毕业院校" width="150" />
          <el-table-column prop="graduationTime" label="毕业时间" width="100" /> -->
        </NCC-table>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle()" v-if="active == 1">取 消</el-button>
      <el-button @click="prev" v-if="active == 2">上一步</el-button>
      <el-button @click="next" type="primary" v-if="active < 3" :loading="btnLoading">下一步
      </el-button>
      <el-button @click="cancle(true)" type="primary" v-else>关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import request from '@/utils/request'
  export default {
    data() {
      return {
        apiPrex:'/api/Extend/Gzcx',
        visible: false,
        btnLoading: false,
        listLoading: false,
        fileName: '',
        fileList: [],
        active: 1,
        fileds:[],
        list: [],
        resultList: [],
        result: {
          resultType: 0,
          snum: 0,
          fnum: 0
        },
        type:0,
        orgId:''
      }
    },
    methods: {
      prev() {
        if (this.active == 1) return
        this.active--
      },
      next() {
        if (this.active == 2) {
          if (!this.list.length) return this.$message({ message: '导入数据为空', type: 'warning' })
          this.btnLoading = true
          request({
            url: this.apiPrex+'/ImportData',
            method: 'post',
            data: { list: this.list,itemStr:this.type }
          }).then(res => {
            console.log(res);
            this.result = res.data
            this.resultList = res.data.failResult
            this.btnLoading = false
            this.active++
          }).catch(() => { this.btnLoading = false })
        }
        if (this.active == 1) {
          if (!this.fileList.length || !this.fileName) return this.$message({ message: '请先上传文件', type: 'warning' })
          this.btnLoading = true

          var data = { fileName: this.fileName,type:this.type,orgId:this.orgId }
          request({
            url:  this.apiPrex+'/ImportPreview?fileName=' + this.fileName ,
            method: 'get',
            data
          }).then(res => {
            var lst = [];
            var fileds = res.data.fileds || {};
            for(var item in fileds)
            {
              lst.push({key:item,value:fileds[item]})
            }
            this.fileds = lst;

            this.list = res.data.dataRow
            this.btnLoading = false
            this.active++
          }).catch(() => { this.btnLoading = false })


        }
      },
      cancle(isRefresh) {
        this.visible = false
        if (isRefresh) this.$emit('refresh')
      },
      init(t,org) {
        this.active = 1
        this.fileList = []
        this.fileName = ''
        this.type = t;
        this.orgId=org;
        this.visible = true
      },
      handleDel(index) {
        this.list.splice(index, 1)
      },
      templateDownload() {
        request({
          url:  this.apiPrex+'/TemplateDownload?type=1&d='+this.type,
          method: 'get'
        }).then(res => {
          if (!res.data.url) return
          window.location.href = this.define.comUrl + res.data.url
        })

      },
      beforeUpload(file) {
        let isRightSize = file.size / 1024 < 500
        if (!isRightSize) this.$message.error(`文件大小不能超过500KB`)
        return isRightSize
      },
      handleRemove(file, fileList) {
        this.fileList = []
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${file.name}?`).catch(() => { })
      },
      handleChange(file, fileList) {
        this.fileList = fileList.slice(-1)
      },
      handleSuccess(res, file, fileList) {
        if (res.code == 200) {
          this.fileList = fileList.slice(-1)
          this.fileName = res.data.name
        } else {
          this.fileList = fileList.filter(o => o.uid != file.uid)
          this.$message({ message: res.msg, type: 'error', duration: 1000 })
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    padding: 20px 40px 2px !important;
  }

  .import-main {
    height: 500px;
    margin-top: 20px;
    overflow: hidden;
    position: relative;

    .upload {
      display: flex;
      border: 1px solid #dcdfe6;
      margin-bottom: 25px;

      &.error-show {
        margin-top: 10px;
        margin-bottom: 15px;

        .up_left {
          height: 120px;
        }

        .up_right {
          padding-top: 20px;
          font-size: 16px;

          ::v-deep .el-link {
            font-size: 16px;
          }
        }
      }

      .up_left {
        width: 126px;
        height: 140px;
        background: #f9f9f9;
        text-align: center;
        padding-top: 20px;
        flex-shrink: 0;

        img {
          width: 80px;
          height: 80px;
        }
      }

      .up_right {
        color: #333;
        margin-left: 30px;
        font-size: 14px;
        padding-top: 30px;
        flex: 1;

        .title {
          font-size: 18px;
          font-weight: bold;
        }

        .tip {
          margin: 15px 0;
        }
      }

      .upload-area {
        display: flex;
        padding-right: 200px;

        ::v-deep {
          .el-upload {
            margin-right: 50px;
            flex-shrink: 0;
          }

          .el-upload-list {
            flex: 1;
          }

          .el-upload-list__item:first-child {
            margin-top: 5px;
          }
        }
      }
    }

    .success {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 110px;

      .success-title {
        margin: 20px 0;
        font-size: 18px;
        font-weight: bold;
      }
    }

    .contips {
      margin-bottom: 15px;
    }
  }
</style>