<template>
  <view class="page">
    <!-- #ifdef H5-->
    <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
                 left-icon="left" title="修改账户信息" @clickLeft="back"/>
    <!-- #endif -->
    <view class="formView">
      <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">

        <u-form-item :labelWidth="80" label="银行卡号：" prop="bankCard" ref="item1">
          <u--input v-model="form.bankCard" placeholder="请输入银行卡号" type="number"></u--input>
        </u-form-item>

        <u-form-item :labelWidth="80" label="开户行：" prop="openingBank" ref="item1">
          <u--input v-model="form.openingBank" placeholder="请输入开户行" type="text"></u--input>
        </u-form-item>

      </u--form>

      <view :style="{'marginTop':'100rpx'}">
        <button class="customStyle" @click="retrievePassword">提交</button>
      </view>
    </view>
    <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code>
    <!--#ifdef H5-->
    <liu-drag-button v-if="$isWxBrowser()" @clickBtn="back">返回</liu-drag-button>
    <!--#endif-->
  </view>
</template>
<script>
export default {
  data() {
    return {
      disabled1: false,
      tips: '',
      form: {
        bankCard: '',
        openingBank: '',
      },
      rules: {
        'bankCard': {
          type: 'string',
          required: true,
          message: '请输入银行卡号',
          trigger: ['blur', 'change']
        },
        'openingBank': {
          type: 'string',
          required: true,
          message: '请输入开户行',
          trigger: ['blur', 'change']
        },
      },
    }
  },
  methods: {
    retrievePassword() {
      this.$refs.uForm.validate().then(res => {
        this.$api.service.updateInfo(this.form).then(res => {
          uni.showToast({
            icon: 'success',
            duration: 2000,
            title: '修改成功，即将返回上一页'
          });
          this.updateInfo()
        })
      })
    },
    //更新个人信息
    updateInfo() {
      this.$api.user.getUserInfo().then(res=>{
        this.userInfo = res.data.data
        uni.setStorageSync('spreadUserInfo', this.userInfo)
        this.back()
      })
    },
    back() {
      let pages = getCurrentPages()
      if (pages.length > 1) {
        uni.navigateBack({
          delta: 1,
          fail: err => {
            console.log(err)
          }
        })
      } else {
        uni.switchTab({
          url: '/pages/my/my'
        });
      }
    },
    codeChange(text) {
      this.tips = text;
    },
  }
}
</script>

<style lang="scss" scoped>
@import './index.rpx.css';
</style>
