<template>
<!--promote/withdrawal/addcard/addcard.wxml-->
<form @submit="formSubmit">
<view class="form mt20">
<view class="dflex ipt pdlr20 bor"><text>开户银行</text><input placeholder="请输入开户银行" name="title"></input></view>
<view class="dflex ipt pdlr20"><text>银行卡号</text><input placeholder="请输入银行卡的卡号" name="card"></input></view>
</view>
<view class="form mt20">
<view class="dflex ipt pdlr20 bor"><text>持卡人姓名</text><input placeholder="请输入持卡人的姓名" name="name"></input></view>
<view class="dflex ipt pdlr20"><text>身份证号</text><input placeholder="请输入您的身份证号" name="identity"></input></view>
</view>
<button class="btn" form-type="submit">立即添加</button>
</form>
</template>

<script>
// promote/withdrawal/addcard/addcard.js
const app = getApp();
const req = require("../../../utils/request.js");

export default {
  data() {
    return {};
  },

  components: {},
  props: {},

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
  methods: {
    formSubmit(event) {
      let data = event.detail.value;
      let sfz = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

      if (!sfz.test(data.identity)) {
        return req.msg('请填写正确的身份证信息！');
      }

      // console.log(data);
      this.submitCard(data);
    },

    submitCard(data) {
      req.postRequest('/api/bank/save', data, res => {
        // console.log(res);
        uni.navigateBack();
      });
    }

  }
};
</script>
<style>
@import "./addcard.css";
</style>