AdminTicketList.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 Assist from 'assets/js/Assist.js'
  34. import { EntityIndex } from 'quasar-crud'
  35. import { Ticket } from 'src/models/Ticket.js'
  36. import { mixinWidget } from 'src/mixin/Mixins.js'
  37. import { APIGateway } from 'src/api/APIGateway.js'
  38. import { FormBuilderAssist } from 'quasar-form-builder'
  39. import BtnControl from 'src/components/Control/btn.vue'
  40. import { TicketCategory, TicketCategoryList } from 'src/models/TicketCategory.js'
  41. const BtnControlComp = shallowRef(BtnControl)
  42. export default {
  43. name: 'AdminTicketList',
  44. components: { EntityIndex },
  45. mixins: [mixinWidget],
  46. data: () => {
  47. return {
  48. api: APIGateway.ticket.APIAdresses.base,
  49. tableKeys: {
  50. data: 'results',
  51. total: 'count',
  52. currentPage: 'current',
  53. perPage: 'per_page',
  54. pageKey: 'page'
  55. },
  56. inputs: [
  57. {
  58. type: 'dateTime',
  59. name: 'creation_time__gte',
  60. label: 'از تاریخ',
  61. placeholder: ' ',
  62. col: 'col-md-4 col-12'
  63. },
  64. {
  65. type: 'dateTime',
  66. name: 'creation_time__lt',
  67. label: 'تا تاریخ',
  68. placeholder: ' ',
  69. col: 'col-md-4 col-12'
  70. },
  71. { type: 'input', name: 'owner__national_code', label: 'کدملی', placeholder: ' ', col: 'col-md-4 col-12' },
  72. // {
  73. // type: 'select',
  74. // name: 'source_type',
  75. // responseKey: 'source_type',
  76. // placeholder: ' ',
  77. // options: [
  78. // { label: ' ', value: null },
  79. // { label: 'مالی', value: 'INVOICE' },
  80. // { label: 'آموزش', value: 'TRAINING_CLASSROOM' },
  81. // { label: 'حلقه های مباحثاتی', value: 'DISCUSSION_CIRCLE_CLASSROOM' },
  82. // { label: 'محتوا', value: 'CONTENT' },
  83. // { label: 'SESSION', value: 'SESSION' }
  84. // ],
  85. // label: 'مرجع',
  86. // value: null,
  87. // col: 'col-md-3 col-12'
  88. // },
  89. {
  90. type: 'select',
  91. name: 'category__type',
  92. responseKey: 'category__type',
  93. placeholder: ' ',
  94. options: (new TicketCategory()).typeEnums,
  95. label: 'معاونت',
  96. value: null,
  97. col: 'col-md-4 col-12'
  98. },
  99. { type: 'select', name: 'category', responseKey: 'category', placeholder: ' ', options: [], label: 'دسته', col: 'col-md-4 col-12' },
  100. { type: 'select', name: 'status', responseKey: 'status', placeholder: ' ', options: (new Ticket()).statusEnums, label: 'وضعیت', col: 'col-md-4 col-12' },
  101. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' },
  102. // { type: 'hidden', name: 'source_type', value: null },
  103. // { type: 'space', name: 'space', value: null, col: 'col-12' },
  104. { type: 'space', name: 'space', value: null, col: 'col-md-8 col-12' },
  105. { type: 'select', name: 'per_page', responseKey: 'per_page', placeholder: ' ', options: [10, 25, 50], value: 10, label: 'تعداد در صفحه', col: 'col-md-2 col-12' }
  106. ],
  107. table: {
  108. columns: [
  109. {
  110. name: 'number',
  111. required: true,
  112. label: 'شماره',
  113. align: 'left',
  114. field: () => ''
  115. },
  116. {
  117. name: 'id',
  118. required: true,
  119. label: 'شناسه',
  120. align: 'left',
  121. field: row => row.id
  122. },
  123. {
  124. name: 'category_info__title',
  125. required: true,
  126. label: 'دسته',
  127. align: 'left',
  128. field: row => row.category_info.title
  129. },
  130. {
  131. name: 'title',
  132. required: true,
  133. label: 'موضوع پیام',
  134. align: 'left',
  135. field: row => row.title
  136. },
  137. {
  138. name: 'sender',
  139. required: true,
  140. label: 'فرستنده',
  141. align: 'left',
  142. field: row => row.creator_info.firstname + ' ' + row.creator_info.lastname
  143. },
  144. {
  145. name: 'national_code',
  146. required: true,
  147. label: 'کد ملی فرستنده',
  148. align: 'left',
  149. field: row => row.creator_info.national_code
  150. },
  151. {
  152. name: 'status',
  153. required: true,
  154. label: 'وضعیت',
  155. align: 'left',
  156. field: row => (new Ticket(row)).status_info.label
  157. },
  158. {
  159. name: 'last_modification_time',
  160. required: true,
  161. label: 'زمان آخرین تغییرات',
  162. align: 'left',
  163. field: row => Assist.miladiToShamsi(row.last_modification_time)
  164. },
  165. {
  166. name: 'action',
  167. required: true,
  168. label: 'جزییات',
  169. align: 'left',
  170. field: row => ''
  171. }
  172. ]
  173. },
  174. mounted: false,
  175. ticketCategoryList: new TicketCategoryList()
  176. }
  177. },
  178. computed: {
  179. selectedPerPage () {
  180. return FormBuilderAssist.getInputsByName(this.inputs, 'per_page')?.value
  181. },
  182. selectedSourceType () {
  183. return FormBuilderAssist.getInputsByName(this.inputs, 'category__type')?.value
  184. },
  185. selectedTicketCategoryType () {
  186. return FormBuilderAssist.getInputsByName(this.inputs, 'category__type')?.value
  187. }
  188. },
  189. watch: {
  190. selectedPerPage () {
  191. this.search()
  192. },
  193. // selectedSourceType () {
  194. // this.loadCategories()
  195. // },
  196. selectedTicketCategoryType () {
  197. this.loadCategories()
  198. }
  199. },
  200. mounted() {
  201. this.loadOptions()
  202. this.setActionBtn()
  203. this.checkSource()
  204. this.$nextTick(() => {
  205. this.mounted = true
  206. })
  207. },
  208. methods: {
  209. checkSource () {
  210. if (this.localOptions.defaultSourceType) {
  211. // FormBuilderAssist.setAttributeByName(this.inputs, 'source_type', 'value', this.localOptions.defaultSourceType)
  212. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.getCategoryTypeFromSourceType())
  213. } else if (this.localOptions.defaultCategoryType) {
  214. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'value', this.localOptions.defaultCategoryType)
  215. } else {
  216. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'type', 'select')
  217. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'label', 'معاونت')
  218. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'placeholder', ' ')
  219. FormBuilderAssist.setAttributeByName(this.inputs, 'category__type', 'options', (new TicketCategory()).typeEnums)
  220. }
  221. },
  222. setActionBtn () {
  223. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.search)
  224. },
  225. loadOptions () {
  226. return this.loadCategories()
  227. },
  228. getShowRoute (ticketId) {
  229. const defaultSourceType = this.localOptions.defaultSourceType
  230. if (!defaultSourceType) {
  231. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  232. }
  233. if (defaultSourceType === 'INVOICE') {
  234. return { name: 'Admin.Invoice.Ticket.Show', params: { id: ticketId } }
  235. } else if (defaultSourceType === 'TRAINING_CLASSROOM') {
  236. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  237. } else if (defaultSourceType === 'DISCUSSION_CIRCLE_CLASSROOM') {
  238. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  239. } else if (defaultSourceType === 'CONTENT') {
  240. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  241. } else {
  242. return { name: 'Admin.Ticket.Show', params: { id: ticketId } }
  243. }
  244. },
  245. getCategoryTypeFromSourceType () {
  246. const defaultSourceType = this.localOptions.defaultSourceType
  247. return (new TicketCategory()).getCategoryTypeFromSourceType(defaultSourceType)
  248. },
  249. loadCategories () {
  250. return new Promise((resolve, reject) => {
  251. // const type = this.localOptions.defaultCategoryType ? this.localOptions.defaultCategoryType : (new TicketCategory()).getCategoryTypeFromSourceType(this.selectedSourceType)
  252. const type = this.selectedTicketCategoryType
  253. APIGateway.ticketCategory.index({ type })
  254. .then(({ list }) => {
  255. FormBuilderAssist.setAttributeByName(this.inputs, 'category', 'options', list.list.map(item => {
  256. return {
  257. value: item.id,
  258. label: item.title
  259. }
  260. }))
  261. resolve()
  262. })
  263. .catch(() => {
  264. reject()
  265. })
  266. })
  267. },
  268. search () {
  269. this.$refs.entityIndex.search()
  270. }
  271. }
  272. }
  273. </script>
  274. <style scoped lang="scss">
  275. .AdminTicketList {
  276. }
  277. </style>