<template>
  
  <view class="page__view">

		<navbar title="提现" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />

    <view class="main">

      <view class="card">
        <view class="card-header">微信提现</view>
        <view class="form">
          <uv-form 
            ref="form"
            :model="form"
            :rules="rules"
            errorType="toast"
          >
            <view class="form-item">
              <uv-form-item prop="name" :customStyle="formItemStyle">
                <view class="form-item-label">真实姓名</view>
                <view class="form-item-content">
                  <formInput v-model="form.name"></formInput>
                </view>
              </uv-form-item>
            </view>
            <view class="form-item">
              <uv-form-item prop="amount" :customStyle="formItemStyle">
                <view class="form-item-label">提现金额</view>
                <view class="form-item-content">
                  <formInput v-model="form.amount"></formInput>
                </view>
              </uv-form-item>
            </view>
					</uv-form>
				</view>
			</view>

      <view class="notice">
        请仔细检查并确认相关信息，因用户个人疏忽导致的充值错误。需由用户自行承担。
        <!-- todo: 替换配置项key -->
        <text class="highlight" @click="$refs.modal.open('user_ys', '提现须知')">《提现须知》</text>
      </view>

		  <agreementModal ref="modal"></agreementModal>

    </view>
  
    <view class="bottom">
      <button class="btn" @click="onSubmit">提现</button>
    </view>

  </view>
</template>

<script>
  import formInput from '@/pages_order/components/formInput.vue'
  import agreementModal from '@/pages_order/components/agreementModal.vue'

  export default {
    components: {
      formInput,
      agreementModal,
    },
    data() {
      return {
        form: {
          name: null,
          amount: null,
        },
        rules: {
          'name': {
            type: 'string',
            required: true,
            message: '请输入真实姓名',
          },
          'amount': {
            type: 'string',
            required: true,
            message: '请输入提现金额',
          },
        },
        formItemStyle: { padding: 0 },
      }
    },
    methods: {
      async onSubmit() {
        try {
          await this.$refs.form.validate()

          const {
          } = this.form

          const params = {
          }

          // todo: fetch
          // await this.$fetch('updateAddress', params)

          uni.showToast({
            icon: 'success',
            title: '提交成功',
          });

          setTimeout(() => {
            this.$utils.navigateBack()
          }, 800)

        } catch (err) {
          console.log('onSave err', err)
        }
      },
    },
  }
</script>

<style lang="scss" scoped>

	.page__view {
		width: 100vw;
		min-height: 100vh;
    background: $uni-bg-color;
		position: relative;
		
		/deep/ .nav-bar__view {
			position: fixed;
			top: 0;
			left: 0;
		}
	}

	.main {
		padding: calc(var(--status-bar-height) + 144rpx) 32rpx 224rpx 32rpx;
	}

	.card {
		padding: 32rpx;
		background: #FFFFFF;
		border: 2rpx solid #FFFFFF;
		border-radius: 32rpx;

		& + & {
			margin-top: 40rpx;
		}

		&-header {
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 36rpx;
			line-height: 1.4;
			color: #252545;
			margin-bottom: 32rpx;
		}
	}

	.form {
		padding: 8rpx 0 0 0;

		&-item {
			border-bottom: 2rpx solid #EEEEEE;

			&:last-child {
				border: none;
			}

			& + & {
				margin-top: 40rpx;
			}

			&-label {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 26rpx;
				line-height: 1.4;
				color: #181818;
			}

			&-content {
				margin-top: 14rpx;
				padding: 6rpx 0;

				.text {
					padding: 2rpx 0;
					font-family: PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					line-height: 1.4;

					&.placeholder {
						color: #C6C6C6;
					}
				}
			}
		}
	}

  .notice {
    margin-top: 40rpx;
    font-size: 24rpx;
    line-height: 1.4;
    color: #BABABA;

    .highlight {
      color: #F79400;
    }
  }

	.bottom {
		position: fixed;
		left: 0;
		bottom: 0;

		width: 100vw;
		// height: 200rpx;
		padding: 24rpx 40rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 24rpx);
		background: #FFFFFF;
		box-sizing: border-box;

		.btn {
			width: 100%;
			padding: 14rpx 0;
			box-sizing: border-box;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 36rpx;
			line-height: 1;
			color: #FFFFFF;
			background: linear-gradient(to right, #21FEEC, #019AF9);
			border: 2rpx solid #00A9FF;
			border-radius: 41rpx;
		}
	}
</style>