<template>
  <view>
    <view class="date-selector-container">
      <view class="date-selector-wrapper">
        <view class="date-selector-header">
          <text class="date-selector-title">选择查询时间</text>
        </view>
        <view class="date-selector-content">
          <view class="date-picker-item">
            <picker
              :range="selYearList"
              :value="index"
              range-key="label"
              @change="changeYear"
            >
              <view class="date-picker-display">
                <view class="date-picker-label">年份</view>
                <view class="date-picker-value">
                  <text class="date-text">{{ whatYear }}</text>
                  <text class="date-unit">年</text>
                  <u-icon name="arrow-down" color="#005BAC" size="24"></u-icon>
                </view>
              </view>
            </picker>
          </view>
          <view class="date-picker-separator"></view>
          <view class="date-picker-item">
            <picker
              :range="selMounthList"
              :value="index"
              range-key="label"
              @change="bindPickerChange"
            >
              <view class="date-picker-display">
                <view class="date-picker-label">月份</view>
                <view class="date-picker-value">
                  <text class="date-text">{{ whatMounth }}</text>
                  <text class="date-unit">月</text>
                  <u-icon name="arrow-down" color="#005BAC" size="24"></u-icon>
                </view>
              </view>
            </picker>
          </view>
        </view>
      </view>
    </view>
    <view class="width-auto"> </view>
  </view>
</template>

<script>
import { getPlaceNewAddAchieve } from '@/config/distribute.js'
export default {
  data() {
    return {
      index: 0,
      show: false,
      achieveData: {},

      whatMounth: '',
      yjType: 1,
      showType: false,
      selMounthList: [],
      yjTypeList: [],
      yearShow: false,
      whatYear: '',
      selYearList: [
        {
          value: 0,
          label: new Date().getFullYear() - 1,
        },
        {
          value: 1,
          label: new Date().getFullYear(),
        },
      ],
      mounthList: [
        {
          value: 1,
          label: 1 + '月',
        },
        {
          value: 2,
          label: 2 + '月',
        },
        {
          value: 3,
          label: 3 + '月',
        },
        {
          value: 4,
          label: 4 + '月',
        },
        {
          value: 5,
          label: 5 + '月',
        },
        {
          value: 6,
          label: 6 + '月',
        },
        {
          value: 7,
          label: 7 + '月',
        },
        {
          value: 8,
          label: 8 + '月',
        },
        {
          value: 9,
          label: 9 + '月',
        },
        {
          value: 10,
          label: 10 + '月',
        },
        {
          value: 11,
          label: 11 + '月',
        },
        {
          value: 12,
          label: 12 + '月',
        },
      ],
    }
  },
  created() {
    this.getMounth()
  },
  methods: {
    goDetail(index) {
      uni.navigateTo({
        url: '/pages/performanceEchart/index?ifDetail=' + index,
      })
    },

    changeYear(e) {
      this.whatYear = this.selYearList[e.detail.value].label
      this.getPlaceNewAddAchieve()
    },
    bindPickerChange(e) {
      this.whatMounth = e.detail.value + 1
      this.getPlaceNewAddAchieve()
    },

    // 获取当前年/月
    getMounth() {
      this.whatMounth = new Date().getMonth() + 1
      let selMounth = []
      this.mounthList.forEach(item => {
        // if (item.value <= this.whatMounth) {
        // selMounth.push(item)
        // }
        selMounth.push(item)
      })
      this.selMounthList = selMounth
      this.whatYear = new Date().getFullYear()
    },
    getPlaceNewAddAchieve() {
      getPlaceNewAddAchieve({
        monthType: this.whatMounth,
        achievementType: this.yjType,
        year: this.whatYear,
      }).then(res => {
        this.achieveData = res.data
      })
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .uni-picker {
  width: 100%;
}

// 新的日期选择器样式
.date-selector-container {
  // width: 100%;
  // margin-bottom: 20rpx;
  padding: 10rpx;
}

.date-selector-wrapper {
  background: linear-gradient(135deg, #005bac 0%, #0074d9 100%);
  border-radius: 20rpx;
  padding: 20rpx 20rpx;
  box-shadow: 0 6rpx 24rpx rgba(0, 91, 172, 0.12);
  position: relative;
  overflow: hidden;
}

.date-selector-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="30" r="1.5" fill="rgba(255,255,255,0.08)"/><circle cx="60" cy="80" r="2.5" fill="rgba(255,255,255,0.06)"/></svg>')
    no-repeat;
  background-size: cover;
  pointer-events: none;
}

.date-selector-header {
  margin-bottom: 16rpx;
}

.date-selector-title {
  color: #ffffff;
  font-size: 24rpx;
  font-weight: 600;
  opacity: 0.9;
}

.date-selector-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}

.date-picker-item {
  flex: 1;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12rpx;
  padding: 16rpx 16rpx;
  backdrop-filter: blur(10rpx);
  transition: all 0.3s ease;
}

.date-picker-item:active {
  transform: scale(0.98);
  background: rgba(255, 255, 255, 0.9);
}

.date-picker-separator {
  width: 20rpx;
  height: 2rpx;
  background: rgba(255, 255, 255, 0.6);
  margin: 0 12rpx;
  border-radius: 1rpx;
}

.date-picker-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6rpx;
}

.date-picker-label {
  font-size: 22rpx;
  color: #666666;
  font-weight: 500;
  margin-bottom: 2rpx;
}

.date-picker-value {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4rpx;
}

.date-text {
  font-size: 32rpx;
  font-weight: 700;
  color: #005bac;
  line-height: 1;
}

.date-unit {
  font-size: 22rpx;
  color: #005bac;
  font-weight: 500;
  margin-right: 6rpx;
}

.title {
  padding: 10rpx 0;
  margin-top: 10rpx;
}

.width-auto {
  background-color: #fff;
  padding: 0 22rpx;
  width: 690rpx;
  margin: 0 auto;
  padding-bottom: 20rpx;
}

.listrefor {
  color: #ffffff;
  border-radius: 10rpx;
  padding: 32rpx 21rpx;
  margin-top: 25rpx;
  display: flex;
  justify-content: space-between;

  .flex_item:nth-child(1) {
    width: 40%;
  }

  .flex_item:nth-child(2) {
    width: 35%;
  }

  .flex_item:nth-child(3) {
    width: 25%;
  }

  .text1 {
    font-size: 28rpx;
  }

  .text2 {
    font-size: 30rpx;
    font-weight: bold;
    margin-top: 30rpx;
  }
}

.bg1 {
  background: linear-gradient(180deg, #fc7c7c 0%, #f65757 100%);
}

.bg2 {
  background: linear-gradient(180deg, #ff9354 0%, #ff7f36 100%);
}

.bg3 {
  background: linear-gradient(180deg, #677af9 0%, #697bf2 100%);
}
</style>
