<template>
  <u-popup
    :show="show"
    mode="bottom"
    :round="10"
    :closeable="false"
    @close="handleClose"
  >
    <view class="c-dialog">
      <view class="confrim-box">
        <text @click="cancel()">取消</text>
        <text class="btn" @click="confirm()">完成</text>
      </view>

      <!-- :class="{ active: state.currentStates === item.id }" -->

      <view class="box-btn">
        <text
          v-for="(item, index) in state.statusList"
          :key="index"
          @click="handleSelect(item)"
          >{{ item.name }}</text
        ></view
      >

      <view class="timeBox">
        <uni-datetime-picker
          class="my-datetime-picker"
          v-model="state.datetimerange"
          type="datetimerange"
          rangeSeparator="-"
        />
      </view>
    </view>
  </u-popup>
</template>
<script setup lang="ts">
import { formatDate, timeRange } from "@/utils";

const props = defineProps<{
  show: boolean;
}>();
const state = reactive<any>({
  datetimerange: [],
  startTime: "",
  endTime: "",
  currentStates: -1,
  statusList: [
    {
      id: 1,
      name: "今日",
    },
    {
      id: 2,
      name: "昨日",
    },
    {
      id: 3,
      name: "本月",
    },
    {
      id: 4,
      name: "本年",
    },
  ],
});
const emit = defineEmits(["handleDialog", "changeTime"]);
const handleClose = () => {
  emit("handleDialog", false);
};

const handleSelect = (item: any) => {
  state.currentStates = item.id;
  const range = timeRange(item.id);
  state.startTime = range.startTime + ' 00:00:00';
  state.endTime = range.endTime + ' 23:59:59';
  state.datetimerange = [state.startTime, state.endTime]
};

const cancel = () => {
  emit("handleDialog", false)
}

const confirm = () => {
  emit("changeTime", {
    startTime: state.datetimerange[0],
    endTime: state.datetimerange[1],
    name: "自定义",
  });
  emit("handleDialog", false);
};
</script>
<style lang="scss" scoped>
::v-deep .u-popup__content {
  box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
  border-radius: 32rpx 32rpx 0rpx 0rpx;
}
.c-dialog {
  margin: 22rpx;
  font-family: Source Han Sans CN;
  font-weight: 500;
  font-size: 26rpx;
  color: #000000;
  .box-btn,
  .box {
    line-height: 80rpx;
    display: flex;
    justify-content: space-between;
    .btn {
      font-weight: 500;
      font-size: 26rpx;
      color: $u-primary;
    }
  }
  .box-btn {
    line-height: 40rpx;
    margin-bottom: 30rpx;
    text {
      font-weight: 400;
      font-size: 26rpx;
      color: #999999;
      width: 140rpx;
      background: #ffffff;
      border-radius: 6rpx;
      border: 1px solid rgba(153, 153, 153, 0.64);
      text-align: center;
      cursor: pointer;
    }
    .active {
      border-color: $u-primary;
      color: $u-primary;
    }
  }

  .box-border {
    border-top: 1px solid rgba(233, 233, 233, 0.76);
  }
  .line {
    height: 18rpx;
    background: #f8f8f8;
  }
}

.confrim-box {
  line-height: 80rpx;
  display: flex;
  justify-content: space-between;
  .btn {
    font-weight: 500;
    font-size: 26rpx;
    color: $u-primary;
  }
}
.timeBox {
  display: flex;
  justify-content: center;
  align-items: center;
  text {
    margin: 0rpx 22rpx;
  }
}
</style>
