<template>
  <div class="home_wrapper">
    <div class="header_main">
      修改零工登记
      <div class="return_btn" @click="onClickLeft"></div>
      <div class="add_btn"></div>
    </div>
    <van-form @submit="onSubmit">
      <div class="list_main">

        <van-field
          readonly
          clickable
          label="出工日期"
          placeholder="请选择"
          v-model="form.jobTime"
          @click="showBuildTime = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
          required
          :border="false"
          :rules="[{ required: true , message:'请选择出工日期' }]"
        />
        <van-popup v-model="showBuildTime" position="bottom">
          <van-datetime-picker
            v-model="jobTime"
            type="year-month"
            title="选择年月日"
            @confirm="onConfirmOpenNy"
            @cancel="showBuildTime = false"
          />
        </van-popup>

        <van-field required label="出工姓名" v-model="form.workerName" placeholder="请输入出工姓名" :rules="[{ required: true , message:'请输入出工姓名' }]" input-align="right" :border="false" />

        <van-field required label="出工事由" v-model="form.workReason" placeholder="请输入出工事由" :rules="[{ required: true , message:'请输入出工事由' }]" input-align="right" :border="false" />

        <van-field required label="记工员" v-model="form.workerNote" placeholder="请输入记工员" :rules="[{ required: true , message:'请输入记工员' }]" input-align="right" :border="false" />

        <van-field required label="出工数" v-model="form.workNum" placeholder="请输入出工数" :rules="[{ required: true , message:'请输入出工数' }]" input-align="right" :border="false" />

        <van-field required label="工日值" v-model="form.perMoney" placeholder="请输入工日值" :rules="[{ required: true , message:'请输入工日值' }]" input-align="right" :border="false" />

        <van-field required label="金额(元)" type="number" v-model="form.totalMoney" placeholder="请输入金额(元)" :rules="[{ required: true , message:'请输入金额' }]" input-align="right" :border="false" />

        <van-field label="备注" v-model="form.remark" placeholder="请输入备注" input-align="right" :border="false" />

      </div>

      <div style="margin: 16px auto;width: 50%;">
        <van-button round block type="primary" native-type="submit">
          保存
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
  import { addOddjob , getOddjob , updateOddjob } from "@/api/sunVillage_info/fixedAssets";
  import Cookies from "js-cookie";
  import request from '@/utils/request'
  export default {
    name: "certificateList",
    data() {
      return {
        showBuildTime:false,
        form:{
          jobTime:this.format(new Date(),'yyyy-MM-dd'),
          workerName:'',
          workReason:'',
          workerNote:'',
          workNum:'',
          perMoney:'',
          totalMoney:'',
          remark:'',
        },
        openPic:[],
        fileList:[],
        fileList1:[],
        jobTime:new Date(),
        type:'',
        openFile:[],
        openFileList:[],
        queryParams:{
          id:'',
          bookId:'',
          deptId:''
        },
        openFile2:[],
        openPic2:[],
      };
    },
    created() {
      this.type = this.$route.query.type;
      this.queryParams.bookId = Cookies.get('bookId');
      this.queryParams.deptId = Cookies.get('deptId');
      this.queryParams.id = this.$route.query.id;
      this.getDetail();
    },
    methods: {
      getDetail(id){
        getOddjob(this.queryParams.id).then((res) => {
          var that = this ;
          that.form = res.data;
        })
      },
      onSubmit(){
        var that = this;
        updateOddjob(that.form).then((r1) => {
          if (r1.code == 200){
            that.$notify({ type: 'success', message: '修改成功' });
            setTimeout(function(){
              history.back(-1);
            },2000)
          }
        })
      },
      onConfirmOpenNy(data){
        this.form.jobTime = this.format(data,'yyyy-MM-dd');
        this.jobTime = data;
        this.showBuildTime = false;
      },

    },
  }
</script>

<style scoped lang="scss">
  /deep/ .van-button--primary{
    background: url("../../assets/images/sunVillage_info/btn_bg.png") no-repeat;
    background-size: 100% 100%;
    border: none;
  }
  .home_wrapper{
    background: #e9e9e9;
    min-height: 100vh;
    width: 100vw;
    .header_main {
      height: 116px;
      background: url('../../assets/images/sunVillage_info/list_head.png') no-repeat;
      background-size: 100% 100%;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      font-size: 36px;
      line-height: 116px;
      text-align: center;
      color: #fff;
      position: relative;

      .return_btn {
        width: 24px;
        height: 43.2px;
        background: url('../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
        background-size: 20px 36px;
        position: absolute;
        left: 38px;
        top: 36px;
      }
    }
    .release_head{
      height: 90px;
      padding:0 23px;
      display: flex;
      align-items: center;
      font-size: 26px;
      color: #929292;
      .people{
        flex: 1;
        display: flex;
        align-items: center;
        .icon{
          width: 24px;
          height: 21px;
          background: url('../../assets/images/sunVillage_info/details_icon_1.png') no-repeat;
          background-size: 100% 100%;
          display: block;
          margin-right: 8px;
        }
      }
      .time{
        flex: 1;
        display: flex;
        align-items: center;
        justify-content:flex-end;
        .icon{
          width: 25px;
          height: 25px;
          background: url('../../assets/images/sunVillage_info/details_icon_2.png') no-repeat;
          background-size: 100% 100%;
          display: block;
          margin-right: 8px;
        }
      }
    }
    .release_conetnt{
      padding:0 22px;
      font-size: 32px;
      color: #252525;
      line-height: 44px;
      img{
        max-width: 100%;
        margin-bottom: 16px;
      }
      p{
        margin-bottom: 16px;
      }
    }
    .list_main{
      padding:25px;
      background: #ffffff;
      width: 94%;
      margin: 25px auto 0;
      border-radius: 15PX;
      box-shadow: 4px 6px 5px rgba(63, 68, 75, 0.1);
    }
    .titBox{
      display: flex;
      align-items: center;
    }
    .tit{
      font-size: 36px;
      font-weight: bold;
    }
    /deep/ .van-cell{
      padding-left: 0!important;
      padding-right: 0!important;
      padding-bottom: 0!important;
    }
    /deep/ .van-field__label{
      padding-left: 10PX;
      width: auto;
      display: flex;
      align-items: center;
    }
    /deep/ .van-cell--required::before{
      left: 0PX;
    }
    /deep/ .van-field__error-message{
      display: none;
    }
  }
</style>
