AdminTicketList.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. {
  57. type: 'dateTime',
  58. name: 'creation_time__gte',
  59. label: 'از تاریخ',
  60. placeholder: ' ',
  61. col: 'col-md-3 col-12'
  62. },
  63. {
  64. type: 'dateTime',
  65. name: 'creation_time__lt',
  66. label: 'تا تاریخ',
  67. placeholder: ' ',
  68. col: 'col-md-3 col-12'
  69. },
  70. { type: 'input', name: 'owner__national_code', label: 'کدملی', placeholder: ' ', col: 'col-md-3 col-12' },
  71. {
  72. type: 'select',
  73. name: 'source_type',
  74. responseKey: 'source_type',
  75. placeholder: ' ',
  76. options: [
  77. { label: ' ', value: null },
  78. { label: 'مالی', value: 'INVOICE' },
  79. { label: 'آموزش', value: 'TRAINING_CLASSROOM' },
  80. { label: 'حلقه های مباحثاتی', value: 'DISCUSSION_CIRCLE_CLASSROOM' },
  81. { label: 'محتوا', value: 'CONTENT' },
  82. { label: 'SESSION', value: 'SESSION' }
  83. ],
  84. label: 'مرجع',
  85. value: null,
  86. col: 'col-md-3 col-12'
  87. },
  88. { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-3 col-12' },
  89. { type: 'select', name: 'status', responseKey: 'status', placeholder: ' ', options: (new Ticket()).statusEnums, label: 'وضعیت', col: 'col-md-3 col-12' },
  90. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' },
  91. { type: 'hidden', name: 'source_type', value: null },
  92. // { type: 'space', name: 'space', value: null, col: 'col-12' },
  93. { type: 'space', name: 'space', value: null, col: 'col-md-2 col-12' },
  94. { type: 'select', name: 'per_page', responseKey: 'per_page', placeholder: ' ', options: [10, 25, 50], value: 10, label: 'تعداد در صفحه', col: 'col-md-2 col-12' }
  95. ],
  96. table: {
  97. columns: [
  98. {
  99. name: 'number',
  100. required: true,
  101. label: 'شماره',
  102. align: 'left',
  103. field: () => ''
  104. },
  105. {
  106. name: 'title',
  107. required: true,
  108. label: 'موضوع پیام',
  109. align: 'left',
  110. field: row => row.title
  111. },
  112. {
  113. name: 'sender',
  114. required: true,
  115. label: 'فرستنده',
  116. align: 'left',
  117. field: row => row.creator_info.firstname + ' ' + row.creator_info.lastname
  118. },
  119. {
  120. name: 'status',
  121. required: true,
  122. label: 'وضعیت',
  123. align: 'left',
  124. field: row => (new Ticket(row)).status_info.label
  125. },
  126. {
  127. name: 'action',
  128. required: true,
  129. label: 'جزییات',
  130. align: 'left',
  131. field: row => ''
  132. }
  133. ]
  134. },
  135. mounted: false,
  136. ticketCategoryList: new TicketCategoryList()
  137. }
  138. },
  139. computed: {
  140. selectedPerPage () {
  141. return FormBuilderAssist.getInputsByName(this.inputs, 'per_page')?.value
  142. },
  143. selectedSourceType () {
  144. return FormBuilderAssist.getInputsByName(this.inputs, 'category__type')?.value
  145. }
  146. },
  147. watch: {
  148. selectedPerPage () {
  149. this.search()
  150. },
  151. selectedSourceType () {
  152. this.loadCategories()
  153. }
  154. },
  155. mounted() {
  156. this.loadOptions()
  157. this.setActionBtn()
  158. this.checkSource()
  159. this.$nextTick(() => {
  160. this.mounted = true
  161. })
  162. },
  163. methods: {
  164. checkSource () {
  165. if (this.localOptions.defaultSourceType) {
  166. FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', this.localOptions.defaultSourceType)
  167. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.getCategoryTypeFromSourceType())
  168. } else if (this.localOptions.defaultCategoryType) {
  169. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.localOptions.defaultCategoryType)
  170. } else {
  171. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'type', 'select')
  172. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'label', 'معاونت')
  173. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'placeholder', ' ')
  174. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'options', [
  175. { label: 'مالی', value: 'FINANCIAL' },
  176. { label: 'آموزش', value: 'EDUCATIONAL' },
  177. { label: 'محتوا', value: 'CONTENT' },
  178. { label: 'عمومی', value: 'GENERAL' }
  179. ])
  180. }
  181. },
  182. setActionBtn () {
  183. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.search)
  184. },
  185. loadOptions () {
  186. return this.loadCategories()
  187. },
  188. getShowRoute (ticketId) {
  189. const defaultSourceType = this.localOptions.defaultSourceType
  190. if (!defaultSourceType) {
  191. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  192. }
  193. if (defaultSourceType === 'INVOICE') {
  194. return { name: 'Admin.Invoice.Ticket.Show', params: { id: ticketId } }
  195. } else if (defaultSourceType === 'TRAINING_CLASSROOM') {
  196. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  197. } else if (defaultSourceType === 'DISCUSSION_CIRCLE_CLASSROOM') {
  198. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  199. } else if (defaultSourceType === 'CONTENT') {
  200. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  201. } else {
  202. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  203. }
  204. },
  205. getCategoryTypeFromSourceType () {
  206. const defaultSourceType = this.localOptions.defaultSourceType
  207. if (!defaultSourceType) {
  208. return null
  209. }
  210. if (defaultSourceType === 'TRAINING_CLASSROOM') {
  211. return 'EDUCATIONAL'
  212. } else if (defaultSourceType === 'DISCUSSION_CIRCLE_CLASSROOM') {
  213. return 'EDUCATIONAL'
  214. } else if (defaultSourceType === 'INVOICE') {
  215. return 'FINANCIAL'
  216. } else if (defaultSourceType === 'CONTENT') {
  217. return 'CONTENT'
  218. } else {
  219. return 'GENERAL'
  220. }
  221. },
  222. loadCategories () {
  223. return new Promise((resolve, reject) => {
  224. const type = this.localOptions.defaultCategoryType ? this.localOptions.defaultCategoryType : (new TicketCategory()).getCategoryTypeFromSourceType(this.selectedSourceType)
  225. APIGateway.ticketCategory.index({ type })
  226. .then(({ list }) => {
  227. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', list.list.map(item => {
  228. return {
  229. value: item.id,
  230. label: item.title
  231. }
  232. }))
  233. resolve()
  234. })
  235. .catch(() => {
  236. reject()
  237. })
  238. })
  239. },
  240. search () {
  241. this.$refs.entityIndex.search()
  242. }
  243. }
  244. }
  245. </script>
  246. <style scoped lang="scss">
  247. .AdminTicketList {
  248. }
  249. </style>