import http from '../../base/httputil'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //
    busEnterpriseId: null,
    xunjianItems: null,
    items_first: null,
    items_second: null,
    items_third: null,
    //
    isFolded: true,
    hui: "block",
    currentIndex: 0,
    child2: [],
    eIndex: 0,
    eIndex2: 0,
    eIndex3: 0,
    selt: "on",
    oneL: "",
    oneLL: "一类/未选择",
    twoL: "二类/未选择",
    threeL: "0",
    listdatachild: [],
    listdatachild2: [],
    //未选中图标
    noselt: "noNo",
    listdata: [{
        info: "建立安全防火制度，明确防火责任人及其职责",
        checked: true,
      },
      {
        info: "建立安全防火制度，明确防火责任人及其职责，建立安全防火制度，明确防火责任人及其职责，建立安全防火制度，明确防火责任人及其职责",
        checked: true,
      },
    ],
    listdata2: [{
        info2: "安全出口、疏散指示标识、应急照明是否齐全、有效",
        checked: true
      },
      {
        info2: "安全出口、疏散通道应保持通畅，严禁将安全出口上锁、阻塞",
        checked: true
      },
      {
        info2: "就餐区内禁止使用液化石油气",
        checked: true
      },
      {
        info2: "电气线路严禁斯拉乱按，是否存在低于2米以下电线（电缆）未穿管防护现象",
        checked: true
      }
    ],
    listdatachoose: [{
        text: "饭点、小饮品店、小超市（食品、药品、水果蔬菜、文具、铁艺制品、生产资料等物资销售）、小诊所检查内容",
        children: [{
            text: "安全管理",
            checked: true,
            children: [{
                text: "儿贼3级1",
                checked: true,
                value: '001',
                choose: false
              },
              {
                text: "儿贼3级2",
                checked: true,
                value: '002',
                choose: false
              }
            ],
          },
          {
            text: "现场",
            children: [{
                text: "儿贼3级1",
                checked: true,
                value: '003',
                choose: false
              },
              {
                text: "儿贼3级2",
                checked: false,
                value: '004',
                choose: false
              }
            ],
            checked: true

          }
        ]
      },
      {
        text: "小浴池、小网吧、小美容院、小旅馆内容",
        children: []
      },
      {
        text: "社会福利业检查内容",
        children: []
      },
      {
        text: "建筑工地检查内容",
        children: []
      },
      {
        text: "机动车修理铺检查内容",
        children: []
      },
      {
        text: "家具制造（床垫）检查内容",
        children: []
      },
      {
        text: "食品加工品类检查内容",
        children: []
      }
    ],

    listdata5: [{
        text: "1、安全出口疏散标识"
      },
      {
        text: "2、就餐区内禁止使用明火"
      }
    ]
  },


  onLoad(e) {
    console.log(e.busEnterpriseId)
    this.data.busEnterpriseId = e.busEnterpriseId
    this.getXunjianczData()
  },
  getXunjianczData() {
    let obj = new Object();
    obj.busEnterpriseId = this.data.busEnterpriseId;
    http.post("/system/AppXunjianController/getXunjianczData", obj, this.getXunjianczDataSuccess)
  },
  getXunjianczDataSuccess(res) {
    console.log(res)
    this.setData({
      xunjianItems: res.xunjianItems,
      items_first: res.items_first
    })
  },

  changeme: function (e) {
    var flag = e.detail.value;

    //flag 为true 代表为选中的状态
    if (flag) {
      this.setData({
        hui: "block"
      })
    } else {
      this.setData({
        hui: "hui"
      })
    }
  },
  // 切换swiper-item触发bindchange事件
  pagechange: function (e) {
    // 通过touch判断，改变tab的下标值
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex;
      currentPageIndex = (currentPageIndex + 1) % 2;
      // 拿到当前索引并动态改变
      this.setData({
        currentIndex: currentPageIndex,
      })
    }
  },

  //点击tab时触发
  titleClick: function (e) {
    this.setData({
      //拿到当前索引并动态改变
      currentIndex: e.currentTarget.dataset.idx
    })
  },
  change_color_1(e) {
    let busitemsid = e.currentTarget.dataset.busitemsid
    this.getSecondItems(busitemsid);
    // console.log(index)
    // console.log(this.data.listdatachoose[index].text)
    // let child1 = this.data.listdatachoose[index].text;
    this.setData({
      myclick: busitemsid,
      currentIndex: "1",
      // oneLL: child1,
      // listdatachild: this.data.listdatachoose[index].children,
      twoL: "二类/未选择",
    })
    // if (this.data.listdatachoose[index].children == '') {
    //   console.log('null')
    //   this.setData({
    //     listdatachild2: ''
    //   })
    // }
  },

  getSecondItems(busitemsid) {
    let obj = new Object();
    obj.parentId = busitemsid
    http.post("/system/AppXunjianController/getItems", obj, this.getSecondItemsSuccess)
  },
  getSecondItemsSuccess(res) {
    console.log(res)
    this.setData({
      items_second: res.data
    })
  },

  change_color_2(e) {
    let busitemsid = e.currentTarget.dataset.busitemsid
    this.getThirdItems(busitemsid)
    // let index = this.data.eIndex
    // let index2 = this.data.eIndex2
    // index2 = e.currentTarget.dataset.index2
    // let child2 = this.data.listdatachoose[index].children[index2].text
    // console.log(this.data.listdatachoose[index].children[index2])

    this.setData({
      myclick2: busitemsid,
      currentIndex: "2",
      // listdatachild2: this.data.listdatachoose[index].children[index2].children,
      // twoL: child2,
    })
  },
  getThirdItems(busitemsid) {
    let obj = new Object();
    obj.parentId = busitemsid
    obj.busEnterpriseId = this.data.busEnterpriseId
    http.post("/system/AppXunjianController/getItemsLast", obj, this.getThirdItemsSuccess)
  },
  getThirdItemsSuccess(res) {
    this.setData({
      items_third: res.data
    })
  },

  checkThirdItem(e){
    console.log(e)
  },


  change_color_3(e) {

    let click = e.currentTarget.dataset.index2
    let index = this.data.eIndex
    let index2 = this.data.eIndex2
    let index3 = this.data.eIndex3
    index3 = e.currentTarget.dataset.index3
    let child2 = this.data.listdatachoose[index].children[index2].text
    console.log(this.data.listdatachoose[index].children[index2])
    this.setData({
      myclick3: e.currentTarget.dataset.index3,
    })
  },

  checkboxChange(e) {
    let index = this.data.eIndex
    let index2 = this.data.eIndex2
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    const items = this.data.listdatachoose[index].children[index2].children
    console.log(items)
    const values = e.detail.value
    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      items[i].choose = false
      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].value === values[j]) {
          items[i].choose = true
          break
        }
      }
      console.log(items[i].choose, 'sladjfklsadjflkasdjflkdjslk')
    }
    this.setData({
      items
    })
  },
  //收起弹层
  updown() {
    console.log('弹出收起')
    this.setData({
      isFolded: !this.data.isFolded,
    })
  }


})