<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
        v-model="circulation.shyqrdm"
        label="使用权人"
        placeholder="请选择"
        @click="showshyqrdm = true"
        input-align="right"
        right-icon="arrow-down" :rules="[{ required: true }]" required
      />
      <van-popup v-model="showshyqrdm" position="bottom">
        <van-picker
          show-toolbar
          :columns="shyqrdmDictionaries"
          @confirm="onConfirmShyqrdm"
          @cancel="showshyqrdm = false"
        />
      </van-popup>
      <van-field
        readonly
        clickable
        v-model="circulation.zjddm"
        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 v-model="circulation.sqrxm" label="申请人姓名" placeholder="申请人姓名" input-align="right" label-width="auto"/>-->
      <van-field
        readonly
        clickable
        v-model="zjlx"
        label="申请人证件类型"
        placeholder="请选择"
        @click="showzjlx = true"
        input-align="right"
        right-icon="arrow-down"
        label-width="auto" :rules="[{ required: true }]" required
      />
      <van-popup v-model="showzjlx" position="bottom">
        <van-picker
          show-toolbar
          :columns="zjlxDictionaries"
          @confirm="onConfirmZjlx"
          @cancel="showzjlx = false"
        />
      </van-popup>
      <van-field v-model="circulation.sqrzjhm" label="申请人证件号码" placeholder="申请人证件号码" input-align="right" label-width="auto" :rules="[{ required: true }]" required/>
      <van-field v-model="circulation.ycsyfs" label="有偿使用方式" placeholder="有偿使用方式" input-align="right" label-width="auto" :rules="[{ required: true }]" required/>


      <van-cell title="是否一户多宅">
        <template #right-icon>
<!--          @change="designPaperChange"-->
          <van-radio-group v-model="circulation.sfyhdz" direction="horizontal">
            <van-radio name="Y">是</van-radio>
            <van-radio name="N">否</van-radio  >
          </van-radio-group>
        </template>
      </van-cell>

      <van-field
        readonly
        clickable
        name="picker"
        v-model="circulation.ycsykssj"
        label="有偿使用开始时间"
        placeholder="选择开始时间"
        @click="showycsykssj = true"
        input-align="right"
        right-icon="arrow-down"
        label-width="auto" :rules="[{ required: true }]" required
      />
      <van-popup v-model="showycsykssj" position="bottom">
        <van-datetime-picker
          :value="new Date"
          type="date"
          title="选择年月日"
          @confirm="onConfirmYcsykssj"
          @cancel="showycsykssj = false"
        />
      </van-popup>

      <van-field
        readonly
        clickable
        name="picker"
        v-model="circulation.ycsydqsj"
        label="有偿使用到期时间"
        placeholder="选择到期时间"
        @click="showycsydqsj = true"
        input-align="right"
        right-icon="arrow-down"
        label-width="auto" :rules="[{ required: true }]" required
      />
      <van-popup v-model="showycsydqsj" position="bottom">
        <van-datetime-picker
          :value="new Date"
          type="date"
          title="选择年月日"
          @confirm="onConfirmYcsydqsj"
          @cancel="showycsydqsj = false"
        />
      </van-popup>

      <van-field v-model="circulation.ycsymj" label="有偿使用面积(㎡)" placeholder="请输入有偿使用面积㎡" input-align="right" label-width="auto" type="number"/>
      <van-field v-model="circulation.ycsymjdj" label="有偿使用面积单价(元)" placeholder="请输入有偿使用面积单价" input-align="right" label-width="auto" type="number"/>
      <van-field v-model="circulation.ycsyfy" label="有偿使用费用(元)" placeholder="请输入有偿使用费用" input-align="right" label-width="auto" type="number"/>
      <van-field v-model="circulation.fkfs" label="付款方式" placeholder="请输入付款方式" input-align="right" label-width="auto"/>
      <van-field v-model="circulation.bz" label="备注" 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="goEdit">取消</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 { getYcsy , ycsyEdit } from "@/api/onlineHome/homestead/paidUtilize";
  import {Notify} from "vant";
  export default {
    name: "paidUtilizeModify",
    data() {
      return {
        tcqllxDictionaries:[],//退出权利类型
        tclxDictionaries:[],//退出类型
        tcfsDictionaries:[],//退出方式
        zjlxDictionaries:[],//申请人证件类型
        bcfsDictionaries:[],//补偿方式
        zjdDictionaries:[],//宅基地代码
        shyqrdmDictionaries:[],//使用权人

        tcqllx:'',
        tclx:'',
        tcfs:'',
        zjlx:'',
        bcfs:'',
        zjddm:'',

        showtcqllx: false,
        showtclx: false,
        showtcfs: false,
        showzjlx: false,
        showbcfs: false,
        showzjddm: false,
        showshyqrdm: false,
        showycsykssj: false,
        showycsydqsj: false,

        circulation:{},
      };
    },
    created() {
      this.getDictionaries();
    },
    methods: {
      getDictionaries(){
        getYcsy(this.$route.query.id).then(response => {
          //退出权利类型
          this.houseGetDicts("tcqllx").then((res) => {
            for (var i = 0; i < res.data.length; i++) {
              this.tcqllxDictionaries.push({text: res.data[i].dictLabel, value: res.data[i].dictValue});
            }
            this.tcqllx = this.selectDictLabel(res.data, response.data.tcqllx);
          });
          //退出类型
          this.houseGetDicts("tclx").then((res) => {
            for (var i = 0; i < res.data.length; i++) {
              this.tclxDictionaries.push({text: res.data[i].dictLabel, value: res.data[i].dictValue});
            }
            this.tclx = this.selectDictLabel(res.data, response.data.tclx);
          });
          //退出方式
          this.houseGetDicts("tcfs").then((res) => {
            for (var i = 0; i < res.data.length; i++) {
              this.tcfsDictionaries.push({text: res.data[i].dictLabel, value: res.data[i].dictValue});
            }
            this.tcfs = this.selectDictLabel(res.data, response.data.tcfs);
          });
          //申请人证件类型
          this.houseGetDicts("zjlx").then((res) => {
            for (var i = 0; i < res.data.length; i++) {
              this.zjlxDictionaries.push({text: res.data[i].dictLabel, value: res.data[i].dictValue});
            }
            this.zjlx = this.selectDictLabel(res.data, response.data.sqrzjlx);
          });
          //补偿方式
          this.houseGetDicts("bcfs").then((res) => {
            for (var i = 0; i < res.data.length; i++) {
              this.bcfsDictionaries.push({text: res.data[i].dictLabel, value: res.data[i].dictValue});
            }
            this.bcfs = this.selectDictLabel(res.data, response.data.bcfs);
          });
          //宅基地代码
          zjdzd().then(zjdRes => {
            for (let i = 0; i < zjdRes.rows.length; i++) {
              this.zjdDictionaries.push(zjdRes.rows[i].zjddm);
            }
          });
          // //使用权人代码
          // listByDeptId().then(zjdRes => {
          //   for (let i = 0; i < zjdRes.rows.length; i++) {
          //     this.shyqrdmDictionaries.push(zjdRes.rows[i].shyqrdm);
          //   }
          // });
          this.circulation = response.data;
        });
      },
      onConfirmZjddm(data){
        console.log(data)
        this.circulation.zjddm = data;
        this.showzjddm = false;
      },
      onConfirmZjlx(data){
        this.zjlx = data.text;
        this.circulation.sqrzjlx = data.value;
        this.showzjlx = false;
      },
      onConfirmTcqllx(data){
        this.tcqllx = data.text;
        this.circulation.tcqllx = data.value;
        this.showtcqllx = false;
      },
      onConfirmTclx(data){
        this.tclx = data.text;
        this.circulation.tclx = data.value;
        this.showtclx = false;
      },
      onConfirmTcfs(data){
        this.tcfs = data.text;
        this.circulation.tcfs = data.value;
        this.showtcfs = false;
      },
      onConfirmBcfs(data){
        this.bcfs = data.text;
        this.circulation.bcfs = data.value;
        this.showbcfs = false;
      },
      onConfirmShyqrdm(data){
        this.circulation.shyqrdm = data;
        this.showshyqrdm = false;
      },
      onConfirmYcsykssj(data){
        this.circulation.ycsykssj = this.getNowFormatDate(data).substr(0,10);
        this.showycsykssj = false;
      },
      onConfirmYcsydqsj(data){
        this.circulation.ycsydqsj = this.getNowFormatDate(data).substr(0,10);
        this.showycsydqsj = false;
      },
      goEdit(){
        window.location.replace("paidUtilizeList")
      },
      goSubmit(){
        this.$refs._Form.validate().then(() => {
        ycsyEdit(this.circulation).then(response => {
          if(response.code = 200){
            this.$toast.success('修改成功');
            setTimeout(function(){
              window.location.replace("paidUtilizeList")
            },1000)
          }
        });
        }).catch((e) => {
          Notify({ type: 'danger', message: '请填写完整的表单项' });
        });
      }
    },
  }
</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>
