<template>
  <view class="card">
    <serveModuleView v-model="isFold" :data="data" @change="onChange"></serveModuleView>
    <view v-if="!isFold" class="content">
      <view class="list">
        <view class="list-item" v-for="item in list" :key="item.id">
          <serveSecondModuleCard :data="item"></serveSecondModuleCard>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import serveModuleView from './serveModuleView.vue';
  import serveSecondModuleCard from './serveSecondModuleCard.vue';

  export default {
    components: {
      serveModuleView,
      serveSecondModuleCard,
    },
    props: {
      data: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    data() {
      return {
        isFold: true,
        list: [],
      }
    },
    methods: {
      async getData() {
        try {
          this.list = (await this.$fetch('queryCategoryServiceModuleList', { pid: this.data.id, pageNo: 1, pageSize: 1000 }))?.records
        } catch (err) {

        }
      },
      onChange(isFold) {
        console.log('onChange', isFold)
        
        if (isFold) {
          return
        }

        if (this.list.length) {
          return
        }

        this.getData()
      },
    },
  }
</script>

<style scoped lang="scss">

  .card,
  .content {
    width: 100%;
    position: relative;
  }

  .absolute {
    position: absolute;
    top: 0;
    left: 0;
  }

  .list {
    padding: 0 12rpx;
    box-sizing: border-box;

    &-item {
      margin-top: 26rpx;
    }
  }
</style>