123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="title"
- :center="true"
- align="left"
- top="25vh"
- width="600px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- @close="closeModel"
- >
- <el-card style="margin-top:-20px">
- <el-row :gutter="10">
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- :rules="rulesThis"
- label-width="110px"
- class="demo-ruleForm"
- >
- <el-form-item prop="password" label="新密码:">
- <el-input
- ref="password"
- v-model="ruleForm.password"
- placeholder="新密码"
- name="password"
- type="password"
- maxlength="6"
- tabindex="1"
- autocomplete="on"
- />
- </el-form-item>
- <el-form-item prop="confirmPassword" label="确认密码:">
- <el-input
- ref="confirmPassword"
- v-model="ruleForm.confirmPassword"
- placeholder="确认密码"
- name="confirmPassword"
- type="password"
- tabindex="1"
- maxlength="6"
- autocomplete="on"
- />
- </el-form-item>
- </el-form>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-button type="primary" @click="submitForm">保 存 </el-button>
- <el-button @click="showModelThis = false">{{
- isDetail ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/mobile/park";
- import { isnumber, isAlphanumeric, validAlphabets } from "@/utils/validate";
- import resToken from "@/mixins/resToken";
- export default {
- name: "Account",
- props: ["showModel", "id", "isDetail"],
- mixins: [resToken],
- data() {
- const validateNewPassword = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("新密码不能为空!"));
- } else {
- if (value.length !== 6) {
- callback(new Error("密码为2位字母+4位数字!"));
- } else {
- let a = value.slice(0, 2);
- let b = value.slice(2, 4);
- if (!isnumber(b)) {
- callback(new Error("密码为2位字母+4位数字!"));
- } else if (!validAlphabets(a)) {
- callback(new Error("密码为2位字母+4位数字!"));
- } else {
- callback();
- }
- }
- }
- };
- const validateConfirmPassword = (rule, value, callback) => {
- if (value === "") {
- callback(new Error("确认密码不能为空!"));
- } else {
- if (this.ruleForm.password !== value) {
- callback(new Error("确认密码与新密码不一致!"));
- } else {
- callback();
- }
- }
- };
- return {
- roleList: [],
- loading: false,
- title: "重置密码",
- showModelThis: this.showModel,
- ruleForm: {
- id: this.id,
- password: "",
- confirmPassword: "",
- },
- rulesThis: this.rules,
- rules: {
- password: [
- { required: true, trigger: "blur", validator: validateNewPassword },
- ],
- confirmPassword: [
- {
- required: true,
- trigger: "blur",
- validator: validateConfirmPassword,
- },
- ],
- },
- };
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.$emit("cancel");
- }
- },
- },
- methods: {
- closeModel() {
- console.log("closeModel!!");
- },
- async initForm() {
- this.rulesThis = this.rules;
- await this.resetForm();
- },
- async resetForm() {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- this.ruleForm = {
- id: this.id,
- password: "",
- confirmPassword: "",
- };
- }
- });
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- this.loading = true;
- let obj = JSON.parse(JSON.stringify(this.ruleForm));
- delete obj["confirmPassword"];
- const res = await asyncRequest.setpwd(obj);
- this.loading = false;
- if (res && res.code === 0) {
- this.$notify.success({
- title: "密码修改成功!",
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- this.$emit("refresh");
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .account {
- }
- </style>
|