<template>
  <view>
    <uv-popup ref="popup" mode="bottom" bgColor="none" >
      <view class="popup__view">
        <view class="flex header">
          <view class="title">线上试剂盒回寄</view>
          <button class="btn" @click="close">关闭</button>
        </view>
        <view class="form">
          <uv-form 
            ref="form"
            :model="form"
            :rules="rules"
            errorType="toast"
          >
            <view class="form-item">
              <uv-form-item prop="trackingNo" :customStyle="formItemStyle">
                <view class="form-item-label">回寄订单号</view>
                <view class="form-item-content">
                  <formInput v-model="form.trackingNo" inputAlign="right"></formInput>
                </view>
              </uv-form-item>
            </view>
          </uv-form>
        </view>
        <view class="footer">
          <button class="flex btn" @click="close">取消</button>
          <button class="flex btn" @click="onConfirm">确认</button>
        </view>
      </view>
		</uv-popup>
  </view>
</template>

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

  export default {
    components: {
      formInput,
    },
    data() {
      return {
        id: null,
        form: {
          trackingNo: null,
        },
        rules: {
          'trackingNo': {
            type: 'string',
            required: true,
            message: '请输入联系人',
          },
        },
        formItemStyle: { padding: 0 },
      }
    },
    methods: {
      open(id) {
        this.id = id
        this.$refs.popup.open()
      },
      close() {
        this.$refs.popup.close()
      },
      async onConfirm() {

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

          console.log('onConfirm res', res)

          // todo: save

          this.$emit('submitted')

          this.close()

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

      },
    },
  }
</script>

<style lang="scss" scoped>

  .popup__view {
    width: 100vw;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background: #FFFFFF;
    border-top-left-radius: 32rpx;
    border-top-right-radius: 32rpx;
  }

  .header {
    position: relative;
    width: 100%;
    padding: 24rpx 0;
    box-sizing: border-box;
    border-bottom: 2rpx solid #EEEEEE;

    .title {
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 34rpx;
      line-height: 1.4;
      color: #181818;
    }

    .btn {
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 32rpx;
      line-height: 1.4;
      color: #8B8B8B;
      position: absolute;
      top: 26rpx;
      left: 40rpx;
    }

  }
  
  .form {
    padding: 32rpx 40rpx;

    &-item {
      padding: 8rpx 0 6rpx 0;
      
      & + & {
        padding-top: 24rpx;
        border-top: 2rpx solid #EEEEEE;
      }

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

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

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

  .footer {
    width: 100%;
    // todo：check
    // height: 214rpx;
    padding: 32rpx 40rpx;
    box-sizing: border-box;
    border-top: 2rpx solid #F1F1F1;

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

</style>