ChoicesItem.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="ChoicesItem">
  3. <template v-if="canEdit || canDelete">
  4. <div class="title">
  5. <q-input v-model="choiceText"
  6. class="full-width"
  7. type="textarea"
  8. @update:model-value="onChangeChoiceText" />
  9. </div>
  10. <div class="actions">
  11. <q-btn v-if="canEdit"
  12. icon="edit"
  13. outline
  14. class="viewBtn"
  15. color="primary"
  16. @click="onEdit" />
  17. <q-btn v-if="canDelete"
  18. class="deleteBtn"
  19. icon="delete"
  20. outline
  21. color="red"
  22. @click="onDelete" />
  23. </div>
  24. </template>
  25. <div v-else
  26. v-html="choiceText" />
  27. </div>
  28. </template>
  29. <script>
  30. import { QuestionChoice } from 'src/models/QuestionChoice.js'
  31. export default {
  32. name: 'ChoicesItem',
  33. props: {
  34. choice: {
  35. type: QuestionChoice,
  36. default: new QuestionChoice()
  37. },
  38. canEdit: {
  39. type: Boolean,
  40. default: true
  41. },
  42. canDelete: {
  43. type: Boolean,
  44. default: true
  45. }
  46. },
  47. emits: ['update:choice', 'onEdit', 'onDelete'],
  48. data () {
  49. return {
  50. choiceText: null,
  51. entityCreateLoading: false
  52. }
  53. },
  54. mounted() {
  55. if (this.canEdit || this.canDelete) {
  56. this.choiceText = this.choice.text.replace(/<br>/g, '\n')
  57. } else {
  58. this.choiceText = this.choice.text.replace(/\n/g, '<br>')
  59. }
  60. },
  61. methods: {
  62. onChangeChoiceText () {
  63. const oldChoice = this.choice
  64. oldChoice.text = this.choiceText.replace(/\n/g, '<br>')
  65. this.$emit('update:choice', oldChoice)
  66. },
  67. onEdit () {
  68. this.$emit('onEdit')
  69. },
  70. onDelete () {
  71. this.$emit('onDelete')
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .ChoicesItem {
  78. background: #F9F9F9;
  79. border: 1px solid #DFE1EC;
  80. border-radius: 10px;
  81. padding: 10px 16px 10px 21px;
  82. display: flex;
  83. flex-flow: row;
  84. justify-content: space-between;
  85. align-items: center;
  86. .title {
  87. width: calc( 100% - 120px );
  88. }
  89. .actions {
  90. display: flex;
  91. flex-flow: row;
  92. justify-content: flex-end;
  93. .q-btn {
  94. width: 42px;
  95. height: 42px;
  96. &.viewBtn {
  97. }
  98. &.deleteBtn {
  99. margin-left: 16px;
  100. }
  101. }
  102. }
  103. }
  104. </style>