<template>
  <wd-popup
    v-model="show"
    position="bottom"
    :safe-area-inset-bottom="true"
    custom-style="border-radius: 16rpx 16rpx 0 0"
    @close="showPayment = false"
    lockScroll
  >
    <view class="pay-card">
      <view class="header">
        <view class="title">立即支付</view>
        <wd-icon name="close" size="20" color="#999" @tap="close"></wd-icon>
      </view>
      <radio-group style="width: 100%" @change="radioChange">
        <view class="pay-item">
          <view class="icon">
            <image src="@/static/shop/wx-icon.png"></image>
            微信
          </view>
          <radio class="radio" color="#F12A2A" value="TENPAY" :checked="'TENPAY' == selectType" />
        </view>
        <view class="pay-item">
          <view class="icon">
            <image src="@/static/shop/yzf-icon.png"></image>
            翼支付
          </view>
          <radio class="radio" color="#F12A2A" value="BESTPAY" :checked="'BESTPAY' == selectType" />
        </view>
      </radio-group>
      <view class="footer">
        <wd-button type="error" @tap="toPay">立即支付</wd-button>
      </view>
    </view>
  </wd-popup>
</template>

<script setup>
import { debounce } from '@/utils/common';
const emits = defineEmits(['payment']);
const selectType = ref('TENPAY');
const show = ref(false);

function radioChange(evt) {
  const { value } = evt.detail;
  selectType.value = value;
}

const toPay = debounce(() => {
  emits('payment', { selectType: selectType.value, orderNumber: orderNumber.value });
  show.value = false;
});

const orderNumber = ref('');
const open = (e) => {
  orderNumber.value = e;
  show.value = true;
};
const close = () => {
  show.value = false;
};
defineExpose({
  open,
  close,
});
</script>

<style lang="scss" scoped>
.pay-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  padding: 30rpx 20rpx;
  box-sizing: border-box;
  margin: 0 auto;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e7e7e7;
    padding-bottom: 30rpx;

    .title {
      font-size: 32rpx;
      color: #333;
    }
  }

  radio-group {
    padding: 30rpx 0;
  }

  .pay-item {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;

    .icon {
      display: flex;
      align-items: center;
      font-size: 28rpx;
      color: #333333;
      gap: 10rpx;

      image {
        width: 45rpx;
        height: 45rpx;
        margin-right: 12rpx;
      }
    }

    .radio {
      margin-left: auto;
    }
  }

  .pay-item:nth-child(2) {
    margin-top: 40rpx;
  }

  .footer {
    width: 100%;
    margin-top: 30rpx;

    &:deep(.wd-button.is-medium.is-round) {
      width: 100%;
    }
  }
}
</style>
