<!-- 遮罩层 -->
<template name="mask">
  <view class="warp-mask">
    <view class="mask">
      <view class="maskbgc"></view>
      <view class="content">
        <view class="header">
          <view class="title">菜单权限</view>
          <image
            src="../../static/images/closeicon.png"
            class="iconclose"
            @tap="closeMask"
          />
        </view>
        <view class="content-warp">
          <view class="message">
            <view class="radiolist">

              <view class="uni-list father-list">
                <checkbox-group @change="fatherChange">
                  <label class="uni-list-cell uni-list-cell-pd checked-bar" v-for="fatheritem in list" :key="fatheritem.menuId">
                    <view class="main-checked-list">
                      <checkbox :value="fatheritem.value" :checked="item.checked"/>
                      <view class="title">{{ fatheritem.name }}</view>
                    </view>
                    <!-- 子权限 -->
                    <view class="childemenu">
                      <view class="uni-list son-list">
                        <checkbox-group @change="sonChange" class="son-checked-warp">
                          <label class="uni-list-cell uni-list-cell-pd son-bar" v-for="sonitem in fatheritem.children" :key="sonitem.value">
                            <view class="son-checked-list">
                              <checkbox style="transform:scale(0.7)" :value="sonitem.value" :checked="item.checked"/>
                              <view class="son-title">{{sonitem.name}}</view>
                            </view>
                          </label>
                        </checkbox-group>
                      </view>
                    </view>

                    <image v-if="!item.checked && item.children" class="moreicon" src="../../static/images/moreicon.png"></image>
                    <image v-if="item.checked && item.children" class="downicon"  src="../../static/images/downmoreicon.png"></image>
                  </label>
                </checkbox-group>
              </view>
              
            </view>
          </view>
          <view class="sure">
            <view class="btn" @tap="sureconver">确认</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import editclassifyVue from '../goods/editclassify.vue';
export default {
  name: 'mask',
  props: {
    list:{
      type:Array,
      default: [],
    },
    hasList: {
      type:Array,
      default: []
    }
  },
  data () {
    //这里存放数据
    return {
      roleArray: []
    }
  },
  //方法集合
  methods: {
    sureconver () {
      this.$emit('isSureConver', true)
    },
    closeMask () {
      this.$emit('isSureConver', false)
    },

    // 显示已经拥有权限


    // 父级权限选择
    fatherChange (e) {
      console.log(this.hasList);

      console.log(e);
      let items = this.list
      values = e.detail.value; // 选中的集合
      for (let i = 0; i < items.length; ++i) {
        const element = items[i]
        if (values.includes(element.value)) {
          this.$set(element, 'checked', true)
        } else {
          this.$set(element, 'checked', false)
        }
      }
      console.log(this.list);
    },

    // 子集权限选择
    sonChange (e) {
      console.log(e);
      let items = this.list,
      values = e.detail.value; // 选中的集合
      for (let i = 0; i < items.length; ++i) {
        const element = items[i]
        if (values.includes(element.value)) {
          this.$set(element, 'checked', true)
        } else {
          this.$set(element, 'checked', false)
        }
      }
    }
  }
};
</script>
<style lang='scss' scoped>
.warp-mask {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.mask {
  position: relative;
  width: 100vw;
  height: 100vh;

  .maskbgc {
    position: absolute;
    bottom: 0;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.4);
  }
  .content {
    position: absolute;
    top: 20%;
    left: 50%;
    margin-left: -320upx;
    width: 640upx;
    z-index: 101;
    box-sizing: border-box;
    overflow: hidden;
    .header {
      position: relative;
      width: 100%;
      height: 102upx;
      border-top-left-radius: 20upx;
      border-top-right-radius: 20upx;
      background-color: #ffcd00;
      .title {
        text-align: center;
        font-weight: 600;
        line-height: 102upx;
        color: #0f1e1a;
        font-size: 36upx;
        letter-spacing: 2upx;
      }
      .iconclose {
        position: absolute;
        right: 24upx;
        top: 50%;
        margin-top: -15upx;
        height: 31upx;
        width: 31upx;
      }
    }
    .content-warp {
      background-color: #fff;
      border-bottom-left-radius: 20upx;
      border-bottom-right-radius: 20upx;
      .message {
        padding: 10upx 60upx 0;
        overflow-y: scroll;
        height: 670upx;
        .radiolist {
          .father-list {
            .checked-bar {
              display: flex;
              flex-direction: column;
              justify-content: flex-end;
              padding-top: 45upx;
              .main-checked-list{
                display: flex;
                width: 100%;
                // flex: 1;
                .title {
                  margin-left: 30upx;
                  color: #666666;
                  font-size: 32upx;
                }
              }
              .moreicon{
                width: 19upx;
                height: 27upx;
              }
              .downicon {
                width: 27upx;
                height: 19upx;
              }
              .childemenu {
                width: 100%;
                .son-checked-warp {
                  display: flex;
                  flex-wrap: wrap;
                  padding-left: 40upx;
                  box-sizing: border-box;
                  .son-bar {
                    width: 45%;
                    display: flex;
                    align-items: center;
                    box-sizing: border-box;
                    &:nth-child(odd){
                      margin-right: 35upx;
                    }
                    .son-checked-list {
                      display: flex;
                    }
                  }
                }
                .son-title {
                  margin-left: 15upx;
                  color: #666666;
                }
              }
            }
          }
        }
      }
      .sure {
        padding-bottom: 40upx;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;
        .btn {
          width: 280upx;
          height: 80upx;
          background-color: #a95cff;
          color: #fff;
          font-size: 32upx;
          letter-spacing: 2upx;
          text-align: center;
          line-height: 80upx;
          border-radius: 10upx;
        }
      }
    }
  }
}
</style>