<!--采购信息-->
<template>
  <div class="app-container">
    <!-- 添加或修改销售单位转换对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="销售单位" label-width="100px" prop="saleUnit">
            <el-input v-model="form.saleUnit" placeholder="请输入销售单位" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="销售换算值" label-width="100px" prop="saleConversionValue">
            <el-input v-model="form.saleConversionValue" type="number" :precision="2" placeholder="请输入销售换算值" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getUnit } from "@/api/mes/md/saleUnit";

export default {
  name: "Unit",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售单位转换表格数据
      unitList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemId: this.itemId,
        saleUnit: null,
        saleConversionValue: null
      },
      // 表单参数
      form: {
        itemId: '',
        saleUnit: '',
        saleConversionValue: ''
      },
      // 表单校验
      rules: {
        itemId: [
          { required: true, message: "产品ID不能为空", trigger: "blur" }
        ],      }
    };
  },
  props: {
    optType: undefined,
    itemId: {
      type: Number | undefined,
      default: undefined,
    },
  },
  created() {
    this.getSaleUnit();
  },
  methods: {
    //获取基本信息表单数据
    async getSaleUnitFormData() {
      await this.submitForm();
      return this.form;
    },

    getSaleUnit() {
      getUnit(this.itemId).then((res) => {
        Object.assign(this.form, res.data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        itemId: this.itemId,
        saleUnit: null,
        saleConversionValue: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    async submitForm() {
      return await this.$refs["form"].validate();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
