<template>
    <div class="applicationInfo">
      <div class="applicationBox">
        <div class="applicationInfoTitle">请填写报名信息</div>
         <ul class="appInfoBox">
           <li class="appInfoLi">
             <span class="appInfoLiTitle">
               <span class="redDoll">*</span>
               <span class="liName">公司名称</span>
             </span>
             <input type="text" name="" id="" v-model="form.companyName" class="appInfoIpt" placeholder="请输入">
           </li>
           <li class="appInfoLi">
             <span class="appInfoLiTitle">
               <span class="redDoll">*</span>
               <span class="liName">参与人姓名</span>
             </span>
             <input type="text" name="" id="" v-model="form.name" class="appInfoIpt" placeholder="请输入">
           </li>
           <li class="appInfoLi">
             <span class="appInfoLiTitle">
               <span class="redDoll">*</span>
               <span class="liName">参与人职位</span>
             </span>
             <input type="text" name="" id="" v-model="form.position" class="appInfoIpt" placeholder="请输入">
           </li>
           <li class="appInfoLi">
             <span class="appInfoLiTitle">
               <span class="redDoll">*</span>
               <span class="liName">联系手机</span>
             </span>
             <input type="text" name="" id="" v-model="form.phone" class="appInfoIpt" placeholder="请输入">
           </li>
           <li class="appInfoLi" style="border: none;flex-direction: column;align-items: start">
             <span class="appInfoLiTitle">
               <span class="liName">说明</span>
             </span>
             <van-field
                 :value="form.remark"
                 autosize
                 type="textarea"
                 placeholder="请输入说明"
                 class="appInfoIpt"
                 maxlength="800"
             />
           </li>
         </ul>
      </div>
      <button v-if="!registrationFlag" class="bmBtn" @tap="submit">提交报名</button>
    </div>
</template>

<script>
import { updateRegistration,getUserLocalStorageInfo } from "@/js_sdk/http";
import {getRegistrationInfo} from "../../../js_sdk/http";

export default {
  name: "applicationInfo",
  data(){
    return{
      getUserLocalStorageInfo: getUserLocalStorageInfo(),
      value:'',
      activityId: '',
      form:{
        companyId: getUserLocalStorageInfo().userId,
        companyName: getUserLocalStorageInfo().username,
      },
      registrationFlag: false
    }
  },
  onLoad(options){
    this.activityId = options.activityId
    this.registrationFlag = options.registrationFlag
    // 如果已报名则回显
    if(this.registrationFlag){
      this.getById()
    }
  },
  methods:{
    getById(){
      const data = {
        activityId: this.activityId,
        companyId: getUserLocalStorageInfo().userId,
      }
      getRegistrationInfo(data).then((res)=>{
        this.form = res.data
      })
    },
    submit(e){
      this.form.communityActivityId = this.activityId
      updateRegistration(this.form).then((res) => {
        if (res.errno === 0){
          uni.showToast({
            title: '报名成功',
            icon: 'success',
            mask: true,
            duration: 1000
          });
          uni.navigateBack({
          })
        }else {
          uni.showToast({
            title: res.msg,
            icon: 'success',
            mask: true,
            duration: 1000
          });
        }
      })
    },
  }
}
</script>

<style lang="scss">
    .applicationInfo{
      padding-bottom: 120rpx;
      .applicationBox{
        background: white;
        margin-top: 24rpx;
        padding: 32rpx;
      }
      .applicationInfoTitle{
        color:#222222;
        font-size: 36rpx;
        font-weight: 600;
      }
      .appInfoBox{
        margin: 16rpx 0;
        .appInfoLi{
          padding: 32rpx 0;
          display: flex;
          justify-content: space-between;
          align-items: center;
          border-bottom: 1px solid #E6E6E6;
          .appInfoLiTitle{
            display: flex;
            align-items: center;
            .redDoll{
              color: red;
              margin-right: 5rpx;
            }
            .liName{
              color: #333333;
              font-size: 32rpx;
            }
          }
          .appInfoIpt{
            width: 400rpx;
            font-size: 32rpx;
            color: #666666;
            text-align: right;
          }
          .van-cell {
            background: #F5F7FA !important;
            border-radius: 8rpx;
            font-size: 28rpx;
            width: 686rpx;
            margin: 24rpx 0;
          }
        }
      }
      .bmBtn{
        width: 654rpx;
        height: 96rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        background: #0365F9;
        border-radius: 8rpx;
        margin: 48rpx 48rpx 0rpx 48rpx;
      }
    }
</style>
