Quellcode durchsuchen

fix AdminTicketShow.vue category options

ali vor 2 Jahren
Ursprung
Commit
e639d98d5d

+ 3 - 3
src/api/models/TicketCategory.js

@@ -1,7 +1,7 @@
 import { appApi } from 'src/boot/axios.js'
+import { Ticket } from 'src/models/Ticket.js'
 import APIRepository from '../classes/APIRepository.js'
-import { Ticket, TicketList } from 'src/models/Ticket.js'
-import { TicketCategory } from 'src/models/TicketCategory.js'
+import { TicketCategory, TicketCategoryList } from 'src/models/TicketCategory.js'
 
 export default class TicketCategoryAPI extends APIRepository {
   constructor() {
@@ -34,7 +34,7 @@ export default class TicketCategoryAPI extends APIRepository {
         const results = response.data.results
         delete paginate.results
         return {
-          list: new TicketList(results),
+          list: new TicketCategoryList(results),
           paginate
           // {
           //   "count": 1,

+ 109 - 0
src/components/FormBuilderCustumComponents/TicketCategorySelector.vue

@@ -0,0 +1,109 @@
+<template>
+  <div class="TicketCategorySelector row q-col-gutter-md">
+    <div class="col-md-6 col-12">
+      <div>
+        معاونت
+      </div>
+      <q-select v-model="ticketCategoryType"
+                map-options
+                emit-value
+                :options="ticketCategoryTypeOptions"
+                :loading="ticketCategoryTypeOptions.laoding" />
+    </div>
+    <div class="col-md-6 col-12">
+      <div>
+        دسته
+      </div>
+      <q-select v-model="ticketCategory"
+                map-options
+                emit-value
+                :options="ticketCategoryOptions"
+                :loading="ticketCategoryTypeOptions.laoding" />
+    </div>
+  </div>
+</template>
+
+<script>
+import { APIGateway } from 'src/api/APIGateway.js'
+import { TicketCategory } from 'src/models/TicketCategory.js'
+
+export default {
+  name: 'TicketCategorySelector',
+  props: {
+    value: {
+      default: () => [],
+      type: [Array, String, Number, Boolean, Object]
+    },
+    disable: {
+      default: false,
+      type: Boolean
+    }
+  },
+  emits: ['update:value'],
+  data () {
+    return {
+      ticketCategoryTypeFirstChanged: false,
+      ticketCategoryType: null,
+      ticketCategory: null,
+      ticketCategoryTypeOptions: (new TicketCategory()).typeEnums,
+      ticketCategoryOptions: []
+    }
+  },
+  watch: {
+    value: {
+      handler: function (newValue) {
+        if (newValue?.type && newValue.id) {
+          this.ticketCategoryType = newValue.type
+          this.getCategories(this.ticketCategoryType)
+        } else {
+          this.inputData = this.value
+        }
+      },
+      immediate: true
+    },
+    ticketCategoryType (newValue) {
+      this.ticketCategory = null
+      this.ticketCategoryOptions = []
+      if (this.ticketCategoryTypeFirstChanged && newValue) {
+        this.getCategories(newValue)
+      } else {
+        this.ticketCategoryTypeFirstChanged = true
+      }
+    },
+    ticketCategory (newValue) {
+      this.$emit('update:value', newValue)
+    }
+  },
+  methods: {
+    getCategories (type) {
+      this.ticketCategoryTypeOptions.laoding = true
+
+      APIGateway.ticketCategory.index({ type, per_page: 99999 })
+        .then(categories => {
+          this.ticketCategoryOptions = categories.list.list.map(item => {
+            return {
+              item,
+              label: item.title,
+              value: item.id
+            }
+          })
+
+          let ticketCategory = null
+          if (this.value?.type && this.value.id) {
+            ticketCategory = this.value.id
+          }
+          if (this.value && !isNaN(this.value)) {
+            ticketCategory = this.value
+          }
+
+          this.$emit('update:value', ticketCategory)
+          this.ticketCategory = ticketCategory
+        })
+        .finally(() => {
+          this.ticketCategoryTypeOptions.laoding = false
+        })
+    }
+  }
+
+}
+</script>

+ 17 - 11
src/components/Widgets/Ticket/AdminTicketShow/AdminTicketShow.vue

@@ -158,15 +158,17 @@ import { APIGateway } from 'src/api/APIGateway.js'
 import { FormBuilderAssist } from 'quasar-form-builder'
 import BtnControl from 'src/components/Control/btn.vue'
 import { InstalmentOfferList } from 'src/models/InstalmentOffer.js'
-import { TicketCategory, TicketCategoryList } from 'src/models/TicketCategory.js'
+import { TicketCategoryList } from 'src/models/TicketCategory.js'
 // import ShowSource from 'src/components/Widgets/Ticket/AdminTicketShow/ShowSource.vue'
 import AdminInvoiceShow from 'src/components/Widgets/Invoice/AdminInvoiceShow/AdminInvoiceShow.vue'
 import InstallmentOffers from 'src/components/Widgets/Ticket/AdminTicketShow/InstallmentOffers.vue'
 import CreateInstallment from 'src/components/Widgets/Ticket/AdminTicketShow/CreateInstallment.vue'
 import FormBuilderDateTime from 'src/components/FormBuilderCustumComponents/FormBuilderDateTime.vue'
+import TicketCategorySelector from 'src/components/FormBuilderCustumComponents/TicketCategorySelector.vue'
 
 const BtnControlComp = shallowRef(BtnControl)
 const FormBuilderDateTimeComp = shallowRef(FormBuilderDateTime)
+const TicketCategorySelectorComp = shallowRef(TicketCategorySelector)
 
 export default {
   name: 'AdminTicketShow',
@@ -204,16 +206,20 @@ export default {
         { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'مشخصات کاربر', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' },
 
         { type: 'separator', name: 'space', label: 'مشخصات تیکت', className: 'custom-separator', col: 'col-12' },
-        {
-          type: 'select',
-          name: 'category_info__type',
-          responseKey: 'category_info.type',
-          options: (new TicketCategory()).typeEnums,
-          label: 'معاونت',
-          placeholder: ' ',
-          col: 'col-md-4 col-12'
-        },
-        { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-4 col-12' },
+
+        { type: TicketCategorySelectorComp, name: 'category', responseKey: 'category_info', col: 'col-md-8 col-12' },
+
+        // {
+        //   type: 'select',
+        //   name: 'category_info__type',
+        //   responseKey: 'category_info.type',
+        //   options: (new TicketCategory()).typeEnums,
+        //   label: 'معاونت',
+        //   placeholder: ' ',
+        //   col: 'col-md-4 col-12'
+        // },
+        // { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-4 col-12' },
+
         { type: 'select', name: 'status', responseKey: 'status', options: (new Ticket()).statusEnums, multiple: false, label: 'وضعیت', placeholder: ' ', readonly: true, col: 'col-md-4 col-12' },
 
         { type: 'file', name: 'attachment', responseKey: 'attachment', placeholder: ' ', label: 'ضمیمه', readonly: true, col: 'col-md-6 col-12' },

+ 1 - 1
src/models/TicketCategory.js

@@ -4,7 +4,7 @@ class TicketCategory extends Model {
   constructor (data) {
     super(data, [
       { key: 'id' },
-      { key: 'name' },
+      { key: 'title' },
       { key: 'type' }
     ], {
       type: {