<template>
    <div class="home_wrapper">
      <div class="return_btn" @click="onClickLeft"></div>
        <div class="focus_head">
        </div>
        <div class="focus_info">
            <div class="icon"></div>
            <div class="title"></div>
        </div>
      <van-form @submit="handleLogin">
        <div class="login_from">
            <div class="flex_block">
                <div class="flex_input_main">
                    <div class="icon_wrap user"></div>
                    <div class="input_wrap">
                        <input type="text" v-model="formData.memberName" class="ipt" placeholder="姓名"/>
                    </div>
                </div>
            </div>
            <div class="flex_block">
                <div class="flex_input_main">
                    <div class="icon_wrap password"></div>
                    <div class="input_wrap">
                        <input type="text" v-model="formData.idcard" class="ipt" placeholder="身份证号码"/>
                    </div>
                </div>
            </div>
<!--            <div class="flex_block">-->
<!--                <div class="flex_input_main valid">-->
<!--                    <div class="icon_wrap valid"></div>-->
<!--                    <div class="input_wrap">-->
<!--                        <input type="text" v-model="formData.code" class="ipt" maxlength="4" placeholder="请输入验证码"/>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div class="valid_main">-->
<!--                    <img :src="codeUrl" @click="getCode" />-->
<!--                </div>-->
<!--            </div>-->
            <van-checkbox v-model="formData.rememberMe">记住我的信息</van-checkbox>
        </div>
        <div class="login_btn">
<!--            <div class="btn" :loading="loading">登录</div>-->
            <van-button
              class="btn"
              round
              block
              type="info"
              native-type="submit"
              color="linear-gradient(to right, #2ec8c4, #30c271)"
              :loading="loading"
            >验证</van-button>
        </div>

      </van-form>
    </div>
</template>

<script>
  import { getCodeImg, getSmsCode } from "@/api/login";
  import { checkFarmer } from "@/api/sunVillage_info/fixedAssets";
  import { getFamilyMemberList } from "@/api/sunVillage_info/homestead/familyMember";
  import Cookies from "js-cookie";
  import { encrypt, decrypt } from "../../utils/jsencrypt";
  //引用wx sdk
  import wx from "weixin-js-sdk";
  export default {
    name: "loginCode",
    data() {
      return {
        formData: {
          memberName:'',
          idcard:'',
          bookId:'',
          deptId:null,
          rememberMe:false
        },
        loading: false,
        codeUrl: "", //验证码
        isSmsLogin: false, //是否手机验证码
        computeTime: 0,
        height:0,
        show:true
      };
    },
    created() {
      this.height = document.body.clientHeight
      this.getCookie();
      this.formData.deptId = Cookies.get('deptId');
    },
    methods: {
      getCookie() {
        const memberName = Cookies.get("memberName");
        const idcard = Cookies.get("idcard");
        const rememberMe = Cookies.get("rememberInformation");
        this.formData = {
          memberName: memberName === undefined ? this.formData.memberName : memberName,
          idcard: idcard === undefined ? this.formData.idcard : idcard,
          rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
        };

      },
      handleLogin(values) {
          if (this.formData.rememberMe) {
            Cookies.set("memberName", this.formData.memberName, { expires: 30 });
            Cookies.set("idcard", this.formData.idcard, { expires: 30 });
            Cookies.set("rememberInformation", this.formData.rememberMe, { expires: 30 });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove("rememberInformation");
          }
          //账号密码登录
          if (this.formData.memberName == "") {
            this.$dialog.alert({
              message: '姓名不能为空',
            });
            return false;
          } else if (this.formData.idcard == "") {
            this.$dialog.alert({
              message: '身份证不能为空',
            });
            return false;
          }
          checkFarmer(this.formData).then(response => {
            // console.log(response.data)
            if (response.code == 200){
              let seconds = 3600;

              let expires = new Date(new Date() * 1 + seconds * 1000);
              getFamilyMemberList({idcard:this.formData.idcard,familyStatus:"02"}).then(res => {
                const farmerCode = res.rows[0].farmerCode;
                Cookies.set("farmerCode",farmerCode, { expires: 30 });
                Cookies.set("user", response.data, { expires: expires });
                this.$router.push({path:'/sunVillage_info/index_code_rights'})
              })

            }
          });
      },
    },
  };
</script>

<style scoped lang="scss">
  /deep/ .van-checkbox__label{
    color: #ffffff;
  }
  /deep/ .van-checkbox{
    justify-content: right;
  }
.home_wrapper{
    background: #f1f2f2;
    width: 100vw;
    min-height: 100vh;
    .return_btn {
      width: 24px;
      height: 43.2px;
      background: url('../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
      background-size: 20px 36px;
      position: absolute;
      left: 38px;
      top: 36px;
    }
    .focus_head{
        height: 450px;
        background: url('../../assets/images/sunVillage_info/login_head_code_green.png') no-repeat;
        background-size: 100% 100%;

    }
    .focus_info{
        margin-top: -74px;
        .icon{
            background: url('../../assets/images/sunVillage_info/login_head_t.png') no-repeat;
            background-size: 100% 100%;
            width: 145px;
            height: 148px;
            margin:0 auto;
        }
        .title{
            width: 180PX;
            height: 52px;
            background: url('../../assets/images/sunVillage_info/login_head_nr_code.png') no-repeat;
            background-size: 100% 100%;
            margin:30px auto 0;
        }
    }
    .login_from{
        width: 676px;
        height: 350px;
        background: url('../../assets/images/sunVillage_info/login_main_green.png') no-repeat;
        background-size: 100% 100%;
        margin: 50px auto 0;
        padding:60px 50px 0;
        .flex_block{
            margin-bottom: 40px;
            display: flex;
            justify-content:space-between;
            .flex_input_main{
                position: relative;
                display: flex;
                flex: 1;
                align-items:center;
                background: rgba(255,255,255,0.7);
                 border-radius: 62px;
                 height: 62px;
                .icon_wrap{
                    width: 35px;
                    height: 35px;
                    &.user{
                        background: url('../../assets/images/sunVillage_info/login_icon_1.png') no-repeat;
                        background-size: 100% 100%;
                        margin-left: 30px;
                    }
                    &.password{
                        background: url('../../assets/images/sunVillage_info/login_icon_2_code.png') no-repeat;
                        height: 25px;
                        background-size: 100% 100%;
                        margin-left: 30px;
                    }
                    &.valid{
                         background: url('../../assets/images/sunVillage_info/login_icon_3.png') no-repeat;
                        background-size: 100% 100%;
                        margin-left: 30px;
                    }
                }
                .input_wrap{
                    flex: 1;
                    margin-left: 16px;
                    padding-right: 30px;
                    .ipt{
                        width: 100%;
                        height: 48px;
                        background:transparent;
                        font-size: 30px;
                        color: #3f3d56;
                    }
                }
                .showHidden{
                    width: 32px;
                    height: 32px;
                    background: url('../../assets/images/sunVillage_info/login_icon_4.png') no-repeat;
                    background-size: 100% 100%;
                    position: absolute;
                    right: 38px;
                    cursor: pointer;
                    &.ico_hide{
                        background: url('../../assets/images/sunVillage_info/login_icon_5.png') no-repeat;
                        background-size: 100% 100%;
                    }
                }
                &.valid{
                    flex:0 0 380px;
                }
            }
            .valid_main{
                width: 165px;
                height: 62px;
                border-radius: 30px;
                img{
                  width: 100%;
                  height: 100%;
                  border-radius: 30px;
                }
            }
        }
    }
    .login_btn{
        padding-top: 80px;
        .btn{
          width: 315px;
          height: 80px;
          margin:0 auto;
          font-size: 32px;
          color: #fff;
          text-align: center;
          border: none;
        }
    }
}

</style>
