<template>
  <view class="switch-roles">
    <nav-bar title="福利待遇" color="#000"></nav-bar>
    <view class="roles-content">
      <view class="content">
        <view class="title">福利待遇</view>
        <view class="check-box">
          <textarea
            v-model="text"
            placeholder="请详细描述公司的福利待遇"
            maxlength="500"
            @input="onInput"
            class="textarea"
          ></textarea>
          <view class="word-count">
            <text>{{ text ? text.length : 0 }}</text> /500</view
          >
        </view>
        <view class="fund-box">
          <view
            class="fund-item"
            :class="{ 'fund-check': checkList.includes(index) }"
            v-for="(item, index) in fundList"
            :key="index"
            @click="checkFund(index)"
          >
            {{ item }}
          </view>
        </view>
        <view class="fund-desc-txt">已选{{ checkList.length }}个</view>
      </view>
    </view>
    <view class="submit-btn" @click="goBack">确定</view>
  </view>
</template>
<script>
import navBar from "@/components/nav-bar/index.vue";
export default {
  data() {
    return {
      fundList: [
        "五险一金",
        "定期体检",
        "年终奖",
        "带薪年假",
        "员工旅游",
        "节日福利",
        "绩效",
        "零食下午茶",
      ],
      text: "",
      checkList: [],
    };
  },
  components: {
    navBar,
  },
  onLoad(options) {
    if (options.text) {
      this.text = options.text;
    }
  },
  methods: {
    onInput(e) {
      //   console.log(e);
      // 如果需要额外的输入控制
      //   this.text = e.detail.value;
    },
    goBack() {
      uni.navigateBack();
    },
    checkFund(index) {
      const currentIndex = this.checkList.indexOf(index);
      if (currentIndex > -1) {
        // 如果已选中，移除
        this.checkList.splice(currentIndex, 1);
      } else {
        // 如果未选中，添加
        this.checkList.push(index);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.switch-roles {
  background-color: #fff;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  .roles-content {
    width: 100%;
    flex: 1;
    overflow: hidden;
    overflow-y: auto;
    .content {
      padding: 40rpx;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .title {
        color: #333;
        width: 100%;
        font-family: DM Sans;
        font-size: 40rpx;
        font-weight: 600;
      }

      .check-box {
        width: 100%;
        border-radius: 12rpx;
        background: rgba(240, 240, 240, 1);
        padding: 34rpx;
        padding-top: 40rpx;
        box-sizing: border-box;
        margin: 20rpx 0;
        .word-count {
          font-family: DM Sans;
          font-size: 20rpx;
          font-weight: 400;
          line-height: 26rpx;
          text-align: right;
          text {
            color: #016bf6;
          }
        }
      }
    }
  }
  .submit-btn {
    flex-shrink: 0;
    border-radius: 999px;
    box-shadow: 0px 2px 4px 0px rgba(9, 196, 116, 0.3);
    background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
    color: rgba(255, 255, 255, 1);
    font-family: DM Sans;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 48rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16rpx 32rpx;
    box-sizing: border-box;
    margin: 60rpx 20rpx;
  }
}
.fund-desc-txt {
  color: #016bf6;
  font-family: DM Sans;
  font-size: 20rpx;
  font-weight: 400;
  line-height: 26rpx;
  width: 100%;
  margin-top: 8rpx;
}
.fund-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8rpx;
  .fund-item {
    flex-shrink: 0;
    box-sizing: border-box;
    border: 1rpx solid rgba(255, 102, 0, 1);
    border-radius: 8rpx;
    padding: 8rpx;
    color: #016bf6;
    font-family: DM Sans;
    font-size: 16rpx;
    font-weight: 400;
    text-align: left;
  }
  .fund-check {
    background: #fce9dc;
    border-color: #fce9dc;
  }
}
::v-deep .textarea-placeholder {
  color: rgba(153, 153, 153, 1);
  font-family: DM Sans;
  font-size: 20rpx !important;
  font-weight: 400;
  line-height: 26rpx;
}
::v-deep .uni-textarea-textarea {
  font-size: 20rpx;
}
</style>
