<template>
    <div class="container">
        <el-steps :space="180" :active="2" align-center>
            <el-step title="验证当前手机号"></el-step>
            <el-step title="修改交易密码"></el-step>
            <el-step title="修改完成"></el-step>
        </el-steps>
        <el-form :label-position="labelPosition" ref="form2" label-width="290px" :model="ruleForm" :rules="rules">
            <el-form-item label="新交易密码" prop="password">
                <el-input
                    style="width: 300px"
                    type="password"
                    v-model="ruleForm.password"
                    placeholder="请输入新密码"
                    autocomplete="off"
                ></el-input>
            </el-form-item>
            <el-form-item label="确认新密码" prop="checkPass">
                <el-input
                    style="width: 300px"
                    type="password"
                    v-model="ruleForm.checkPass"
                    placeholder="请再次输出新密码"
                    autocomplete="off"
                ></el-input>
            </el-form-item>
        </el-form>
        <div class="btn1">
            <div class="btn2">
                <el-button type="primary" @click="phoneSend">确认</el-button>
                <div class="btn3" @click="Jump">返回</div>
            </div>
        </div>
    </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
    props: {
        code: {
            type: Object
        }
    },
    data() {
        return {
            labelPosition: 'right',
            ruleForm: {
                password: ''
            },
            rules: {
                checkPass: [
                    {
                        validator: (rule, value, callback) => {
                            if (value !== this.ruleForm.password) {
                                callback(new Error('两次密码输入不一致'));
                            } else {
                                callback();
                            }
                        },
                        trigger: 'blur'
                    },
                    { min: 6, max: 6, message: '密码长度在 6 到 6 个数字', trigger: 'blur' }
                ]
            }
        };
    },
    computed: {
        ...mapState(['userInfo'])
    },
    methods: {
        phoneSend() {
            this.$refs.form2.validate(valid => {
                if (valid) {
                    this.$http
                        .post('/user/setTradeCode', {
                            token: this.code,
                            tradeCode: this.ruleForm.password
                        })
                        .then(() => {
                            this.$message.success('设置成功');
                            setTimeout(() => {
                                this.$router.push('/transactionsuccess');
                            }, 1000);
                        })
                        .catch(e => {
                            if (e) {
                                this.$message(e.error);
                            }
                        });
                }
            });
        },
        Jump() {
            this.$emit('Jump');
        }
    }
};
</script>
<style>
input[type='number'] {
    -moz-appearance: textfield;
}
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0;
}
</style>
<style lang="less" scoped>
/deep/ .el-steps {
    margin-left: 329px;
}
/deep/.el-step:nth-child(1) {
    .el-step__icon {
        background: linear-gradient(143deg, @prim 0%, @warn 100%, @warn 100%);
        color: #ffffff;
        border: 0;
    }
}
/deep/.el-step:nth-child(2) {
    .el-step__icon {
        background: linear-gradient(143deg, @prim 0%, @warn 100%, @warn 100%) !important;
        color: #ffffff;
        border: 0;
    }
}
/deep/.el-step:nth-child(3) {
    .el-step__icon {
        background: #c8c9cc;
        color: #ffffff;
        border: 0;
    }
}
/deep/ .el-form-item__label {
    font-size: 13px !important;
}
/deep/ .el-step__title.is-process {
    font-weight: 400;
    color: #939599;
}
/deep/ .el-step__title.is-wait {
    color: #939599;
}
/deep/ .el-form-item__error {
    margin-left: 176px;
}

.container {
    .btn1 {
        margin-left: 10px;
        .btn2 {
            display: flex;
            justify-content: center;
            margin-top: 87px;
            .btn3 {
                width: 130px;
                height: 36px;
                background: #c4c7cc;
                border-radius: 4px;
                cursor: pointer;
                color: #ffffff;
                font-size: 13px;
                text-align: center;
                line-height: 38px;
                margin-left: 20px;
            }
        }
    }
}
</style>
