You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fieldEditor.vue 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div>
  3. <div v-if="!edit" class="input-group-prepend">
  4. <input class="form-control" v-model="myDisplay" disabled />
  5. <span
  6. v-if="mayEdit"
  7. @click="EditClick()"
  8. class="input-group-text spanCursor"
  9. style="color: #60CBEB"
  10. >
  11. <eva-icon name="edit-outline" fill="#60CBEB"></eva-icon>
  12. </span>
  13. </div>
  14. <div v-if="edit" class="input-group-prepend">
  15. <input v-if="type === 'text'" class="form-control" v-model="value" />
  16. <input v-if="type === 'number'" type="number" class="form-control" v-model="value" />
  17. <select v-if="type === 'select'" class="form-control" @change="selectionClick">
  18. <option>Please select</option>
  19. <option
  20. v-for="option in selectOptions"
  21. :value="option[selectValue]"
  22. :key="option[selectValue]"
  23. >{{ option[selectText] }}</option
  24. >
  25. </select>
  26. <select v-if="type === 'selectlist'" class="form-control" v-model="value">
  27. <option v-for="item in selectOptions" :value="item" :key="item">{{ item }}</option>
  28. </select>
  29. <!-- <Datetime class="form-control" v-if="type === 'datetime'" v-model="value" /> -->
  30. <span
  31. v-if="edit"
  32. @click="UpdateValue()"
  33. class="input-group-text spanCursor"
  34. style="color: #60CBEB"
  35. >
  36. <eva-icon name="checkmark-outline" fill="#60CBEB"></eva-icon>
  37. </span>
  38. <span v-if="edit" @click="Close()" class="input-group-text spanCursor" style="color: #60CBEB">
  39. <eva-icon name="close-outline" fill="#60CBEB"></eva-icon>
  40. </span>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. props: ['value', 'type', 'mayEdit', 'selectOptions', 'selectValue', 'selectText', 'display'],
  47. data() {
  48. return {
  49. edit: false,
  50. myDisplay: '',
  51. };
  52. },
  53. methods: {
  54. UpdateValue() {
  55. this.edit = false;
  56. if (this.type !== 'select' && this.value) {
  57. this.$emit('input', this.value);
  58. this.$emit('change', this.value);
  59. }
  60. },
  61. EditClick() {
  62. this.edit = true;
  63. },
  64. Close() {
  65. this.edit = false;
  66. },
  67. selectionClick(item) {
  68. if (item.target.options.selectedIndex > 0) {
  69. if (!this.value) {
  70. this.myDisplay = this.selectOptions[item.target.options.selectedIndex - 1][
  71. this.selectText
  72. ];
  73. }
  74. if (this.selectOptions[item.target.options.selectedIndex - 1]) {
  75. this.$emit('input', this.selectOptions[item.target.options.selectedIndex - 1]);
  76. this.$emit('change', this.selectOptions[item.target.options.selectedIndex - 1]);
  77. }
  78. }
  79. },
  80. },
  81. mounted() {
  82. if (this.value) {
  83. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  84. this.myDisplay = this.value;
  85. }
  86. if (this.value && this.selectText) {
  87. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  88. this.myDisplay = this.value[this.selectText];
  89. }
  90. if (this.display) {
  91. this.myDisplay = this.display;
  92. }
  93. },
  94. computed: {
  95. // eslint-disable-next-line vue/return-in-computed-property
  96. checkValue() {
  97. if (this.value) {
  98. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  99. this.myDisplay = this.value;
  100. }
  101. if (this.value && this.selectText) {
  102. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  103. this.myDisplay = this.value[this.selectText];
  104. }
  105. if (this.display) {
  106. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  107. this.myDisplay = this.display;
  108. }
  109. },
  110. },
  111. watch: {
  112. checkValue() {
  113. return null;
  114. },
  115. },
  116. };
  117. </script>