<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>
      <van-form ref="_Form">
      <div class="main_box">
        <van-field
          readonly
          clickable
          name="picker"
          v-model="circulation.nmfwdm"
          label="农民房屋代码"
          placeholder="请选择"
          @click="showzjddm = true"
          input-align="right"
          right-icon="arrow-down" :rules="[{ required: true }]" required
        />
        <van-popup v-model="showzjddm" position="bottom">
          <van-picker
            show-toolbar
            :columns="zjdDictionaries"
            @confirm="onConfirmZjddm"
            @cancel="showzjddm = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="fwzt"
          label="房屋状态"
          placeholder="请选择"
          @click="showfwzt = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto" :rules="[{ required: true }]" required
        />
        <van-popup v-model="showfwzt" position="bottom">
          <van-picker
            show-toolbar
            :columns="fwztDictionaries"
            @confirm="onConfirmFwzt"
            @cancel="showfwzt = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="fwaqxjddj"
          label="房屋安全性鉴定等级"
          placeholder="请选择"
          @click="showfwaqxjddj = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
        />
        <van-popup v-model="showfwaqxjddj" position="bottom">
          <van-picker
            show-toolbar
            :columns="fwaqxjddjDictionaries"
            @confirm="onConfirmFwaqxjddj"
            @cancel="showfwaqxjddj = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="lyzk"
          label="利用状况"
          placeholder="请选择"
          @click="showlyzk = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto" :rules="[{ required: true }]" required
        />
        <van-popup v-model="showlyzk" position="bottom">
          <van-picker
            show-toolbar
            :columns="lyzkDictionaries"
            @confirm="onConfirmLyzk"
            @cancel="showlyzk = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="fwsfxz"
          label="房屋是否闲置"
          placeholder="请选择"
          @click="showfwsfxz = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto" :rules="[{ required: true }]" required
        />
        <van-popup v-model="showfwsfxz" position="bottom">
          <van-picker
            show-toolbar
            :columns="fwsfxzDictionaries"
            @confirm="onConfirmFwsfxz"
            @cancel="showfwsfxz = false"
          />
        </van-popup>
        <van-field v-model="circulation.fwxzyy" label="闲置原因" placeholder="闲置原因" input-align="right" label-width="auto"/>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="circulation.fwxzqssj"
          label="房屋闲置起始时间"
          placeholder="房屋闲置起始时间"
          @click="showfwxzqssj = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
        />
        <van-popup v-model="showfwxzqssj" position="bottom">
          <van-datetime-picker
            :value="new Date"
            type="date"
            title="选择年月日"
            @confirm="onConfirmFwxzqssj"
            @cancel="showfwxzqssj = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="phlyms"
          label="盘活利用模式"
          placeholder="请选择"
          @click="showphlyms = true"
          input-align="right"
          right-icon="arrow-down"
          label-width="auto"
        />
        <van-popup v-model="showphlyms" position="bottom">
          <van-picker
            show-toolbar
            :columns="phlymsDictionaries"
            @confirm="onConfirmPhlyms"
            @cancel="showphlyms = false"
          />
        </van-popup>
        <van-field
          readonly
          clickable
          name="picker"
          v-model="circulation.dcsj"
          label="调查时间"
          placeholder="选择调查时间"
          @click="showdcsj = true"
          input-align="right"
          right-icon="arrow-down" :rules="[{ required: true }]" required
        />
        <van-popup v-model="showdcsj" position="bottom">
          <van-datetime-picker
            :value="new Date"
            type="date"
            title="选择年月日"
            @confirm="onConfirmDcsj"
            @cancel="showdcsj = false"
          />
        </van-popup>
        <van-field v-model="circulation.nsy" label="年收益" placeholder="年收益" input-align="right" label-width="auto" type="number"/>
      </div>

      <p class="main_title">照片信息</p>
      <div class="main_box" style="padding: 5%;">
        <van-row>
          <van-col span="12">
            <p style="margin-bottom: 5%;color: #333333;font-size: 14px;">现场照片东</p>
            <MultiImageUploadComp v-model="circulation.xczpd"/>
          </van-col>
          <van-col span="12">
            <p style="margin-bottom: 5%;color: #333333;font-size: 14px;">现场照片南</p>
            <MultiImageUploadComp v-model="circulation.xczpn"/>
          </van-col>
        </van-row>
        <van-row>
          <van-col span="12">
            <p style="margin-bottom: 5%;color: #333333;font-size: 14px;">现场照片西</p>
            <MultiImageUploadComp v-model="circulation.xczpx" />
          </van-col>
          <van-col span="12">
            <p style="margin-bottom: 5%;color: #333333;font-size: 14px;">现场照片北</p>
            <MultiImageUploadComp v-model="circulation.xczpb" />
          </van-col>
        </van-row>
      </div>

      <p class="main_title">补偿信息</p>
      <div class="main_box">
        <van-field v-model="circulation.bz" label="备注" type="textarea" placeholder="请输入内容" input-align="right" label-width="auto"/>
      </div>
      </van-form>

      <div style="padding: 16px 0;">
        <van-row>
          <van-col span="12" align="center">
            <van-button type="info" color="#B4B0B0" native-type="submit" class="submitButton" @click="$router.back()">关闭</van-button>
          </van-col>
          <van-col span="12" align="center">
            <van-button type="info" native-type="submit" class="submitButton" @click="goSubmit">保存</van-button>
          </van-col>
        </van-row>
        <div class="clear"></div>
      </div>
    </div>
</template>

<script>
import { zjdzd } from "@/api/onlineHome/homestead/circulation";
import { getZjdly , nmfwlyEdit , upload} from "@/api/onlineHome/homestead/utilization";
import {Notify} from "vant";
import MultiImageUploadComp from "@/components/house/MultiImageUploadComp"
export default {
    name: "utilizationModify",
  components: {MultiImageUploadComp},
  data() {
    return {
      phlyms : '',
      fwsfxz : '',
      lyzk : '',
      fwaqxjddj : '',
      fwzt: '',

      showzjddm:false,
      showphlyms:false,
      showfwsfxz:false,
      showlyzk:false,
      showfwaqxjddj:false,
      showfwzt:false,
      showdcsj: false,
      showfwxzqssj: false,

      phlymsDictionaries: [],
      fwsfxzDictionaries: [],
      lyzkDictionaries: [],
      fwaqxjddjDictionaries: [],
      fwztDictionaries: [],
      zjdDictionaries: [],

      circulation: {}
    };
  },
  created() {
    this.getDetail();
  },
  methods: {
    getDetail(){
      getZjdly(this.$route.query.id).then(response => {
        console.log(response)
        //退出权利类型
        this.houseGetDicts("fwzt").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.fwztDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
          this.fwzt = this.selectDictLabel(res.data, response.data.fwzt);
        });
        this.houseGetDicts("fwaqxjddj").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.fwaqxjddjDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
          this.fwaqxjddj = this.selectDictLabel(res.data, response.data.fwaqxjddj);
        });
        this.houseGetDicts("nmfwlyzk").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.lyzkDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
          this.lyzk = this.selectDictLabel(res.data, response.data.lyzk);
        });
        this.houseGetDicts("sys_yes_no").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.fwsfxzDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
          this.fwsfxz = this.selectDictLabel(res.data, response.data.fwsfxz);
        });
        this.houseGetDicts("phlyms").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.phlymsDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
          this.phlyms = this.selectDictLabel(res.data, response.data.phlyms);
        });
        //宅基地代码
        zjdzd().then(zjdRes => {
          for( let i = 0 ; i < zjdRes.rows.length ; i++){
            this.zjdDictionaries.push(zjdRes.rows[i].zjddm);
          }
        });
        this.circulation = response.data;
      });
    },
    onConfirmZjddm(data){
      console.log(data)
      this.circulation.nmfwdm = data;
      this.showzjddm = false;
    },
    onConfirmPhlyms(data){
      this.phlyms = data.text;
      this.circulation.phlyms = data.value;
      this.showphlyms = false;
    },
    onConfirmFwsfxz(data){
      this.fwsfxz = data.text;
      this.circulation.fwsfxz = data.value;
      this.showfwsfxz = false;
    },
    onConfirmLyzk(data){
      this.lyzk = data.text;
      this.circulation.lyzk = data.value;
      this.showlyzk = false;
    },
    onConfirmFwaqxjddj(data){
      this.fwaqxjddj = data.text;
      this.circulation.fwaqxjddj = data.value;
      this.showfwaqxjddj = false;
    },
    onConfirmFwzt(data){
      this.fwzt = data.text;
      this.circulation.fwzt = data.value;
      this.showfwzt = false;
    },
    onConfirmFwxzqssj(data){
      this.circulation.fwxzqssj = this.getNowFormatDate(data).substr(0,10);;
      this.showfwxzqssj = false;
    },
    onConfirmDcsj(data){
      this.circulation.dcsj = this.getNowFormatDate(data).substr(0,10);;
      this.showdcsj = false;
    },
    goSubmit(){
      console.log(this.circulation);
      this.$refs._Form.validate().then(() => {
      nmfwlyEdit(this.circulation).then(response => {
        if(response.code = 200){
          this.$toast.success('保存成功');
          this.back();
        }
      });
      }).catch((e) => {
        Notify({ type: 'danger', message: '请填写完整的表单项' });
      });
    },
    back() {
      setTimeout(() => this.$router.back(), 1000);
    }
  },
}
</script>

<style scoped lang="scss">
  .app-container {
    padding: 2% 0;
  }
  .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;
    background-color: #1D6FE9;

  }
</style>
