<template>
  <div class="addPredetermine">
    <ul class="detailUl">
      <li class="detailLi">
        <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
          项目/企业名称
        </span>
        <span class="liInfo">{{ companyName }}</span>
      </li>
      <li class="detailLi2">
          <span class="liName" style="margin-bottom: 24rpx">
            项目/企业简介
          </span>
        <van-field
            :value="form.projectInfo"
            autosize
            type="textarea"
            placeholder="请输入文字进行报事报修描述"
            class="myField"
            maxlength="800"
            show-word-limit
            @change="changeProjectInfo"
        />
      </li>
      <li class="detailLi2">
          <span class="liName" style="margin-bottom: 24rpx">
            <span style="color: red;margin-right: 5rpx">*</span>
            企业需求
          </span>
        <van-field
            :value="form.companyNeed"
            autosize
            type="textarea"
            placeholder="请输入文字进行报事报修描述"
            class="myField"
            maxlength="800"
            show-word-limit
            @change="changeCompanyNeed"
        />
      </li>
      <li class="detailLi">
        <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
          项目/企业联系人
        </span>
        <input class="liInfo" placeholder="请输入" v-model="form.projectManager"></input>
      </li>
      <li class="detailLi" style="border-bottom: none">
        <span class="liName">
          <span style="color: red;margin-right: 5rpx">*</span>
          联系电话
        </span>
        <input class="liInfo" placeholder="请输入" v-model="form.managerPhone"></input>
      </li>
    </ul>
    <div class="whiteBoard">
      <div class="boardTitle">关于房源</div>
      <div class="boardInfo">
        <div class="boardItem">{{ roomInfo.groupName }}</div>
        <div class="boardItem">{{ roomInfo.floorDiscName }}</div>
        <div class="boardItem">{{ roomInfo.buildName }}</div>
        <div class="boardItem">{{ roomInfo.roomNo }}</div>
      </div>
    </div>
    <button @tap="submit()" class="toYy">提交预定</button>
  </div>
</template>

<script>
import {getByCodes, getUserLocalStorageInfo, getRoomInfo, parkRoomSlateAdd, getParkRoomSlateInfoById, parkRoomSlateEdit} from "@/js_sdk/http";

export default {
  name: "addPredetermine",
  onLoad(options) {
    this.roomId = options.roomId
    this.id = options.id
    if(options.id){
      uni.setNavigationBarTitle({
        title: '编辑预定',
      });
      this.getById()
    }
    this.getRoomById()
  },
  data(){
    return{
      id: '',
      roomId: '',
      companyName: getUserLocalStorageInfo().username,
      getUserLocalStorageInfo: getUserLocalStorageInfo(),
      form:{

      },
      roomInfo:{
        groupName: '',
        floorDiscName: '',
        buildName: '',
        roomNo: ''
      }
    }
  },
  methods:{
    changeProjectInfo(e){
      this.form.projectInfo = e.detail
    },
    changeCompanyNeed(e){
      this.form.companyNeed = e.detail
    },
    getRoomById(){
      getRoomInfo(this.roomId).then(res=>{
        if(res){
          this.roomInfo = res
        }
      })
    },
    submit(){
      if(this.id){
        this.edit()
      }else {
        this.add()
      }
    },
    add(){
      this.form.projectName = this.companyName
      this.form.companyId = getUserLocalStorageInfo().userId
      this.form.createdBy = getUserLocalStorageInfo().userId
      this.form.userId = getUserLocalStorageInfo().userId
      this.form.roomIds= this.roomId
      parkRoomSlateAdd(this.form).then((res) => {
        if(res.code == '200'){
          this.$showToast("填报成功");
          uni.navigateBack({});
        }else {
          this.$showToast(res.msg);
        }
      }).catch(err=>{

      })
    },
    edit(){
      this.form.updatedBy = getUserLocalStorageInfo().userId
      this.form.userId = getUserLocalStorageInfo().userId
      parkRoomSlateEdit(this.form).then((res) => {
        if(res.code == '200'){
          this.$showToast("填报成功");
          uni.navigateBack({});
        }else {
          this.$showToast(res.msg);
        }
      }).catch(err=>{

      })
    },
    getById(){
      const data = {
        id: this.id
      }
      getParkRoomSlateInfoById(data).then(res=>{
        if(res.code == '200'){
          this.form = res.data
        }
      })
    }
  }
}
</script>

<style lang="scss">
.addPredetermine{
  .detailUl{
    margin-top: 20rpx;
    background: white;
    padding: 24rpx 32rpx;
    .liName{
      font-size: 32rpx;
      color: rgba(51, 51, 51, 1);
      white-space: nowrap;
      .callNumber{
        color: rgba(24, 23, 42, 1);
        font-size: 36rpx;
        font-weight: 600;
      }
      .callName{
        color: rgba(102, 102, 102, 1);
        font-size: 28rpx;
      }
    }
    .phoneIcon{
      width: 64rpx;
      height: 64rpx;
    }
    .detailLi{
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 32rpx 0;
      border-bottom: 2rpx solid #E6E6E6;
      .liInfo{
        display: inline-block;
        text-align: right;
        max-width: 428rpx;
        color: rgba(102, 102, 102, 1);
        font-size: 32rpx;
        line-height: 38rpx;
        overflow: hidden;
        word-wrap: break-word;
      }
    }
    .detailLi2{
      display: flex;
      flex-direction: column;
      padding: 32rpx 0;
      border-bottom: 2rpx solid #E6E6E6;
      .detailLi2BoxTop{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        margin: 12rpx 0;
        .checkItem{
          width: 160rpx;
          height: 64rpx;
          font-size: 28rpx;
          color: #666666;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #F5F7FA;
          border-radius: 8rpx;
          margin: 12rpx 0;
        }
        .checked{
          background: #0365F9;
          color: white;
        }
      }
    }
    .van-cell {
      background: #F5F7FA !important;
      border-radius: 8rpx;
      font-size: 28rpx;
    }
  }
  .whiteBoard{
    padding: 32rpx;
    background: white;
    margin-top: 24rpx;
    min-height: 260rpx;
    box-sizing: border-box;
    .boardTitle{
      color: rgba(51, 51, 51, 1);
      font-size: 32rpx;
      margin-bottom: 24rpx;
    }
    .boardInfo{
      display: flex;
      flex-wrap: wrap;
      color: rgba(51, 51, 51, 1);
      font-size: 32rpx;
      .boardItem{
        margin-right: 24rpx;
      }
    }
  }
  .toYy{
    width: 654rpx;
    height: 96rpx;
    background: rgba(3, 101, 249, 1);
    margin: 64rpx 48rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36rpx;
    color: white;
  }
}

</style>
