/*******************************************************************************
 * Copyright(c) 2022 dongke All rights reserved. / Confidential
 * 类的信息：
 *		1.程序名称：
 *		2.功能描述：折叠面板
 * 编辑履历：
 *		作者				日期					版本				修改内容
 *		admin		  	2022-11-17  	 1.00		   	  新建
 *******************************************************************************/
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 数据源
    list: {
      type: Array,
      value: []
    },
    activeNames: {
      type: Array,
      value: []
    },
  },

  /**
   * 组件的选项
   */
  options: {
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    tableData:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({
        activeNames: event.detail,
      });
    },

    onCheckedItem(e) {
      console.log(e)
      let _that = this
      let index = e.currentTarget.dataset.index
      let list =_that.data.list
      list[index].checked = !list[index].checked
      if (list[index].children && list[index].children.length > 0) {
        if(list[index].checked){
          list[index].childrenChecked = false
        }
        list[index].children.forEach(res => {
          res.checked = list[index].checked
        })
      }
      list[index].checked = list[index].checked
      console.log('list',list)
      _that.setData({
        list: list
      })
      this.triggerEvent("obtainList", { list: list })
    },
    //todo
    onCheckedItem_(e) {
      let index = e.currentTarget.dataset.index
      let index_ = e.currentTarget.dataset.index_
      let list = this.data.list
      list[index].children[index_].checked = !list[index].children[index_].checked
      let  checkedList = []
      list[index].children.forEach(it=>{
        if(it.checked){
          checkedList.push(it)
        }
      })
      if(checkedList.length ==  list[index].children.length){
        list[index].checked = true
        list[index].childrenChecked = false
      }else{
        list[index].checked = false
        //控制父级选中图标
        list[index].childrenChecked = checkedList.length  == 0  ? false : true  
      }
      this.setData({
        list: list
      })
      this.triggerEvent("obtainList", { list: list })
    },
  }
})
