<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="props.form.code" :disabled="Boolean(props.form.disabled)" :placeholder="tLang('common', '请输入') + tLang('product', '产品编码')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '产品名称')" prop="name">
        <el-input v-model="props.form.name" :placeholder="tLang('common', '请输入') + tLang('product', '产品名称')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '产品类型')" prop="type">
        <el-input v-model="props.form.type" :placeholder="tLang('common', '请输入') + tLang('product', '产品类型')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '备注')" prop="remark">
        <el-input v-model="props.form.remark" style="width: 600px" :rows="4" type="textarea"
          :placeholder="tLang('common', '请输入')" />
      </el-form-item>
      <el-form-item :label="tLang('product', '图片')" prop="file">
        <image-upload v-model="props.form.file" />
      </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 = {
  name: [{ required: true, message: "请输入产品名称", trigger: "blur" }],
  code: [{ required: true, message: "请输入产品编码", trigger: "blur" }],
  type: [{ required: true, message: "请输入产品类型", 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 validateWorking(rule, value, callback) {
  if (value[0].min === "" || value[0].max === "" || value[1].min === "" || value[1].max === "") {
    callback(new Error("请输入加工针数"));
  } else {
    callback();
  }
}
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>
