<!--产品基本信息-->
<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="packageNum">
            <!-- {{ form.packageNum }} -->
            <el-input-number v-model="form.packageNum" :step="1"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="装箱数量" prop="encasementNum">
            <!-- {{ form.encasementNum }} -->
            <el-input-number v-model="form.encasementNum" :step="1" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
        <el-form-item label="毛重" prop="grossWeight">
            <el-input v-model="form.grossWeight" placeholder="毛重" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
        <el-form-item label="净重" prop="netWeight">
            <el-input v-model="form.netWeight" placeholder="净重" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="重量单位" prop="weightUnit">
            <el-select v-model="form.weightUnit" placeholder="请选择版面">
              <el-option
                v-for="dict in dict.type.md_weight_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="体积" prop="volume">
            <el-input v-model="form.volume" placeholder="体积" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="体积单位" prop="volumeUnit">
            <el-select v-model="form.volumeUnit" placeholder="请选择体积单位">
              <el-option
                v-for="dict in dict.type.md_volumetric_unit"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="品牌" prop="brandName">
            <el-input
              v-model="form.brandName"
              disabled
              placeholder="请选择品牌"
            >
              <el-button
                icon="el-icon-search"
                slot="append"
                @click="openBrandSelected"
              />
            </el-input>
          </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="8">
          <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="8">
          <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","md_weight_unit","md_volumetric_unit"],
  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: "",
        grossWeight: '',
        volume: '',
        volumeUnit: '',
        weightUnit: '',
        netWeight: ''
      },
      // 表单校验
      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>
