DeviceTreeNodeEditDlg.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <FormDlg :title="title" @hide="onHide" @show="onShow" @submit="onSubmit" ref="dlg" :disabled="errors.any()">
  3. <div :class="{'form-group':true,'has-error': errors.has('parentid')}">
  4. <label for="input-parentid" class="col-sm-4 control-label">父节点
  5. <!-- <span class="text-red">*</span> -->
  6. </label>
  7. <div class="col-sm-7">
  8. <select class="form-control" id="input-parentid" v-model.trim="form.parentid" data-vv-as="父节点" disabled="disabled">
  9. <option :value="form.parentid">{{form.parentname}}</option>
  10. </select>
  11. </div>
  12. </div>
  13. <div :class="{'form-group':true,'has-error': errors.has('serial')}">
  14. <label for="input-serial" class="col-sm-4 control-label">设备编号
  15. <span class="text-red">*</span>
  16. </label>
  17. <div class="col-sm-7">
  18. <input type="text" class="form-control" readonly="readonly" id="input-serial" name="serial" :value="form.serial" data-vv-as="设备编号" >
  19. </div>
  20. </div>
  21. <div :class="{'form-group':true,'has-error': errors.has('code')}">
  22. <label for="input-code" class="col-sm-4 control-label">通道编号
  23. <span class="text-red" v-if="form.add">*</span>
  24. </label>
  25. <div class="col-sm-7">
  26. <input type="text" class="form-control" id="input-code" name="code" v-model.trim="form.code" :placeholder="codePlaceholder" data-vv-as="通道编号" v-validate="'required|regex:^[0-9]+$'" @keydown.enter="$el.querySelector('#input-name').focus()" v-if="form.add">
  27. <input type="text" class="form-control" readonly="readonly" id="input-code" name="code" v-model.trim="form.code" data-vv-as="通道编号" v-else>
  28. </div>
  29. </div>
  30. <div :class="{'form-group':true,'has-error': errors.has('name')}">
  31. <label for="input-name" class="col-sm-4 control-label">节点名称
  32. </label>
  33. <div class="col-sm-7">
  34. <input type="text" class="form-control" id="input-name" name="name" :placeholder="form.name||form.id" v-model.trim="form.customName" data-vv-as="节点名称" @keydown.enter="onSubmit">
  35. </div>
  36. </div>
  37. </FormDlg>
  38. </template>
  39. <script>
  40. import FormDlg from 'components/FormDlg.vue'
  41. import $ from 'jquery'
  42. export default {
  43. data() {
  44. return {
  45. form: this.defForm(),
  46. }
  47. },
  48. components: {
  49. FormDlg
  50. },
  51. computed: {
  52. title() {
  53. return (this.form.code || this.form.parentname == '根节点') ? "编辑节点" : "新建节点";
  54. },
  55. codePlaceholder() {
  56. if(!this.form.add) return "";
  57. if(!this.form.serial || this.form.serial.length < 10) return "20位数字";
  58. return `20位数字, 如: ${this.form.serial.substring(0,10)}2160000001`;
  59. }
  60. },
  61. methods: {
  62. defForm() {
  63. return {
  64. id: '',
  65. serial: '',
  66. code: '',
  67. name: '',
  68. customName: '',
  69. parentid: '',
  70. parentname: '根节点',
  71. add: false,
  72. }
  73. },
  74. onHide() {
  75. this.form = this.defForm();
  76. this.$emit("hide");
  77. },
  78. onShow() {
  79. this.errors.clear();
  80. this.$emit("show");
  81. },
  82. async onSubmit() {
  83. var ok = await this.$validator.validateAll();
  84. if(!ok) {
  85. var e = this.errors.items[0];
  86. this.$message({
  87. type: 'error',
  88. message: e.msg
  89. })
  90. $(`[name=${e.field}]`).focus();
  91. return;
  92. }
  93. $.get('/api/v1/channel/save', {
  94. serial: this.form.serial,
  95. code: this.form.code,
  96. name: this.form.customName,
  97. parentid: this.form.parentid,
  98. add: this.form.add,
  99. }).then(data => {
  100. this.$refs['dlg'].hide();
  101. this.$emit("submit");
  102. })
  103. },
  104. show(data) {
  105. this.errors.clear();
  106. if(data) {
  107. this.form.add = !!data.add;
  108. this.form.id = data.id;
  109. this.form.serial = data.serial;
  110. this.form.code = data.code;
  111. this.form.name = data.name;
  112. this.form.customName = data.customName;
  113. if(data.custom) {
  114. this.form.customName = data.name;
  115. this.form.name = '';
  116. }
  117. if(data.parent) {
  118. this.form.parentid = data.parent.code;
  119. this.form.parentname = data.parent.customName || data.parent.name || data.parent.id;
  120. }
  121. }
  122. this.$nextTick(() => {
  123. this.$refs['dlg'].show();
  124. })
  125. }
  126. }
  127. }
  128. </script>