<template>
  <div v-if="visibility" class="Dialog">
    <div class="DialogTit">
      <div class="back" @click="backAction">
        <span class="iconfont">&#xe720;</span>返回
      </div>
      <h1 class="name">{{ title }}</h1>
      <span class="success" style="width:36px;"></span>
    </div>

    <div class="optionsBox">
      <div class="list">
        <ul>
          <li @click="itemClick(-1)">请选择</li>
          <li
            @click="itemClick(index)"
            v-for="(option, index) in options"
            :key="
              option_key != null && option_key.length > 0
                ? option[option_key]
                : index
            "
            :class="select_index == index ? 'tick' : ''"
          >
            {{
              option_label_key != null && option_label_key.length > 0
                ? option[option_label_key]
                : option
            }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "SingleOptionDialogContent",
  data() {
    return {
      select_index: -1
    };
  },
  props: {
    visibility: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ""
    },
    options: {
      type: Array,
      required: true
    },
    option_key: {
      // 如果 options 是Object数组，选项唯一标识的 key，可不传
      type: String,
      default: ""
    },
    option_label_key: {
      // 如果 options 是Object数组，选项显示文本的object 的 key，否则不传则显示 options 元素
      type: String,
      default: ""
    }
  },
  methods: {
    backAction: function() {
      this.$emit("back");
    },
    itemClick: function(index) {
      this.select_index = index;
      this.$emit("did-selected", this.select_index);
    }
  }
};
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.optionsBox {
  background: #fff;
  min-height: 5rem;
  @media only screen and (max-width: 767px) {
    min-height: 15.8rem;
  }
  // @media only screen and (max-width: 812px) {
  //   min-height: 11.8rem;
  // }
  ul {
    overflow-y: scroll;
    max-height: 16rem;
    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: 6.8rem;
  min-height: 5rem;
  overflow-y: scroll;
  @media only screen and (max-width: 767px) {
    max-height: 11.8rem !important;
    min-height: 8rem !important;
  }
  // @media only screen and (max-width: 812px) {
  //   max-height: 8rem !important;
  //   min-height: 8rem !important;
  // }
  ul {
    li {
      line-height: 1rem;
    }
  }
}
</style>
