<!--产品基本信息-->
<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="$t('包装数量')" 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="$t('装箱数量')" 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="$t('毛重')" prop="grossWeight">
            <el-input v-model="form.grossWeight" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>  
        <el-col :span="8">
        <el-form-item :label="$t('净重')" prop="netWeight">
            <el-input v-model="form.netWeight" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('重量单位')" prop="weightUnit">
            <el-select v-model="form.weightUnit">
              <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="$t('体积')" prop="volume">
            <el-input v-model="form.volume" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item :label="$t('体积单位')" prop="volumeUnit">
            <el-select v-model="form.volumeUnit">
              <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="$t('品牌')" prop="brandName">
            <el-input
              v-model="form.brandName"
              disabled
             
            >
              <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="$t('尺码组')" prop="sizeGroupId">
            <el-input
              v-model="form.sizeGroupName"
              disabled
             
            >
              <el-button
                icon="el-icon-search"
                slot="append"
                @click="openSizeGroupSelect"
              />
            </el-input>
            <SizeGroupSelect
              ref="SizeGroupSelectRef"
              @onSelected="onSizeGroupSelect"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item :label="$t('版面')" prop="layout">
            <el-select v-model="form.layout">
              <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="$t('有效开始日期')" prop="expirationDateStart">
            <el-date-picker
              clearable
              v-model="form.expirationDateStart"
              type="date"
              value-format="yyyy-MM-dd"
             
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('有效结束日期')" prop="expirationDateEnd">
            <el-date-picker
              clearable
              v-model="form.expirationDateEnd"
              type="date"
              value-format="yyyy-MM-dd"
             
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-col :span="8">
          <el-form-item :label="$t('是否排版')">
            <el-radio-group v-model="form.isLayout"  v-if="optType=='view'">
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
              <el-radio-group v-model="form.isLayout" v-else>
                <el-radio
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
        </el-col>

    </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","sys_yes_no"],
  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>
