<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="static/js/vue.js"></script>
    <script src="static/js/axios.js"></script>
    <script src="static/js/dayjs.js"></script>
    <script src="static/js/element-ui/index.js"></script>
    <link rel="stylesheet" href="static/js/element-ui/index.css">
    <link href="static/assets/index.css" rel="stylesheet"/>
</head>
<style type="text/css">
    html,
    body,
    #app {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;

    }

    #app {
        background: #f5f7fa;
        width: calc(100% - 32px);
        padding: 16px;
    }

    .main {
        background: #fff;
        padding: 16px;
        min-height: calc(100% - 60px);
    }

    #app .el-dialog__header{
        display: none;
    }

</style>

<body>
<div id="app">
    <div class="main">
        <a :href="url">返回</a >
        <el-tabs v-model="activeName" @tab-click="handleClick" :tab-position="tabPosition">
            <el-tab-pane v-for="(item,index) in tabList" :label="item" :name="item" :key="index">
                <el-button type="primary" size="small" @click="execute(item)">手工执行</el-button>
            </el-tab-pane>
        </el-tabs>
    </div>
    <el-dialog
            :visible.sync="dialogVisible"
            width="40%" >
        <el-form ref="form" :model="form"    label-width="100px">
            <el-form-item label="员工编码" prop="personNum" v-if="activeName==='AD用户同步'||activeName==='OA员工同步'||activeName==='考勤打卡同步'">
                <el-input v-model="form.personNum">
                </el-input>
            </el-form-item>
            <el-form-item   v-if="activeName==='OA组织同步'" >

            </el-form-item>
            </el-form-item>
            <el-form-item label="时间" prop="startDate">
                <div style="display: flex;justify-content: start">
                    <el-date-picker v-model="form.startDate" type="date" placeholder="请选择">
                    </el-date-picker>
                    -
                    <el-date-picker v-model="form.endDate" type="date" placeholder="请选择">
                    </el-date-picker>
                </div>
            </el-form-item>
            <el-form-item >
                <el-button @click="dialogVisible = false" size="small">取 消</el-button>
                <el-button :disabled="submissionFlag" type="primary" @click="handleSubmit"    size="small">确 定</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

</div>

</body>
<script>
  const apiUrl = `http://localhost:8081`
  var app = new Vue({
    el: '#app',
    data() {
      return {
          url:apiUrl+'/index',
        rules: {
          num: [
            { required: true, message:'员工编码不可以为空' , trigger: 'blur' }
          ],
          personNum: [
            { required: true, message: '员工编码不可以为空', trigger: 'blur' }
          ],
          startDate:[ { required: true, message: '开始时间不可以为空', trigger: 'blur' }],
          endDate:[ { required: true, message: '结束时间不可以为空', trigger: 'blur' }],
        },
        dialogVisible:false,
          submissionFlag:false,
        form: {
          num: '',
          personNum: '',
          deptNum:'',
          startDate: dayjs().add(-6, 'day'),
          endDate: dayjs().add(0, 'day'),
        },
        tabList: ['AD用户同步', 'OA组织同步', 'OA岗位同步', 'OA员工同步', '考勤打卡同步', '备份员工信息','备份员工历史','备份部门信息','备份职务信息','备份职位信息'],
        tabPosition: 'left',
        activeName: 'AD用户同步',
      }
    },
    methods: {
      handleSubmit () {

        if(this.form.endDate){
          this.$refs['form'].validate(async valid => {
            if (valid) {
              let res
                //点击提交,按钮置灰
                this.submissionFlag=true
                this.option =this.$message({
                    message:this.activeName+"正在执行中,请稍等！",
                    type:'warning',
                    duration:0
                })
              if(this.activeName==='OA员工同步'){
                res = await axios({
                  // url: `${apiUrl}/OA/synPerson`,
                  url: `${apiUrl}/new/person`,
                  method: 'get',
                  params:{
                      startDate:dayjs(this.form.startDate).format("YYYY-MM-DD"),
                      endDate:dayjs(this.form.endDate).format("YYYY-MM-DD"),
                      personNumber:this.form.personNum
                  },
                  headers: {
                    // Authorization: this.token,
                    'Content-Type': 'application/json;charset=utf-8'
                  }
                }).then(res=>{
                    if(res.data.code == 1){
                        this.$message.success(res.data.message)
                    }else {
                        this.$message.error(res.data.message)
                    }

                })
              }

                if(this.activeName==='AD用户同步'){
                    res = await axios({
                        url: `${apiUrl}/syncAD`,
                        method: 'get',
                        params:{
                            startDate:dayjs(this.form.startDate).format("YYYY-MM-DD"),
                            endDate:dayjs(this.form.endDate).format("YYYY-MM-DD"),
                            personNumber:this.form.personNum
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 200){
                            this.$message.success(res.data.data)
                        }else {
                            this.$message.error(res.data.data)
                        }

                    })

                }

                if(this.activeName==='考勤打卡同步'){
                    res = await axios({
                        url: `${apiUrl}/attendance`,
                        method: 'get',
                        params:{
                            attNum:this.form.personNum,
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='OA组织同步'){
                    res = await axios({
                        // url: `${apiUrl}/admin`,
                        url: `${apiUrl}/new/admin`,
                        method: 'get',
                        params:{
                            statrTime:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endTime:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='OA岗位同步'){
                    res = await axios({
                        // url: `${apiUrl}/position`,
                        url: `${apiUrl}/new/position`,
                        method: 'get',
                        params:{
                            statrTime:dayjs(this.form.startDate).format("YYYY-MM-DD"),
                            endTime:dayjs(this.form.endDate).format("YYYY-MM-DD")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='备份员工信息'){
                    res = await axios({
                        url: `${apiUrl}/local/savePerson`,
                        method: 'get',
                        params:{
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='备份员工历史'){
                    res = await axios({
                        url: `${apiUrl}/local/savePersonOffice`,
                        method: 'get',
                        params:{
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='备份部门信息'){
                    res = await axios({
                        url: `${apiUrl}/local/saveDept`,
                        method: 'get',
                        params:{
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='备份职务信息'){
                    res = await axios({
                        url: `${apiUrl}/local/saveJob`,
                        method: 'get',
                        params:{
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                if(this.activeName==='备份职位信息'){
                    res = await axios({
                        url: `${apiUrl}/local/savePosition`,
                        method: 'get',
                        params:{
                            bigDat:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
                            endDat:dayjs(this.form.endDate).format("YYYY-MM-DD HH:mm:ss")
                        },
                        headers: {
                            // Authorization: this.token,
                            'Content-Type': 'application/json;charset=utf-8'
                        }
                    }).then(res=>{
                        if(res.data.code == 1){
                            this.$message.success(res.data.message)
                        }else {
                            this.$message.error(res.data.message)
                        }

                    })

                }

                this.dialogVisible = false,
                this.submissionFlag=false,
                    this.option ? this.option.close():''
            }
          })
        }else{
          this.$message({
            message: '结束时间不能为空哦',
            type: 'warning'
          });
        }

      },
      execute(row){
        // if( this.$refs['form']){
        //   this.$refs['form'].resetFields();
        // }
        //
        // this.$confirm(`确认要执行${row.des}嘛?`, '警告', {
        //   confirmButtonText: '确定',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // }).then(() => {
        //
        //   // 接口
        //   // cancelSetGroup(row.id).then(response => {
        //   //   this.getSignalList()
        //   // })
        // })
        this.form = {
          personNum:'',
          num:'',
          deptNum:'',
          startDate: dayjs().add(-6, 'day'),
          endDate: dayjs().add(0, 'day'),
        }
        this.dialogVisible = true
      },
      async handleQuery(){
        this.loading = true
        let res = await axios({
          url: `${apiUrl}/attendance`,
          method: 'get',
          headers: {
            // Authorization: this.token,
            'Content-Type': 'application/json;charset=utf-8'
          }
        })
        console.log('接口返回',res)
        // offlinePageForList(this.pagination).then(res => {
        //   res.data.content.forEach(ele=>{
        //     ele.time = dayjs(parseInt(ele.created)).format('YYYY-MM-DD HH:mm:ss')
        //   })
        //   this.tableData =res.data.content
        //   this.pagination.total = parseFloat(res.data.totalElements)
        //   if (parseInt(res.data.totalElements) > 0 && res.data.content.length == 0) {
        //     this.form.page = 0
        //     this.handleQuery()
        //   }
        // }).finally(() => {
        //   this.loading = false
        // })
      },
      handleClick(tab, event) {
          this.form ={
              startDate: dayjs().add(-6, 'day'),
              endDate: dayjs().add(0, 'day'),
          }
      }
    },
    mounted() {

    }
  })
</script>
</html>
