<template>
  <div id="login">
    <!-- <h1 class="logot-title">
        美容美发单店版平台管理系统
      </h1> -->
    <div class="login">
      <!-- <img src="../../image/title.png" alt=""> -->
      <div v-if="showLogin==0">
        <h2>账号密码登录</h2>
        <el-form :model="form" status-icon ref="form" label-width="100px" class="demo-user" @submit.native.prevent>
          <el-form-item style="color: red" label="手机号码：" :rules="[
              { required: true, message: '请输入账号', trigger: 'blur' },
            ]" prop="mobilePhone">
            <el-input type="text" maxlength="11" v-model="form.mobilePhone" autocomplete="off" @keyup.enter.native="openPass"></el-input>
          </el-form-item>
          <el-form-item label="密码：" :rules="[
              { required: true, message: '请输入密码', trigger: 'blur' },
            ]" prop="password">
            <el-input label="密码" type="password" v-focus ref="password" v-model="form.password" autocomplete="off" @keyup.enter.native="submitPassword"></el-input>
          </el-form-item>
          <el-form-item>
            <router-link :to="route">
              <el-button plain class="log" size="mini" type="primary" @click="submitPassword()" @keydown.enter="submitPassword" :disabled="logindisabled" :loading="loading">登录
              </el-button>
            </router-link>
            <el-button size="mini" type="primary" @click="clear" plain>清空
            </el-button>
            <el-button plain class="log" size="mini" type="primary" @click="getPassword()">密码</el-button>
          </el-form-item>
          <div class="cut">
            <p class="span" @click="showLogin=1,loading=false">
              手机号登录
              <i class="el-icon-arrow-right"></i>
            </p>
            <p class="pointer text-white" @click="showLogin=2,loading=false">
              总店用户登录
              <i class="el-icon-arrow-right"></i>
            </p>
          </div>
        </el-form>
      </div>
      <div v-if="showLogin==1">
        <h2>手机号登录</h2>
        <el-form>
          <el-form :model="form" status-icon ref="user" label-width="100px" class="demo-user" @submit.native.prevent>
            <el-form-item label="手机号码：" prop="mobilePhone">
              <el-input @blur="staffOne" v-model="form.mobilePhone" placeholder="请输入手机号" maxlength="11"></el-input>
            </el-form-item>
            <el-form-item label="验证码：" prop="code">
              <el-input style="margin-bottom: 15px" v-model="form.passCode" placeholder="请输入验证码">
              </el-input><br />
              <el-button class="sendcode" type="primary" plain @click="sendcode" :disabled="disabled" v-if="disabled == false" size="mini">发送验证码</el-button>
              <el-button type="primary" plain @click="sendcode" :disabled="disabled" size="mini" v-if="disabled == true">{{ btntxt }}</el-button>
            </el-form-item>
            <el-form-item>
              <el-button class="log" size="mini" type="primary" @keydown.enter="phonesubmit" @click="phonesubmit()" :loading="loading">登录</el-button>
              <el-button size="mini" type="primary" @click="clear" plain>清空
              </el-button>
            </el-form-item>
          </el-form>
          <div class="cut">
            <span class="span" @click="showLogin=0,loading=false">
              密码登录
              <i class="el-icon-arrow-right"></i>
            </span>
            <p class="pointer text-white" @click="showLogin=2,loading=false">
              总店用户登录
              <i class="el-icon-arrow-right"></i>
            </p>
          </div>
        </el-form>
      </div>
      <div v-if="showLogin==2">
        <h2>总店用户登录</h2>
        <el-form :model="form" status-icon ref="form" label-width="100px" class="demo-user" @submit.native.prevent>
          <el-form-item style="color: red" placeholder="必须是总店的员工账号" label="手机号码：" :rules="[
              { required: true, message: '请输入账号', trigger: 'blur' },
            ]" prop="mobilePhone">
            <el-input type="text" maxlength="11" v-model="form.mobilePhone" autocomplete="off" @keyup.enter.native="openPass"></el-input>
          </el-form-item>
          <el-form-item label="密码：" :rules="[
              { required: true, message: '请输入密码', trigger: 'blur' },
            ]" prop="password">
            <el-input label="密码" type="password" v-model="form.password" v-focus ref="password" autocomplete="off" @keyup.enter.native="submitPassword"></el-input>
          </el-form-item>
          <el-form-item>
            <router-link :to="route">
              <el-button plain class="log" size="mini" type="primary" @click="submitPassword()" @keydown.enter="submitPassword" :disabled="logindisabled" :loading="loading">登录
              </el-button>
            </router-link>
            <el-button size="mini" type="primary" @click="clear" plain>清空 </el-button>
            <el-button plain class="log" size="mini" type="primary" @click="getPassword()">密码</el-button>
          </el-form-item>
          <div class="cut">
            <span class="span" @click="showLogin=1,loading=false">
              手机号登录
              <i class="el-icon-arrow-right"></i>
            </span>
            <p class="pointer text-white" @click="showLogin=0,loading=false">
              密码登录
              <i class="el-icon-arrow-right"></i>
            </p>
          </div>
        </el-form>
      </div>
    </div>
    <storelist ref="storelist" @storeData="storeData"></storelist>
    <choice ref="choice" @radioData="radioData"></choice>
  </div>
</template>

<script>
import {
  phoneLogin,
  phonePassLogin,
  getSmsCode,
  staffls,
  storeLists,
  getSmsCodesPassword,
  phonePassLoginzd,
  phonePassLoginNew,
  phonePassLoginNews,
} from "../api/login.js";
import { storeParaList } from "../api/storeManage.js";
import { storeOne } from "../api/eashier";
import { setCookie, getCookie, delCookie } from "../utils/utils";
import { partten } from "../../partten/index";
import storelist from "./components/storelist.vue";
import choice from "./components/radio.vue";
export default {
  inject: ["reload"],
  components: { storelist, choice },
  data() {
    return {
      loading: false,
      showLogin: 0,
      form: {}, //主对象
      disabled: false,
      time: 0,
      btntxt: "重新发送",
      logindisabled: false,
      onpresscTime: 0,
      route: "",
      codeData: {},
      hello: "hello",
      hours: new Date().getHours(),
      storeId: null,
      storeName: "",
      storeNum: "",
      storeList: [],
      rowIndex: -1,
      rowItem: null,
      passText: "",
      rowForm: {},
      loginText: "",
    };
  },
  methods: {
    openPass() {
      this.$refs.password.focus();
      this.$refs.password.select();
    },
    staffOne() {
      if (partten.phoneNum.test(this.form.mobilePhone)) {
        let form = {};
        form.mobilePhone = this.form.mobilePhone;
        this.loginText = "验证码登录";
        this.$refs.storelist.show(form, "登录");
      } else {
        this.$alert("请输入正确格式的手机号", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => {
            this.loading = false;
          },
        });
      }
    },
    getPassword() {
      this.$confirm("获取当前手机号密码(短信方式发送)", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "success",
        cancelButtonClass: "cancelbtnFalses",
        confirmButtonClass: "confirmbtnFalses",
      })
        .then(() => {
          if (partten.phoneNum.test(this.form.mobilePhone)) {
            let form = { mobilePhone: this.form.mobilePhone };
            this.$refs.storelist.show(form, "获取密码");
          } else {
            this.$alert("请先输入正确手机号", "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => {},
            });
          }
        })
        .catch(() => {});
    },
    submitPassword() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
      }, 3000);
      if (partten.phoneNum.test(this.form.mobilePhone)) {
        phonePassLoginNew(this.form).then((res) => {
          if (res.code == "000000") {
            console.log(res.data);
            if (res.data.token) {
              localStorage.setItem("token", res.data.token);
              sessionStorage.setItem("token", res.data.token);
              setCookie("token", res.data.token, 120); //设置
              this.toHome(res);
            } else {
              console.log("选择");
              this.$refs.choice.show(res.data.baseStores);
            }
          } else {
            this.$alert(res.message, "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => {
                this.loading = false;
              },
            });
          }
        });
      } else {
        this.$alert("请输入正确格式的手机号", "提示", {
          confirmButtonText: "确定",
          confirmButtonClass: "confirmbtnFalses",
          type: "warning",
          center: true,
          callback: (action) => {
            this.loading = false;
          },
        });
      }
    },
    radioData(v) {
      let form = { ...this.form };
      form.storeId = v.id;
      form.storeName = v.storeName;
      form.storeNum = v.storeNum;
      phonePassLoginNews(form).then((res) => {
        if (res.code == "000000") {
          localStorage.setItem("token", res.data.token);
          sessionStorage.setItem("token", res.data.token);
          setCookie("token", res.data.token, 120); //设置
          this.toHome(res);
        } else {
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {
              this.loading = false;
            },
          });
        }
      });
    },
    toHome(res) {
      this.$router.push("/storeParameters");
      if (this.hours < 9) {
        this.hello = "早上好！";
      } else if (this.hours < 12) {
        this.hello = "上午好！";
      } else if (this.hours < 15) {
        this.hello = "中午好！";
      } else if (this.hours < 19) {
        this.hello = "下午好！";
      } else {
        this.hello = "晚上好！";
      }
      this.$notify({
        title: this.hello + " " + res.data.staffName,
        message: "( " + res.data.roleName + " ) " + res.data.storeName,
        type: "success",
        duration: 3000,
        offset: 100,
      });
      this.setPara();
      var parentId = "";
      storeOne({
        id: res.data.storeId,
      }).then((res) => {
        if (res.code == "000000") {
          sessionStorage.setItem("storeInfo", JSON.stringify(res.data));
          if (res.data.parentId == null) {
            /* ------------ sessionStorage.setItem("parentId", res.data.id); ------------ */
            sessionStorage.setItem("parentName", res.data.storeName);
            sessionStorage.setItem("parentName", res.data.storeId);
            sessionStorage.setItem("headOffice", 1);
            let storeIds = [];
            storeIds.push(res.data.id);
            sessionStorage.setItem("storeIds", JSON.stringify(storeIds));
            sessionStorage.setItem("storeIdLists", JSON.stringify(storeIds));
          } else {
            sessionStorage.setItem("headOffice", 0);
            localStorage.setItem("headOffice", 0);
            sessionStorage.setItem("parentId", res.data.parentId);
            parentId = res.data.parentId;
            let storeIdLists = [parentId, res.data.id];
            sessionStorage.setItem(
              "storeIdLists",
              JSON.stringify(storeIdLists)
            );
            storeLists({
              id: res.data.id,
              parentId: res.data.parentId,
            }).then((res) => {
              if (res.code == "000000") {
                let storeIds = [];
                storeIds.push(parentId);
                res.rows.forEach((item) => {
                  storeIds.push(item.id);
                });
                sessionStorage.setItem("storeIds", JSON.stringify(storeIds));
              } else {
                this.$alert("加载总店/分店信息 :" + res.message, "提示", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => {},
                });
              }
            });
            storeOne({
              id: res.data.parentId,
            }).then((res) => {
              if (res.code == "000000") {
                sessionStorage.setItem("parentName", res.data.storeName);
              } else {
                this.$alert("加载总店信息 :" + res.message, "提示", {
                  confirmButtonText: "确定",
                  confirmButtonClass: "confirmbtnFalses",
                  type: "warning",
                  center: true,
                  callback: (action) => {},
                });
              }
            });
          }
        } else {
          this.$alert("加载门店信息 :" + res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
      sessionStorage.setItem("keyPath", "25");
      sessionStorage.setItem("indexPath", "home");
      sessionStorage.setItem("staffName", res.data.staffName);
      sessionStorage.setItem("roleName", res.data.roleName);
      sessionStorage.setItem("storeName", res.data.storeName);
      sessionStorage.setItem("storeId", res.data.storeId);
      sessionStorage.setItem("mobilePhone", res.data.mobilePhone);
      sessionStorage.setItem("userInfo", JSON.stringify(res.data));
      sessionStorage.setItem("list", JSON.stringify(res.data.list));
    },

    //选中门店返回方法
    storeData(v) {
      console.log(v);
      this.loading = false;
      this.rowForm = { ...v };
      if (this.showLogin == 0) {
        this.submit();
      }
      if (this.showLogin == 1) {
        if (this.loginText == "验证码登录") {
        } else {
          this.phonesubmit();
        }
      }
      if (this.showLogin == 2) {
        this.submitzd();
      }
    },
    clear() {
      this.form = {
        passCode: null,
        mobilePhone: null,
        password: null,
      };
      this.loading = false;
    },
    //点击选中
    rowClick(row) {
      this.rowIndex = row.id;
      this.rowItem = row;
    },
    submitzd() {
      let form = { ...this.form };
      form.storeId = this.rowForm.id;
      form.reason = this.rowForm.reason;
      console.log(this.form);
      this.loading = true;
      phonePassLoginzd(form).then((res) => {
        if (res.code == "000000") {
          this.loading = false;
          this.$router.push("/home");
          if (this.hours < 9) {
            this.hello = "早上好！";
          } else if (this.hours < 12) {
            this.hello = "上午好！";
          } else if (this.hours < 15) {
            this.hello = "中午好！";
          } else if (this.hours < 19) {
            this.hello = "下午好！";
          } else {
            this.hello = "晚上好！";
          }
          this.$notify({
            title: this.hello + " " + res.data.staffName,
            message: "( " + res.data.roleName + " ) " + res.data.storeName,
            type: "success",
            duration: 3000,
            offset: 100,
          });
          this.setPara();
          localStorage.setItem("token", res.data.token);
          sessionStorage.setItem("token", res.data.token);
          setCookie("token", res.data.token, 120); //设置
          var parentId = "";
          storeOne({
            id: res.data.storeId,
          }).then((res) => {
            if (res.code == "000000") {
              sessionStorage.setItem("storeInfo", JSON.stringify(res.data));
              if (res.data.parentId == null) {
                /* ------------ sessionStorage.setItem("parentId", res.data.id); ------------ */
                sessionStorage.setItem("parentName", res.data.storeName);
                sessionStorage.setItem("headOffice", 1);

                let storeIds = [];
                storeIds.push(res.data.id);
                sessionStorage.setItem("storeIds", JSON.stringify(storeIds));
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIds)
                );
              } else {
                sessionStorage.setItem("headOffice", 0);
                localStorage.setItem("headOffice", 0);
                sessionStorage.setItem("parentId", res.data.parentId);
                parentId = res.data.parentId;
                let storeIdLists = [parentId, res.data.id];
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIdLists)
                );
                storeLists({
                  id: res.data.id,
                  parentId: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    let storeIds = [];
                    storeIds.push(parentId);
                    res.rows.forEach((item) => {
                      storeIds.push(item.id);
                    });
                    sessionStorage.setItem(
                      "storeIds",
                      JSON.stringify(storeIds)
                    );
                  } else {
                    this.$alert("加载总店/分店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
                storeOne({
                  id: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    sessionStorage.setItem("parentName", res.data.storeName);
                  } else {
                    this.$alert("加载总店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
              }
            } else {
              this.$alert("加载门店信息 :" + res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });

          sessionStorage.setItem("keyPath", "25");
          sessionStorage.setItem("indexPath", "home");
          sessionStorage.setItem("staffName", res.data.staffName);
          sessionStorage.setItem("roleName", res.data.roleName);
          sessionStorage.setItem("storeName", res.data.storeName);
          sessionStorage.setItem("storeId", res.data.storeId);

          sessionStorage.setItem("mobilePhone", res.data.mobilePhone);
          sessionStorage.setItem("userInfo", JSON.stringify(res.data));
          sessionStorage.setItem("list", JSON.stringify(res.data.list));
        } else {
          this.loading = false;
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //手机号登录
    phonesubmit() {
      this.loading = true;
      var that = this;
      setTimeout(() => {
        that.loading = false;
      }, 10000);
      let form = { ...this.form };
      if (this.rowForm) {
        form.storeId = this.rowForm.storeId;
      }
      phoneLogin(form).then((res) => {
        //console.log(res);
        if (res.code == "000000") {
          this.$router.push("/storeParameters");
          this.$message({
            type: "success",
            message: "登录成功!",
            showClose: true,
          });
          this.$router.push("/home");
          if (this.hours < 9) {
            this.hello = "早上好！";
          } else if (this.hours < 12) {
            this.hello = "上午好！";
          } else if (this.hours < 15) {
            this.hello = "中午好！";
          } else if (this.hours < 19) {
            this.hello = "下午好！";
          } else {
            this.hello = "晚上好！";
          }
          this.$notify({
            title: this.hello + " " + res.data.staffName,
            message: "( " + res.data.roleName + " ) " + res.data.storeName,
            type: "success",
            duration: 3000,
            offset: 100,
          });
          this.setPara();
          localStorage.setItem("token", res.data.token);
          sessionStorage.setItem("token", res.data.token);
          setCookie("token", res.data.token, 120); //设置
          storeOne({
            id: res.data.storeId,
          }).then((res) => {
            if (res.code == "000000") {
              sessionStorage.setItem("storeInfo", JSON.stringify(res.data));
              if (res.data.parentId == null) {
                sessionStorage.setItem("parentId", res.data.id);
                sessionStorage.setItem("parentName", res.data.storeName);
                sessionStorage.setItem("headOffice", 1);

                let storeIds = [];
                storeIds.push(res.data.id);
                sessionStorage.setItem("storeIds", JSON.stringify(storeIds));
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIds)
                );
              } else {
                sessionStorage.setItem("headOffice", 0);
                localStorage.setItem("headOffice", 0);
                sessionStorage.setItem("parentId", res.data.parentId);
                let parentId = res.data.parentId;
                let storeIdLists = [parentId, res.data.id];
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIdLists)
                );
                storeLists({
                  id: res.data.id,
                  parentId: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    console.log(res);
                    let storeIds = [];
                    storeIds.push(parentId);
                    res.rows.forEach((item) => {
                      storeIds.push(item.id);
                    });
                    sessionStorage.setItem(
                      "storeIds",
                      JSON.stringify(storeIds)
                    );
                  } else {
                    this.$alert("加载总店/分店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
                storeOne({
                  id: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    sessionStorage.setItem("parentName", res.data.storeName);
                  } else {
                    this.$alert("加载总店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
              }
            } else {
              this.$alert("加载门店信息 :" + res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
          localStorage.setItem("token", res.data.token);
          sessionStorage.setItem("token", res.data.token);
          sessionStorage.setItem("keyPath", "25");
          sessionStorage.setItem("indexPath", "home");
          sessionStorage.setItem("staffName", res.data.staffName);
          sessionStorage.setItem("roleName", res.data.roleName);
          sessionStorage.setItem("storeName", res.data.storeName);
          sessionStorage.setItem("storeId", res.data.storeId);

          sessionStorage.setItem("mobilePhone", res.data.mobilePhone);
          sessionStorage.setItem("userInfo", JSON.stringify(res.data));
          sessionStorage.setItem("list", JSON.stringify(res.data.list));
        } else {
          this.loading = false;
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
    //手机号密码登录
    //提交信息
    submit() {
      let form = { ...this.form };
      if (this.rowForm) {
        form.storeId = this.rowForm.storeId;
      }
      this.loading = true;
      phonePassLogin(form).then((res) => {
        if (res.code == "000000") {
          this.loading = false;
          this.$router.push("/home");
          if (this.hours < 9) {
            this.hello = "早上好！";
          } else if (this.hours < 12) {
            this.hello = "上午好！";
          } else if (this.hours < 15) {
            this.hello = "中午好！";
          } else if (this.hours < 19) {
            this.hello = "下午好！";
          } else {
            this.hello = "晚上好！";
          }
          this.$notify({
            title: this.hello + " " + res.data.staffName,
            message: "( " + res.data.roleName + " ) " + res.data.storeName,
            type: "success",
            duration: 3000,
            offset: 100,
          });
          this.setPara();
          localStorage.setItem("token", res.data.token);
          sessionStorage.setItem("token", res.data.token);
          setCookie("token", res.data.token, 120); //设置
          var parentId = "";
          storeOne({
            id: res.data.storeId,
          }).then((res) => {
            if (res.code == "000000") {
              sessionStorage.setItem("storeInfo", JSON.stringify(res.data));
              if (res.data.parentId == null) {
                sessionStorage.setItem("parentId", res.data.id);
                sessionStorage.setItem("parentName", res.data.storeName);
                sessionStorage.setItem("headOffice", 1);
                let storeIds = [];
                storeIds.push(res.data.id);
                sessionStorage.setItem("storeIds", JSON.stringify(storeIds));
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIds)
                );
              } else {
                sessionStorage.setItem("headOffice", 0);
                localStorage.setItem("headOffice", 0);
                sessionStorage.setItem("parentId", res.data.parentId);
                parentId = res.data.parentId;
                let storeIdLists = [parentId, res.data.id];
                sessionStorage.setItem(
                  "storeIdLists",
                  JSON.stringify(storeIdLists)
                );
                storeLists({
                  id: res.data.id,
                  parentId: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    let storeIds = [];
                    storeIds.push(parentId);
                    res.rows.forEach((item) => {
                      storeIds.push(item.id);
                    });
                    sessionStorage.setItem(
                      "storeIds",
                      JSON.stringify(storeIds)
                    );
                  } else {
                    this.$alert("加载总店/分店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
                storeOne({
                  id: res.data.parentId,
                }).then((res) => {
                  if (res.code == "000000") {
                    sessionStorage.setItem("parentName", res.data.storeName);
                  } else {
                    this.$alert("加载总店信息 :" + res.message, "提示", {
                      confirmButtonText: "确定",
                      confirmButtonClass: "confirmbtnFalses",
                      type: "warning",
                      center: true,
                      callback: (action) => {},
                    });
                  }
                });
              }
            } else {
              this.$alert("加载门店信息 :" + res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          });
          sessionStorage.setItem("keyPath", "25");
          sessionStorage.setItem("indexPath", "home");
          sessionStorage.setItem("staffName", res.data.staffName);
          sessionStorage.setItem("roleName", res.data.roleName);
          sessionStorage.setItem("storeName", res.data.storeName);
          sessionStorage.setItem("storeId", res.data.storeId);
          sessionStorage.setItem("mobilePhone", res.data.mobilePhone);
          sessionStorage.setItem("userInfo", JSON.stringify(res.data));
          sessionStorage.setItem("list", JSON.stringify(res.data.list));
        } else {
          this.loading = false;
          this.$alert(res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },

    phone() {
      this.showPass = false;
      this.showPhone = true;
    },
    pass() {
      this.showPass = true;
      this.showPhone = false;
    },
    //手机验证发送验证码
    sendcode() {
      const reg = 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/;
      if (this.form.mobilePhone == "") {
        this.$message({
          message: "手机号码不能为空",
          center: true,
        });
        return;
      }
      if (!reg.test(this.form.mobilePhone)) {
        this.$message({
          message: "手机号码尚未注册或绑定，或者手机格式不对,请先前往注册！",
          center: true,
        });
        return;
      } else {
        var form = {
          mobilePhone: this.form.mobilePhone,
          storeId: this.rowForm.storeId,
        };
        getSmsCode(form)
          .then((res) => {
            this.time = 60;
            this.disabled = true;
            this.timer();
            //console.log(res);
            if (res.code == "000000") {
              this.$message.success({
                message: "已发送验证码",
              });
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          })
          .catch((res) => {});
      }
    },
    //60S倒计时
    timer() {
      if (this.time > 0) {
        this.time--;
        this.btntxt = this.time + "s后重新获取";
        setTimeout(this.timer, 1000);
      } else {
        this.time = 0;
        this.btntxt = "获取验证码";
        this.disabled = false;
      }
    },
    //  门店参数
    setPara() {
      var dataList = {};
      storeParaList({}).then((res) => {
        //console.log(res);
        if (res.code == "000000") {
          for (let i in res.rows) {
            if (res.rows[i].paramentName == "minimum") {
              dataList.minimum = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "refundCard") {
              dataList.refundCard = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "refillCard") {
              dataList.refillCard = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "payroll") {
              dataList.payroll = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "serviceTicke") {
              dataList.serviceTicke = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "debtUsable") {
              dataList.debtUsable = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "debtRatio") {
              dataList.debtRatio = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "useRecharge") {
              dataList.useRecharge = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "refundDay") {
              dataList.refundDay = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "allowdebt") {
              dataList.allowdebt = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "course") {
              dataList.course = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "integral") {
              dataList.integral = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "recharge") {
              dataList.recharge = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "cashier") {
              dataList.cashier = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "memberIntegral") {
              dataList.memberIntegral = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "expMoney") {
              dataList.expMoney = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "expIntegral") {
              dataList.expIntegral = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "excMoney") {
              dataList.excMoney = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "excIntegral") {
              dataList.excIntegral = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "buycourse") {
              dataList.buycourse = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "takeNumber") {
              dataList.takeNumber = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "expMoneyByIntegral") {
              dataList.expMoneyByIntegral = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "excIntegralByMoney") {
              dataList.excIntegralByMoney = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "exceed") {
              dataList.exceed = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "memberUsing") {
              dataList.memberUsing = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "refundCourse") {
              dataList.refundCourse = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "memberPay") {
              dataList.memberPay = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "allowValid") {
              dataList.allowValid = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "guide") {
              dataList.guide = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "balance") {
              dataList.balance = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "withinBalance") {
              dataList.withinBalance = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "recDebtUsable") {
              dataList.recDebtUsable = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "recDebtRatio") {
              dataList.recDebtRatio = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "recDebt") {
              dataList.recDebt = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "refundCourseNum") {
              dataList.refundCourseNum = res.rows[i].paramentValue * 1;
            }
            if (res.rows[i].paramentName == "promotionUsable") {
              dataList.promotionUsable = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "promotionRatio") {
              dataList.promotionRatio = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "promotion") {
              dataList.promotion = res.rows[i].paramentValue;
            }
            if (res.rows[i].paramentName == "allowMonth") {
              dataList.allowMonth = res.rows[i].paramentValue * 1;
            }

            if (dataList.guide == 1) {
              dataList.guide = true;
            } else {
              dataList.guide = false;
            }
            if (dataList.refundCourse == 1) {
              dataList.refundCourse = true;
            } else {
              dataList.refundCourse = false;
            }
            if (dataList.memberIntegral == 1) {
              dataList.memberIntegral = true;
            } else {
              dataList.memberIntegral = false;
            }
            if (dataList.buycourse == 1) {
              dataList.buycourse = true;
            } else {
              dataList.buycourse = false;
            }
            if (dataList.recharge == 1) {
              dataList.recharge = true;
            } else {
              dataList.recharge = false;
            }
            if (dataList.cashier == 1) {
              dataList.cashier = true;
            } else {
              dataList.cashier = false;
            }
            if (dataList.integral == 1) {
              dataList.integral = false;
            } else {
              dataList.integral = true;
            }
            if (dataList.allowdebt == 1) {
              dataList.allowdebt = true;
            } else {
              dataList.allowdebt = false;
            }
            if (dataList.recDebt == 1 && dataList.recDebt != undefined) {
              dataList.recDebt = true;
            } else {
              dataList.recDebt = false;
            }
            if (dataList.promotion == 1 && dataList.promotion != undefined) {
              dataList.promotion = true;
            } else {
              dataList.promotion = false;
            }

            if (dataList.minimum == 1) {
              dataList.minimum = true;
            } else {
              dataList.minimum = false;
            }
            if (dataList.refillCard == 1) {
              dataList.refillCard = true;
            } else {
              dataList.refillCard = false;
            }
            if (dataList.refundCard == 1) {
              dataList.refundCard = true;
            } else {
              dataList.refundCard = false;
            }
            if (dataList.course == 1) {
              dataList.course = true;
            } else {
              dataList.course = false;
            }
          }
          dataList.useRecharge = dataList.useRecharge * 1;
          if (dataList.memberUsing != undefined) {
            if (dataList.memberUsing * 1 != 0) {
              this.memberUsing = dataList.memberUsing * 1;
              dataList.memberUsing = 1;
            } else {
              dataList.memberUsing = 1 * dataList.memberUsing;
            }
          }
          sessionStorage.setItem(
            "sessionStorageData",
            JSON.stringify(dataList)
          );
        } else {
          this.$alert("门店参数查询 , " + res.message, "提示", {
            confirmButtonText: "确定",
            confirmButtonClass: "confirmbtnFalses",
            type: "warning",
            center: true,
            callback: (action) => {},
          });
        }
      });
    },
  },
  created() {
    //在用充值卡买疗程和支付时允许的容差
    localStorage.removeItem("token");
    sessionStorage.removeItem("token");
  },
};
</script>
<style>
.particles-js-canvas-el {
  min-height: 100vh;
}

#login .codes {
  height: 36px;
  width: 80px;
  background: white;
  border-radius: 5px;
  margin-top: 5px;
  /* margin-bottom: 10px; */
}

#login {
  /* height: 100%;
  width: 100%; */
  background-image: url(../../image/HomeBackground.png);
  background-size: 100%;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  position: relative;
  background-attachment: fixed;
  min-height: 100vh;
  background-size: cover;
  min-width: 500px;
}

#login .el-form-item__label {
  color: white !important;
}

#login .cut {
  width: 100%;
  position: relative;
}

#login .cut .span {
  position: absolute;
  bottom: 0;
  right: 5%;
  color: white;
  font-size: 14px;
  text-decoration: none;
  font-weight: 700;
}

.sendcode {
  margin-top: 5px;
}

#login h2 {
  font-size: 16px;
  text-align: left;
  margin-bottom: 20px;
  color: white;
}

#login .span:hover {
  color: #f78989;
  cursor: pointer;
}

#login .login {
  height: 360px;
  width: 480px;
  margin: 150px auto;
  position: absolute;
  right: 150px;
  top: 0px;
  border: 1px solid #4484b2;
  box-shadow: 5px 5px 5px #4484b2;
  padding-top: 60px;
  padding-left: 60px;
}

#login .login img {
  height: 50px;
  width: 50px;
  position: absolute;
  top: 5%;
  left: 45%;
}

#login .el-input {
  width: 240px;
  margin: 0px auto;
}

#login .log {
  margin: 5px 15px 0px 20px;
}

#login label {
  display: inline-block;
}

.logot-title {
  position: relative;
  top: 100px;
  left: 200px;
  color: #fff;
  font-weight: 900;
  font-size: 48px;
  letter-spacing: 5px;
  font-family: "幼圆";
}
</style>
