<!--产品基本信息-->
<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="产品代号" prop="productNo">
            <el-input v-model="form.productNo" placeholder="请输入产品代号" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="英文名称" prop="productEnglishName">
            <el-input
              v-model="form.productEnglishName"
              placeholder="请输入英文名称"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="计量单位" prop="unitOfMeasure">
            <el-input
              v-model="form.unitOfMeasure"
              placeholder="请输入计量单位"
            />
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="品牌" prop="brandId">
            <el-input
              v-model="form.brandName"
              disabled
              placeholder="请选择品牌"
            >
              <el-button
                icon="el-icon-search"
                slot="append"
                @click="openBrandSelected"
              />
            </el-input>
            <BrandSelect ref="BrandSelectRef" @onSelected="onBrandSelected" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="尺码组" prop="sizeGroupId">
            <el-input
              v-model="form.sizeGroupName"
              disabled
              placeholder="请输入尺码组"
            >
              <el-button
                icon="el-icon-search"
                slot="append"
                @click="openSizeGroupSelect"
              />
            </el-input>
            <SizeGroupSelect
              ref="SizeGroupSelectRef"
              @onSelected="onSizeGroupSelect"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="版面" prop="layout">
            <el-select v-model="form.layout" placeholder="请选择版面">
              <el-option
                v-for="dict in dict.type.product_layout"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="有效开始日期" prop="expirationDateStart">
            <el-date-picker
              clearable
              v-model="form.expirationDateStart"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择有效开始日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效结束日期" prop="expirationDateEnd">
            <el-date-picker
              clearable
              v-model="form.expirationDateEnd"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择有效结束日期"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getInfo } from "@/api/mes/md/baseInfo";
import BrandSelect from "@/components/brandSelect/single.vue";
import SizeGroupSelect from "@/components/SizeGroupSelect/index.vue";
export default {
  name: "BaseInfo",
  dicts: ["product_layout"],
  components: { BrandSelect, SizeGroupSelect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemId: this.itemId,
      },
      // 表单参数
      form: {
        itemId: "",
        productNo: "",
        productEnglishName: "",
        unitOfMeasure: "",
        expirationDateStart: "",
        expirationDateEnd: "",
        brandId: "",
        brandName: "",
        sizeGroupId: "",
        sizeGroupName: "",
        layout: "",
      },
      // 表单校验
      rules: {
        /*quantity: [
          { required: true, message: "物料使用比例不能为空", trigger: "blur" }
        ]*/
      },
    };
  },
  props: {
    optType: undefined,
    itemId: {
      type: Number | undefined,
      default: undefined,
    },
  },
  created() {
    this.getBaseInfo();
  },
  methods: {
    //获取基本信息表单数据
    async getBaseInfoData() {
      await this.submitForm();
      return this.form;
    },

    getBaseInfo() {
      getInfo(this.itemId).then((res) => {
        Object.assign(this.form, res.data);
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        itemId: this.itemId,
        productNo: "",
        productEnglishName: "",
        unitOfMeasure: "",
        expirationDateStart: "",
        expirationDateEnd: "",
        brandId: "",
        brandName: "",
        sizeGroupId: "",
        sizeGroupName: "",
        layout: "",
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    async submitForm() {
      return await this.$refs["form"].validate();
    },
    openSizeGroupSelect() {
      this.$refs["SizeGroupSelectRef"].showFlag = true;
    },
    onSizeGroupSelect(row) {
      if (row != undefined && row != null) {
        this.form.sizeGroupId = row.sizeGroupId;
        this.form.sizeGroupName = row.sizeGroupName;
      }
    },
    openBrandSelected() {
      this.$refs["BrandSelectRef"].showFlag = true;
    },
    onBrandSelected(row) {
      if (row != undefined && row != null) {
        this.form.brandId = row.brandId;
        this.form.brandName = row.brandName;
      }
    },
  },
};
</script>
