<template>
  <div v-if="visibility" class="Dialog">
    <div class="DialogTit">
      <div class="back" @click="cancle()">
        <span class="iconfont">&#xe720;</span>返回
      </div>
      <h1 class="name">{{ propsForm.title }}</h1>
      <span
        v-if="propsForm.isMultiple == 1"
        @click="comfirm"
        class="success"
      ></span>
      <span v-if="propsForm.isMultiple == 2" @click="comfirm" class="success"
        >保存</span
      >
    </div>

    <div v-if="propsForm.isMultiple == 1" class="optionsBox">
      <div class="list">
        <ul>
          <li @click="itemClick(-2)" :key="-2" value="-2">请选择</li>
          <li
            @click="itemClick(item.id)"
            v-for="item in propsForm.optionList"
            :key="item.id"
            value="item"
            :class="propsForm.selectId == item.id ? 'tick' : ''"
          >
            {{ item.name }}
          </li>
          <!--<li v-if="propsForm.isHasOther == 1 && this.$store.getters.user.template_info.template_id == 2" @click="itemClick(-1)"  :key="-1" value="-1" :class="propsForm.selectId == -1? 'tick':'' ">其他</li>-->
        </ul>
      </div>
    </div>

    <div v-if="propsForm.isMultiple == 2" class="CheckBox">
      <ul>
        <li>
          <van-checkbox-group v-model="propsForm.result">
            <van-checkbox
              style="border-bottom: 1px #e5e5e5 solid;padding: 0 0.38rem"
              v-for="(item, index) in propsForm.list"
              :key="index"
              :name="item.name"
              >{{ item.name }}</van-checkbox
            >
          </van-checkbox-group>
        </li>
      </ul>
      <!--<div style="margin-top: 10px" v-if="propsForm.isShowOther == 2">-->
      <!--<el-form>-->
      <!--<el-form-item label-width="90px" label="其他"  >-->
      <!--<el-input clearable v-model="other" ></el-input>-->
      <!--</el-form-item>-->
      <!--</el-form>-->
      <!--</div>-->
    </div>
  </div>
</template>

<script>
export default {
  name: "checkBoxSubMenu",
  created() {},
  data() {
    return {
      result: [],
      id: 0,
      selectName: "",
      other: ""
    };
  },
  props: {
    propsForm: {
      type: Object
    },
    visibility: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    cancle: function() {
      this.$emit("menu-cancle");
    },
    comfirm: function() {
      this.$emit("menu-comfirm", this.getValue());
      // this.other = ""
    },
    getValue: function() {
      let form = {};
      if (this.propsForm.isMultiple == 2) {
        form["type"] = this.propsForm.type;
        form["result"] = this.propsForm.result;
        // form['other'] = this.other

        // form["click_ref"] = this.propsForm.click_ref
      } else {
        form["type"] = this.propsForm.type;
        form["selectId"] = this.propsForm.selectId;
        // form["click_ref"] = this.propsForm.click_ref
      }
      return form;
    },
    itemClick: function(id) {
      if (id == -2) {
        this.$emit("menu-empty", this.getValue());
      }
      this.propsForm.selectId = id;
      this.$emit("menu-comfirm", this.getValue());
    }
  },
  watch: {
    visibility(val) {
      //初始化数据操作
    }
  }
};
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.optionsBox {
  background: #fff;
  max-height: 10rem;
  min-height: 5rem;
  @media only screen and (max-width: 812px) {
    min-height: 8rem !important;
  }
  @media only screen and (max-width: 415px) {
    height: 16.8rem !important;
  }
  @media only screen and (min-width: 666px) and (max-width: 737px) {
    max-height: 8rem;
    min-height: 7rem !important;
  }
  @media only screen and (max-width: 767px) {
    max-height: 16rem !important;
  }
  @media only screen and (max-width: 768px) {
    max-height: 11.8rem !important;
  }
  @media only screen and (min-width: 415px) and (max-width: 767px) {
    max-height: 13.8rem !important;
  }
  @media only screen and (min-width: 666px) and (max-width: 737px) {
    max-height: 8rem;
    min-height: 7rem !important;
  }
  ul {
    overflow-y: scroll;
    max-height: 9rem;
    @media only screen and (min-width: 666px) and (max-width: 737px) {
      max-height: 8rem;
    }
    @media only screen and (max-width: 767px) {
      max-height: 16rem;
    }
    @media only screen and (max-width: 768px) {
      max-height: 11.8rem !important;
    }
    @media only screen and (min-width: 415px) and (max-width: 767px) {
      max-height: 13.8rem !important;
    }
    li {
      height: 1.2rem;
      line-height: 1.2rem;
      border-bottom: 1px #e5e5e5 solid;
      padding: 0 0.38rem;
      font-size: 0.45rem;
      color: $title-color;
      @media only screen and (max-width: 767px) {
        height: 1.4rem;
        line-height: 1.4rem;
      }
    }
    .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: 812px) {
    max-height: 8rem !important;
    min-height: 8rem !important;
  }
  @media only screen and (max-width: 767px) {
    max-height: 15rem !important;
    min-height: 8rem !important;
  }
  @media only screen and (min-width: 768px) {
    max-height: 11.8rem !important;
    min-height: 8rem !important;
  }
  @media only screen and (min-width: 813px) and (max-width: 1024px) {
    max-height: 10.8rem !important;
  }
  ul {
    li {
      line-height: 1.2rem;
      @media only screen and (max-width: 767px) {
        line-height: 1.4rem;
      }
    }
  }
}
</style>
