BlackEditDlg.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <FormDlg title="编辑黑名单" @hide="onHide" @show="onShow" @submit="onSubmit" ref="dlg" :disabled="errors.any()">
  3. <div :class="{'form-group':true,'has-error': errors.has('serial')}">
  4. <label class="col-sm-4 control-label">设备国标编号
  5. <span class="text-red">*</span>
  6. </label>
  7. <div class="col-sm-7">
  8. <input type="text" class="form-control" :readonly="form.oper == 'edit'" name="serial" v-model.trim="form.serial" data-vv-as="设备编号" v-validate="'required'">
  9. </div>
  10. </div>
  11. <div :class="{'form-group':true,'has-error': errors.has('description')}">
  12. <label class="col-sm-4 control-label">描述
  13. </label>
  14. <div class="col-sm-7">
  15. <input type="text" class="form-control" name="description" v-model.trim="form.description" data-vv-as="描述信息">
  16. </div>
  17. </div>
  18. </FormDlg>
  19. </template>
  20. <script>
  21. import FormDlg from 'components/FormDlg.vue'
  22. import $ from 'jquery'
  23. export default {
  24. data() {
  25. return {
  26. form: this.defForm()
  27. }
  28. },
  29. components: {
  30. FormDlg
  31. },
  32. methods: {
  33. defForm() {
  34. return {
  35. oper : 'edit',
  36. serial: '',
  37. description: '',
  38. password: '',
  39. }
  40. },
  41. onHide() {
  42. this.form = this.defForm();
  43. this.$emit("hide");
  44. },
  45. onShow() {
  46. this.errors.clear();
  47. this.$emit("show");
  48. if (!this.form.serial) {
  49. this.form.oper = 'add';
  50. this.$el.querySelector('[name=serial]').focus();
  51. }
  52. },
  53. async onSubmit() {
  54. var ok = await this.$validator.validateAll();
  55. if (!ok) {
  56. var e = this.errors.items[0];
  57. this.$message({
  58. type: 'error',
  59. message: e.msg
  60. })
  61. $(`[name=${e.field}]`).focus();
  62. return;
  63. }
  64. $.get('/api/v1/black/save', this.form).then(data => {
  65. this.$refs['dlg'].hide();
  66. this.$emit("submit");
  67. })
  68. },
  69. show(data) {
  70. this.errors.clear();
  71. if (data) {
  72. Object.assign(this.form, data);
  73. }
  74. this.$nextTick(() => {
  75. this.$refs['dlg'].show();
  76. })
  77. }
  78. }
  79. }
  80. </script>