| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <template>
- <view class="select-view">
- <view class="select-mark-view" v-show="showList" @click="touchMarkEvent">
- </view>
- <view class="content-view" @click.stop="touchContent">
- <slot> </slot>
- <view class="filter-view">
- <view class="filter-header">
- <view
- class="filter-title"
- v-for="(item, listIndex) in dataList"
- :key="listIndex"
- >
- <view @click="showListEvent(listIndex)">
- <text>{{ getListCheckName(item) }}</text>
- <text
- v-if="listIndex == curIndex"
- class="iconfont iconsanjiaoshang"
- ></text>
- <text v-else class="iconfont iconsanjiao_xia"></text>
- </view>
- </view>
- </view>
- <view class="filter-list" v-if="showList">
- <view
- class="filter-item"
- v-for="(item, index) in dataList[curIndex].data"
- :key="index"
- @click="selectItemEvent(item)"
- >
- <text class="iconfont icondagou" v-if="item.checked"> </text>
- <text>
- {{ item.name }}
- </text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { copyObject } from "@/utils/util";
- const SELECT_TYPES = {
- RADIO: "radio",
- MULTIPLE: "multiple"
- };
- export default {
- props: {
- list: {
- type: Array,
- default() {
- return [
- // {
- // title:'', //标题
- // key:'', //字段名
- // data:[
- // {
- // name:'',
- // value:''
- // }
- // ]
- // }
- ];
- }
- },
- type: {
- type: String,
- default: SELECT_TYPES.RADIO //multiple
- }
- },
- data() {
- return {
- curValue: "",
- curIndex: -1,
- showList: false,
- dataList: []
- };
- },
- onLoad() {},
- created() {
- this.initList();
- },
- computed: {
- curItemName() {
- let curlist = [];
- if (this.dataList && this.dataList[this.curIndex]) {
- curlist = this.dataList[this.curIndex].data;
- }
- let item = curlist.find(ele => {
- return ele.value == this.curValue;
- });
- if (item) {
- return item.name;
- }
- return false;
- }
- },
- methods: {
- initList() {
- this.dataList = [];
- for (const item of this.list) {
- let ele = copyObject(item);
- ele.data.forEach(element => {
- if (element.value == ele.default) {
- element.checked = true;
- } else {
- element.checked = false;
- }
- });
- this.dataList.push(ele);
- }
- },
- getListCheckName(info) {
- let name = info.title;
- for (const item of info.data) {
- if (item.checked) {
- name = item.name;
- break;
- }
- }
- return name;
- },
- touchContent() {},
- touchMarkEvent() {
- this.showList = false;
- this.curIndex = -1;
- },
- selectItemEvent(item) {
- if (SELECT_TYPES.RADIO == this.type) {
- let list = this.dataList[this.curIndex].data;
- list.forEach(element => {
- element.checked = false;
- });
- console.log(444444, list);
- }
- this.curValue = item.value;
- item.checked = true;
- this.$nextTick(() => {
- this.searchEvent();
- });
- },
- showListEvent(index) {
- this.curIndex = index;
- this.showList = true;
- },
- searchEvent() {
- this.showList = false;
- let params = this.getParams();
- this.$emit("search", params);
- },
- getParams() {
- let params = {};
- for (const item of this.dataList) {
- for (const listItem of item.data) {
- params[item.key] = "";
- if (listItem.checked) {
- params[item.key] = listItem.value;
- break;
- }
- }
- }
- return params;
- }
- },
- watch: {
- list(val, old) {
- if (val && val instanceof Array) {
- this.initList();
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .select-view {
- display: fixed;
- width: 100%;
- .select-mark-view {
- /* #ifndef H5 */
- height: 100vh;
- /* #endif */
- /* #ifdef H5 */
- height: 100%;
- /* #endif */
- position: absolute;
- width: 100%;
- background-color: rgba(0, 0, 0, 0.5);
- }
- .content-view {
- position: relative;
- z-index: 1;
- .filter-view {
- .filter-header {
- display: flex;
- background-color: #fff;
- .filter-title {
- position: relative;
- flex: 1;
- height: 80upx;
- line-height: 80upx;
- text-align: center;
- &:not(:last-child):after {
- position: absolute;
- content: "";
- width: 1px;
- height: 50%;
- background-color: #dddddd;
- top: 50%;
- right: 0;
- transform: translateY(-50%);
- }
- .iconfont {
- font-size: 30upx;
- }
- }
- }
- .filter-list {
- position: absolute;
- top: 100%;
- left: 0;
- width: 100%;
- padding: 20upx 30upx;
- max-height: 400upx;
- background-color: #f8f9fb;
- border-radius: 0 0 25upx 25upx;
- .filter-item {
- width: 100%;
- height: 70upx;
- line-height: 70upx;
- font-size: 26upx;
- .iconfont {
- font-size: 36upx;
- color: $mainColor;
- }
- text {
- margin: 0 10upx;
- }
- }
- }
- }
- }
- }
- </style>
|