图书馆小程序
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.

165 lines
3.8 KiB

1 week ago
  1. <template>
  2. <view class="reader-card">
  3. <!-- 顶部背景图 -->
  4. <image class="card-top-bg" src="@/static/images/card-img1.png" mode="widthFix" />
  5. <!-- 读者证列表 -->
  6. <view class="card-list">
  7. <radio-group v-model="selectedValue" @change="radioChange">
  8. <view
  9. class="card-list-item"
  10. v-for="(item, index) in cardList"
  11. :key="index"
  12. @click="handleSelectItem(item.value)"
  13. :class="{ active: selectedValue === item.value }"
  14. >
  15. <image class="card-left-img" src="@/static/images/card-img2.png" mode="widthFix" />
  16. <view class="card-right-info">
  17. <text class="info-title">读者证号</text>
  18. <text class="info-num">{{ item.cardNum }}</text>
  19. </view>
  20. <radio :value="item.value" :checked="selectedValue === item.value"/>
  21. </view>
  22. </radio-group>
  23. </view>
  24. <!-- 确定按钮 -->
  25. <button class="submit-btn" @click="handleSubmit">确定</button>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. data() {
  31. return {
  32. // 选中的radio值
  33. selectedValue: '1',
  34. // 读者证列表数据(支持多条数据渲染)
  35. cardList: [
  36. {
  37. value: '1',
  38. cardNum: 'NO.10078398329'
  39. },
  40. {
  41. value: '2',
  42. cardNum: 'NO.10078398330'
  43. },
  44. {
  45. value: '3',
  46. cardNum: 'NO.10078398331'
  47. }
  48. ]
  49. }
  50. },
  51. methods: {
  52. // 单选框change事件
  53. radioChange(e) {
  54. console.log('radio选中值:', e.detail.value)
  55. this.selectedValue = e.detail.value
  56. },
  57. // 点击item选中对应radio
  58. handleSelectItem(value) {
  59. this.selectedValue = value
  60. },
  61. // 提交按钮事件
  62. handleSubmit() {
  63. if(!this.selectedValue){
  64. uni.showToast({
  65. title: '请选择读者证',
  66. icon: 'none'
  67. })
  68. return
  69. }
  70. console.log('提交选中的读者证:', this.selectedValue)
  71. uni.showToast({
  72. title: '选择成功'
  73. })
  74. // 这里可以写后续业务逻辑
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .reader-card{
  81. position: relative;
  82. min-height: 100vh;
  83. background-color: #f5f5f5;
  84. .card-top-bg{
  85. position: absolute;
  86. left: 0;
  87. top: 0;
  88. width: 100%;
  89. display: block;
  90. }
  91. .card-list{
  92. position: absolute;
  93. left: 0;
  94. top: 60px;
  95. width: calc(100% - 24px);
  96. height: calc(100vh - 195px);
  97. overflow-y: auto;
  98. padding: 12px;
  99. z-index: 999;
  100. .card-list-item{
  101. display: flex;
  102. justify-content: space-between;
  103. align-items: center;
  104. padding: 10px;
  105. margin-bottom: 12px;
  106. border: 2px solid #C6C6E2;
  107. border-radius: 8px;
  108. background: rgba(241,241,249,0.4);
  109. cursor: pointer;
  110. transition: all 0.2s;
  111. // 选中样式
  112. &.active{
  113. border-color: #01a4fe;
  114. background: rgba(1, 164, 254, 0.1);
  115. }
  116. .card-left-img{
  117. width: 80px;
  118. margin-right: 12px;
  119. display: block;
  120. }
  121. .card-right-info{
  122. display: flex;
  123. flex-direction: column;
  124. justify-content: flex-start;
  125. flex: 1;
  126. .info-title{
  127. font-size: 16px;
  128. color: #333333;
  129. font-weight: bold;
  130. padding-bottom: 12px;
  131. }
  132. .info-num{
  133. font-size: 14px;
  134. color: #999999;
  135. }
  136. }
  137. }
  138. }
  139. .submit-btn{
  140. position: fixed;
  141. bottom: 40px;
  142. left: 0;
  143. right: 0;
  144. width: calc(100% - 40px);
  145. padding: 5px 0;
  146. color: #fff;
  147. background-color: #01a4fe;
  148. border-radius: 23px;
  149. border: none;
  150. font-size: 16px;
  151. }
  152. }
  153. </style>