<template>
  <div class="mimititle">

    <template>
      <table>
        <tbody v-for="(item,index) in dataList" :key="index">
          <tr>
            <td>
              {{item.firstItem.PageName}}
            </td>
            <td>
              <el-input v-model="item.firstItem.SelePageName" />
            </td>
            <td>
               <span v-if="item.secondItem">  {{item.secondItem.PageName}}</span>
            </td>
            <td>
              <el-input v-if="item.secondItem" v-model="item.secondItem.SelePageName" />
            </td>
          </tr>
        </tbody>
      </table>
    </template>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        loading: false,
        dataList: [],
      };
    },
    created() {

    },
    methods: {
      getList() {
        this.dataList = [];

        this.apipost("/api/Tenant/MiniprogramPageListExt", {}, res => {
          if (res.data.resultCode == 1) {
            var data = res.data.data;
            var myArray = [];
            if (data && data.length > 0) {
              data.forEach(item => {
                if (item.SubMenuList && item.SubMenuList.length > 0) {
                  item.SubMenuList.forEach(subItem => {
                    myArray.push(subItem);
                  })
                }
              });
              console.log("myArray", myArray);
              if (myArray && myArray.length > 0) {
                var totalpage = 0;
                if (myArray.length % 2 == 1) {
                  totalpage = parseInt(myArray.length / 2) + parseInt(1);
                } else {
                  totalpage = parseInt(myArray.length / 2);
                }
                console.log("totalpage", totalpage)
                for (var index = 0; index < totalpage; index++) {
                  var singleIndex = index * 2;
                  var doubleIndex = Number(index * 2) + Number(1)
                  var obj = {
                    firstItem: "",
                    secondItem: ""
                  };
                  if (singleIndex <= myArray.length) {
                    obj.firstItem = myArray[singleIndex];
                  }
                  if (doubleIndex <= myArray.length) {
                    obj.secondItem = myArray[doubleIndex];
                  }
                  console.log("obj", obj);
                  this.dataList.push(obj)
                }
                console.log(" this.dataList", this.dataList)
              }
            }
          } else {
            this.Info(res.data.message);
          }
        })
      },
    },
    mounted() {
      this.getList();
    }
  };

</script>
<style>
  .navNavIconImg {
    width: 80px;
    height: 80px;
  }

  .navNavIconImg NavIconImg {
    width: 100%;
    height: 100%;
  }

  .mimititle .blue {
    color: #409EFF;

  }

  .mimititle .content .searchInput {
    border: 1px solid #DCDFE6;
    border-radius: 4px;
  }

  .mimititle .content .searchInput .el-input__inner {
    border: none;
    outline: none;
    height: 30px;
    line-height: 30px;
  }

  .mimititle .content .searchInput {
    line-height: normal;
    display: inline-table;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    width: 250px;
    margin-right: 20px;
  }

  .mimititle .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }

</style>
