<template>
  <!-- 扫码点餐-选择就餐人数 -->
  <view class="content">
    <view class="title">请选择就餐人数</view>
    <view class="number-list">
      <view class="number-item" :class="{ 'current': currentDiners === item }" v-for="item in diners" :key="item"
        @click="selectDiners(item)" hover-class="hover-active">
        <view class="number-item-content">
          <view class="number-item-content-title">{{ item }}</view>
        </view>
      </view>
    </view>

    <view class="more-number" @click="addDiners" v-if="diners < 16">查看更多</view>

    <view class="confirm-button" @click="toOrderFood" hover-class="hover-active">确定</view>
  </view>
</template>

<script setup>
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
import { go } from "@/utils/utils.js";

const diners = ref(12);
const currentDiners = ref(2);

const addDiners = () => {
  diners.value = 16
};

const selectDiners = (item) => {
  currentDiners.value = item;
};

const toOrderFood = () => {
  uni.setStorageSync('currentDiners', currentDiners.value);
  go('/pages/orderFood/index');
};

onLoad((e) => {
  let currentDiners = uni.getStorageSync('currentDiners');
  if (currentDiners) currentDiners.value = currentDiners;
});
</script>

<style lang="scss" scoped>
.title {
  font-size: 32rpx;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20rpx;
  margin-top: 60rpx;
}

.number-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 20rpx;
  margin-top: 60rpx;

  .number-item {
    width: 160rpx;
    height: 160rpx;
    background-color: #f0f0f0;
    border-radius: 8rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32rpx;
    transition: all 0.3s ease;

    &.current {
      background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
      color: #fff;
      box-shadow: 0 8rpx 24rpx rgba(252, 183, 63, 0.4);
    }

    &.hover-active {
      opacity: 0.8;
    }
  }
}

.more-number {
  font-size: 28rpx;
  color: #aaa;
  text-align: center;
  margin-top: 20rpx;
  margin-top: 30rpx;
}

.confirm-button {
  width: 90%;
  height: 80rpx;
  background: linear-gradient(180deg, #FCB73F 0%, #FC743D 100%);
  color: #fff;
  text-align: center;
  line-height: 80rpx;
  border-radius: 24rpx;
  position: fixed;
  bottom: 80rpx;
  left: 50%;
  transform: translateX(-50%);
  font-size: 32rpx;
}
</style>
