123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <template>
- <div class="Dialog" v-show="show">
- <div class="DialogTit">
- <div class="back" @click="hide()">
- <span class="iconfont"></span>返回
- </div>
- <h1 class="name">{{ title }}</h1>
- <!-- <span class="success" @click="handle_selected()">完成</span> -->
- <span v-if="type == 1" class="success"></span>
- <span v-if="type == 2" @click="handle_selected" class="success"
- >确定</span
- >
- </div>
-
- <div class="optionsBox" v-show="type == 1">
- <div class="list">
- <ul>
- <li
- v-for="(item, i) in single.options"
- :key="i"
- :value="single.id_key.lenght == 0 ? item : item[single.id_key]"
- :class="
- single.cur_id ==
- (single.id_key.lenght == 0 ? item : item[single.id_key])
- ? 'tick'
- : ''
- "
- @click="
- single_click(
- single.id_key.lenght == 0 ? item : item[single.id_key]
- )
- "
- >
- {{ single.show_key.lenght == 0 ? item : item[single.show_key] }}
- </li>
- </ul>
- </div>
- </div>
-
- <div class="CheckBox" v-show="type == 2">
- <ul>
- <li>
- <van-checkbox-group v-model="mutable.selected_values">
- <van-checkbox
- style="border-bottom: 1px #e5e5e5 solid;padding: 0 0.38rem;width:100%;"
- v-for="(item, index) in mutable.options"
- :key="index"
- :name="mutable.id_key.lenght == 0 ? item : item[mutable.id_key]"
- >
- {{ mutable.show_key.lenght == 0 ? item : item[mutable.show_key] }}
- </van-checkbox>
- </van-checkbox-group>
- </li>
- </ul>
- </div>
- </div>
- </template>
-
- <script>
- export default {
- name: "TwoMenu",
- data() {
- return {
- // list: ["复选框1", "复选框2"],
- // result: ["复选框1"],
-
- show: false,
- type: 1, // 1.单选 2.复选
- handle_select: null, // function
- handle_hide: null, // function
-
- title: "",
- single: {
- options: [],
- cur_id: 0,
- show_key: "",
- id_key: ""
- },
-
- mutable: {
- options: [],
- selected_values: [],
- show_key: "",
- id_key: ""
- }
- };
- },
- methods: {
- showSingleSelect(
- list_options,
- current_select_id,
- title,
- show_key,
- id_key,
- handle_select,
- handle_hide
- ) {
- this.show = true;
- this.type = 1;
- this.title = title;
- this.single.options = list_options;
- this.single.cur_id = current_select_id;
- this.single.show_key = show_key;
- this.single.id_key = id_key;
- this.handle_select = handle_select;
- this.handle_hide = handle_hide;
- console.log(this.single.cur_id);
- },
- // showMutableSelect(list_options, selected_values, title, show_key, id_key, handle_select) {
- // this.show = true
- // this.type = 2
- // this.title = title
- // this.mutable.options = list_options
- // this.mutable.selected_values = selected_values
- // this.mutable.show_key = show_key
- // this.mutable.id_key = id_key
- // this.handle_select = handle_select
- // },
- hide() {
- if (this.handle_hide != null && this.handle_hide != undefined) {
- this.handle_hide();
- }
- this.show = false;
- },
- single_click: function(id) {
- this.single.cur_id = id;
- this.finish_selected();
- this.hide();
- },
- finish_selected: function() {
- if (this.handle_select != null && this.handle_select != undefined) {
- this.handle_select(this.single.cur_id);
- }
- }
- }
- };
- </script>
-
- <style style="stylesheet/scss" lang="scss" scoped>
- .van-checkbox__icon--checked .van-icon {
- color: #fff;
- border-color: $main-color !important;
- background-color: $main-color !important;
- }
- .optionsBox {
- background: #fff;
- max-height: 10.6rem;
- min-height: 5rem;
- overflow-y: scroll;
- @media only screen and (max-width: 812px) {
- min-height: 8rem !important;
- }
- @media only screen and (min-width: 415px) and (max-width: 737px) {
- max-height: 12.6rem !important;
- }
- ul {
- li {
- height: 1.2rem;
- line-height: 1.2rem;
- border-bottom: 1px #e5e5e5 solid;
- padding: 0 0.38rem;
- font-size: 0.45rem;
- }
- .tick {
- position: relative;
- &::before {
- content: "";
- display: inline-block;
- border: 2px solid $main-color;
- border-top-width: 0;
- border-right-width: 0;
- width: 0.3rem;
- height: 0.15rem;
- -webkit-transform: rotate(-50deg);
- position: absolute;
- top: 0.38rem;
- right: 0.44rem;
- }
- }
- }
- }
- .CheckBox {
- background: #fff;
- max-height: 10.6rem;
- min-height: 5rem;
- overflow-y: scroll;
- ul {
- li {
- line-height: 1rem;
- }
- }
- }
- </style>
|