<template>
    <div class="app-container">
      <van-nav-bar
        left-arrow
        fixed
        placeholder
        @click-left="$router.back(-1)"
      >
        <template #title>
          <p style="font-weight: bold;">使用权抵押</p>
        </template>
      </van-nav-bar>
        <div class="main_box">
          <van-field
            readonly
            v-model="circulation.zjddm"
            label="宅基地代码"
            input-align="right"
          />
          <van-field readonly label="不动产单元号" v-model="circulation.bdcdyh" input-align="right" label-width="auto"/>
          <van-field readonly label="不动产权证号" v-model="circulation.bdcqzh" input-align="right" label-width="auto"/>
          <van-field readonly label="不动产抵押登记业务号" v-model="circulation.bdcdydjywh" input-align="right" label-width="auto"/>
          <van-field readonly label="在建建筑物坐落" v-model="circulation.zjjzwzl" input-align="right" label-width="auto"/>
          <van-field readonly label="在建建筑物抵押范围" v-model="circulation.zjjzwdyfw" input-align="right" label-width="auto"/>
          <van-field
            readonly
            v-model="circulation.qszt"
            label="权属状态"
            input-align="right"
            label-width="auto"
          />
        </div>

        <div class="main_box">
          <van-field
            readonly
            v-model="circulation.dybdclx"
            label="抵押不动产类型"
            input-align="right"
            label-width="auto"
          />
          <van-field readonly label="抵押人" v-model="circulation.dyr" input-align="right" label-width="auto"/>
          <van-field
            readonly
            v-model="circulation.dyfs"
            label="抵押方式"
            input-align="right"
            label-width="auto"
          />
        </div>

        <div class="main_box">
          <van-field
            readonly
            v-model="circulation.djlx"
            label="登记类型"
            label-width="auto"
            input-align="right"
          />
          <van-field readonly label="登记原因" v-model="circulation.djyy" input-align="right" label-width="auto"/>
          <van-field readonly label="登记机构" v-model="circulation.djjg" input-align="right" label-width="auto"/>
          <van-field readonly label="登薄人" v-model="circulation.dbr" input-align="right" label-width="auto"/>
          <van-field
            readonly
            v-model="circulation.djsj"
            label="登记时间"
            input-align="right"
            label-width="auto"
          />
        </div>

        <div class="main_box">
          <van-field readonly label="附记" v-model="circulation.fj" input-align="right" label-width="auto"/>
          <van-field readonly label="备注" v-model="circulation.bz" input-align="right" label-width="auto"/>
        </div>

      <!-- 审批 -->
      <template v-if="approval.type === 'todo'">
        <div class="main_box examine_box">
          <van-row type="flex" justify="space-between" align="center">
            <van-col span="5">审核<br/>意见</van-col>
            <van-col span="19">
              <van-field required :readonly="approval.type !== 'todo'" v-model="approval.comment" rows="2" autosize type="textarea" placeholder="审核意见"/>
            </van-col>
          </van-row>
        </div>

        <van-row style="margin-top: 0.2rem;">
          <van-col span="12" align="center">
            <van-button type="info" native-type="submit" class="submitButton" @click="complete(true)">同意</van-button>
          </van-col>
          <van-col span="12" align="center">
            <van-button type="danger" native-type="submit" class="submitButton" @click="complete(false)">驳回</van-button>
          </van-col>
        </van-row>
        <div class="clear"></div>
      </template>
    </div>
</template>

<script>
import { getDy } from "@/api/onlineHome/homestead/mortgage";
import request from '@/utils/request';
import {Notify} from "vant";
export default {
  name: "mortgageDetail",
  data() {
    return {
      circulation:[],
      approval: {
        taskId: null,
        instanceId: null,
        type: null,
        id: null,
        comment: '',
      },
    };
  },
  created() {
    this.approval.id = this.$route.query.id;
    this.approval.instanceId = this.$route.query.instanceId;
    this.approval.type = this.$route.query.type;
    this.approval.taskId = this.$route.query.taskId;
    this.getDetail();
  },
  methods: {
    getDetail(){
      getDy(this.$route.query.id).then(response => {
        console.log(response)
        this.circulation = response.data;
        //抵押不动产类型
        this.houseGetDicts("dybdclx").then((res) => {
          this.circulation.dybdclx = this.selectDictLabel(res.data, response.data.dybdclx);
        });
        //抵押方式
        this.houseGetDicts("dyfs").then((res) => {
          this.circulation.dyfs = this.selectDictLabel(res.data, response.data.dyfs);
        });
        //登记类型
        this.houseGetDicts("djlx").then((res) => {
          this.circulation.djlx = this.selectDictLabel(res.data, response.data.djlx);
        });
        //权属状态
        this.houseGetDicts("qszt").then((res) => {
          this.circulation.qszt = this.selectDictLabel(res.data, response.data.qszt);
        });
      });
    },
    complete(pass) {
      if(!this.approval.taskId || !this.approval.instanceId || this.approval.type !== 'todo')
      {
        console.error("无效操作");
        return false;
      }
      if(!this.approval.comment)
      {
        this.notify("请填写审批意见", 'danger');
        return false;
      }
      let data = {
        taskId: this.approval.taskId,
        instanceId: this.approval.instanceId,
        variables: JSON.stringify({
          pass: pass ? "true" : "false",
          comment: this.approval.comment ? this.approval.comment : (pass ? '同意' : '驳回'),
        }),
      };
      request({
        url: "/activiti/process/complete",
        method: "post",
        params: data,
      }).then((response) => {
        this.notify("操作成功", 'success');
        this.$router.back();
      }).catch(e => {
        this.notify("操作失败!", 'danger');
      });
      return true;
    },
    notify(message, type) {
      Notify.clear();
      Notify({ type: type || 'primary', message: message });
    },
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding-bottom: 5%;
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    margin-top:2%;
  }
  .submitButton{
    width: 80%;
    margin: 0 auto;
    border-radius: 14px;
  }
  .examine_box{
    background-color: #1D6FE9!important;
    padding: 0.18rem!important;
    padding-left: 0!important;
    border-radius: 0.15rem!important;
    margin-top: 0.3rem!important;
    .van-col:first-child{
      color: #FFF!important;
      font-size: 0.45rem!important;
      text-align: center!important;
    }
    .van-col:last-child{
      background-color: #FFF!important;
      border-radius: 0.15rem!important;
      overflow: hidden!important;
      .van-radio-group--horizontal{
        padding: 0.2rem 0;
        border-bottom: 1px solid #eee;
      }
    }
  }
</style>
