AdminTicketList.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div class="AdminTicketList"
  3. :style="localOptions.style">
  4. <entity-index v-if="mounted"
  5. ref="entityIndex"
  6. v-model:value="inputs"
  7. title="لیست درخواست ها"
  8. :api="api"
  9. :table="table"
  10. :table-keys="tableKeys"
  11. :show-search-button="false"
  12. :show-expand-button="false"
  13. :show-reload-button="false">
  14. <template #entity-index-table-cell="{inputData}">
  15. <template v-if="inputData.col.name === 'number'">
  16. {{ inputData.rowNumber }}
  17. </template>
  18. <template v-else-if="inputData.col.name === 'action'">
  19. <q-btn color="primary"
  20. :to="getShowRoute(inputData.props.row.id)">
  21. مشاهده جزییات
  22. </q-btn>
  23. </template>
  24. <template v-else>
  25. {{ inputData.col.value }}
  26. </template>
  27. </template>
  28. </entity-index>
  29. </div>
  30. </template>
  31. <script>
  32. import { shallowRef } from 'vue'
  33. import { EntityIndex } from 'quasar-crud'
  34. import { Ticket } from 'src/models/Ticket.js'
  35. import { mixinWidget } from 'src/mixin/Mixins.js'
  36. import { APIGateway } from 'src/api/APIGateway.js'
  37. import { FormBuilderAssist } from 'quasar-form-builder'
  38. import BtnControl from 'src/components/Control/btn.vue'
  39. import { TicketCategory, TicketCategoryList } from 'src/models/TicketCategory.js'
  40. const BtnControlComp = shallowRef(BtnControl)
  41. export default {
  42. name: 'AdminTicketList',
  43. components: { EntityIndex },
  44. mixins: [mixinWidget],
  45. data: () => {
  46. return {
  47. api: APIGateway.ticket.APIAdresses.base,
  48. tableKeys: {
  49. data: 'results',
  50. total: 'count',
  51. currentPage: 'current',
  52. perPage: 'per_page',
  53. pageKey: 'page'
  54. },
  55. inputs: [
  56. { type: 'hidden', name: 'category__type', value: null },
  57. { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-4 col-12' },
  58. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' },
  59. { type: 'hidden', name: 'source_type', value: null },
  60. // { type: 'space', name: 'space', value: null, col: 'col-12' },
  61. { type: 'space', name: 'space', value: null, col: 'col-md-4 col-12' },
  62. { type: 'select', name: 'per_page', responseKey: 'per_page', placeholder: ' ', options: [10, 25, 50], value: 10, label: 'تعداد در صفحه', col: 'col-md-2 col-12' }
  63. ],
  64. table: {
  65. columns: [
  66. {
  67. name: 'number',
  68. required: true,
  69. label: 'شماره',
  70. align: 'left',
  71. field: () => ''
  72. },
  73. {
  74. name: 'title',
  75. required: true,
  76. label: 'موضوع پیام',
  77. align: 'left',
  78. field: row => row.title
  79. },
  80. {
  81. name: 'sender',
  82. required: true,
  83. label: 'فرستنده',
  84. align: 'left',
  85. field: row => row.creator_info.firstname + ' ' + row.creator_info.lastname
  86. },
  87. {
  88. name: 'status',
  89. required: true,
  90. label: 'وضعیت',
  91. align: 'left',
  92. field: row => (new Ticket(row)).status_info.label
  93. },
  94. {
  95. name: 'action',
  96. required: true,
  97. label: 'جزییات',
  98. align: 'left',
  99. field: row => ''
  100. }
  101. ]
  102. },
  103. mounted: false,
  104. ticketCategoryList: new TicketCategoryList()
  105. }
  106. },
  107. computed: {
  108. selectedPerPage () {
  109. return FormBuilderAssist.getInputsByName(this.inputs, 'per_page')?.value
  110. },
  111. selectedSourceType () {
  112. return FormBuilderAssist.getInputsByName(this.inputs, 'category__type')?.value
  113. }
  114. },
  115. watch: {
  116. selectedPerPage () {
  117. this.search()
  118. },
  119. selectedSourceType () {
  120. this.loadCategories()
  121. }
  122. },
  123. mounted() {
  124. this.loadOptions()
  125. this.setActionBtn()
  126. this.checkSource()
  127. this.$nextTick(() => {
  128. this.mounted = true
  129. })
  130. },
  131. methods: {
  132. checkSource () {
  133. if (this.localOptions.defaultSourceType) {
  134. FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', this.localOptions.defaultSourceType)
  135. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.getCategoryTypeFromSourceType())
  136. } else if (this.localOptions.defaultCategoryType) {
  137. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.localOptions.defaultCategoryType)
  138. } else {
  139. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'type', 'select')
  140. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'label', 'معاونت')
  141. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'placeholder', ' ')
  142. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'options', [
  143. { label: 'مالی', value: 'FINANCIAL' },
  144. { label: 'آموزش', value: 'EDUCATIONAL' },
  145. { label: 'محتوا', value: 'CONTENT' },
  146. { label: 'عمومی', value: 'GENERAL' }
  147. ])
  148. }
  149. },
  150. setActionBtn () {
  151. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.search)
  152. },
  153. loadOptions () {
  154. return this.loadCategories()
  155. },
  156. getShowRoute (ticketId) {
  157. const defaultSourceType = this.localOptions.defaultSourceType
  158. if (!defaultSourceType) {
  159. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  160. }
  161. if (defaultSourceType === 'INVOICE') {
  162. return { name: 'Admin.Invoice.Ticket.Show', params: { id: ticketId } }
  163. } else if (defaultSourceType === 'TRAINING_CLASSROOM') {
  164. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  165. } else if (defaultSourceType === 'DISCUSSION_CIRCLE_CLASSROOM') {
  166. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  167. } else if (defaultSourceType === 'CONTENT') {
  168. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  169. } else {
  170. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  171. }
  172. },
  173. getCategoryTypeFromSourceType () {
  174. const defaultSourceType = this.localOptions.defaultSourceType
  175. if (!defaultSourceType) {
  176. return null
  177. }
  178. if (defaultSourceType === 'TRAINING_CLASSROOM') {
  179. return 'EDUCATIONAL'
  180. } else if (defaultSourceType === 'DISCUSSION_CIRCLE_CLASSROOM') {
  181. return 'EDUCATIONAL'
  182. } else if (defaultSourceType === 'INVOICE') {
  183. return 'FINANCIAL'
  184. } else if (defaultSourceType === 'CONTENT') {
  185. return 'CONTENT'
  186. } else {
  187. return 'GENERAL'
  188. }
  189. },
  190. loadCategories () {
  191. return new Promise((resolve, reject) => {
  192. const type = this.localOptions.defaultCategoryType ? this.localOptions.defaultCategoryType : (new TicketCategory()).getCategoryTypeFromSourceType(this.selectedSourceType)
  193. APIGateway.ticketCategory.index({ type })
  194. .then(({ list }) => {
  195. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', list.list.map(item => {
  196. return {
  197. value: item.id,
  198. label: item.title
  199. }
  200. }))
  201. resolve()
  202. })
  203. .catch(() => {
  204. reject()
  205. })
  206. })
  207. },
  208. search () {
  209. this.$refs.entityIndex.search()
  210. }
  211. }
  212. }
  213. </script>
  214. <style scoped lang="scss">
  215. .AdminTicketList {
  216. }
  217. </style>