<template>
  <div>
    <div class="login">
      <button @click="onSubmit1">虚拟登录</button>
      <!-- <van-form @submit="onSubmit" style="width: 100%;">
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="请输入用户名"
          :rules="[{ required: true, message: '请输入用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请输入密码' }]"
        />
        <div class="agent-box">
          <div class="left-label">应用入口：</div>
          <el-select v-model="agentValue" placeholder="请选择" size="small">
            <el-option
                    v-for="item in agentOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form> -->
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
import {  initGuidInfo,doWecomLogin } from '@/utils/wecomLogin.ts';


@Component
export default class extends Vue {
  username: string = "";
  password: string = "";
  wxUserId: string = "";
  agentValue: string = "hbs";
  agentOptions: any = [{
    value: 'hbs',
    label: '好邦手'
  }, {
    value: 'ssb',
    label: '随身邦'
  }, {
    value: 'stoneLikePaint',
    label: '服务商随身邦'
  }, {
    value: 'goldShop',
    label: '金牌店随身邦'
  }]
  async created() {
    let that = this;
    that.wxUserId = that.$route.query.wxUserId as string;
  }
  async onSubmit(values) {
    console.log("submit", values);
    let that = this;
    let obj = values;
    // obj.wxUserId = this.wxUserId;
    // let [err, data] = await this.$post("/sysuser/bindingUser", obj);
    // let bindingUser: any = data;
    // if (err && err.code == 301) {
    //   this.$toast(err.msg);
    //   this.username = "";
    //   this.password = "";
    // } else {
    //   let [err, data] = await this.$post("/sysuser/getUserInfo", {
    //     userId: bindingUser.user.userId
    //   });
    //   let getUserInfo: any = data;
    //   window.localStorage.setItem(
    //     "userInfoV1",
    //     JSON.stringify(getUserInfo.wxUser)
    //   );
    //   this.$router.push(`/home`);
    // }
    let paramValueAgent = that.agentValue;
    if (paramValueAgent == 'hbs') {
      obj.userType = '0';
    } else if (paramValueAgent == 'ssb') {
      obj.userType = '1';
    } else {
      obj.userType = '2';
    }
    let [err, data] = await this.$post("/wx/getUserByPassWord", obj);
    console.log(err);
    console.log(data);
    if (!err) {
      console.log("login --sysUser = " + data.sysUser)
      let getUserInfo: any = data;
      window.localStorage.setItem("userInfoV1", JSON.stringify(getUserInfo.sysUser));
      window.localStorage.setItem('agentFrom', that.agentValue);
      window.localStorage.setItem("loginNumber", 1);
      this.$router.push(`/homeIndex?userId=${data.sysUser.userId}&agent=${that.agentValue}`);
    }
  }
  onSubmit1() {
    initGuidInfo();
    doWecomLogin('QWert!@345')
      .then(() => {
        this.$router.push('/');
        console.log(`模拟登录成功`);
      })
  }
}
</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  padding-right: 15px;
  box-sizing: border-box;
}

.agent-box {
  flex-direction: row;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  padding: 10px 16px;
  overflow: hidden;
  color: #323233;
  font-size: 14px;
  line-height: 24px;
  background-color: #fff;

  .left-label {
    -webkit-box-flex: 0;
    -webkit-flex: none;
    flex: none;
    box-sizing: border-box;
    width: 6.2em;
    margin-right: 12px;
    color: #646566;
    text-align: left;
    word-wrap: break-word;
  }
}
</style>
