<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="id" :customStyle="formItemStyle">
                <view class="form-item-label">绑定人ID</view>
                <view class="form-item-content">
                  <view class="flex search">
                    <uv-search 
                      v-model="keyword" 
                      placeholder="请输入" 
                      color="#181818"
                      bgColor="transparent" 
                      :showAction="true"
                      @custom="search" 
                      @search="search"
                    >
                    </uv-search>
                  </view>
                </view>
              </uv-form-item>
            </view>
            <view class="form-item" v-for="item in list" :key="item.id">
              <view 
                :class="['flex', 'list-item', item.id === form.id ? 'is-active' : '']"
                @click="onSelect"
              >
                <view class="avatar">
							    <image class="img" :src="item.avatar" mode="scaleToFill"></image>
                </view>
                <view>
                  <view class="title">{{ item.name }}</view>
                  <view class="desc">{{ `ID：${item.id}` }}</view>
                </view>
              </view>
            </view>
					</uv-form>
				</view>
			</view>

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

  </view>
</template>

<script>
	import mixinsList from '@/mixins/list.js'

  import formInput from '@/pages_order/components/formInput.vue'

  export default {
		mixins: [mixinsList],
    components: {
      formInput,
    },
    data() {
      return {
				keyword: '',
				queryParams: {
					pageNo: 1,
					pageSize: 1000,
					title: '',
				},
        // todo
        mixinsListApi: '',
        form: {
          id: null,
        },
        rules: {
          'id': {
            type: 'string',
            required: true,
            message: '请选择绑定人',
          },
        },
        formItemStyle: { padding: 0 },
      }
    },
    methods: {
      search() {
				this.queryParams.title = this.keyword
        this.getData()
      },
      onSelect(id) {
        this.form.id = id
      },
      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) + 160rpx) 32rpx calc(env(safe-area-inset-bottom) + 198rpx) 32rpx;
	}

	.card {
    min-height: calc(100vh - (var(--status-bar-height) + 160rpx) - calc(env(safe-area-inset-bottom) + 198rpx));
		padding: 40rpx 32rpx;
    box-sizing: border-box;
		background: #FFFFFF;
		border: 2rpx solid #FFFFFF;
		border-radius: 32rpx;

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

	.form {
		padding: 8rpx 0 0 0;

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

			&:last-child {
				border: none;
			}

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

			&-content {
			}
		}
	}

  .list-item {
    justify-content: flex-start;
    column-gap: 24rpx;
    padding: 10rpx;
    border: 2rpx solid #EEEEEE;
    border-radius: 24rpx;

    .avatar {
      width: 96rpx;
      height: 96rpx;
      border-radius: 50%;
      
      .img {
        width: 100%;
        height: 100%;
      }
    } 

    .title {
      font-size: 32rpx;
      font-weight: 600;
      color: #000000;
    }

    .desc {
      margin-top: 8rpx;
      font-size: 24rpx;
      color: #939393;
    }
    
    &.is-active {
      background: #E9F8FF;
      border-color: #00A9FF;
    }
  }

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

		width: 100vw;
		// height: 200rpx;
		padding: 32rpx 40rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
		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.4;
			color: #FFFFFF;
			background: linear-gradient(to right, #21FEEC, #019AF9);
			border: 2rpx solid #00A9FF;
			border-radius: 41rpx;
		}
	}
</style>