TicketCategorySelector.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div class="TicketCategorySelector row q-col-gutter-md">
  3. <div class="col-md-6 col-12">
  4. <div>
  5. معاونت
  6. </div>
  7. <q-select v-model="ticketCategoryType"
  8. map-options
  9. emit-value
  10. :disable="disable"
  11. :options="ticketCategoryTypeOptions"
  12. :loading="ticketCategoryTypeOptions.laoding" />
  13. </div>
  14. <div class="col-md-6 col-12">
  15. <div>
  16. دسته
  17. </div>
  18. <q-select v-model="ticketCategory"
  19. map-options
  20. emit-value
  21. :disable="disable"
  22. :options="ticketCategoryOptions"
  23. :loading="ticketCategoryTypeOptions.laoding" />
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import { APIGateway } from 'src/api/APIGateway.js'
  29. import { TicketCategory } from 'src/models/TicketCategory.js'
  30. export default {
  31. name: 'TicketCategorySelector',
  32. props: {
  33. value: {
  34. default: () => [],
  35. type: [Array, String, Number, Boolean, Object]
  36. },
  37. disable: {
  38. default: false,
  39. type: Boolean
  40. }
  41. },
  42. emits: ['update:value'],
  43. data () {
  44. return {
  45. ticketCategoryTypeFirstChanged: false,
  46. ticketCategoryType: null,
  47. ticketCategory: null,
  48. ticketCategoryTypeOptions: (new TicketCategory()).typeEnums,
  49. ticketCategoryOptions: []
  50. }
  51. },
  52. watch: {
  53. value: {
  54. handler: function (newValue) {
  55. if (newValue?.type && newValue.id) {
  56. this.ticketCategoryType = newValue.type
  57. this.getCategories(this.ticketCategoryType)
  58. } else {
  59. this.inputData = this.value
  60. }
  61. },
  62. immediate: true
  63. },
  64. ticketCategoryType (newValue) {
  65. this.ticketCategory = null
  66. this.ticketCategoryOptions = []
  67. if (this.ticketCategoryTypeFirstChanged && newValue) {
  68. this.getCategories(newValue)
  69. } else {
  70. this.ticketCategoryTypeFirstChanged = true
  71. }
  72. },
  73. ticketCategory (newValue) {
  74. this.$emit('update:value', newValue)
  75. }
  76. },
  77. methods: {
  78. getCategories (type) {
  79. this.ticketCategoryTypeOptions.laoding = true
  80. APIGateway.ticketCategory.index({ type, per_page: 99999 })
  81. .then(categories => {
  82. this.ticketCategoryOptions = categories.list.list.map(item => {
  83. return {
  84. item,
  85. label: item.title,
  86. value: item.id
  87. }
  88. })
  89. let ticketCategory = null
  90. if (this.value?.type && this.value.id) {
  91. ticketCategory = this.value.id
  92. }
  93. if (this.value && !isNaN(this.value)) {
  94. ticketCategory = this.value
  95. }
  96. this.$emit('update:value', ticketCategory)
  97. this.ticketCategory = ticketCategory
  98. })
  99. .finally(() => {
  100. this.ticketCategoryTypeOptions.laoding = false
  101. })
  102. }
  103. }
  104. }
  105. </script>