<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="pointCode">
        <el-input v-model="form.pointCode" 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-item label="工单号" prop="orderNumber">
        <el-input v-model="form.orderNumber" 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="bindOrderConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import boxurl from '@/api/box'
import CRUD from '@crud/crud'

export default {
  mixins: [crud],
  data() {
    return {
      dialogVisible: false,
      BindOrder: {
        pointCode: '',
        itemCode: '',
        orderNumber: ''
      },
      rules: {
        pointCode: [
          {required: true, message: '点位必填', trigger: 'blur'}
        ],
        itemCode: [
          {required: true, message: '物料必填', trigger: 'blur'}
        ],
        orderNumber: [
          {required: true, message: '工单号必填', trigger: 'blur'}
        ],
      }


    };
  },
  methods: {
    //关闭
    handleClose(done) {
      done();
    },
    bindOrderConfirm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          alert(0)
          this.BindOrder.pointCode = this.form.pointCode
          this.BindOrder.itemCode = this.form.itemCode
          this.BindOrder.orderNumber = this.form.orderNumber
          boxurl.bindOrder(this.BindOrder).then(res => {
            this.dialogVisible = false
            this.toQuery()
            this.$parent.crud.notify('绑定成功！', CRUD.NOTIFICATION_TYPE.SUCCESS);
          }).catch(() => {
            this.$parent.crud.notify('绑定失败！', CRUD.NOTIFICATION_TYPE.ERROR);
          })
        } else {
          return false;
        }
      });
    },
    cancelForm() {
      this.dialogVisible = false
      this.$refs['form'].resetFields();
    }
  }

};
</script>


<style scoped>

</style>
