<template>
  <view class="container">
    <view class="form">
      <input class="input" type="text" placeholder="请输入您的账号" v-model="username" />
      <input class="input" type="password" placeholder="请输入您的密码" v-model="password" />
      <view class="agreement">
        <checkbox-group @change="handleAgreementChange">
          <label>
            <checkbox value="agree" /> 阅读并同意《用户协议》和《隐私政策》
          </label>
        </checkbox-group>
      </view>
      <button class="button" @click="handleLogin">登录</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      agreed: false
    };
  },
  methods: {
    handleAgreementChange(e) {
      this.agreed = e.detail.value.includes('agree');
    },
    handleLogin() {
      if (!this.agreed) {
        uni.showToast({
          title: '请先同意用户协议和隐私政策',
          icon: 'none'
        });
        return;
      }

      // 简单的登录验证逻辑
      if (this.username === 'admin' && this.password === '123456') {
        uni.showToast({
          title: '登录成功',
          icon: 'success',
          duration: 1500, // 提示持续时间
          success: () => {
            // 延迟跳转，确保用户看到提示
            setTimeout(() => {
              uni.navigateTo({
                url: '/pages/home/home' // 跳转到首页或其他页面
              });
            }, 1500);
          }
        });
      } else {
        uni.showToast({
          title: '账号或密码错误',
          icon: 'none'
        });
      }
    }
  }
};
</script>

<style>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}

.form {
  width: 80%;
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.input {
  width: 100%;
  height: 40px;
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.agreement {
  margin-bottom: 15px;
}

.button {
  width: 100%;
  height: 40px;
  background-color: #007aff;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 16px;
}
</style>