<template>
<!--pages/activity/signIn/index.wxml-->
<view class="signIn-page">
  <view class="title-box">
    <text>参加活动人员信息填写</text>
    <text>请仔细填写，方便后台快速审核通过</text>
  </view>
  <view class="form-box">
    <form @submit="toConfirm">
      <view class="form-item">
        <view class="form-label">昵称<text style="color:#FF3B30;">*</text></view>
        <input type="text" placeholder="请输入姓名" name="name">
      </view>
      <view class="form-item">
        <view class="form-label">手机号<text style="color:#FF3B30;">*</text></view>
        <input type="text" placeholder="请输入手机号" name="phone" maxlength="11">
        <!-- <view class="input-box acea-row row-middle">
          <input type="text" placeholder="请输入手机号" name="phone" />
          <input type="button" value="发送验证码" bindtap="sendCode" />
        </view> -->
      </view>
      <!-- <view class="form-item">
        <view class="form-label">验证码<text style="color:#FF3B30;">*</text></view>
        <input type="text" placeholder="请输入验证码" name="code" />
      </view> -->
      <view class="form-item">
        <view class="form-label">微信号</view>
        <input type="text" placeholder="请输入微信" name="WeChat">
      </view>
      <view class="form-item">
        <view class="form-label acea-row row-between">
          <text>门票<text style="color:#FF3B30;">*</text></text> 
          <input type="number" @blur="inpChange" :value="num" style="width:30rpx" name="num">
        </view>
      </view>
      <button class="submit-btn" form-type="submit">下一步</button>
    </form>
    
  </view>
</view>
</template>

<script>
// pages/activity/signIn/index.js
const app = getApp();

export default {
  data() {
    return {
      activityId: '',
      num: '2'
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      activityId: options.id
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    toConfirm(e) {
      console.log(e);
      const values = e.detail.value;
      let name = values.name,
          phone = values.phone,
          code = values.code,
          WeChat = values.WeChat,
          num = values.num;

      if (name == '' || phone == '' || code == '') {
        uni.showToast({
          title: '带*项为必填项，请检查后重新提交！',
          icon: 'none'
        });
        return;
      } else if (!/^1(3|4|5|7|8)\d{9}$/.test(phone)) {
        uni.showToast({
          title: '请填写正确手机号',
          icon: 'none'
        });
        return;
      } else if (num == '') {
        num = 1;
      }

      app.http('post', 'activity/joinActivity', {
        activiyId: this.activityId,
        name: name,
        phone: phone,
        num: num
      }).then(res => {
        console.log(res);

        if (res.data.success) {
          let payInfo = encodeURIComponent(JSON.stringify(res.data.data));
          uni.navigateTo({
            url: './confirm/index?payInfo=' + payInfo
          });
        }
      });
    },

    inpChange(e) {
      console.log(e);
      let num = e.detail.value;

      if (num <= 0) {
        num = 1;
      } else if (num > 2) {
        num = 2;
      }

      this.setData({
        num
      });
    }

  }
};
</script>
<style>
/* pages/activity/signIn/index.wxss */
.signIn-page{
  padding: 56rpx 32rpx;
}
.title-box text:nth-child(1){
  font-size: 42rpx;
  font-weight: bold;
  display: block;
  line-height: 58rpx;
  margin-bottom: 8rpx;
}
.title-box text:nth-child(2){
  font-size: 24rpx;
  display: block;
  color: #F96B1C;
}
.form-item{
  font-size: 32rpx;
  color: #333;
  margin-top: 46rpx;
}
.form-item input[type="text"]{
  padding: 26rpx 0 32rpx;
  border-bottom: 2px solid #F4F4F4;
  font-size: 28rpx;
}
.input-box input[type="text"]{
  width: calc(100% - 310rpx);
}
.form-item input[type="button"]{
  width: 175rpx;
  height:78rpx;
  line-height: 78rpx;
  text-align: center;
  color: #fff;
  background: #EBB672;
  padding: 0 10rpx;
  border-radius: 8rpx;
  font-size: 28rpx;
  margin-left: 12rpx;
}

.submit-btn{
  width: 100% !important;
  position: fixed;
  bottom: 60rpx;
  left: 0;
  width: 100%;
  height: 76rpx !important;
  background: #EBB672;
  color: #FFF;
  font-size: 32rpx;
  line-height: 76rpx !important;
  padding: 0 !important;
  text-align: center;
  border-radius: 0 !important;
}
</style>