<template>
  <view class="list u-font-28 color-333">
    <view class="u-m-t-32 item" v-for="(item, index) in list" :key="item.id">
      <view class="color-000 font-bold u-font-32">
        <view> {{ item.name }} </view>
      </view>
      <view class="u-m-t-32 u-flex">
        <view class="u-flex-1">
          <text class="color-666">所需成长值：</text>
          <text>{{ item.experienceValue || 0 }}</text>
        </view>
        <view class="u-flex-1">
          <text class="color-666">会员折扣：</text>
          <text>{{ item.discount || 100 }}%</text>
        </view>
      </view>

      <view class="u-m-t-32 u-flex u-row-right gap-20">
        <view class="del" @click="delItem(item)" v-if="index != 0">删除</view>
        <view class="edit" @click="editItem(item)">编辑</view>
      </view>
    </view>
    <view class="u-p-30">
      <up-loadmore :status="isEnd ? 'nomore' : 'loading'"></up-loadmore>
    </view>
    <view style="height: 100rpx"></view>
    <view class="bottom">
      <my-button @click="go.to('PAGES_MARKET_SUPER_VIP_LV_ADD')">
        <view class="u-flex">
          <text>+ 添加会员等级</text>
        </view>
      </my-button>
    </view>
  </view>
</template>
<script setup>
import {
  ref,
  reactive,
  watch,
  toRaw,
  onMounted,
  onUnmounted,
  inject,
} from "vue";
import go from "@/commons/utils/go.js";
const memberApi=inject('memberApi')
const props = defineProps({
  list: {
    type: Array,
    default: () => [],
  },
  isEnd: {
    type: Boolean,
    default: false,
  },
});

function delItem(item) {
  uni.showModal({
    title: "提示",
    content: "确定删除该会员等级吗？",
    success: (res) => {
      if (res.confirm) {
        memberApi.levelDel(item.id).then((res) => {
          if (res) {
            uni.showToast({
              title: "删除成功",
              icon: "none",
            });
            emits("refresh");
          }
        });
      }
    },
  });
}

function editItem(item) {
  go.to("PAGES_MARKET_SUPER_VIP_LV_ADD", {
    id: item.id,
    type: "edit",
  });
}

const emits = defineEmits(["refresh"]);
</script>
<style lang="scss">
.list {
  padding: 0 30rpx;

  .item {
    padding: 32rpx 24rpx;
    border-radius: 14rpx;
    background-color: #fff;
    overflow: hidden;
  }
}

.tag {
  border-radius: 12rpx;
  padding: 8rpx 22rpx;
  font-size: 28rpx;

  &.success {
    background-color: #edfff0;
    color: #5bbc6d;
  }

  &.end {
    background-color: #f7f7f7;
    color: #999;
  }
}

.my-btn {
  font-size: 28rpx;
  line-height: 36rpx;
  padding: 8rpx 32rpx;
  border-radius: 12rpx;
  margin: 0;
}
.money {
  background-color: #f8f8f8;
  border-radius: 8rpx;
  padding: 16rpx 28rpx;
}
.more {
  display: flex;
  height: 56rpx;
  padding: 8rpx 28rpx;
  justify-content: center;
  align-items: center;
  gap: 20rpx;
  border-radius: 28rpx;
  border: 2rpx solid $my-main-color;
  color: $my-main-color;
  background: #fff;
}
.del {
  display: flex;
  height: 56rpx;
  padding: 8rpx 28rpx;
  justify-content: center;
  align-items: center;
  gap: 20rpx;
  border-radius: 28rpx;
  border: 2rpx solid #f7f7fa;
  color: #999;
  background: #f7f7fa;
}
.edit {
  display: flex;
  height: 56rpx;
  padding: 8rpx 28rpx;
  justify-content: center;
  align-items: center;
  gap: 20rpx;
  border-radius: 28rpx;
  border: 2rpx solid $my-main-color;

  color: #fff;
  background: $my-main-color;
}

.bottom {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 30rpx);
  left: 30rpx;
  right: 30rpx;
}
</style>
