<template>
  <view>
    <view v-if="showTitle" style="padding: 6px 0 6px 0; color: #333; font-size: 16px; display: flex; align-items: center">
      <view style="width: 4px; height: 20px; background: linear-gradient(to bottom, #f89c33, #f86834); margin-right: 4px" />
      {{ title }}
    </view>
    <view class="list">
      <view v-for="(item, index) in lists" :key="index" class="list-item" @click="_handleClick(item.url)">
        <view class="content">
          <image v-if="iconShow" class="icon" :src="item.image" :alt="item.image" />
          <view class="title">{{ item.text }}</view>
        </view>
        <view>{{ '>' }}</view>
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  lists: {
    type: Array,
    default: () => [],
  },
  iconShow: {
    type: Boolean,
    default: true,
  },
  showTitle: {
    type: Boolean,
    default: true,
  },
  title: {
    type: String,
    default: '',
  },
});

const _handleClick = (url) => {
  if (url) {
    uni.navigateTo({
      url,
      fail: (err) => {
        uni.switchTab({
          url,
        });
      },
    });
  }
};
</script>

<style lang="less" scoped>
.list {
  width: 100%;
  box-sizing: border-box;
  border-radius: 8px;

  .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #fff;
    cursor: pointer;
    border-bottom: 1px solid #f2f2f2;
    &:first-child {
      border-radius: 8px 8px 0 0;
    }
    &:last-child {
      border-radius: 0 0 8px 8px;
    }
    .content {
      display: flex;
      align-items: center;

      .icon {
        width: 48rpx;
        height: 48rpx;
        margin-right: 12px;
        border-radius: 8px;
      }

      .title {
        font-size: 16px;
        color: #333;
      }
    }

    .arrow {
      color: #999;
    }
  }
}
</style>
