|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
- <view @touchmove.stop @touch.stop>
- <myCell v-show="cellVisible" :multiple="multiple" :hasValue="value?true:false" :cellValue="cellValue"
- :title="title_" isLink :border="false" @click="show = true">
- </myCell>
- <u-popup :show="show" mode="bottom" :closeable="true" :round="10" @close="close" @open="open">
- <view>
- <view class="title">
- {{popupTitle}}
- </view>
- <view v-if="filterable" style="padding: 0rpx 30rpx 30rpx 30rpx;">
- <u-search height="90rpx" :inputStyle="{fontSize:'30rpx'}" v-model="searchText"
- :placeholder="searchPlaceholder" shape="square" :showAction="false"></u-search>
- </view>
- <u-radio-group v-if="!multiple" v-model="value_" iconPlacement="right" placement="column" borderBottom>
- <u-radio labelSize="30rpx" v-show="item.label.includes(searchText)" v-for="(item,index) in options"
- :key="index" :label="item.label" :name="item.value"></u-radio>
- </u-radio-group>
- <u-checkbox-group v-else v-model="value_" iconPlacement="right" placement="column" borderBottom>
- <u-checkbox labelSize="30rpx" v-show="item.label.includes(searchText)"
- v-for="(item, index) in options" :key="index" :label="item.label" :name="item.value">
- </u-checkbox>
- </u-checkbox-group>
- <view style="padding: 36rpx 50rpx;display:flex">
- <u-button @click="cancel" type="info"
- customStyle="border-radius: 45rpx;height: 90rpx;font-weight: 700;font-size: 32rpx;color:#666;"
- text="取消" v-if="value_"></u-button>
- <view style="width: 36rpx;" v-if="value_"></view>
- <u-button @click="cofirm" type="primary"
- customStyle="border-radius: 45rpx;height: 90rpx;font-weight: 700;font-size: 32rpx;"
- text="确定"></u-button>
- </view>
- </view>
- </u-popup>
- </view>
- </template>
-
- <script>
- import myCell from "@/components/cell.vue"
- export default {
- name: "selectRadio",
- components: {
- myCell
- },
- props: {
- value: {
- default: "",
- },
- options: {
- default: [],
- type: Array
- },
- // 是否显示cell回显
- cellVisible: {
- default: true,
- },
- // cell回显默认文字
- placeholder: {
- default: '请选择'
- },
- // 弹框标题
- popupTitle: {
- default: "请选择",
- type: String
- },
- // 是否显示搜索
- filterable: {
- default: true,
- },
- // 搜索框默认文字
- searchPlaceholder: {
- default: "请输入",
- type: String
- },
- // 单选时候cell回显的文字
- title: {
- default: "",
- },
- // 是否多选
- multiple: {
- default: false,
- },
- },
- data() {
- return {
- show: false,
- // title_: this.title || this.placeholder,
- value_: this.value,
- searchText: '',
- cellValue: [],
- };
- },
- computed: {
- title_() {
- if (!this.multiple) {
- let obj = this.options.find(e1 => e1.value == this.value_)
- return obj ? obj.label : this.placeholder
- } else {
- let arr = this.options.filter(e1 => this.value_.includes(e1.value))
- this.cellValue = arr.map(e => e.label)
- return this.placeholder
- }
- }
- },
- mounted() {
- this.value_ = JSON.parse(JSON.stringify(this.value))
- if (!this.multiple) {
- let obj = this.options.find(e1 => e1.value == this.value_)
- if (obj) {
- this.$emit("update:title", this.title_)
- } else {
- this.$emit("update:title", '')
- }
- } else {
- this.$emit("update:title", this.cellValue)
- }
- },
- methods: {
- close() {
- this.show = false
- },
- open() {
- this.value_ = JSON.parse(JSON.stringify(this.value))
- this.searchText = ''
- this.show = true
- },
- cofirm() {
- this.$emit("input", this.value_)
- this.$emit("change", this.value_)
- if (!this.multiple) {
- let obj = this.options.find(e1 => e1.value == this.value_)
- if (obj) {
- this.$emit("update:title", this.title_)
- } else {
- this.$emit("update:title", '')
- }
- } else {
- this.$emit("update:title", this.cellValue)
- }
- this.close()
- },
- cancel(){
- if (!this.multiple) {
- this.value_ = ''
- this.$emit("input", this.value_)
- this.$emit("change", this.value_)
- let obj = this.options.find(e1 => e1.value == this.value_)
- if (obj) {
- this.$emit("update:title", this.title_)
- } else {
- this.$emit("update:title", '')
- }
- } else {
- this.value_ = []
- }
- }
- }
- }
- </script>
-
- <style scoped lang="scss">
- .title {
- color: #333;
- font-size: 34rpx;
- text-align: center;
- line-height: 100rpx;
- }
-
- .u-checkbox-group,
- .u-radio-group {
- width: 92%;
- height: 780rpx;
- overflow-y: auto;
- padding: 0 30rpx;
- box-shadow: inset 0 0 20rpx rgba(0, 0, 0, 0.08);
-
- .u-radio,
- .u-checkbox {
- height: 98rpx;
- box-sizing: border-box;
- padding-bottom: 0rpx !important;
- margin-top: 0rpx !important;
- }
- }
-
- .u-border-bottom {
- border-color: #F6F6F6 !important;
- }
-
- .u-radio {
- margin-top: 18rpx;
- }
-
- .u-checkbox {
- margin-top: 18rpx;
- }
- </style>
|