<template>
  <div class="cmain">
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <el-form-item label="企业出口退税额" prop="companyDrawback">
        <el-input
          v-model="form.companyDrawback"
          placeholder="请输入企业出口退税额"
        ></el-input>
      </el-form-item>

      <el-form-item label="园区出口退税总额" prop="gardenDrawback">
        <el-input
          v-model="form.gardenDrawback"
          placeholder="请输入园区出口退税总额"
        ></el-input>
      </el-form-item>

      <el-form-item label="园区运营单位缴税总额" prop="gardenTax">
        <el-input
          v-model="form.gardenTax"
          placeholder="请输入园区运营单位缴税总额"
        ></el-input>
      </el-form-item>

      <el-form-item label="企业承接单量" prop="companyLists">
        <el-input
          v-model="form.companyLists"
          placeholder="请输入企业承接单量"
        ></el-input>
      </el-form-item>

      <el-form-item label="园区承接单总量" prop="gardenLits">
        <el-input
          v-model="form.gardenLits"
          placeholder="请输入园区承接单总量"
        ></el-input>
      </el-form-item>

      <el-form-item label="企业创新获奖量" prop="companyInnovative">
        <el-input
          v-model="form.companyInnovative"
          placeholder="请输入企业创新获奖量"
        ></el-input>
      </el-form-item>

      <el-form-item label="园区内创新获奖总量" prop="gardenInnovative">
        <el-input
          v-model="form.gardenInnovative"
          placeholder="请输入园区内创新获奖总量"
        ></el-input>
      </el-form-item>

      <el-form-item label="企业工业用水、用电量" prop="companyWaterElectric">
        <el-input
          v-model="form.companyWaterElectric"
          placeholder="请输入企业工业用水、用电量"
        ></el-input>
      </el-form-item>

      <el-form-item label="园区工业用水、用电总量" prop="gardenWaterElectric">
        <el-input
          v-model="form.gardenWaterElectric"
          placeholder="请输入园区工业用水、用电总量"
        ></el-input>
      </el-form-item>
    </el-form>
    <div class="mfooter">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
import {
  getUser,
  listGARDENTRADEDATA,
  getGARDENTRADEDATA,
  delGARDENTRADEDATA,
  addGARDENTRADEDATA,
  updateGARDENTRADEDATA,
} from "@/api/portal/GARDENTRADEDATA/GARDENTRADEDATA.js";
export default {
  data() {
    return {
      deptList: [],
      form: {},
      deptId: "",
      rules: {
        gardenId: [
          { required: true, message: "园区ID不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "保税区ID不能为空", trigger: "blur" },
        ],
        companyDrawback: [
          {
            required: true,
            message: "企业出口退税额 不能为空",
            trigger: "blur",
          },
        ],
        gardenDrawback: [
          {
            required: true,
            message: "园区出口退税总额 不能为空",
            trigger: "blur",
          },
        ],
        gardenTax: [
          {
            required: true,
            message: "园区运营单位缴税总额 不能为空",
            trigger: "blur",
          },
        ],
        companyLists: [
          { required: true, message: "企业承接单量 不能为空", trigger: "blur" },
        ],
        gardenLits: [
          {
            required: true,
            message: "园区承接单总量 不能为空",
            trigger: "blur",
          },
        ],
        companyInnovative: [
          {
            required: true,
            message: "企业创新获奖量 不能为空",
            trigger: "blur",
          },
        ],
        gardenInnovative: [
          {
            required: true,
            message: "园区内创新获奖总量 不能为空",
            trigger: "blur",
          },
        ],
        companyWaterElectric: [
          {
            required: true,
            message: "企业工业用水、用电量 不能为空",
            trigger: "blur",
          },
        ],
        gardenWaterElectric: [
          {
            required: true,
            message: "园区工业用水、用电总量 不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  props: {
    param: {
      type: Object,
      default: () => {
        return {};
      },
    },
    layerid: {
      type: String,
    },
  },
  mounted() {
    if (this.param.id) {
      getGARDENTRADEDATA(this.param.id).then((response) => {
        this.form = response.data;
      });
    } else {
        //如果没传ID过来那就是新增，需要获取当前用户deptId
      getUser().then((res) => {
        this.deptId = res.user.deptId;
      });
    }
  },
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.gardenId != null) {
            updateGARDENTRADEDATA(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          } else {
            addGARDENTRADEDATA(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.$layer.close(this.layerid);
              this.$parent.getList();
            });
          }
        }
      });
    },
  },
};
</script>

<style>
</style>