<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
        label="是否在建建筑物"
        v-model="sfzjjzw"
        @click="showSys = true"
        input-align="right"
        label-width="auto" :rules="[{ required: true }]" required
      />
      <van-field readonly label="宅基地代码" v-model="jgList.zjddm" input-align="right"  :rules="[{ required: true }]" required/>
      <!--        <van-popup v-model="showZjd" position="bottom">-->
      <!--          <van-picker-->
      <!--            show-toolbar-->
      <!--            @cancel="showZjd = false"-->
      <!--          />-->
      <!--        </van-popup>-->
      <van-field
        readonly
        clickable
        label="监管类型"
        v-model="jglx"
        @click="showjglx = true"
        input-align="right" :rules="[{ required: true }]" required
      />
      <van-field
        readonly
        clickable
        v-model="jgList.lasj"
        label="立案时间"
        @click="showlasj = true"
        input-align="right"
      />
      <van-field readonly label="巡查人" v-model="jgList.inspector" input-align="right" label-width="auto"/>
      <van-field
        readonly
        clickable
        label="巡查时间"
        v-model="jgList.inspectorTime"
        @click="showinspectorTime = true"
        input-align="right"
      />
    </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" :rules="[{ required: true }]" required
      />
      <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" :rules="[{ required: true }]" required type="number"/>
      <van-field v-model="jgList.fmkje" label="罚没款金额" placeholder="请输入金额" input-align="right" label-width="auto" :rules="[{ required: true }]" required type="number"/>
      <van-field v-model="jgList.msmj" label="没收面积" placeholder="请输入面积" input-align="right" label-width="auto" :rules="[{ required: true }]" required type="number"/>
      <van-field v-model="jgList.ccmj" label="拆除面积" placeholder="请输入面积" input-align="right" label-width="auto" :rules="[{ required: true }]" required type="number"/>
    </div>
    </van-form>
    <div style="padding: 16px 0;" v-if="allowCUD">
      <van-row>
        <van-col span="12" align="center">
          <van-button type="info" color="#B4B0B0" @click="goBack" native-type="submit" 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 { closeCase , getJg } from "@/api/onlineHome/homestead/reporting";
  import {Notify} from "vant";
  export default {
    name: "taskCloseCaseAdd",
    data() {
      return {
        showSys:false,
        showjglx:false,
        showlasj:false,
        showinspectorTime:false,
        showwfydlx:false,

        jgList:{},

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

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

      };
    },
    created() {
      this.jgList.taskId = this.$route.query.id;
      this.houseGetDicts("jglx").then((res) => {
        this.jglxDictionaries = res.data;
      });
      this.houseGetDicts("sys_yes_no").then((res) => {
        console.log(res)
        this.sysDictionaries = res.data;
      });
      this.getDictionaries();
    },
    computed: {
      allowCUD: function () {
        return this.$store.getters.businessLevel == '2'
      },
    },
    methods: {
      getDictionaries(){
        getJg(this.$route.query.id).then(response => {
          console.log(this.selectDictLabel(this.jglxDictionaries, response.data.jglx))
          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.wfydlx = this.selectDictLabel(res.data, response.data.wfydlx);
          });
          this.jglx = this.selectDictLabel(this.jglxDictionaries, response.data.jglx);
          this.sfzjjzw = this.selectDictLabel(this.sysDictionaries, response.data.sfzjjzw);

          this.jgList = response.data;
        })
      },
      onConfirmWfydlx(data){
        this.wfydlx = data.text;
        this.jgList.wfydlx = data.value;
        this.showwfydlx = false;
      },
      goAdd(){
        this.$refs._Form.validate().then(() => {
        closeCase(this.jgList).then(response => {
          console.log(response);
          this.$toast.success('结案成功');
          setTimeout(function(){
            history.go(-1)
          },2000)
        })
        }).catch((e) => {
          Notify({ type: 'danger', message: '请填写完整的表单项' });
        });
      },
      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>
