<template>
  <div class="edit-fill-pane">
    <el-form
      ref="modalFormComp"
      :key="modalForm.id"
      :model="modalForm"
      :rules="rules"
      label-width="120px"
    >
      <el-form-item prop="paneCount" label="方格数量：">
        <el-input-number
          v-model.number="modalForm.paneCount"
          style="width: 125px"
          :min="1"
          :max="100"
          :step="1"
          step-strictly
          :controls="false"
        ></el-input-number>
      </el-form-item>
      <el-form-item prop="paneGap" label="方格间距：">
        <el-input-number
          v-model="modalForm.paneGap"
          style="width: 125px"
          :min="1"
          :max="100"
          :step="1"
          step-strictly
          :controls="false"
        ></el-input-number>
      </el-form-item>
      <el-form-item prop="paneWidth" label="方格宽度：">
        <el-input-number
          v-model="modalForm.paneWidth"
          style="width: 125px"
          :min="1"
          :max="100"
          :step="1"
          step-strictly
          :controls="false"
        ></el-input-number>
      </el-form-item>
      <el-form-item prop="paneHeight" label="方格高度：">
        <el-input-number
          v-model="modalForm.paneHeight"
          style="width: 125px"
          :min="1"
          :max="100"
          :step="1"
          step-strictly
          :controls="false"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="方格边框形状：">
        <line-style-select v-model="modalForm.borderStyle"></line-style-select>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { deepCopy } from "../../plugins/utils";
import LineStyleSelect from "../../components/common/LineStyleSelect";

const initModalForm = {
  id: "",
  paneGap: 6,
  paneCount: 9,
  paneWidth: 30,
  paneHeight: 30,
  borderStyle: "solid",
};

export default {
  name: "EditFillPane",
  components: { LineStyleSelect },
  props: {
    instance: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalForm: { ...initModalForm },
      rules: {
        paneGap: [
          {
            required: true,
            type: "number",
            message: "请输入方格间距",
            trigger: "change",
          },
        ],
        paneCount: [
          {
            required: true,
            type: "number",
            message: "请输入方格数量",
            trigger: "change",
          },
        ],
        paneWidth: [
          {
            required: true,
            type: "number",
            message: "请输入方格宽度",
            trigger: "change",
          },
        ],
        paneHeight: [
          {
            required: true,
            type: "number",
            message: "请输入方格高度",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    this.initData(this.instance);
  },
  methods: {
    initData(val) {
      this.modalForm = deepCopy(val);
    },
    async submit() {
      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
      if (!valid) return;

      this.$emit("modified", this.modalForm);
    },
  },
};
</script>
