<template>
  <view class="switch-roles">
    <nav-bar 
      title="岗位描述" 
      color="#000" 
      background="#fff"
      border-bottom="true"
    ></nav-bar>
    
    <view class="roles-content">
      <view class="content">
        <view class="title">岗位描述</view>
        
        <!-- 提示文本 -->
        <view class="desc">
          请填写岗位信息（工作内容、任务要求等），请勿包含联系方式、特殊符号或违规内容，否则可能导致账号封禁。
        </view>
        
        <!-- 输入区域 -->
        <view class="input-container">
          <textarea
            v-model="jobDesc"
            placeholder="1. 工作内容：例如负责客户对接、日常运营等
2. 任务要求：例如本科以上学历、熟练使用Excel等
3. 其他说明：例如周末双休、五险一金等"
            maxlength="500"
            class="textarea"
            @input="updateWordCount"
          ></textarea>
          
          <!-- 字数统计 -->
          <view class="word-count">
            <text :class="{ over: wordCount > 500 }">{{ wordCount }}</text>/500
          </view>
        </view>
      </view>
    </view>
    
    <!-- 提交按钮 -->
    <button 
      class="submit-btn" 
      @click="sendToPrevPage"
      :disabled="wordCount > 500"
    >
      确定
    </button>
  </view>
</template>

<script>
import navBar from "@/components/nav-bar/index.vue";

export default {
  components: { navBar },
  data() {
    return {
      jobDesc: "", // 当前页填写的岗位描述
      wordCount: 0 // 字数统计
    };
  },
  methods: {
    // 实时更新字数
    updateWordCount(e) {
      this.wordCount = e.detail.value.length;
    },
    
    // 回传数据到上一页
    sendToPrevPage() {
         // 触发全局事件，传递当前页填写的岗位描述
           uni.$emit("jobDescUpdated", { 
             desc: this.jobDesc 
           });
           
           // 返回上一页
           uni.navigateBack({ delta: 1 });
    }
  }
};
</script>

<style lang="scss" scoped>
.switch-roles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #f5f5f5;
  display: flex;
  flex-direction: column;

  .roles-content {
    flex: 1;
    padding: 24rpx;
    overflow-y: auto;

    .content {
      background: #fff;
      border-radius: 16rpx;
      padding: 30rpx;
      box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);

      .title {
        font-size: 34rpx;
        font-weight: 600;
        color: #333;
        margin-bottom: 20rpx;
        padding-bottom: 15rpx;
        border-bottom: 1rpx solid #eee;
      }

      .desc {
        font-size: 24rpx;
        color: #666;
        line-height: 36rpx;
        margin-bottom: 28rpx;
        padding: 12rpx 16rpx;
        background: #f9f9f9;
        border-radius: 8rpx;
      }

      .input-container {
        background: #f7f7f7;
        border-radius: 12rpx;
        padding: 24rpx;

        .textarea {
          width: 100%;
          min-height: 280rpx;
          font-size: 26rpx;
          color: #333;
          line-height: 1.6;
          background: transparent;
          padding: 0;
          margin-bottom: 12rpx;
          resize: none;

          &::placeholder {
            color: #999;
            line-height: 1.6;
          }
        }

        .word-count {
          text-align: right;
          font-size: 22rpx;
          color: #999;

          .over {
            color: #ff4d4f;
            font-weight: 500;
          }
        }
      }
    }
  }

  .submit-btn {
    margin: 30rpx 24rpx;
    padding: 22rpx 0;
    width: calc(100% - 48rpx);
    background: linear-gradient(90deg, #0d27f7, #13c1ea);
    color: #fff;
    font-size: 32rpx;
    font-weight: 500;
    border-radius: 100rpx;
    box-shadow: 0 4rpx 12rpx rgba(19, 193, 234, 0.3);
    transition: all 0.2s;

    &:disabled {
      background: #e5e5e5;
      color: #999;
      box-shadow: none;
    }

    &:active {
      opacity: 0.9;
      transform: scale(0.99);
    }
  }
}
</style>