<template>
  <div>
    <el-dialog title="重置密码"
               :visible.sync="isModifyPassword"
               width="500px"
               :before-close="handleClose">
      <div class="box">

        <el-form :model="form"
                 label-width="100px"
                 ref="form">
          <el-form-item label="新密码：">
            <el-input v-model="form.password"
                      maxlength="16"
                      show-word-limit
                      auto-complete="off"
                      style="width:200px"></el-input>

          </el-form-item>、
          <el-form-item label="确认密码：">
            <el-input v-model="form.confirmPassword"
                      maxlength="16"
                      show-word-limit
                      auto-complete="off"
                      style="width:200px"></el-input>

          </el-form-item>
          <div class="zhu">注：密码应为数字+字母混排,字母区分大小写</div>
        </el-form>

        <div>
          <el-button @click="submitAudit"
                     type="primary"
                     style="margin-top:30px">提交</el-button>
          <el-button @click="handleClose"
                     class="quxiao">取消</el-button>
        </div>

      </div>

    </el-dialog>
  </div>
</template>

<script>
import { getRechargType } from '@/libs/common/constant'
import { selectListALL } from '@/utils/json'
export default {
  name: '',
  props: {
    isModifyPassword: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        password: '',
        confirmPassword: ''
      }
    }
  },
  watch: {
    isModifyPassword(val) {
      if (val) {
        for (let key in this.form) {
          this.form[key] = ''
        }
      }
    }
  },
  methods: {
    selectListALL(myJson) {
      return selectListALL(myJson)
    },
    // 验证密码
    validateString(string) {
      var pattern = /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]+$/
      return pattern.test(string)
    },
    submitAudit() {
      if (!this.validateString(this.form.password)) {
        this.$message.error('密码格式错误！！！')
        return
      }
      if (this.form.password != this.form.confirmPassword) {
        this.$message.error('两次密码输入不正确！！！')
        return
      }
      console.log('这里执行了')
      this.$emit('modifyPsw', this.form)
    },
    handleClose() {
      this.$emit('noModify')
    },
    go() {
      this.$emit('goRecharge')
    }
  }
}
</script>
<style lang="scss" scoped>
.box {
  padding-left: 70px;

  .titleNmae {
    text-align: center;
    font-size: 18px;
    margin-bottom: 5px;
  }
  .quxiao {
    margin-left: 145px;
  }
}
.zhu {
  margin-top: 5px;
  margin-left: 10px;
  color: red;
}
</style>
