|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <template>
- <view @touchmove.stop @touch.stop>
- <myCell v-show="cellVisible" :title="title" isLink :hasValue="value&&value.length?true:false" :border="false" @click="show = true"></myCell>
- <u-popup :show="show" mode="bottom" :closeable="true" :round="10" @close="close" @open="open">
- <view class="title">
- {{popupTitle}}
- </view>
- <view>
- <u-tabs :list="tabsList" :current="tabIndex" @change="tabsChange" :activeStyle="{
- color: '#000000',
- }" itemStyle="height:84rpx;width:33.33%;box-sizing:border-box;background:#fff;border-top:1rpx solid rgba(0,0,0,0.03)"></u-tabs>
- <view v-for="(item) in tabsList" :key="item.value">
- <template v-if="tabIndex == item.value">
- <u-radio-group v-model="selectValue" iconPlacement="right" placement="column" @change="change"
- borderBottom>
- <u-radio v-for="(item,index) in selectOptions" :key="index" :label="item.label"
- :name="item.value"></u-radio>
- </u-radio-group>
- </template>
- </view>
- <view style="padding: 36rpx 50rpx">
- <u-button @click="cofirm" type="primary" style="border-radius: 36rpx;height: 72rpx;"
- 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: () => [],
- type: Array
- },
- labels: {
- default: () => [],
- type: Array
- },
- placeholder: {
- default: '请选择'
- },
- popupTitle: {
- default: "请选择",
- type: String
- },
- cellVisible: {
- default: true,
- },
- },
- data() {
- return {
- show: false,
- title: this.labels.join('/') || this.placeholder,
- tabsList: [{
- name: "系部",
- cate:"系部",
- value: 0,
- disabled: false,
- list: [{
- value: 222,
- label: '信息系'
- }, {
- value: 333,
- label: '金融系'
- }]
- },
- {
- name: "专业",
- cate:"专业",
- value: 1,
- disabled: true,
- list: [{
- value: 222,
- label: '计算机应用'
- }, {
- value: 333,
- label: '土木工程'
- }]
- },
- {
- name: "班级",
- cate:"班级",
- value: 2,
- disabled: true,
- list: [{
- value: 222,
- label: '1班'
- }, {
- value: 333,
- label: '2班'
- }]
- },
- ],
- tabIndex: 0,
- selectValue: null,
- selectOptions: [],
-
- selectValues: this.value,
- selectLabels: [],
- };
- },
- mounted() {
- // 获取第一个tab的selectOptions
- },
- methods: {
- close() {
- this.show = false
- },
- // 打开选择弹框
- open() {
- this.selectValues = this.value || []
- this.title = this.labels.join('/') || this.placeholder
- if(!this.selectValues.length){
- // 展示tabs第一个数据
- this.tabIndex = 0
- }else{
- // 展示tabs最后一个数据
- this.tabIndex = 2
- }
- this.setSelectOptions()
- this.show = true
- },
- // 设置单选列表数据
- setSelectOptions(){
- switch(this.tabIndex){
- case 0:
- this.selectOptions = this.tabsList[0].list
- break
- case 1:
- this.selectOptions = this.tabsList[1].list
- break
- case 2:
- this.selectOptions = this.tabsList[2].list
- break
- }
- },
- // 单选改变
- change(e) {
- // 赋值
- this.selectValues[this.tabIndex] = e
- let obj = this.selectOptions.find(e1 => e1.value == e)
- this.selectLabels[this.tabIndex] = obj.label
- // 切换tab
- if (this.tabIndex < this.tabsList.length - 1) {
- let nextItem = this.tabsList[this.tabIndex + 1]
- this.tabsChange(nextItem)
- }
- if(this.tabIndex == this.tabsList.length - 1){
- this.tabsList[this.tabIndex].name = obj.label
- }
- },
- // 切换tab
- tabsChange(item) {
- if (this.tabIndex == item.value) return
- this.tabIndex = item.value
- setTimeout(() => {
- this.setSelectOptions()
- this.selectValue = null
- this.initTabs()
- }, 150)
- },
- // 初始化tab数据
- initTabs() {
- for (let item of this.tabsList) {
- if (item.value > this.tabIndex) {
- item.disabled = true
- this.selectValues[item.value] = ''
- this.selectLabels[item.value] = ''
- } else if (item.value < this.tabIndex) {
- item.disabled = false
- } else {
- item.disabled = false
- this.selectValues[item.value] = ''
- this.selectLabels[item.value] = ''
- }
- item.name = this.selectLabels[item.value]||item.cate
- }
- },
- // 确定
- cofirm() {
- if (this.selectValues[2]) {
- this.$emit("input", this.selectValues)
- this.$emit("update:labels", this.selectLabels)
- this.$emit("change", this.selectValues)
- this.title = this.selectLabels.join('/')
- this.close()
- }else{
- this.$emit("input", [])
- this.$emit("update:labels", [])
- this.$emit("change", [])
- this.title = this.placeholder
- this.close()
- }
- },
- }
- }
- </script>
-
- <style scoped lang="scss">
- .title {
- color: #333;
- font-size: 32rpx;
- text-align: center;
- line-height: 100rpx;
- }
-
- .u-radio-group {
- width: 92%;
- height: 780rpx;
- overflow-y: auto;
- padding: 0 30rpx;
-
- .u-cell {
- background-color: #fff;
- border-radius: 20rpx 20rpx 0 0;
- padding: 24rpx 0;
- }
- }
-
- .u-border-bottom {
- border-color: #F6F6F6 !important;
- }
-
- .u-radio {
- margin-top: 18rpx;
- }
-
- .u-checkbox {
- margin-top: 18rpx;
- }
- </style>
|