uniapp页面开发
实现用户选择,选择完成后进行页面跳转。
/**
* @Author: 858834013@qq.com
* @Name: typeSelector
* @Date: 2022-01-18
* @Desc: 类型选择器
*/
<template>
<div>
<div @click="getshow">
<slot></slot>
</div>
<u-picker :title="title" :show="show" @cancel="show=false" @confirm="getConfirm" :columns="list"></u-picker>
</div>
</template>
<script>
import {
industryGetList
} from '@/config/api.js'
export default {
name: 'typeSelector',
components: {},
props: {
title: {
type: String,
default () {
return ''
}
},
type: {
type: Boolean,
default () {
return false
}
},
},
data() {
return {
show: false,
datalist: [],
data: [],
list: [
[]
]
};
},
mounted() {
this.getdata()
},
methods: {
getshow() {
this.show = true
},
getConfirm(e) {
var that = this;
console.log(e)
this.switchPage(that.data[e.indexs[0]])
this.$emit('getdata', that.list[0][e.indexs[0]])
this.show = false
},
switchPage(e) {
uni.setStorageSync('uid', e.Id)
uni.setStorageSync('userData', JSON.stringify(e))
if (e.UserType == 1) {
uni.redirectTo({
url: '/pages/home/enterprise/index'
})
} else if (e.UserType == 2) {
uni.redirectTo({
url: '/pages/home/client/index'
})
} else if (e.UserType == 3) {
uni.redirectTo({
url: '/pages/home/owner/index'
})
} else if (e.UserType == 4) {
uni.redirectTo({
url: '/pages/home/driver/index'
})
} else {
uni.redirectTo({
url: '/pages/home/home'
})
}
},
getdata() {
var that = this;
that.list[0] = [];
that.data = uni.getStorageSync('allUserData')
that.data.forEach((type) => {
that.list[0].push(type.CompanyName)
});
}
}
}
</script>
<style lang="scss" scoped>
</style>