classrooms.vue 8.2 KB

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