
<style scoped>
.user-panel {
  margin: 10px auto;
}
</style>
<template>
  <el-dialog
    :visible.sync="showDialog"
    :title="title"
    :modal-append-to-body="true"
    append-to-body
    :close-on-click-modal="false"
    style="text-align: left"
    width="80%"
    @close="closeDialog"
  >
    <div class="user-panel" v-loading="loading">
      <el-form
        ref="form"
        :model="formModel"
        :rules="ruleValidate"
        :label-width="'150px'"
        inline
      >
        <el-form-item label="楼栋" prop="biulding">
          <el-input
            v-model="formModel.biulding"
            placeholder="请输入楼栋"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="房号" prop="room">
          <el-input
            v-model="formModel.room"
            placeholder="请输入房号"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="企业名称" prop="name">
          <el-input
            v-model="formModel.name"
            placeholder="请输入企业名称"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="法人" prop="artificialPerson">
          <el-input
            v-model="formModel.artificialPerson"
            placeholder="请输入法人"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="artificialPersonPhone">
          <el-input
            v-model="formModel.artificialPersonPhone"
            placeholder="请输入联系电话"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="面积" prop="area">
          <el-input
            v-model="formModel.area"
            placeholder="请输入面积"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="入驻时间" prop="checkinTime">
          <el-date-picker v-model="formModel.checkinTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 300px"></el-date-picker>
        </el-form-item>
        <el-form-item label="费用到期时间" prop="feeExpirationTime">
          <el-date-picker v-model="formModel.feeExpirationTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 300px"></el-date-picker>
        </el-form-item>
        <el-form-item label="合同到期时间" prop="contractExpirationTime">
          <el-date-picker v-model="formModel.contractExpirationTime" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 300px"></el-date-picker>
        </el-form-item>
        <el-form-item label="租赁期限" prop="leaseTerm">
          <el-input
            v-model="formModel.leaseTerm"
            placeholder="请输入租赁期限"
            style="width: 300px"
          ></el-input>
      </el-form-item>
        <el-form-item label="租金" prop="rent">
          <el-input
            v-model="formModel.rent"
            placeholder="请输入租金"
            style="width: 300px"
          ></el-input>
        </el-form-item>
        <el-form-item label="缴纳方式" prop="paymentMethod">
          <el-select v-model="formModel.paymentMethod" style="width:300px;" clearable>
          <el-option v-for="(item,index) in paymentMethodList" 
          :label="item.name" :value="item.value" :key="index"></el-option>
        </el-select>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitting"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import Constant from "@/constant";
import checkinInfoApi from "@/api/base/checkinInfo";
import dataDictionaryApi from "@/api/sys/dataDictionary";
import SelectTree from "@/components/SelectTree";

export default {
  props: ["businessKey", "title"],
  data() {
    return {
      paymentMethodList: [],
      formModel: {},
      ruleValidate: {
        id: [{ required: true, message: "编号不能为空", trigger: "blur" }],
        biulding: [
          { required: true, message: "楼栋不能为空", trigger: "blur" },
        ],
        room: [{ required: true, message: "房号不能为空", trigger: "blur" }],
        name: [
          { required: true, message: "企业名称不能为空", trigger: "blur" },
        ],
        artificialPersonPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
        ],
        feeExpirationTime: [
          { required: true, message: "费用到期时间不能为空", trigger: "blur" },
        ],
        contractExpirationTime: [
          { required: true, message: "合同到期时间不能为空", trigger: "blur" },
        ],
      },
      showDialog: true,
      loading: false,
      submitting: false,
    };
  },
  created() {
    dataDictionaryApi.findByCatalogName({
      "catalogName" : "缴纳方式"
    }).then(response => {
      var jsonData = response.data;
      this.paymentMethodList = jsonData.data;
    });
  },
  methods: {
    closeDialog() {
      this.$emit("close", false);
    },
    handleSubmit() {
      var self = this;

      this.$refs["form"].validate((valid) => {
        if (valid) {
          (function () {
            var id = self.formModel.id;

            if (id == null || id.length == 0) {
              return checkinInfoApi.add(self.formModel);
            } else {
              return checkinInfoApi.update(self.formModel);
            }
          })().then(function (response) {
            var jsonData = response.data;

            if (jsonData.result) {
              self.$message({
                message: "保存成功!",
                type: "success",
              });

              self.$emit("close", true);
            } else {
              self.$message({
                message: jsonData.message + "",
                type: "warning",
              });

              self.$emit("close", false);
            }
          });
        }
      });
    },
  },
  mounted: function () {
    var self = this;

    (function () {
      if (self.businessKey.length == 0) {
        return checkinInfoApi.create();
      } else {
        return checkinInfoApi.edit(self.businessKey);
      }
    })()
      .then((response) => {
        var jsonData = response.data;
        self.loading = false;

        if (jsonData.result) {
          self.formModel = jsonData.data;
        } else {
          self.$message.error(jsonData.message + "");
        }
      })
      .catch((error) => {
        self.$message.error(error + "");
      });
  },
  // components: {
  //   "el-select-tree": SelectTree
  // },
};
</script>