<template>
  <div class="edit-fill-pane">
    <el-form
      ref="modalFormComp"
      :model="modalForm"
      :rules="rules"
      :key="modalForm.id"
      label-width="120px"
    >
      <el-form-item prop="paneCount" label="方格数量：">
        <el-input-number
          style="width: 125px"
          v-model.number="modalForm.paneCount"
          :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
          style="width: 125px"
          v-model="modalForm.paneGap"
          :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
          style="width: 125px"
          v-model="modalForm.paneWidth"
          :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
          style="width: 125px"
          v-model="modalForm.paneHeight"
          :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: "edit-fill-pane",
  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>
