@<template>
  <section>
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true">
            <el-form-item label="数据迁移" style="margin-left:20px"></el-form-item>
        </el-form>
    </el-col>
    <el-col :span="24" style="padding:25px">
        <el-form style="width:500px;margin:0 auto" label-position="left" label-width="100px">
            <el-form-item label="当前公司" style="margin-top:40px">
                <el-input v-model="nowCompanyId" placeholder="请输入" clearable style="width:250px"></el-input>
            </el-form-item>
            <el-form-item label="当前公司超管" style="margin-top:40px">
                <el-input v-model="nowCompanyCg" placeholder="请输入" clearable style="width:250px"></el-input>
            </el-form-item>
            <el-form-item label="目标公司" style="margin-top:40px">
                <el-input v-model="toCompanyId" placeholder="请输入" clearable style="width:250px"></el-input>
            </el-form-item>
            <el-form-item label="目标公司超管" style="margin-top:40px">
                <el-input v-model="toCompanyCg" placeholder="请输入" clearable style="width:250px"></el-input>
            </el-form-item>
        </el-form>
        <div style="width:500px;margin:100px auto">
            <div style="width:350px;text-align:center">
                <el-button type="primary" @click="submit" style="margin:0 auto">立即迁移</el-button>
            </div>
        </div>
    </el-col>
  </section>
</template>

<script>
export default {
    data(){
        return{
            list:[],
            nowCompanyId: '',
            toCompanyId: '',
            nowCompanyCg: '',
            toCompanyCg: ''
        }
    },
    mounted(){
        // this.getList()
    },
    methods:{
        getList() {
                this.http.post('/company/getList', {
                    pageIndex: 1,
                    pageSize: 9999,
                    companyName: '',
                    isMeal: 0
                },
                res => {
                    if (res.code == "ok") {
                        this.list = res.data.records;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
        submit() {
            this.nowCompanyId = this.nowCompanyId.trim()
            this.nowCompanyCg = this.nowCompanyCg.trim()
            this.toCompanyId = this.toCompanyId.trim()
            this.toCompanyCg = this.toCompanyCg.trim()
            if(this.nowCompanyId == ''){
                this.$message({
                    message: '当前公司未输入！',
                    type: 'warning'
                })
                return
            }else if(this.toCompanyId == ''){
                this.$message({
                    message: '目标公司未输入！',
                    type: 'warning'
                })
                return
            }else if(this.nowCompanyCg == ''){
                this.$message({
                    message: '当前公司超管未输入！',
                    type: 'warning'
                })
                return
            }else if(this.toCompanyCg == ''){
                this.$message({
                    message: '目标公司超管未输入！',
                    type: 'warning'
                })
                return
            }else if(this.nowCompanyId == this.toCompanyId){
                this.$message({
                    message: '当前公司与目标公司相同！',
                    type: 'warning'
                })
                return
            }
            this.$confirm('确认进行数据迁移吗？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(()=>{
                this.http.post('/company/dataMigration',{
                    oldCompanyId: this.nowCompanyId,
                    targetCompanyId: this.toCompanyId,
                    oldUserName: this.nowCompanyCg,
                    targetUserName: this.toCompanyCg
                },res => {
                    if(res.code == 'ok'){
                        this.$message({
                            message: '数据迁移成功',
                            type: 'success'
                        })
                        this.nowCompanyId = null
                        this.toCompanyId = null
                        this.getList()
                    }else {
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        })
                    }
                },err => {
                    this.$message({
                        message: err,
                        type: 'error'
                    })
                })
            }).catch(()=>{
                this.$message({
                    message: '已取消操作',
                    type: 'info'
                })
            })
            
        }
    }
}
</script>

<style scoped>
.sidebars {
  height: 100%;
  position: absolute;
  border-right: 1px solid #E6E6E6;
  z-index: 2;
  top: 0;
}
</style>