平安校园
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

178 satır
4.2 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. computed: {
  89. title_() {
  90. if (!this.multiple) {
  91. let obj = this.options.find(e1 => e1.value == this.value)
  92. return obj ? obj.label : this.placeholder
  93. } else {
  94. let arr = this.options.filter(e1 => this.value_.includes(e1.value))
  95. this.cellValue = arr.map(e => e.label)
  96. return this.placeholder
  97. }
  98. }
  99. },
  100. mounted() {
  101. this.value_ = JSON.parse(JSON.stringify(this.value))
  102. if (!this.multiple) {
  103. let obj = this.options.find(e1 => e1.value == this.value_)
  104. if (obj) {
  105. this.$emit("update:title", this.title_)
  106. } else {
  107. this.$emit("update:title", '')
  108. }
  109. } else {
  110. this.$emit("update:title", this.cellValue)
  111. }
  112. },
  113. methods: {
  114. close() {
  115. this.show = false
  116. },
  117. open() {
  118. this.value_ = JSON.parse(JSON.stringify(this.value))
  119. this.searchText = ''
  120. this.show = true
  121. },
  122. cofirm() {
  123. this.$emit("input", this.value_)
  124. this.$emit("change", this.value_)
  125. if (!this.multiple) {
  126. let obj = this.options.find(e1 => e1.value == this.value_)
  127. if (obj) {
  128. this.$emit("update:title", this.title_)
  129. } else {
  130. this.$emit("update:title", '')
  131. }
  132. } else {
  133. this.$emit("update:title", this.cellValue)
  134. }
  135. this.close()
  136. },
  137. }
  138. }
  139. </script>
  140. <style scoped lang="scss">
  141. .title {
  142. color: #333;
  143. font-size: 34rpx;
  144. text-align: center;
  145. line-height: 100rpx;
  146. }
  147. .u-checkbox-group,
  148. .u-radio-group {
  149. width: 92%;
  150. height: 780rpx;
  151. overflow-y: auto;
  152. padding: 0 30rpx;
  153. box-shadow: inset 0 0 20rpx rgba(0, 0, 0, 0.08);
  154. .u-radio,
  155. .u-checkbox {
  156. height: 98rpx;
  157. box-sizing: border-box;
  158. padding-bottom: 0rpx !important;
  159. margin-top: 0rpx !important;
  160. }
  161. }
  162. .u-border-bottom {
  163. border-color: #F6F6F6 !important;
  164. }
  165. .u-radio {
  166. margin-top: 18rpx;
  167. }
  168. .u-checkbox {
  169. margin-top: 18rpx;
  170. }
  171. </style>