<template>
  <div>
    <van-nav-bar
      title="修改批准书"
      left-arrow
      fixed
      placeholder
      @click-left="$router.back()"
      z-index="998"
    >
    </van-nav-bar>

    <div style="padding-bottom: 1.33rem;">
      <van-form ref="form">

        <van-divider>基本信息</van-divider>

        <van-field v-model="licenseForm.licenseRatification.year" required label="年度" placeholder="年度" input-align="right" type="digit" label-width="auto" :rules="[{ pattern: /^\d+$/ }]"/>
        <van-field v-model="licenseForm.licenseRatification.approvalNumber" required label="批准书号" placeholder="批准书号" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.issuingAuthority" required label="填发机关" placeholder="填发机关" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <field-date-picker
          v-model="licenseForm.licenseRatification.issueDate"
          label="发证日期"
          placeholder="发证日期"
          :rules="[{ required: true }]"
          formatter="yyyy-MM-dd"
          required
        />
        <van-field v-model="licenseForm.licenseRatification.memberName" required label="申请人姓名" placeholder="申请人姓名" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.landArea" required label="批准用地面积" placeholder="批准用地面积" input-align="right" label-width="auto" :rules="[{required: true}]" type="number"><template #right-icon>㎡</template></van-field>
        <van-field v-model="licenseForm.licenseRatification.landOwner" required label="土地所有权人" placeholder="土地所有权人" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <field-select
          v-model="licenseForm.licenseRatification.landUse"
          label="土地用途"
          value-key="dictLabel"
          data-key="dictValue"
          placeholder="选择土地用途"
          :rules="[{ required: true }]"
          required
          remote-url="/open/zdzh/list/land_use"
          :on-remote-response="'data'"
        />

        <van-divider>房屋位置</van-divider>

        <van-field v-model="licenseForm.licenseRatification.location" required label="位置" placeholder="位置" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.east" required label="东至" placeholder="东至" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.west" required label="西至" placeholder="西至" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.south" required label="南至" placeholder="南至" input-align="right" label-width="auto" :rules="[{required: true}]"/>
        <van-field v-model="licenseForm.licenseRatification.north" required label="北至" placeholder="北至" input-align="right" label-width="auto" :rules="[{required: true}]"/>

        <van-divider>其他信息</van-divider>

        <field-date-picker
          v-model="licenseForm.licenseRatification.startTime"
          label="开始时间"
          placeholder="开始时间"
          :rules="[{ required: true }]"
          formatter="yyyy-MM-dd"
          required
        />
        <field-date-picker
          v-model="licenseForm.licenseRatification.endTime"
          label="结束时间"
          placeholder="结束时间"
          :rules="[{ required: true }]"
          formatter="yyyy-MM-dd"
          required
        />
        <van-field v-model="licenseForm.licenseRatification.remark" required label="备注" placeholder="备注" input-align="left" :rules="[{required: true}]"
                   rows="2"
                   :autosize="true"
                   type="textarea"/>
      </van-form>
    </div>

    <van-goods-action style="z-index: 999;">
        <van-goods-action-button type="info" text="关闭" @click="close()"/>
        <van-goods-action-button type="info" text="保存" @click="submit()"/>
    </van-goods-action>
  </div>
</template>

<script>
import {updateRatification, updatePermit} from "@/api/onlineHome/homestead/license";
import {selectAllLicense} from "@/api/onlineHome/homestead/houseProposer";
import FieldDatePicker from "@/components/form/FieldDatePicker";
import FieldSelect from "@/components/form/FieldSelect";
import {Notify} from "vant";

export default {
  name: "licenseRatificationEdit",
  components: {FieldDatePicker, FieldSelect},
  props: ['id'],
  data() {
    return {
      proposerId: null,
      licenseForm:{
        "licensePermit": {
          "searchValue": null,
          "createBy": "",
          "createTime": "",
          "updateBy": "",
          "updateTime": null,
          "proposerId": null,
          "applyProposerId": null,
          "year": null,
          "licenseKey": null,
          "issuingAuthority": null,
          "issueDate": null,
          "constructionUnit": null,
          "constructionItem": null,
          "constructionLocation": null,
          "constructionScale": null,
          "locationPlan": null
        },
        "licenseRatification": {
          "searchValue": null,
          "createBy": "",
          "createTime": null,
          "updateBy": "",
          "updateTime": null,
          "proposerId": null,
          "applyProposerId": null,
          "year": null,
          "approvalNumber": null,
          "issuingAuthority": null,
          "issueDate": null,
          "memberName": null,
          "landArea": 0,
          "landOwner": null,
          "landUse": null,
          "location": null,
          "east": null,
          "west": null,
          "south": null,
          "north": null,
          "startTime": null,
          "endTime": null,
          "remark": null,
          'fjzdmj': 0, // 房基占地面积
        },
      },
      options: {
      },
    };
  },
  created() {
    this.proposerId = this.$route.query.id;
    this.getDetail();
  },
  methods: {
    getDetail() {
      selectAllLicense(this.proposerId).then((response) => {
        this.licenseForm = response.data;
      }).catch((e) => {
        this.$toast.fail('获取证书失败!');
      });
    },
    close() {
      this.$router.back();
    },
    submit() {
      this.$refs.form.validate().then(() => {
        updateRatification(this.licenseForm.licenseRatification).then(response => {
          this.notify('保存成功', 'success');
          this.$router.back();
        }).catch((e) => {
          this.notify('保存失败！', 'danger');
        });
      });
    },
    notify(message, type) {
      Notify.clear();
      Notify({ type: type || 'primary', message: message });
    },
  },
}
</script>

<style scoped lang="scss">
.van-divider {
  margin: 0;
  padding: 0.2rem;
  color: #1989fa;
  border-color: #1989fa;
  background-color: #FFFFFF;
}
.van-goods-action-button--first {
  border-radius: 0.053333rem;
}
.van-goods-action-button--last {
  border-radius: 0.053333rem;
}
.van-goods-action-button {
  margin-left: 0.1rem;
}
</style>
