<template>
  <el-dialog
    title="上传License"
    :visible.sync="dialogVisible"
    width="500px"
    :before-close="handleClose">

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

      <el-form-item label="机器码" prop="deviceCode">
        <el-input v-model="form.deviceCode" placeholder=""></el-input>
      </el-form-item>

      <el-form-item label="License" prop="licenseCode">
        <el-input v-model="form.licenseCode" type="textarea" :rows="10" placeholder="请输入License" ></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 { putLicenseCode } from '@/api/login'
import CRUD from '@crud/crud'

export default {
  mixins: [crud],
  data() {
    return {
      dialogVisible: false,
      rules: {
        licenseCode: [
          { required: true, message: 'License必填', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 关闭
    handleClose(done) {
      done()
    },
    bindOrderConfirm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          putLicenseCode(this.form.licenseCode).then(res => {
            this.dialogVisible = false
            this.$parent.crud.notify('绑定成功！', CRUD.NOTIFICATION_TYPE.SUCCESS)
          }).catch(() => {

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

}
</script>
<style scoped>

</style>
