平安校园
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
4.1 KiB

  1. <template>
  2. <view @touchmove.stop @touch.stop>
  3. <myCell v-show="cellVisible" :multiple="multiple" :hasValue="value?true:false" :cellValue="cellValue"
  4. :title="title_" isLink :border="false" @click="show = true">
  5. </myCell>
  6. <u-popup :show="show" mode="bottom" :closeable="true" :round="10" @close="close" @open="open">
  7. <view>
  8. <view class="title">
  9. {{popupTitle}}
  10. </view>
  11. <view v-if="filterable" style="padding: 0rpx 30rpx 30rpx 30rpx;">
  12. <u-search height="90rpx" :inputStyle="{fontSize:'30rpx'}" v-model="searchText" :placeholder="searchPlaceholder" shape="square"
  13. :showAction="false"></u-search>
  14. </view>
  15. <u-radio-group v-if="!multiple" v-model="value_" iconPlacement="right" placement="column" borderBottom>
  16. <u-radio labelSize="30rpx" v-show="item.label.includes(searchText)" v-for="(item,index) in options" :key="index"
  17. :label="item.label" :name="item.value"></u-radio>
  18. </u-radio-group>
  19. <u-checkbox-group v-else v-model="value_" iconPlacement="right" placement="column" borderBottom>
  20. <u-checkbox labelSize="30rpx" v-show="item.label.includes(searchText)" v-for="(item, index) in options" :key="index"
  21. :label="item.label" :name="item.value">
  22. </u-checkbox>
  23. </u-checkbox-group>
  24. <view style="padding: 36rpx 50rpx">
  25. <u-button @click="cofirm" type="primary" style="border-radius: 45rpx;height: 90rpx;font-weight: 700;font-size: 32rpx;"
  26. text="确定"></u-button>
  27. </view>
  28. </view>
  29. </u-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import myCell from "@/components/cell.vue"
  34. export default {
  35. name: "selectRadio",
  36. components: {
  37. myCell
  38. },
  39. props: {
  40. value: {
  41. default: "",
  42. },
  43. options: {
  44. default: [],
  45. type: Array
  46. },
  47. // 是否显示cell回显
  48. cellVisible: {
  49. default: true,
  50. },
  51. // cell回显默认文字
  52. placeholder: {
  53. default: '请选择'
  54. },
  55. // 弹框标题
  56. popupTitle: {
  57. default: "请选择",
  58. type: String
  59. },
  60. // 是否显示搜索
  61. filterable: {
  62. default: true,
  63. },
  64. // 搜索框默认文字
  65. searchPlaceholder: {
  66. default: "请输入",
  67. type: String
  68. },
  69. // 单选时候cell回显的文字
  70. title: {
  71. default: "",
  72. },
  73. // 是否多选
  74. multiple: {
  75. default: false,
  76. },
  77. },
  78. data() {
  79. return {
  80. show: false,
  81. title_: this.title || this.placeholder,
  82. value_: this.value,
  83. searchText: '',
  84. cellValue: [],
  85. };
  86. },
  87. mounted() {
  88. if (this.multiple) this.value_ = []
  89. if (!this.multiple) {
  90. let obj = this.options.find(e1 => e1.value == this.value)
  91. if (obj) this.title_ = obj.label
  92. } else {
  93. let arr = this.options.filter(e1 => this.value.includes(e1.value))
  94. this.cellValue = arr.map(e => e.label)
  95. }
  96. },
  97. methods: {
  98. close() {
  99. this.show = false
  100. },
  101. open() {
  102. if (this.multiple) this.value_ = []
  103. if (!this.multiple) {
  104. let obj = this.options.find(e1 => e1.value == this.value)
  105. if (obj) this.title_ = obj.label
  106. } else {
  107. let arr = this.options.filter(e1 => this.value.includes(e1.value))
  108. this.cellValue = arr.map(e => e.label)
  109. }
  110. this.value_ = this.value
  111. this.searchText = ''
  112. this.show = true
  113. },
  114. cofirm() {
  115. this.$emit("input", this.value_)
  116. this.$emit("change", this.value_)
  117. if (!this.multiple) {
  118. let obj = this.options.find(e1 => e1.value == this.value_)
  119. if (obj) this.title_ = obj.label
  120. } else {
  121. let arr = this.options.filter(e1 => this.value_.includes(e1.value))
  122. this.cellValue = arr.map(e => e.label)
  123. }
  124. this.close()
  125. },
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .title {
  131. color: #333;
  132. font-size: 34rpx;
  133. text-align: center;
  134. line-height: 100rpx;
  135. }
  136. .u-checkbox-group,.u-radio-group {
  137. width: 92%;
  138. height: 780rpx;
  139. overflow-y: auto;
  140. padding: 0 30rpx;
  141. box-shadow: inset 0 0 20rpx rgba(0, 0, 0, 0.08);
  142. .u-radio,.u-checkbox {
  143. height: 98rpx;
  144. box-sizing: border-box;
  145. padding-bottom: 0rpx!important;
  146. margin-top: 0rpx!important;
  147. }
  148. }
  149. .u-border-bottom {
  150. border-color: #F6F6F6 !important;
  151. }
  152. .u-radio {
  153. margin-top: 18rpx;
  154. }
  155. .u-checkbox {
  156. margin-top: 18rpx;
  157. }
  158. </style>