|
|
- <template>
- <up-popup :show="show" @close="close" round="10" mode="bottom">
- <view class="popup-content">
- <view class="popup-header">
- <text class="popup-title">选择性别</text>
- <up-icon name="close" size="24" @click="close"></up-icon>
- </view>
- <view class="popup-body">
- <view class="option-item" v-for="(item, index) in options" :key="index" @click="selectItem(item)">
- <text :class="['option-text', { 'selected': modelValue === item.value }]">{{ item.name }}</text>
- </view>
- </view>
- <view class="popup-footer">
- <view class="confirm-btn" @click="confirm">确定</view>
- </view>
- </view>
- </up-popup>
- </template>
-
- <script setup>
- import { ref, defineProps, defineEmits } from 'vue';
-
- const props = defineProps({
- modelValue: {
- type: String,
- default: ''
- }
- });
-
- const emit = defineEmits(['update:modelValue', 'confirm']);
-
- const show = ref(false);
- const selectedValue = ref(props.modelValue);
-
- const options = [
- { name: '男', value: '男' },
- { name: '女', value: '女' }
- ];
-
- const open = () => {
- show.value = true;
- selectedValue.value = props.modelValue;
- };
-
- const close = () => {
- show.value = false;
- };
-
- const selectItem = (item) => {
- selectedValue.value = item.value;
- emit('update:modelValue', item.value);
- };
-
- const confirm = () => {
- close();
- emit('confirm');
- };
-
- // 暴露方法给父组件
- defineExpose({
- open,
- close
- });
- </script>
-
- <style lang="scss" scoped>
- .popup-content {
- padding: 30rpx;
- }
-
- .popup-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 30rpx;
- }
-
- .popup-title {
- font-size: 32rpx;
- font-weight: bold;
- }
-
- .popup-body {
- max-height: 600rpx;
- overflow-y: auto;
- }
-
- .option-item {
- padding: 30rpx 0;
- border-bottom: 1px solid #f5f5f5;
- }
-
- .option-text {
- font-size: 28rpx;
- color: #333;
- }
-
- .selected {
- color: #FFBF60;
- font-weight: bold;
- }
-
- .popup-footer {
- margin-top: 40rpx;
- }
-
- .confirm-btn {
- height: 80rpx;
- line-height: 80rpx;
- text-align: center;
- background-color: #FFBF60;
- color: #fff;
- border-radius: 40rpx;
- font-size: 28rpx;
- }
- </style>
|