classrooms.vue 10.0 KB

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