DiscussionCirclesClassrooms.vue 8.5 KB

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