<template>
  <el-dialog
    title="容器入场"
    :visible.sync="dialogVisible"
    width="400px"
    :before-close="handleClose">

    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">

      <el-form-item label="容器编号" prop="containerCode">
        <el-input v-model="form.containerCode" disabled placeholder="请输入容器号"></el-input>
      </el-form-item>

      <el-form-item label="点位编号" prop="position">
        <el-input v-model="form.position" placeholder="请输入点位"></el-input>
      </el-form-item>

      <el-form-item label="物料编号" prop="itemCode" >
        <el-input v-model="form.itemCode" placeholder="请输入物料"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
    <el-button @click="cancelForm">取 消</el-button>
    <el-button type="primary" @click="containerInConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import stockUrl from '@/api/stock'
import CRUD from '@crud/crud'

export default {
  mixins: [crud],
  data() {
    return {
      dialogVisible: false,
      ContainerIn: {
        containerCode: '',
        position: '',
        itemCode:''
      },
      rules: {
        position: [
          {required: true, message: '点位必填', trigger: 'blur'}
        ],
        containerCode: [
          {required: true, message: '容器必填', trigger: 'blur'}
        ]

      }


    };
  },
  methods: {
    //关闭
    handleClose(done) {
      done();
      this.dialogVisible = false
      this.$refs['form'].resetFields();
    },
    containerInClick(data){
    this.form.containerCode=data.code;
    },
    containerInConfirm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.ContainerIn.containerCode = this.form.containerCode
          this.ContainerIn.position = this.form.position
          this.ContainerIn.itemCode=this.form.itemCode
          stockUrl.containerIn(this.ContainerIn).then(res => {
            if(res.status==200){
              this.dialogVisible = false
              this.$parent.crud.notify(res.message, CRUD.NOTIFICATION_TYPE.SUCCESS);
              this.$parent.crud.toQuery();
              this.$refs['form'].resetFields();
            }else{
              this.$parent.crud.notify(res.message, CRUD.NOTIFICATION_TYPE.ERROR);
            }
          }).catch(() => {

          })
        } else {
          return false;
        }
      });
    },
    cancelForm() {
      this.dialogVisible = false
      this.$refs['form'].resetFields();
    }
  }

};
</script>


<style scoped>

</style>
