平安校园
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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