平安校园
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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