<template>
  <view class="task-box" >
    <en-nav :title="title"></en-nav>
    <post-loan-item v-model="postLoan" :showKeys="[]"></post-loan-item>
    <view class="but but-all" @click="setPostLoan">保存</view>
  </view>
</template>

<script>

import EnNav from "@/components/en-utils/en-nav/en-nav";
import PostLoanItem from "@/pages-task/add-client/new-model/post-loan-item";
import {setPostLoan} from "@/api/task";
import tools from "@/common/js/tools";

export default {
  components: {
    PostLoanItem,
    EnNav,
  },
  data() {
    return {
      title: '完善贷后',
      titleColor: '#fff',
      titleBg: '',
      businessId: '',
      postLoan: {
        'bank_id':'',
        'loans_money':'',
        'interest_rate':'',
        'repayment_money':'',
        'refund_num':'',
        'repayment_type':'1',
        'repayment_date':'',
      },
    }
  },
  onLoad(data) {
    if (data.id === undefined) {
      this.backEvent();
    } else {
      this.businessId = data.id
    }
  },
  mounted() {

  },
  methods: {
    setPostLoan(){
      setPostLoan({'businessId':this.businessId,'postLoan':this.postLoan}).then((res)=>{
        if(res.code===1){
          tools.success(res.msg)
          uni.$emit('newTaskList')
          uni.$emit('newTaskInfo')
          setTimeout(()=>{
            this.backEvent()
          },1500)
        }else {
          tools.error(res.msg)
        }
      })
    },
    backEvent() {
      uni.navigateBack({
        delta: 1
      })
    }

  },
}
</script>
<style lang="scss" scoped>
.task-box{
  background: #fff;
  .but{
    width: 90%;
    margin: auto;
    border-radius: 8rpx;
    text-align: center;
    height: 88rpx;
    line-height: 88rpx;
  }
  .but-all{
    color: #fff;
    background: #306AFB;
  }
}


</style>
