TicketCreate.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="TicketCreate"
  3. :style="localOptions.style">
  4. <div class="title">
  5. ارسال پیام
  6. <div class="back-action">
  7. <q-btn flat
  8. :to="{name: 'UserPanel.Ticket.List'}"
  9. color="grey">
  10. بازگشت
  11. >
  12. </q-btn>
  13. </div>
  14. </div>
  15. <q-card class="form"
  16. flat>
  17. <q-linear-progress v-if="categoriesLoading"
  18. indeterminate />
  19. <entity-create v-if="mounted"
  20. ref="entityCreate"
  21. v-model:value="inputs"
  22. title="نقش جدید"
  23. :api="api"
  24. :default-layout="false"
  25. :entity-id-key-in-response="entityIdKeyInResponse"
  26. :show-route-param-key="showRouteParamKey"
  27. :index-route-name="indexRouteName"
  28. :show-route-name="showRouteName" />
  29. <div class="action">
  30. <div class="row q-mt-lg justify-end">
  31. <div class="col-md-4 col-12">
  32. <q-btn color="primary"
  33. class="full-width"
  34. :loading="entityLoading"
  35. @click="create">
  36. ارسال
  37. </q-btn>
  38. </div>
  39. </div>
  40. </div>
  41. </q-card>
  42. </div>
  43. </template>
  44. <script>
  45. import { EntityCreate } from 'quasar-crud'
  46. import { mixinWidget } from 'src/mixin/Mixins.js'
  47. import { APIGateway } from 'src/api/APIGateway.js'
  48. import { FormBuilderAssist } from 'quasar-form-builder'
  49. import { TicketCategory } from 'src/models/TicketCategory.js'
  50. export default {
  51. name: 'TicketCreate',
  52. components: { EntityCreate },
  53. mixins: [mixinWidget],
  54. data: () => {
  55. return {
  56. mounted: false,
  57. categoriesLoading: false,
  58. entityLoading: false,
  59. api: APIGateway.ticket.APIAdresses.base,
  60. entityIdKeyInResponse: 'id',
  61. showRouteParamKey: 'id',
  62. showRouteName: 'UserPanel.Ticket.Show',
  63. indexRouteName: 'UserPanel.Ticket.List',
  64. inputs: [
  65. {
  66. type: 'select',
  67. name: 'category_info__type',
  68. options: [
  69. { label: 'مالی', value: 'FINANCIAL' },
  70. { label: 'آموزش', value: 'EDUCATIONAL' },
  71. { label: 'محتوا', value: 'CONTENT' },
  72. { label: 'عمومی', value: 'GENERAL' }
  73. ],
  74. label: 'معاونت',
  75. ignoreValue: true,
  76. placeholder: ' ',
  77. col: 'col-md-4 col-12'
  78. },
  79. { type: 'select', name: 'category', responseKey: 'category', options: [], label: 'دسته', placeholder: ' ', col: 'col-md-4 col-12' },
  80. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان', placeholder: ' ', col: 'col-md-4 col-12' },
  81. { type: 'separator', name: 'separator', size: '0', label: 'توضیحات عنوان اینجا قرار میگیرد', col: 'col-12' },
  82. { type: 'inputEditor', name: 'body', label: 'متن درخواست', col: 'col-md-12 col-12' },
  83. { type: 'file', name: 'attachment', label: 'انتخاب فایل ضمیمه', col: 'col-md-3 col-12' },
  84. { type: 'hidden', name: 'owner', value: 1 },
  85. { type: 'hidden', name: 'source_type', value: null },
  86. { type: 'hidden', name: 'source_id', value: null }
  87. ]
  88. }
  89. },
  90. computed: {
  91. selectedSourceType () {
  92. return FormBuilderAssist.getInputsByName(this.inputs, 'category_info__type')?.value
  93. }
  94. },
  95. watch: {
  96. selectedSourceType () {
  97. this.loadCategories()
  98. }
  99. },
  100. mounted() {
  101. this.checkSource()
  102. this.$nextTick(() => {
  103. this.mounted = true
  104. })
  105. },
  106. methods: {
  107. checkSource () {
  108. const sourceId = this.$route.query.source_id
  109. const sourceType = this.$route.query.source_type
  110. const ticketCategory = (new TicketCategory()).getCategoryTypeFromSourceType(sourceType)
  111. if (sourceType && sourceId) {
  112. FormBuilderAssist.setAttributeByName(this.inputs, 'source_id', 'value', sourceId)
  113. FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', sourceType)
  114. FormBuilderAssist.setAttributeByName(this.inputs, 'category_info__type', 'value', ticketCategory)
  115. FormBuilderAssist.setAttributeByName(this.inputs, 'category_info__type', 'readonly', true)
  116. } else if (this.localOptions.defaultSourceType) {
  117. FormBuilderAssist.setAttributeByName(this.inputs, 'category_info__type', 'value', this.localOptions.defaultSourceType)
  118. FormBuilderAssist.setAttributeByName(this.inputs, 'category_info__type', 'readonly', true)
  119. }
  120. },
  121. create() {
  122. this.entityLoading = true
  123. this.$refs.entityCreate.createEntity()
  124. .then(() => {
  125. this.entityLoading = false
  126. })
  127. .catch(() => {
  128. this.entityLoading = false
  129. })
  130. },
  131. loadCategories () {
  132. const type = (new TicketCategory()).getCategoryTypeFromSourceType(this.selectedSourceType)
  133. if (!type) {
  134. return
  135. }
  136. this.categoriesLoading = true
  137. APIGateway.ticketCategory.index({ type })
  138. .then(({ list }) => {
  139. const ticketCategoryList = list
  140. this.setInputOptions('category', ticketCategoryList.list.map(item => {
  141. return {
  142. value: item.id,
  143. label: item.title
  144. }
  145. }))
  146. this.categoriesLoading = false
  147. })
  148. .catch(() => {
  149. this.categoriesLoading = false
  150. })
  151. },
  152. setInputOptions (name, options) {
  153. this.$refs.entityCreate.setInputAttributeByName(name, 'options', options)
  154. }
  155. }
  156. }
  157. </script>
  158. <style scoped lang="scss">
  159. .TicketCreate {
  160. .title {
  161. font-style: normal;
  162. font-weight: 700;
  163. font-size: 24px;
  164. line-height: 140%;
  165. color: #424242;
  166. margin-bottom: 27px;
  167. position: relative;
  168. .back-action {
  169. position: absolute;
  170. right: 0;
  171. top: 0;
  172. }
  173. }
  174. :deep(.form) {
  175. padding: 24px;
  176. }
  177. }
  178. </style>