平安校园
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

182 řádky
4.2 KiB

  1. <template>
  2. <view @touchmove.stop @touch.stop>
  3. <myCell v-show="cellVisible" :multiple="multiple" :hasValue="value&&value.length?true:false" :cellValue="cellValue" :title="title_" isLink :border="false" @click="show = true">
  4. </myCell>
  5. <u-popup :show="show" mode="bottom" :closeable="true" :round="10" @close="close" @open="open">
  6. <view>
  7. <view class="title">
  8. {{popupTitle}}
  9. </view>
  10. <view v-if="filterable" style="padding: 0 30rpx 30rpx 30rpx">
  11. <u-search v-model="searchText" :placeholder="searchPlaceholder" shape="round"
  12. :showAction="false"></u-search>
  13. </view>
  14. <u-radio-group v-if="!multiple" :value="value_" iconPlacement="right" placement="column"
  15. @change="change" borderBottom>
  16. <u-radio 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" @change="change"
  20. borderBottom>
  21. <u-checkbox v-show="item.label.includes(searchText)" v-for="(item, index) in options" :key="index"
  22. :label="item.label" :name="item.value">
  23. </u-checkbox>
  24. </u-checkbox-group>
  25. <view style="padding: 36rpx 50rpx">
  26. <u-button @click="cofirm" type="primary" style="border-radius: 36rpx;height: 72rpx;"
  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. gruopValue: '',
  85. searchText: '',
  86. cellValue:[],
  87. };
  88. },
  89. mounted() {
  90. if (this.multiple) this.gruopValue = []
  91. if (!this.multiple) {
  92. let obj = this.options.find(e1 => e1.value == this.value)
  93. if (obj) this.title_ = obj.label
  94. } else {
  95. let arr = this.options.filter(e1 => this.value.includes(e1.value))
  96. this.cellValue = arr.map(e => e.label)
  97. }
  98. },
  99. methods: {
  100. close() {
  101. this.show = false
  102. },
  103. open() {
  104. if (this.multiple) this.gruopValue = []
  105. if (!this.multiple) {
  106. let obj = this.options.find(e1 => e1.value == this.value)
  107. if (obj) this.title_ = obj.label
  108. } else {
  109. let arr = this.options.filter(e1 => this.value.includes(e1.value))
  110. this.cellValue = arr.map(e => e.label)
  111. }
  112. this.value_ = this.value
  113. this.searchText = ''
  114. this.show = true
  115. },
  116. change(e) {
  117. this.gruopValue = e
  118. },
  119. cofirm() {
  120. this.$emit("input", this.gruopValue)
  121. this.$emit("change", this.gruopValue)
  122. if (!this.multiple) {
  123. let obj = this.options.find(e1 => e1.value == this.gruopValue)
  124. if (obj) this.title_ = obj.label
  125. } else {
  126. let arr = this.options.filter(e1 => this.gruopValue.includes(e1.value))
  127. this.cellValue = arr.map(e => e.label)
  128. }
  129. this.close()
  130. },
  131. }
  132. }
  133. </script>
  134. <style scoped lang="scss">
  135. .title {
  136. color: #000000;
  137. font-size: 32rpx;
  138. text-align: center;
  139. line-height: 100rpx;
  140. }
  141. .u-radio-group {
  142. width: 92%;
  143. height: 680rpx;
  144. overflow-y: auto;
  145. padding: 0 30rpx;
  146. .u-cell {
  147. background-color: #fff;
  148. border-radius: 20rpx 20rpx 0 0;
  149. padding: 24rpx 0;
  150. }
  151. }
  152. .u-checkbox-group {
  153. width: 92%;
  154. max-height: 680rpx;
  155. min-height: 360rpx;
  156. overflow-y: auto;
  157. padding: 0 30rpx;
  158. .u-cell {
  159. background-color: #fff;
  160. border-radius: 20rpx 20rpx 0 0;
  161. padding: 24rpx 0;
  162. }
  163. }
  164. .u-border-bottom {
  165. border-color: #F6F6F6 !important;
  166. }
  167. .u-radio {
  168. margin-top: 18rpx;
  169. }
  170. .u-checkbox {
  171. margin-top: 18rpx;
  172. }
  173. </style>