<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="phone" :customStyle="formItemStyle">
                <view class="form-item-label">手机号</view>
                <view class="form-item-content">
                  <formInput v-model="form.phone"></formInput>
                </view>
              </uv-form-item>
            </view>
            <view class="form-item">
              <uv-form-item prop="phone" :customStyle="formItemStyle">
                <view class="form-item-label">所在地区</view>
                <view class="form-item-content">
                  <picker mode="region" @change="onAreaChange" :value="form.area">
                    <view class="flex region">
                      <view v-if="form.area">{{ form.area.join('') }}</view>
                      <view v-else class="placeholder">选择省市区街道</view>
                    </view>
                  </picker>
                </view>
              </uv-form-item>
            </view>
            <view class="form-item">
              <uv-form-item prop="address" :customStyle="formItemStyle">
                <view class="form-item-label">详细地址</view>
                <view class="form-item-content">
                  <formInput v-model="form.address" placeholder="小区楼栋、门牌号、村等"></formInput>
                </view>
              </uv-form-item>
            </view>
					</uv-form>
				</view>
			</view>
    </view>
  
    <view class="bottom">
      <button class="btn" @click="onConfirm">确认</button>
    </view>

  </view>
  
</template>

<script>
	import { mapState } from 'vuex'

	import util from '@/utils/utils.js'

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

  export default {
    components: {
      formInput,
    },
    data() {
      return {
        form: {
          name: null,
          phone: null,
          area: null,
          address: null,
        },
        rules: {
          'name': {
            type: 'string',
            required: true,
            message: '请输入联系人',
          },
          'phone': {
            type: 'string',
            required: true,
            message: '请输入正确的手机号',
						validator: (rule, value, callback) => {
							return util.validatePhone(value)
						},
          },
          'area': {
            type: 'array',
            required: true,
            message: '请选择省市区',
          },
          'address': {
            type: 'string',
            required: true,
            message: '请输入详细地址',
          },
        },
        formItemStyle: { padding: 0 },
      }
    },
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
    methods: {
      onAreaChange(e) {
        this.form.area = e.detail.value
      },
      async onConfirm() {

        try {
          const res = await this.$refs.form.validate()

          console.log('onSave res', res)

          // todo: save

          this.$utils.redirectTo(`/pages_order/order/userInfo/idUpload`)

        } catch (err) {
          console.log('onSave err', err)
        }

      },
    },
  }
</script>

<style lang="scss" scoped>

	.page__view {
		width: 100vw;
		min-height: 100vh;
		background-color: $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: #FAFAFF;
		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;
		}
	}

	.row {
		justify-content: space-between;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 1.4;
		column-gap: 24rpx;

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

		&-label {
			flex: none;
			font-size: 26rpx;
			color: #8B8B8B;
		}

		&-content {
			font-size: 32rpx;
			color: #181818;
		}
	}

	.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;

        .placeholder {
          color: #C6C6C6; 
          font-size: 32rpx; 
          font-weight: 400;
        }

        .region {
          min-height: 44rpx;
          justify-content: flex-start;
        }

			}
		}
	}

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

		width: 100vw;
		height: 200rpx;
		padding: 24rpx 40rpx;
		background: #FFFFFF;
		box-sizing: border-box;

		.btn {
			width: 100%;
			padding: 16rpx 0;
			box-sizing: border-box;
			font-family: PingFang SC;
			font-weight: 500;
			font-size: 36rpx;
			line-height: 1;
			color: #FFFFFF;
			background-image: linear-gradient(to right, #4B348F, #845CFA);
			border-radius: 41rpx;
		}
	}

</style>