<template>
  <div>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <!--      <RaddarChart :risk-data="riskData" />-->
    </el-row>
    <el-dialog :visible.sync="dialogWarnEnable" :show-close="false" title="提示" width="600px">
      <div style="margin-right: auto; margin-left: auto ; width: 400px ;height: auto; font-size: large ;text-indent: 30px" >
        <span>您的客户(</span>
        <span v-text="custom"/>
        <span>)实施时间已超过三个月，请您尽快联系实施人员进行沟通</span>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="closeWarn">确 认</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormEdit" :before-close="handleClose" :append-to-body="true" title="登录的密码强度为弱，请修改密码！" width="600px">
      <div style="padding:0 40px">
        <el-form ref="userForm" :model="userForm" :rules="userFormRules" status-icon label-width="100px">
          <el-form-item label="用户名" >
            <el-input v-model="userForm.USERNAME" disabled placeholder="默认用户手机号码..." />
          </el-form-item>
          <el-form-item label="新密码：" prop="newpwd">
            <el-input v-model="userForm.newpwd" type="password" auto-complete="off" />
          </el-form-item>
          <el-form-item label="确认密码：" prop="newpassword1">
            <el-input v-model="userForm.newpassword1" type="password" auto-complete="off" />
          </el-form-item>
        </el-form>
        <div style="text-align: center;margin-top:30px">
          <el-button type="primary" @click.native.prevent="editUser">确认修改</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import RaddarChart from './components/RaddarChart'
/* eslint-disable */
import { requestFN } from '@/utils/request'
import { MessageBox } from 'element-ui'
export default {
  components: {
    // RaddarChart
  },
  data() {
    const validatePass = (rule, value, callback) => {
      if (value.length < 1) {
        callback(new Error('密码不能为空'))
      }
      if (value) {
        var reg1 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*.])[\da-zA-Z~!@#$%^&*.]{8,}$/
        if (!reg1.test(value)) {
          callback(new Error('密码必须是8位以上、必须包含大小写字母、数字、特殊符号'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    const validatePass2 = (rule, value, callback) => {
      if (this.userForm.newpwd != '' && value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.userForm.newpwd) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      dialogFormEdit: false,
      userForm: {
        USERNAME: '',
        newpwd: '',
        newpassword1: ''
      },
      userFormRules: {
        newpwd: [
          { required: true, validator: validatePass, trigger: 'blur' }
        ],
        newpassword1: [
          { required: true, validator: validatePass2, trigger: 'blur' }
        ]
      },
      dialogWarnEnable: false,
      custom: '',
      riskData: {}
    }
  },
  created() {
    // this.getRiskData()
    this.implementationReminder()
    if (JSON.parse(sessionStorage.getItem('user')).passwordType === '0') {
      this.dialogFormEdit = true
    }
    this.userForm.USERNAME = JSON.parse(sessionStorage.getItem('user')).USERNAME
  },
  methods: {
    handleClose(done) {
      if (!this.dialogFormEdit) {
        done()
      }
    },
    // 是否实施逾期提醒
    implementationReminder(){
      requestFN(
        '/corpinfo/implementationReminder'
      ).then((data) => {
        if (data.data){
          this.custom = data.data
          this.dialogWarnEnable = true
        } else {
          return false
        }
      }).catch((e) => {
      })
    },
    editUser() {
      this.$refs.userForm.validate(valid => {
        if (valid) {
          requestFN(
            '/user/editUserOwn',
            { USER_ID: this.USER_ID,
              USERNAME: this.userForm.USERNAME,
              PASSWORD: this.userForm.newpwd,
              NAME: this.userForm.NAME,
              PHONE: this.userForm.PHONE,
              EMAIL: this.userForm.EMAIL,
              DEPARTMENT_ID: this.DEPARTMENT_ID,
              POST_ID: this.userForm.POST_ID,
              BZ: this.userForm.BZ,
              OPERATIONTYPE: '1' }
          ).then((data) => {
            MessageBox.alert('密码修改成功,请重新登录！', {
              confirmButtonText: '确定',
              callback: action => {
                sessionStorage.clear()
                this.goOut()
                location.reload()
              }
            })
            this.dialogFormEdit = false
          }).catch((e) => {
          })
        } else {
          return false
        }
      })
    },
    // 下线
    goOut: function(msg) {
      requestFN(
        '/main/logout',
        {}
      ).then((data) => {
        // this.fwebsocket.close()
        sessionStorage.clear()
        window.location.href = localStorage.getItem('out_url')
        // window.location.href = 'http://192.168.0.112:8080/'
      })
        .catch((e) => {
          // this.fwebsocket.close()
          sessionStorage.clear()
          window.location.href = localStorage.getItem('out_url')
          // window.location.href = 'http://192.168.0.112:8080/'
        })
    },
    closeWarn(){
      this.dialogWarnEnable = false
      this.custom = ''
    },
    getRiskData() {
      requestFN(
        '/statistics/index',
        {
        }
      ).then((data) => {
        this.riskData = data.indexlist
      }).catch((e) => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  // border: 1px solid red;
  padding: 15px;
  background-color: rgb(240, 242, 245);
  position: relative;
  height: 100%;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 0px;
    .chart-search {
      text-align: right;
      align-items: center;
    }
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
