猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.1 KiB

  1. <template>
  2. <up-popup :show="show" @close="close" round="10" mode="bottom">
  3. <view class="popup-content">
  4. <view class="popup-header">
  5. <text class="popup-title">选择性别</text>
  6. <up-icon name="close" size="24" @click="close"></up-icon>
  7. </view>
  8. <view class="popup-body">
  9. <view class="option-item" v-for="(item, index) in options" :key="index" @click="selectItem(item)">
  10. <text :class="['option-text', { 'selected': modelValue === item.value }]">{{ item.name }}</text>
  11. </view>
  12. </view>
  13. <view class="popup-footer">
  14. <view class="confirm-btn" @click="confirm">确定</view>
  15. </view>
  16. </view>
  17. </up-popup>
  18. </template>
  19. <script setup>
  20. import { ref, defineProps, defineEmits } from 'vue';
  21. const props = defineProps({
  22. modelValue: {
  23. type: String,
  24. default: ''
  25. }
  26. });
  27. const emit = defineEmits(['update:modelValue', 'confirm']);
  28. const show = ref(false);
  29. const selectedValue = ref(props.modelValue);
  30. const options = [
  31. { name: '男', value: '男' },
  32. { name: '女', value: '女' }
  33. ];
  34. const open = () => {
  35. show.value = true;
  36. selectedValue.value = props.modelValue;
  37. };
  38. const close = () => {
  39. show.value = false;
  40. };
  41. const selectItem = (item) => {
  42. selectedValue.value = item.value;
  43. emit('update:modelValue', item.value);
  44. };
  45. const confirm = () => {
  46. close();
  47. emit('confirm');
  48. };
  49. // 暴露方法给父组件
  50. defineExpose({
  51. open,
  52. close
  53. });
  54. </script>
  55. <style lang="scss" scoped>
  56. .popup-content {
  57. padding: 30rpx;
  58. }
  59. .popup-header {
  60. display: flex;
  61. justify-content: space-between;
  62. align-items: center;
  63. margin-bottom: 30rpx;
  64. }
  65. .popup-title {
  66. font-size: 32rpx;
  67. font-weight: bold;
  68. }
  69. .popup-body {
  70. max-height: 600rpx;
  71. overflow-y: auto;
  72. }
  73. .option-item {
  74. padding: 30rpx 0;
  75. border-bottom: 1px solid #f5f5f5;
  76. }
  77. .option-text {
  78. font-size: 28rpx;
  79. color: #333;
  80. }
  81. .selected {
  82. color: #FFBF60;
  83. font-weight: bold;
  84. }
  85. .popup-footer {
  86. margin-top: 40rpx;
  87. }
  88. .confirm-btn {
  89. height: 80rpx;
  90. line-height: 80rpx;
  91. text-align: center;
  92. background-color: #FFBF60;
  93. color: #fff;
  94. border-radius: 40rpx;
  95. font-size: 28rpx;
  96. }
  97. </style>