<template>
    <div>
        <el-form ref="form" :model="form" label-width="120px" label-position="left">

            <el-form-item label="操作密码">
                <el-input v-model="form.password" type="number" @input="jiantingshuru" :disabled="disabled"
                    :placeholder="disabled ? '******' : '请输入操作密码'" style="width: 200px;"></el-input>
                <el-button type="primary" @click="resetting">重置</el-button>
            </el-form-item>
            <el-form-item label="安全手机号">
                {{ form.phone | phoneFilter }}
            </el-form-item>
            <el-form-item label="验证码">
                <el-input v-model="form.prepareAmount" placeholder="点击发送" style="width: 200px;"></el-input>
                <el-button type="primary" @click="onSubmit">发送</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitHandle">保存 </el-button>
            </el-form-item>
        </el-form>
        <hr />
        <el-form ref="form" :model="form" label-width="120px" label-position="left">
            <el-form-item label="校验安全密码">
                <el-checkbox v-model="form.isReturn">退款</el-checkbox>
                <el-checkbox v-model="form.isMemberIn">会员充值</el-checkbox>
                <el-checkbox v-model="form.isMemberReturn">会员退款</el-checkbox>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitHandles">保存 </el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import md5 from 'js-md5';
import { tbShopInfo } from "@/api/user";
import { sendMsg, modfiyUserInfo, tbShopInfoPUT } from "@/api/securitySetting"
export default {
    data() {
        return {
            disabled: true,
            form: {
            },
        }
    },
    mounted() {
        this.getinfo()
    },
    methods: {
        jiantingshuru(e) {
            this.form.password = e.substr(0, 6)
        },
        // 获取用户信息
        async getinfo() {
            const shopId = localStorage.getItem("shopId");
            const res = await tbShopInfo(shopId);
            this.form = res
            this.form.isReturn = this.form.isReturn == 1 ? true : false
            this.form.isMemberIn = this.form.isMemberIn == 1 ? true : false
            this.form.isMemberReturn = this.form.isMemberReturn == 1 ? true : false
        },
        async submitHandle() {

            if (!this.form.prepareAmount) {
                this.$message({
                    message: "请输入验证码"
                })
                return
            }
            if (!this.form.password) {
                this.$message({
                    message: "请输入密码"
                })
                return
            }
            const res = await modfiyUserInfo({
                code: this.form.prepareAmount,
                pwd: md5(this.form.password),
            });
            console.log(222)


            this.form.prepareAmount = ''
            this.form.password = "******"
            this.disabled = true
            this.$message({
                message: '修改成功',
                type: 'success'
            })
        },
        async submitHandles() {
            const res = await tbShopInfoPUT({
                // code: this.form.prepareAmount,
                // id: this.form.id,
                // status:this.form.status,
                ...this.form,
                isReturn: this.form.isReturn == true ? 1 : 0,
                isMemberIn: this.form.isMemberIn == true ? 1 : 0,
                isMemberReturn: this.form.isMemberReturn == true ? 1 : 0,
            });
            this.$message({
                message: '修改成功',
                type: 'success'
            })
        },
        resetting() {
            this.form.password = ''
            this.disabled = false
        },
        async onSubmit() {
            const res = await sendMsg();
            this.$message({
                message: '发送成功',
                type: 'success'
            })
        },
    },
    filters: {
        phoneFilter(d) {
            let str = d + ''
            return str.substr(0, 3) + '***' + str.substr(-4)
        }
    }
}
</script>