<template>
  <div class="demo roll-list-land-plan" style="height: 100%" ref="refroll">
    <!-- <div class="list-item-header item-warp" :style="{ flex: listKeys.length }">
      <template v-for="(h, indexh) in listKeys" :key="indexh">
        <div class="item-td" :style="{ width: 'calc(100% / ' + listKeys.length + ')' }">{{ listKeysHeader[h] }}</div>
      </template>
    </div> -->
    <vue3ScrollSeamless class="scroll-wrap" :class-options="classOptions" :data-list="datalist">
      <div v-for="(item, index) in datalist" :key="index" class="list-item">
        <div class="list-item-content">
          <div class="list-item-boday item-warp" :style="{ flex: listKeys.length }">
            <div class="item-content">
              <div class="label">{{ item.title }}</div>
              <customProgress height="10px" :percent="item.percent"></customProgress>
            </div>
          </div>
        </div>
      </div>
    </vue3ScrollSeamless>
  </div>
  <!-- </div> -->
</template>

<script setup>
import { ref, onMounted, onUnmounted, computed, reactive } from 'vue';
import { vue3ScrollSeamless } from 'vue3-scroll-seamless';
import customProgress from '@/components/customProgress.vue';
const props = defineProps({
  //   items: {
  //     type: Array,
  //     default: () => [],
  //   },
});

let list = reactive([
  { title: '农药', value: 357 },
  { title: '肥料', value: 159 },
  { title: '种源', value: 516 },
  { title: '兽药', value: 82 },
  { title: '农机', value: 45 },
]);

let refroll = ref(null);

let datalist = computed(() => {
  let maxwidth = refroll.value && refroll.value.clientWidth;
  return list.map((m) => {
    return {
      ...m,
      percent: Number((Number(parseInt(m.value) / max.value) * 100).toFixed(0)),
      pwidth: parseInt(Number(parseInt(m.value) / max.value) * maxwidth),
    };
  });
});

let max = computed(() => {
  let valueList = new Set(list.map((item) => item.value));
  let sortValue = [...valueList].sort((a, b) => b - a) || [];
  // console.info('valueList', sortValue);
  return sortValue.length ? sortValue[0] : 0;
});

const listKeys = reactive(['title', 'value']);
const listKeysHeader = reactive({
  title: '分类',
  value: '数量',
});

const classOptions = {
  singleHeight: 48,
};
onMounted(() => {});
</script>

<style scoped lang="scss">
.roll-list-land-plan {
  margin-top: 8px;
  ::v-deep() {
    .el-progress-bar__outer {
      background: transparent;
    }
  }
  .scroll-wrap {
    height: 90%;
    width: 100%;
    margin: 4px auto;
    overflow: hidden;
  }
  .list-item-header {
    background: #144482;
    font-size: 10px;
    width: 100%;
    .item-td {
      padding: 8px 6px;
    }
  }
  .list-item-boday {
    background: transparent;
    width: 100%;
    .item-td {
      padding: 4px 6px;
      &.td-title {
        color: #6beff9 !important;
      }
      &.zebra-b {
        background: #051225 !important;
      }
    }
  }
  .item-warp {
    display: inline-flex;
    justify-content: space-around;
    .item-td {
      display: inline-block;
      vertical-align: middle;

      text-align: center;
      color: #fff;
    }
    .item-content {
      width: 100%;
      display: inline-flex;
      justify-content: flex-start;
      margin: 8px 0;
      .label,
      .val {
        display: inline-block;
        vertical-align: middle;
      }
      .label {
        width: 50px;
        color: #fff;
      }
    }
  }
  .list-item {
    // border-bottom: 1px dashed rgba(255, 255, 255, 0.2);
    line-height: 18px;

    .list-item-content {
      display: inline-flex;
      width: 100%;
      justify-content: space-around;
      position: relative;
    }
  }
}
.demo {
  //   display: flex;
  //   align-items: center;
  //   justify-content: center;
  //   margin-top: 10px;
}
</style>
