classrooms.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <breadcrumbs style="margin-top: 29px; margin-bottom: 19px;" />
  3. <entity-index ref="entityIndex"
  4. v-model:value="inputs"
  5. title="لیست دوره ها"
  6. :api="api"
  7. :table="table"
  8. :table-keys="tableKeys"
  9. :table-grid-size="$q.screen.lt.sm"
  10. :show-expand-button="false"
  11. :show-reload-button="false"
  12. :show-search-button="false">
  13. <template #entity-index-table-cell="{inputData}">
  14. <template v-if="inputData.col.name === 'number'">
  15. {{ inputData.rowNumber }}
  16. </template>
  17. <template v-else-if="inputData.col.name === 'action'">
  18. <q-btn size="md"
  19. color="primary"
  20. label="جزییات"
  21. :to="{name: 'UserPanel.Profile.ClassroomInfo', params: {id: inputData.props.row.classroom_info.id}}" />
  22. </template>
  23. <template v-else>
  24. {{ inputData.col.value }}
  25. </template>
  26. </template>
  27. <template #entity-index-table-item-cell="{inputData}">
  28. <entity-index-grid-item :input-data="inputData">
  29. <template #col="{col, row}">
  30. <template v-if="col.name === 'number'">
  31. {{ inputData.rowNumber }}
  32. </template>
  33. <template v-else-if="col.name === 'action'">
  34. <q-btn size="md"
  35. color="primary"
  36. label="جزییات"
  37. :to="{name: 'UserPanel.Profile.ClassroomInfo', params: {id: row.classroom_info.id}}" />
  38. </template>
  39. </template>
  40. </entity-index-grid-item>
  41. </template>
  42. </entity-index>
  43. </template>
  44. <script>
  45. import { shallowRef } from 'vue'
  46. import { EntityIndex } from 'quasar-crud'
  47. import Enums from 'src/assets/Enums/Enums.js'
  48. import ShamsiDate from 'src/assets/ShamsiDate.js'
  49. import { APIGateway } from 'src/api/APIGateway.js'
  50. import BtnControl from 'src/components/Control/btn.vue'
  51. import EntityIndexGridItem from 'src/components/EntityIndexGridItem.vue'
  52. import Breadcrumbs from 'src/components/Widgets/Breadcrumbs/Breadcrumbs.vue'
  53. const BtnControlComp = shallowRef(BtnControl)
  54. export default {
  55. name: 'UserPanel.Profile.AllClassrooms',
  56. components: {
  57. EntityIndex,
  58. Breadcrumbs,
  59. EntityIndexGridItem
  60. },
  61. data () {
  62. return {
  63. inputs: [
  64. {
  65. type: 'select',
  66. name: 'classroom__unit__category__type',
  67. options: [
  68. {
  69. label: 'دوره های آموزشی',
  70. value: 'TRAINING'
  71. },
  72. {
  73. label: 'حلقه های مباحثاتی',
  74. value: 'DISCUSSION_CIRCLE'
  75. }
  76. ],
  77. value: 'TRAINING',
  78. label: 'نوع',
  79. placeholder: ' ',
  80. col: 'col-md-2 col-12'
  81. },
  82. {
  83. type: 'select',
  84. name: 'status',
  85. options: Enums.classroomStatuses,
  86. value: null,
  87. label: 'وضعیت دوره',
  88. placeholder: ' ',
  89. col: 'col-md-2 col-12'
  90. },
  91. {
  92. type: 'select',
  93. name: 'category',
  94. options: [],
  95. value: null,
  96. label: 'گروه آموزشی',
  97. placeholder: ' ',
  98. col: 'col-md-2 col-12'
  99. },
  100. {
  101. type: 'select',
  102. name: 'unit',
  103. responseKey: 'unit',
  104. options: [],
  105. value: null,
  106. label: 'درس',
  107. placeholder: ' ',
  108. col: 'col-md-2 col-12'
  109. },
  110. { type: 'input', name: 'search', label: 'جستجو', placeholder: ' ', col: 'col-md-2 col-12' },
  111. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' }
  112. ],
  113. api: APIGateway.registration.APIAdresses.base,
  114. table: {
  115. columns: [
  116. {
  117. name: 'number',
  118. required: true,
  119. label: 'شماره',
  120. align: 'left',
  121. field: () => ''
  122. },
  123. {
  124. name: 'id',
  125. required: true,
  126. label: 'شناسه',
  127. align: 'left',
  128. field: row => row.id
  129. },
  130. {
  131. name: 'title',
  132. required: true,
  133. label: 'نام درس',
  134. align: 'left',
  135. field: row => row.classroom_info.unit_info.title
  136. },
  137. {
  138. name: 'audience_gender_type',
  139. required: true,
  140. label: 'جنسیت',
  141. align: 'left',
  142. field: row => (row.classroom_info.audience_gender_type === 'FEMALE') ? 'خواهران' : (row.classroom_info.audience_gender_type === 'MALE') ? 'برادران' : 'خواهران و برادران'
  143. },
  144. {
  145. name: 'title',
  146. required: true,
  147. label: 'تاریخ شروع',
  148. align: 'left',
  149. field: row => ShamsiDate.getDateTime(row.classroom_info.beginning_registration_period)
  150. },
  151. {
  152. name: 'title',
  153. required: true,
  154. label: 'نوع',
  155. align: 'left',
  156. field: row => (row.classroom_info?.unit_info?.category_info?.type === 'TRAINING') ? 'دوره آموزشی' : (row.classroom_info?.unit_info?.category_info?.type === 'DISCUSSION_CIRCLE') ? 'حلقه مباحثاتی' : '-'
  157. },
  158. {
  159. name: 'title',
  160. required: true,
  161. label: 'نوع برگزاری',
  162. align: 'left',
  163. field: row => this.getClassroomHoldingTypeTitle(row.classroom_info.holding_type)
  164. },
  165. {
  166. name: 'title',
  167. required: true,
  168. label: 'استاد',
  169. align: 'left',
  170. field: row => row.classroom_info.professor
  171. },
  172. {
  173. name: 'status',
  174. required: true,
  175. label: 'تعداد جلسات',
  176. align: 'left',
  177. field: row => row.classroom_info.sessions_info.length
  178. },
  179. {
  180. name: 'status',
  181. required: true,
  182. label: 'وضعیت',
  183. align: 'left',
  184. field: row => this.getClassroomStatusTitle(row.classroom_info.status)
  185. },
  186. {
  187. name: 'title',
  188. required: true,
  189. label: 'زمان ثبت نام',
  190. align: 'left',
  191. field: row => ShamsiDate.getDateTime(row.classroom_info.beginning_registration_period)
  192. },
  193. {
  194. name: 'status',
  195. required: true,
  196. label: 'وضعیت مالی',
  197. align: 'left',
  198. field: row => row.invoice_info ? this.getInvoiceStatusTitle(row.invoice_info) : 'نام مشخص'
  199. },
  200. {
  201. name: 'action',
  202. required: true,
  203. label: 'جزییات',
  204. align: 'left',
  205. field: ''
  206. }
  207. ],
  208. data: []
  209. },
  210. tableKeys: {
  211. data: 'results',
  212. total: 'count',
  213. currentPage: 'current',
  214. perPage: 'per_page',
  215. pageKey: 'page'
  216. }
  217. }
  218. },
  219. computed: {
  220. selectedCategoryId () {
  221. return this.getInputValue('category')
  222. }
  223. },
  224. watch: {
  225. selectedCategoryId () {
  226. this.setInputValue('unit', null)
  227. this.getUnits(this.selectedCategoryId)
  228. }
  229. },
  230. created () {
  231. this.setActionBtn()
  232. this.loadInputDataOptions()
  233. },
  234. methods: {
  235. setActionBtn () {
  236. this.inputs.forEach((item, index) => {
  237. if (item.name === 'btn') {
  238. this.inputs[index].atClick = this.search
  239. }
  240. })
  241. },
  242. search () {
  243. this.$refs.entityIndex.search()
  244. },
  245. getClassroomHoldingTypeTitle (type) {
  246. const target = Enums.classroomHoldingTypes.find(item => item.value === type)
  247. if (!target) {
  248. return '-'
  249. }
  250. return target.label
  251. },
  252. getClassroomStatusTitle (type) {
  253. const target = Enums.classroomStatuses.find(item => item.value === type)
  254. if (!target) {
  255. return '-'
  256. }
  257. return target.label
  258. },
  259. getInvoiceStatusTitle (type) {
  260. const target = Enums.invoiceStatus.find(item => item.value === type)
  261. if (!target) {
  262. return '-'
  263. }
  264. return target.label
  265. },
  266. loadInputDataOptions () {
  267. this.getCategories()
  268. this.getUnits()
  269. },
  270. getCategories () {
  271. APIGateway.classroom.index({ per_page: 9999 })
  272. .then(classroomList => {
  273. this.loadSelectOptions('category', this.getSelectOptions(classroomList.list.list, 'id', 'title'))
  274. })
  275. .catch(() => {
  276. })
  277. },
  278. getUnits (selectedcategoryId) {
  279. APIGateway.unit.index({ category: selectedcategoryId })
  280. .then(unitList => {
  281. this.loadSelectOptions('unit', this.getSelectOptions(unitList.list.list, 'id', 'title'))
  282. })
  283. .catch(() => {
  284. })
  285. },
  286. getInputValue (name) {
  287. const inputIndex = this.inputs.findIndex(input => input.name === name)
  288. return this.inputs[inputIndex].value
  289. },
  290. setInputValue (name, value) {
  291. const inputIndex = this.inputs.findIndex(input => input.name === name)
  292. this.inputs[inputIndex].value = value
  293. },
  294. getSelectOptions (result, value, label) {
  295. return result.map(item => {
  296. return {
  297. value: item[value],
  298. label: item[label]
  299. }
  300. })
  301. },
  302. loadSelectOptions (name, value) {
  303. const inputIndex = this.inputs.findIndex(input => input.name === name)
  304. this.inputs[inputIndex].options = value
  305. }
  306. }
  307. }
  308. </script>