<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
        clickable
        label="是否在建建筑物"
        placeholder="请选择"
        v-model="sfzjjzw"
        @click="showSys = true"
        input-align="right"
        right-icon="arrow-down"
        label-width="auto"
      />
      <van-popup v-model="showSys" position="bottom">
        <van-picker
          show-toolbar
          :columns="sysDictionaries"
          @confirm="onConfirmSys"
          @cancel="showSys = false"
        />
      </van-popup>
      <van-field label="宅基地代码" v-model="jgList.zjddm" placeholder="请输入宅基地代码" input-align="right" />
      <!--        <van-popup v-model="showZjd" position="bottom">-->
      <!--          <van-picker-->
      <!--            show-toolbar-->
      <!--            @cancel="showZjd = false"-->
      <!--          />-->
      <!--        </van-popup>-->
      <van-field
        readonly
        clickable
        label="监管类型"
        placeholder="请选择"
        v-model="jglx"
        @click="showjglx = true"
        input-align="right"
        right-icon="arrow-down"
      />
      <van-popup v-model="showjglx" position="bottom">
        <van-picker
          show-toolbar
          :columns="jglxDictionaries"
          @confirm="onConfirmJglx"
          @cancel="showjglx = false"
        />
      </van-popup>
      <van-field
        readonly
        clickable
        v-model="jgList.lasj"
        label="立案时间"
        placeholder="请选择立案时间"
        @click="showlasj = true"
        input-align="right"
        right-icon="arrow-down"
      />
      <van-popup v-model="showlasj" position="bottom">
        <van-datetime-picker
          v-model="currentDate"
          type="date"
          title="选择年月日"
          :min-date="minDate"
          :max-date="maxDate"
          @confirm="onConfirmLasj"
        />
      </van-popup>
      <van-field label="巡查人" v-model="jgList.inspector" placeholder="请输入巡查人" input-align="right" label-width="auto"/>
      <van-field
        readonly
        clickable
        label="巡查时间"
        v-model="jgList.inspectorTime"
        placeholder="请选择巡查时间"
        @click="showinspectorTime = true"
        input-align="right"
        right-icon="arrow-down"
      />
      <van-popup v-model="showinspectorTime" position="bottom">
        <van-datetime-picker
          v-model="currentDate"
          type="date"
          title="选择年月日"
          :min-date="minDate"
          :max-date="maxDate"
          @confirm="onConfirmInspectorTime"
        />
      </van-popup>
      <van-field label="备注" v-model="jgList.bz" placeholder="填写备注" input-align="right" label-width="auto"/>
    </div>

    <p class="main_title">违法信息</p>
    <div class="main_box">
      <van-field
        readonly
        clickable
        label="违法用地类型"
        placeholder="请选择"
        v-model="wfydlx"
        @click="showwfydlx = true"
        input-align="right"
        right-icon="arrow-down"
      />
      <van-popup v-model="showwfydlx" position="bottom">
        <van-picker
          show-toolbar
          :columns="wfydlxDictionaries"
          @confirm="onConfirmWfydlx"
          @cancel="showwfydlx = false"
        />
      </van-popup>
      <van-field v-model="jgList.wfydmj" label="违法用地面积" placeholder="请输入面积" input-align="right" label-width="auto"/>
      <van-field v-model="jgList.fmkje" label="罚没款金额" placeholder="请输入金额" input-align="right" label-width="auto"/>
      <van-field v-model="jgList.msmj" label="没收面积" placeholder="请输入面积" input-align="right" label-width="auto"/>
      <van-field v-model="jgList.ccmj" label="拆除面积" placeholder="请输入面积" input-align="right" label-width="auto"/>
      <van-field
        readonly
        clickable
        label="整改截止时间"
        placeholder="选择整改截止时间"
        v-model="jgList.reformDeadline"
        @click="showReformDeadline = true"
        input-align="right"
        right-icon="arrow-down"
      />
      <van-popup v-model="showReformDeadline" position="bottom">
        <van-datetime-picker
          v-model="currentDate"
          type="date"
          title="选择年月日"
          :min-date="minDate"
          :max-date="maxDate"
          @confirm="onConfirmReformDeadline"
        />
      </van-popup>
    </div>
    <div style="padding: 16px 0;">
      <van-row>
        <van-col span="12" align="center">
          <van-button type="info" color="#B4B0B0" native-type="submit" @click="goBack" class="submitButton">取<i style="margin-right: 1em;"></i>消</van-button>
        </van-col>
        <van-col span="12" align="center">
          <van-button type="info" native-type="submit" @click="goAdd" class="submitButton">添<i style="margin-right: 1em;"></i>加</van-button>
        </van-col>
      </van-row>
      <div class="clear"></div>
    </div>
  </div>
</template>

<script>
  import { jgAdd } from "@/api/onlineHome/homestead/reporting";
  export default {
    name: "supervisionAdd",
    data() {
      return {
        showSys:false,
        showjglx:false,
        showlasj:false,
        showinspectorTime:false,
        showwfydlx:false,
        showReformDeadline:false,

        minDate: new Date(),
        maxDate: new Date(2025, 10, 1),
        currentDate: new Date(),
        jgList:{},

        sfzjjzw:'',
        jglx:'',
        wfydlx:'',

        wfydlxDictionaries:[],
        jglxDictionaries:[],
        sysDictionaries:[],

      };
    },
    created() {
      this.getDictionaries();
    },
    methods: {
      getDictionaries(){
        //违法用地类型
        this.houseGetDicts("villations_type").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.wfydlxDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
        });
        //监管类型
        this.houseGetDicts("jglx").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.jglxDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
        });
        //是否在建建筑物
        this.houseGetDicts("sys_yes_no").then((res) => {
          for(var i = 0 ; i < res.data.length ; i++){
            this.sysDictionaries.push({text:res.data[i].dictLabel,value:res.data[i].dictValue});
          }
        });

      },
      onConfirmSys(data){
        this.sfzjjzw = data.text;
        this.jgList.sfzjjzw = data.value;
        this.showSys = false;
      },
      onConfirmJglx(data){
        this.jglx = data.text;
        this.jgList.jglx = data.value;
        this.showjglx = false;
      },
      onConfirmWfydlx(data){
        this.wfydlx = data.text;
        this.jgList.wfydlx = data.value;
        this.showwfydlx = false;
      },
      onConfirmLasj(data){
        this.jgList.lasj = this.getNowFormatDate(data).substr(0,10);
        this.showlasj = false;
      },
      onConfirmInspectorTime(data){
        this.jgList.inspectorTime = this.getNowFormatDate(data).substr(0,10);
        this.showinspectorTime = false;
      },
      onConfirmReformDeadline(data){
        this.jgList.reformDeadline = this.getNowFormatDate(data).substr(0,10);
        this.showReformDeadline = false;
      },
      goAdd(){
        console.log(this.jgList)
        jgAdd(this.jgList).then(response => {
          console.log(response);
          this.$toast.success('保存成功');
          setTimeout(function(){
            history.go(-1)
          },2000)
        });
      },
      goBack(){
        window.history.go(-1)
      }
    },
  }
</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>
