<template>
  <div>
    <el-form :model="formData" label-width="200px">
      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="当前工位：">
            <el-input v-model="formData.workPlaceName" disabled></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="10">
          <el-form-item class="query-form-item" label="产品名称：">
            <el-input v-model="formData.cpmctymc" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="产品规格：">
            <el-input v-model="formData.ggxh" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="批次号：">
            <el-input v-model="formData.batchNo" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="业务类型：">
            <el-input v-model="formData.busTypeName" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-divider></el-divider>
      <el-row>
        <el-col :span="10">
          <el-form-item class="query-form-item" label="是否开启库存预警">
            <el-select v-model="formData.enableRemind">
              <el-option :value="true" label="开启"></el-option>
              <el-option :value="false" label="关闭"></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="10">
          <el-form-item class="query-form-item" label="库存预警数量：">
            <el-input v-model="formData.invRemindCount" ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click.native="closeDialog">取消</el-button>
      <el-button type="primary" @click.native="addInvRemindSet()" :loading="formLoading"
      >提交
      </el-button>
    </div>
  </div>
</template>

<script>
import {remindSet} from "@/api/inout/splitInv";
export default {
  name: "ioSplitFifoCodeRemindSetDialog",
  props: {
    prescribeData: {
      type: Object,
      required: true
    },
    closeDialog: {
      type: Function,
      required: true
    }
  },
  data() {
    return {
      formData: {
        workPlaceName: null,
        ggxh: null,
        cpmctymc: null,
        batchNo: null,
        enableRemind:null,
        invRemindCount:null,
        id:null
      },
      formLoading: false
    };
  },
  methods: {
    getRemindSetInfo() {
      this.formData = this.prescribeData;
      if (this.prescribeData.monopoly == 0){
        this.formData.busTypeName = '共享库存'
      }else {
        this.formData.busTypeName = this.prescribeData.busName
      }
    },

    addInvRemindSet() {
      this.formLoading = true
      let param = {
        id:this.formData.id,
        enableRemind:this.formData.enableRemind,
        invRemindCount:this.formData.invRemindCount
      }
      remindSet(param).then((res) => {
        this.formLoading = false
        if (res.code === 20000) {
          this.closeDialog();
        } else {
          this.$message.error(res.message);
        }
      }).catch((error) => {
        this.formLoading = false
        this.$message.error(error.message);
        this.closeDialog();
      })
    },
  },
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },
  created() {
    this.getRemindSetInfo();
  },
};
</script>

<style type="text/scss" lang="scss">
</style>

