| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- <template>
- <el-dialog
- :visible="show"
- :append-to-body="true"
- :close-on-click-modal="false"
- title="导入任务"
- width="750px"
- @close="closeView">
- <div class="dialog-body">
- <el-steps
- :active="stepsActive"
- simple>
- <el-step
- v-for="(item, index) in stepList"
- :key="index"
- :title="item.title"
- :icon="item.icon"
- :status="item.status" />
- </el-steps>
-
- <div v-if="stepsActive == 1" class="step-section">
- <div class="sections">
- <div class="sections__title">一、请按照数据模板的格式准备要导入的数据。<span
- class="download"
- @click="download">点击下载《任务导入模板》</span></div>
- <div class="sections__tips">一次最多导入1000条任务,超出的部分不予导入</div>
- </div>
- <div class="sections">
- <div class="sections__title">三、请选择需要导入的文件</div>
- <div class="content">
- <flexbox class="file-select">
- <el-input
- v-model="file.name"
- :disabled="true"/>
- <el-button
- type="primary"
- @click="selectFile">选择文件</el-button>
- </flexbox>
- </div>
- </div>
- </div>
-
- <div
- v-loading="loading"
- v-else-if="stepsActive == 2"
- element-loading-text="数据导入中"
- element-loading-spinner="el-icon-loading"
- class="step-section"/>
-
- <div
- v-loading="loading"
- v-else-if="stepsActive == 3"
- class="step-section">
- <div class="result-info">
- <i class="wk wk-success result-info__icon" />
- <p class="result-info__des">数据导入完成</p>
- <p v-if="resultData" class="result-info__detail">导入总数据<span class="result-info__detail--all">{{ resultData.total }}</span>条,导入成功<span class="result-info__detail--suc">{{ resultData.total - resultData.error }}</span>条,导入失败<span class="result-info__detail--err">{{ resultData.error }}</span>条</p>
- <el-button
- v-if="resultData && resultData.error > 0"
- class="result-info__btn--err"
- type="text"
- @click="downloadErrData">下载错误数据</el-button>
- </div>
- </div>
-
- <input
- id="importInputFile"
- type="file"
- @change="uploadFile">
- </div>
- <span
- slot="footer"
- class="dialog-footer">
- <el-button
- :class="{ 'is-hidden': !showCancel }"
- @click="closeView">取消</el-button>
- <el-button
- v-if="sureTitle"
- type="primary"
- @click="sureClick">{{ sureTitle }}</el-button>
- </span>
- </el-dialog>
- </template>
-
- <script>
- import {
- workDownloadExcelAPI,
- workExcelImportAPI,
- workDownloadErrorExcelAPI
- } from '@/api/pm/project'
- import {
- crmQueryImportNumAPI,
- crmQueryImportInfoAPI
- } from '@/api/crm/common'
-
- import { downloadExcelWithResData, verifyFileTypeWithFileName } from '@/utils/index'
-
- export default {
- name: 'TaskImport', // 文件导入
- components: {},
- props: {
- show: {
- type: Boolean,
- default: false
- },
- workId: {
- require: true,
- type: [String, Number]
- }
- },
- data() {
- return {
- loading: false,
- file: { name: '' },
-
- stepsActive: 1,
- stepList: [
- {
- icon: 'wk wk-upload',
- title: '上传文件',
- status: 'wait'
- },
- {
- icon: 'wk wk-data-import',
- title: '导入数据',
- status: 'wait'
- },
- {
- icon: 'wk wk-success',
- title: '导入完成',
- status: 'wait'
- }
- ],
- resultData: null,
- processData: {
- count: 0,
- status: ''
- },
- messageId: null,
- intervalTimer: null,
-
- historyPopoverShow: false
-
- }
- },
- computed: {
-
- sureTitle() {
- return {
- 1: '立即导入',
- 2: '',
- 3: '确定'
- }[this.stepsActive]
- },
-
- showCancel() {
- return this.stepsActive != 2
- }
- },
- watch: {
-
- show: function(val) {
- if (!val) {
- if (this.stepsActive == 3) {
- this.resetData()
- }
- }
- },
-
- stepsActive() {
- this.$emit('status', {
- 1: 'wait',
- 2: 'process',
- 3: 'finish'
- }[this.stepsActive])
- }
-
- },
- created() {},
- methods: {
- sureClick() {
- if (this.stepsActive == 1) {
- if (this.stepList[0].status == 'finish') {
- this.stepList[1].status = 'process'
- this.stepsActive = 2
- this.firstUpdateFile(res => {
- this.messageId = res.data
- // this.stepList[1].status = 'finish'
- // this.stepsActive = 3
- // if (res.data) {
- // this.resultData = res.data
- // if (this.resultData.errSize > 0) {
- // this.stepList[2].status = 'error'
- // } else {
- // this.stepList[2].status = 'finish'
- // }
- // }
- this.loopSecondQueryNum()
- })
- } else {
- if (!this.file.name) {
- this.$message.error('请选择导入文件')
- }
- }
- } else {
- this.closeView()
- }
- },
-
-
- /**
- * 第一步上传
- */
- firstUpdateFile(result) {
- var params = {}
- params.work_id = this.workId
- params.file = this.file
- this.loading = true
- workExcelImportAPI(params)
- .then(res => {
- if (result) {
- result(res)
- }
- // this.loading = false
- // this.$emit('success')
- })
- .catch(() => {
- if (result) {
- result(false)
- }
- this.loading = false
- })
- },
- /**
- * 第二步查询数量
- */
- loopSecondQueryNum() {
- this.secondQueryNum()
- this.intervalTimer = setInterval(() => {
- if (this.processData.status == 'end') {
- clearInterval(this.intervalTimer)
- this.intervalTimer = null
- this.thirdQueryResult()
- } else {
- this.secondQueryNum()
- }
- }, 2000)
- },
-
- secondQueryNum() {
- crmQueryImportNumAPI({ messageId: this.messageId })
- .then(res => {
- if (res.data === '') {
- this.processData.status = 'end'
- } else {
- this.processData.status = ''
- this.processData.count = res.data
- }
- })
- .catch(() => {
- // this.processData.status = 'err'
- })
- },
-
- /**
- * 第三部 查询结果
- */
- thirdQueryResult() {
- crmQueryImportInfoAPI({ messageId: this.messageId })
- .then(res => {
- this.loading = false
- this.stepList[1].status = 'finish'
- this.stepsActive = 3
- this.$emit('status', 'finish')
- if (res) {
- this.resultData = res.data
- if (res.data.error > 0) {
- this.stepList[2].status = 'error'
- } else {
- this.stepList[2].status = 'finish'
- }
- }
- })
- .catch(() => {})
- },
- /**
- * 下载错误模板
- */
- downloadErrData() {
- this.loading = true
- workDownloadErrorExcelAPI({ name: '导入错误数据', path: this.resultData.error_file_path })
- .then(res => {
- downloadExcelWithResData(res)
- this.loading = false
- })
- .catch(() => {
- this.loading = false
- })
- },
-
- // 下载模板操作
- download() {
- workDownloadExcelAPI()
- .then(res => {
- downloadExcelWithResData(res)
- })
- .catch(() => {})
- },
- // 选择文件
- selectFile() {
- document.getElementById('importInputFile').click()
- },
- /** 图片选择出发 */
- uploadFile(event) {
- var files = event.target.files
- const file = files[0]
- if (verifyFileTypeWithFileName(file.name)) {
- this.file = file
- // 阶段一状态
- this.getFirstStepStatus()
- }
- event.target.value = ''
- },
- getFirstStepStatus() {
- // 阶段一状态
- const hasFile = this.file && this.file.size
-
- this.stepList[0].status = hasFile ? 'finish' : 'wait'
- },
-
- // 关闭操作
- closeView() {
- this.$emit('update:show', false)
- this.$emit('close', this.stepsActive == 3 ? 'finish' : '')
- },
-
- /**
- * 重置页面数据
- */
- resetData() {
- this.file = { name: '' }
-
- this.stepsActive = 1
- this.stepList = [
- {
- icon: 'wk wk-upload',
- title: '上传文件',
- status: 'wait'
- },
- {
- icon: 'wk wk-data-import',
- title: '导入数据',
- status: 'wait'
- },
- {
- icon: 'wk wk-success',
- title: '导入完成',
- status: 'wait'
- }
- ]
- this.resultData = null
- }
- }
- }
- </script>
-
- <style scoped lang="scss">
- .el-steps {
- margin-bottom: 15px;
-
- /deep/ .el-step__title {
- font-size: 14px;
- }
-
- /deep/ .el-step.is-simple .el-step__arrow::before,
- /deep/ .el-step.is-simple .el-step__arrow::after {
- height: 10px;
- width: 2px;
- }
-
- /deep/ .el-step.is-simple .el-step__arrow::after {
- transform: rotate(45deg) translateY(3px);
- }
- /deep/ .el-step.is-simple .el-step__arrow::before {
- transform: rotate(-45deg) translateY(-2px);
- }
- }
-
- .step-section {
- min-height: 300px;
- position: relative;
-
- /deep/ .el-loading-spinner {
- top: 45%;
- .el-icon-loading {
- font-size: 40px;
- color: #999;
- }
-
- .el-loading-text {
- color: #333;
- margin: 8px 0;
- }
- }
-
- &__tips {
- color: #999;
- font-size: 12px;
- position: absolute;
- left: 0;
- bottom: 0;
- right: 0;
- text-align: center;
- z-index: 3000;
- }
- }
-
- .sections {
- font-size: 14px;
- color: #333;
-
- &__title {
- font-weight: 600;
- }
-
- &__tips {
- padding-left: 30px;
- margin: 8px 0 15px;
- color: #999;
- font-size: 12px;
- line-height: 1.4;
- }
-
- .download {
- cursor: pointer;
- color: #2362FB;
- }
-
- }
-
- .sections__tips + .content {
- padding-top: 0;
- }
-
- .content {
- padding: 10px 10px 10px 30px;
- .el-select {
- width: 400px;
- }
- .user-cell {
- width: 400px;
- }
- }
-
- #importInputFile {
- display: none;
- }
-
- .file-select {
- .el-input {
- width: 400px;
- }
- button {
- margin-left: 20px;
- }
- }
-
- .is-hidden {
- visibility: hidden;
- }
-
-
- // 结果信息
- .result-info {
- text-align: center;
- padding-top: 80px;
-
- &__icon {
- font-size: 40px;
- color: $xr-color-primary;
- }
-
- &__des {
- margin-top: 15px;
- color: #333;
- font-size: 14px;
- }
-
- &__detail {
- margin-top: 15px;
- font-size: 12px;
- color: #666;
- &--all {
- color: #333;
- font-weight: 600;
- }
-
- &--suc {
- color: $xr-color-primary;
- font-weight: 600;
- }
-
- &--err {
- color: #f94e4e;
- font-weight: 600;
- }
- }
-
- &__btn--err {
- margin-top: 10px;
- }
- }
- </style>
|