<template>
  <el-dialog v-model="props.modelValue" :title="props.title" @close="close" width="800">
    <el-form ref="formRef" :inline="true" :model="props.form" :rules="rules" class="demo-form-inline"
      label-width="100px">
      <el-form-item :label="tLang('product', '产品编码')" prop="code">
        <el-input v-model="form.code" :disabled="Boolean(props.form.id)" :placeholder="tLang('common', '请输入') + tLang('product', '产品编码')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '第几次')" prop="num">
        <el-input-number v-model="form.num" :min="1" @change="handleChange" />
      </el-form-item>
      <el-form-item :label="tLang('product', '步骤')" prop="step">
        <el-input v-model="form.step" :placeholder="tLang('common', '请输入') + tLang('product', '步骤')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '排序')" prop="sort">
        <el-input v-model="form.sort" :placeholder="tLang('common', '请输入') + tLang('product', '排序')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '最小针数')" prop="min">
        <el-input-number v-model="form.min" :min="1" @change="handleChange" />
      </el-form-item>
      <el-form-item :label="tLang('product', '最大针数')" prop="max">
        <el-input-number v-model="form.max" :min="1" @change="handleChange" />
      </el-form-item>
      <el-form-item :label="tLang('product', '备注')" prop="remark">
        <el-input :rows="3" type="textarea" v-model="form.remark" style="width: 520px"
          :placeholder="tLang('common', '请输入') + tLang('product', '备注')" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ tLang('common', '确 定') }}</el-button>
        <el-button @click="cancel">{{ tLang('common', '取 消') }}</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from "vue";
const emit = defineEmits();
const { proxy } = getCurrentInstance();
const formRef = ref()
const rules = {
  code: [{ required: true, message: `${proxy.tLang('common', '请输入') + proxy.tLang('product', '产品编码')}`, trigger: "blur" }],
};
const props = defineProps({
  modelValue: [String, Object, Array],
  title: String,
  form: {
    type: Object,
    default: () => ({}),
  },
});
const baseUrl = import.meta.env.VITE_APP_BASE_API;


function close() {
  emit("update:modelValue", false);
}
function submitForm() {
  formRef.value.validate((valid) => {
    if (valid) {
      emit("submitForm", props.form);
    }
  });

}
function cancel() {
  emit("update:form", {});
  close();
}
</script>

<style lang="scss" scoped></style>
