<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>
        <p class="main_title">转出方信息</p>
        <div class="main_box">
          <van-field
            readonly
            v-model="circulation.zjddm"
            label="宅基地代码"
            input-align="right"
          />

          <van-field
            readonly
            v-model="circulation.lzfs"
            label="流转方式"
            input-align="right"
          />

          <van-field
            readonly
            v-model="circulation.shyqrdm"
            label="转出方使用权人代码"
            label-width="auto"
            input-align="right"
          />
          <van-field
            readonly
            v-model="circulation.hncysl"
            label="家庭人口"
            placeholder="家庭人口"
            label-width="auto"
            input-align="right"
          />
          <van-field
            readonly
            v-model="circulation.zjdsyqr"
            label="使用权人"
            label-width="auto"
            placeholder="使用权人"
            input-align="right"
          />
          <van-field
            readonly
            v-model="circulation.currentResidence"
            label="现居住地"
            label-width="auto"
            placeholder="现居住地"
            input-align="right"
          />
          <van-field
            readonly
            v-model="circulation.householdRegister"
            label="户口所在地"
            label-width="auto"
            input-align="right"
          />
          <van-field
            readonly
            v-model="circulation.zcfsfbjtjjzzcy == 'Y' ? '是' : '否'"
            label="是否本集体经济组织成员"
            label-width="auto"
            input-align="right"

          />
        </div>

        <p class="main_title">流转信息</p>
        <div class="main_box">
          <van-field readonly label="房屋层数" v-model="zjdData.fwcs" placeholder="房屋层数" input-align="right" label-width="auto" type="number"/>
          <van-field readonly label="建筑面积(㎡)" v-model="zjdData.jzmj" placeholder="流转面积(㎡)" input-align="right" label-width="auto" type="number"/>
          <van-field readonly label="宅基地面积(㎡)" v-model="zjdData.zjdmj" placeholder="宅基地面积(㎡)" input-align="right" label-width="auto" type="number"/>
          <van-field readonly label="不动产证书编号" v-model="zjdData.zjdzsh" placeholder="不动产证书编号(㎡)" input-align="right" label-width="auto" type="number"/>
        </div>

        <p class="main_title">转入方信息</p>
        <div class="main_box">
          <van-field
            readonly
            label="转入方代表名称"
            label-width="auto"
            input-align="right"
            v-model="circulation.zrfdbmc"
          />

          <van-field
            readonly
            label="转入方代表证件类型"
            label-width="auto"
            input-align="right"
            v-model="circulation.zrfdbzjlx"
          />
          <van-field readonly label="转入方代表证件号码" v-model="circulation.zrfdbzjhm" input-align="right" label-width="auto"/>
          <van-field readonly label="是否本集体经济组织成员" v-model="circulation.zrfsfbjtjjzzcy == 'Y' ? '是' : '否'" input-align="right" label-width="auto"/>
          <van-field
            readonly
            v-model="circulation.lzhfwyt"
            label="流转后房屋用途"
            placeholder="流转后房屋用途"
            input-align="right"
            right-icon="arrow-down"
            label-width="auto"
          />
<!--          <van-popup v-model="showLzhfwyt" position="bottom">-->
<!--            <van-picker-->
<!--              show-toolbar-->
<!--              :columns="lzhfwytDictionaries"-->
<!--            />-->
          </van-popup>
          <van-field readonly label="流转金额" v-model="circulation.lzfy" placeholder="流转金额" input-align="right" label-width="auto" type="number"/>
          <van-field readonly label="集体收益金额" v-model="circulation.jtsyje" placeholder="集体收益金额" input-align="right" label-width="auto" type="number"/>
        </div>

        <p class="main_title">其他</p>
        <div class="main_box">
          <van-field readonly label="所有权人代表姓名" v-model="circulation.suyqrdbxm" input-align="right" label-width="auto"/>
          <van-field readonly label="所有权人意见" v-model="circulation.suyqryj" input-align="right" label-width="auto"/>
          <van-field readonly label="备注" v-model="circulation.bz" input-align="right" label-width="auto"/>
        </div>
      <p class="main_title">转入方意见</p>
      <div class="main_box">
        <van-field readonly label="意见" v-model="lzspyjData.zrryj" placeholder="转入方意见" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.zrrqz" placeholder="转入方签字" input-align="right" label-width="auto"/>
        <van-field readonly label="签字日期" v-model="lzspyjData.zrryjrq" placeholder="签字日期" input-align="right" label-width="auto"/>
      </div>
      <p class="main_title">转出方意见</p>
      <div class="main_box">
        <van-field readonly label="意见" v-model="lzspyjData.zcryj" placeholder="转出方意见" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.zcrqz" placeholder="转出方签字" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.zcryjrq" placeholder="签字日期" input-align="right" label-width="auto"/>
      </div>
      <p class="main_title">村集体经济组织意见</p>
      <div class="main_box">
        <van-field readonly label="意见" v-model="lzspyjData.cjtjjzzyj" placeholder="村集体经济组织意见" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.cjtjjzzqz" placeholder="村集体经济组织签字" input-align="right" label-width="auto"/>
        <van-field readonly label="签字日期" v-model="lzspyjData.cjtjjzzyjrq" placeholder="签字日期" input-align="right" label-width="auto"/>
      </div>
      <p class="main_title">宅基地审批管理办公室意见</p>
      <div class="main_box">
        <van-field readonly label="意见" v-model="lzspyjData.zzjdspyj" placeholder="审批管理办公室意见" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.zzjdspqz" placeholder="审批管理办公室签字" input-align="right" label-width="auto"/>
        <van-field readonly label="签字日期" v-model="lzspyjData.zzjdspyjrq" placeholder="签字日期" input-align="right" label-width="auto"/>
      </div>
      <p class="main_title">镇级人民政府意见</p>
      <div class="main_box">
        <van-field readonly label="意见" v-model="lzspyjData.zjrmzfyj" placeholder="镇级人民政府意见" input-align="right" label-width="auto"/>
        <van-field readonly label="签字" v-model="lzspyjData.zjrmzfqz" placeholder="镇级人民政府签字" input-align="right" label-width="auto"/>
        <van-field readonly label="签字日期" v-model="lzspyjData.zjrmzfyjrq" placeholder="签字日期" 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 { getLz,queryGeoZjdzd,queryHouserBaseNh, getByZjddm ,} from "@/api/onlineHome/homestead/circulation";
import { listLzspyj } from "@/api/onlineHome/homestead/lzspyj";
import request from '@/utils/request';
import {Notify} from "vant";
export default {
    name: "circulationDetail",
  data() {
    return {
      value: '',
      circulation:[],
      houseApplyStatus:[],
      lzhfwytDictionaries: [],//流转后房屋类型
      approval: {
        taskId: null,
        instanceId: null,
        type: null,
        id: null,
        comment: '',
      },
      zjdData:{
        jzmj:null,
        fwcs:null,
        zjdmj:null
      },
      lzhfwyt:null,
      //流转审批意见
      lzspyjData:{},
    };
  },
  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(){
      getLz(this.$route.query.id).then(response => {
        this.circulation = response.data;
        //流转方式
        this.houseGetDicts("lzfs").then((res) => {
          this.circulation.lzfs = this.selectDictLabel(res.data, response.data.lzfs);
        });
        //转入方证件类型
        this.houseGetDicts("zjlx").then((res) => {
          this.circulation.zrfdbzjlx = this.selectDictLabel(res.data, response.data.zrfdbzjlx);
        });
        //流转前房屋用途
        this.houseGetDicts("fwyt").then((res) => {//流转前房屋用途
          this.circulation.lzqfwyt = this.selectDictLabel(res.data, response.data.lzqfwyt);
          this.circulation.lzhfwyt = this.selectDictLabel(res.data, response.data.lzhfwyt);
        });
        //流转后房屋用途
        this.houseGetDicts("fwyt").then((res) => {//流转后房屋用途
          for( let i = 0 ; i < res.data.length ; i++){
            this.lzhfwytDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue})
          }
        });
        this.onConfirmZjd(response.data.zjddm);
        listLzspyj({lzId:response.data.id}).then((response) => {
          if(response.rows.length > 0){
            this.lzspyjData = response.rows[0];
          }
        });
      });

    },
    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;
    },
    zjddmChange(value){
      let _this = this;
      queryGeoZjdzd({zjddm:value}).then(zjdRes => {
        if(zjdRes.data != null){
          _this.$set(this.zjdData, "zjdzsh", zjdRes.data.zjdzsh);
          if(zjdRes.data.thouseBaseStandardNmfw.length > 0){
            zjdRes.data.thouseBaseStandardNmfw.forEach(function (item) {
              if(_this.zjdData.jzmj != null &&  _this.zjdData.jzmj !== ""){
                _this.$set(_this.zjdData, "jzmj", parseInt(_this.zjdData.jzmj) + parseInt(item.jzmj));
              }else{
                _this.$set(_this.zjdData, "jzmj", item.jzmj);
              }
            })

            this.$set(this.zjdData, "fwcs", zjdRes.data.thouseBaseStandardNmfw[0].sjcs);
          }
          if(zjdRes.data.thouseBaseStandardZjdzdxx.length > 0){
            this.$set(this.zjdData, "zjdmj", zjdRes.data.thouseBaseStandardZjdzdxx[0].zjdpzmj);
          }
        }
      });
    },
    onConfirmZjd(value) {
      this.zjddmChange(value);
      this.circulation.zjddm = value;
      let form = {};
      form.zjddm = value;
      getByZjddm(form).then(qlrRes => {
        let data = qlrRes.data;
        this.circulation.shyqrdm = data.shyqrdm;
        let queryMember = {
          hzxm :  data.shyqrdbxm,
        };
        queryHouserBaseNh(queryMember).then((response) => {
          this.$set(this.circulation, 'hncysl', response.rows[0].hncysl);
        });
        this.$set(this.circulation, 'suyqrdbxm', data.shyqrdbxm);
        this.$set(this.circulation, 'zjdsyqr', data.shyqrdbxm);
        this.$set(this.circulation, 'zcfsfbjtjjzzcy', data.sfbncjtjjzzcy == '1' || data.sfbncjtjjzzcy == 'Y' ? 'Y' : 'N');
        this.$forceUpdate();
      });
      this.showZjd = false;

    },
    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;
  }
  .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>
