<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="安全手机号">
        {{ phoneFilter(form.phone) }}
      </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.isReturnPwd">退款</el-checkbox>
        <el-checkbox v-model="form.isMemberInPwd">余额充值</el-checkbox>
        <el-checkbox v-model="form.isMemberReturnPwd">余额退款</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 ShopApi from "@/api/account/shop";

import commonApi from "@/api/account/common";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      disabled: true,
      form: {},
    };
  },
  mounted() {
    this.getinfo();
  },
  methods: {
    jiantingshuru(e) {
      this.form.password = e.substr(0, 6);
    },
    // 获取用户信息
    async getinfo() {
      const res = await ShopApi.get();
      this.form = res;
      this.form.isReturnPwd = this.form.isReturnPwd == 1 ? true : false;
      this.form.isMemberInPwd = this.form.isMemberInPwd == 1 ? true : false;
      this.form.isMemberReturnPwd = this.form.isMemberReturnPwd == 1 ? true : false;
    },
    async submitHandle() {
      if (!this.form.prepareAmount) {
        ElMessage({
          message: "请输入验证码",
        });
        return;
      }
      if (!this.form.password) {
        ElMessage({
          message: "请输入密码",
        });
        return;
      }
      const res = await ShopApi.edit({
        id: this.form.id,
        code: this.form.prepareAmount,
        operationPwd: this.form.password,
      });

      this.form.prepareAmount = "";
      this.form.password = "******";
      this.disabled = true;
      ElMessage({
        message: "修改成功",
        type: "success",
      });
    },
    async submitHandles() {
      const res = await ShopApi.edit({
        // code: this.form.prepareAmount,
        id: this.form.id,
        // status:this.form.status,
        isReturnPwd: this.form.isReturnPwd == true ? 1 : 0,
        isMemberInPwd: this.form.isMemberInPwd == true ? 1 : 0,
        isMemberReturnPwd: this.form.isMemberReturnPwd == true ? 1 : 0,
      });
      ElMessage({
        message: "修改成功",
        type: "success",
      });
    },
    resetting() {
      this.form.password = "";
      this.disabled = false;
    },
    async onSubmit() {
      const res = await commonApi.sms({ type: "editShopInfoOpePwd" });
      ElMessage({
        message: "发送成功",
        type: "success",
      });
    },
    phoneFilter(d) {
      let str = d + "";
      return str.substr(0, 3) + "***" + str.substr(-4);
    },
  },
};
</script>