ChannelNameEditDlg.vue 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 for="input-serial" 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="readonly" id="input-serial" name="serial" :value="form.serial" data-vv-as="设备编号" >
  9. </div>
  10. </div>
  11. <div :class="{'form-group':true,'has-error': errors.has('code')}">
  12. <label for="input-code" class="col-sm-4 control-label">通道编号
  13. <span class="text-red">*</span>
  14. </label>
  15. <div class="col-sm-7">
  16. <input type="text" class="form-control" readonly="readonly" id="input-code" name="code" :value="form.code" data-vv-as="通道编号">
  17. </div>
  18. </div>
  19. <div :class="{'form-group':true,'has-error': errors.has('name')}">
  20. <label for="input-name" class="col-sm-4 control-label">自定义名称
  21. </label>
  22. <div class="col-sm-7">
  23. <input type="text" class="form-control" id="input-name" name="name" :placeholder="form.name||'-'" v-model.trim="form.customName" data-vv-as="自定义名称" @keydown.enter="onSubmit">
  24. </div>
  25. </div>
  26. </FormDlg>
  27. </template>
  28. <script>
  29. import FormDlg from 'components/FormDlg.vue'
  30. import $ from 'jquery'
  31. export default {
  32. data() {
  33. return {
  34. form: this.defForm(),
  35. }
  36. },
  37. components: {
  38. FormDlg
  39. },
  40. methods: {
  41. defForm() {
  42. return {
  43. serial: '',
  44. code: '',
  45. name: '',
  46. customName: '',
  47. }
  48. },
  49. onHide() {
  50. this.form = this.defForm();
  51. this.$emit("hide");
  52. },
  53. onShow() {
  54. this.errors.clear();
  55. this.$emit("show");
  56. this.$el.querySelector('#input-name').focus()
  57. },
  58. async onSubmit() {
  59. var ok = await this.$validator.validateAll();
  60. if(!ok) {
  61. var e = this.errors.items[0];
  62. this.$message({
  63. type: 'error',
  64. message: e.msg
  65. })
  66. $(`[name=${e.field}]`).focus();
  67. return;
  68. }
  69. $.get('/api/v1/device/setchannelname', {
  70. serial: this.form.serial,
  71. code: this.form.code,
  72. name: this.form.customName,
  73. }).then(data => {
  74. this.$refs['dlg'].hide();
  75. this.$emit("submit");
  76. })
  77. },
  78. show(data) {
  79. this.errors.clear();
  80. if(data) {
  81. this.form.serial = data.serial;
  82. this.form.code = data.code;
  83. this.form.name = data.name;
  84. this.form.customName = data.customName;
  85. if(data.custom) {
  86. this.form.customName = data.name;
  87. this.form.name = '';
  88. }
  89. }
  90. this.$nextTick(() => {
  91. this.$refs['dlg'].show();
  92. })
  93. }
  94. }
  95. }
  96. </script>