AdminClassroomList.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="AdminClassroomIndex">
  3. <div class="add-new-action-row">
  4. <q-btn color="primary"
  5. :to="{name: createPageRouteName}">
  6. <svg data-name="Close Square"
  7. xmlns="http://www.w3.org/2000/svg"
  8. width="20"
  9. height="20"
  10. viewBox="0 0 20 20"
  11. class="q-mr-md">
  12. <path id="Combined_Shape"
  13. data-name="Combined Shape"
  14. d="M5.665,20C2.276,20,0,17.623,0,14.084V5.916C0,2.377,2.276,0,5.665,0h8.67C17.723,0,20,2.377,20,5.916v8.168C20,17.623,17.723,20,14.333,20ZM1.5,5.916v8.168c0,2.683,1.634,4.416,4.164,4.416h8.669c2.532,0,4.167-1.733,4.167-4.416V5.916c0-2.682-1.635-4.415-4.166-4.415H5.665C3.135,1.5,1.5,3.234,1.5,5.916Zm7.968,8a.747.747,0,0,1-.22-.53V10.741H6.611a.75.75,0,0,1-.75-.75.749.749,0,0,1,.75-.75H9.249V6.6a.75.75,0,1,1,1.5,0V9.241h2.639a.75.75,0,0,1,0,1.5H10.748v2.642a.75.75,0,0,1-1.28.53Z"
  15. fill="#fff" />
  16. </svg>
  17. ایجاد
  18. {{ classroomTypeTitle }}
  19. جدید
  20. </q-btn>
  21. </div>
  22. <entity-index v-if="mounted"
  23. ref="entityIndex"
  24. v-model:value="inputs"
  25. :title="'لیست ' + classroomTypeTitle"
  26. :api="api"
  27. :table="table"
  28. :table-keys="tableKeys"
  29. :show-expand-button="false"
  30. :show-reload-button="false"
  31. :show-search-button="false">
  32. <template v-slot:entity-index-table-cell="{inputData, showConfirmRemoveDialog}">
  33. <template v-if="inputData.col.name === 'number'">
  34. {{ inputData.rowNumber }}
  35. </template>
  36. <template v-else-if="inputData.col.name === 'action'">
  37. <div class="action-column-entity-index">
  38. <q-btn size="md"
  39. color="primary"
  40. label="جزییات"
  41. :to="{name: showPageRouteName, params: {id: inputData.props.row.id}}"
  42. class="q-mr-md" />
  43. <delete-btn @click="showConfirmRemoveDialog(inputData.props.row, 'id', getRemoveMessage(inputData.props.row))" />
  44. </div>
  45. </template>
  46. <template v-else>
  47. {{ inputData.col.value }}
  48. </template>
  49. </template>
  50. </entity-index>
  51. </div>
  52. </template>
  53. <script>
  54. import { shallowRef } from 'vue'
  55. import { EntityIndex } from 'quasar-crud'
  56. import Enums from 'src/assets/Enums/Enums.js'
  57. import ShamsiDate from 'src/assets/ShamsiDate.js'
  58. import { mixinWidget } from 'src/mixin/Mixins.js'
  59. import { APIGateway } from 'src/api/APIGateway.js'
  60. import BtnControl from 'src/components/Control/btn.vue'
  61. import { FormBuilderAssist } from 'quasar-form-builder'
  62. import { UnitCategory } from 'src/models/UnitCategory.js'
  63. import DeleteBtn from 'src/components/Control/DeleteBtn.vue'
  64. const BtnControlComp = shallowRef(BtnControl)
  65. export default {
  66. name: 'Admin.Classroom.Index',
  67. components: {
  68. EntityIndex,
  69. DeleteBtn
  70. },
  71. mixins: [mixinWidget],
  72. data () {
  73. return {
  74. mounted: false,
  75. inputs: [
  76. {
  77. type: 'select',
  78. name: 'status',
  79. options: Enums.classroomStatuses,
  80. value: null,
  81. label: 'وضعیت ',
  82. placeholder: ' ',
  83. col: 'col-md-2 col-12'
  84. },
  85. {
  86. type: 'select',
  87. name: 'unit',
  88. options: [],
  89. value: null,
  90. label: 'درس',
  91. placeholder: ' ',
  92. col: 'col-md-2 col-12'
  93. },
  94. { type: 'hidden', name: 'unit__category__type', value: null },
  95. { type: BtnControlComp, name: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' }
  96. ],
  97. defaultOptions: {
  98. classroomType: 'TRAINING'
  99. },
  100. api: APIGateway.classroom.APIAdresses.base,
  101. table: {
  102. columns: [
  103. {
  104. name: 'number',
  105. required: true,
  106. label: 'شماره',
  107. align: 'left',
  108. field: () => ''
  109. },
  110. {
  111. name: 'id',
  112. required: true,
  113. label: 'شناسه',
  114. align: 'left',
  115. field: row => row.id
  116. },
  117. {
  118. name: 'title',
  119. required: true,
  120. label: 'عنوان',
  121. align: 'left',
  122. field: row => row.title
  123. },
  124. {
  125. name: 'audience_gender_type',
  126. required: true,
  127. label: 'جنسیت',
  128. align: 'left',
  129. field: row => (row.audience_gender_type === 'FEMALE') ? 'خواهران' : (row.audience_gender_type === 'MALE') ? 'برادران' : 'خواهران و برادران'
  130. },
  131. {
  132. name: 'status',
  133. required: true,
  134. label: 'وضعیت',
  135. align: 'left',
  136. field: row => this.getClassroomStatusesTitle(row.status)
  137. },
  138. {
  139. name: 'holding_type',
  140. required: true,
  141. label: 'نوع برگزاری',
  142. align: 'left',
  143. field: row => this.getClassroomHoldingTypeTitle(row.holding_type)
  144. },
  145. {
  146. name: 'price',
  147. required: true,
  148. label: 'هزینه(ریال)',
  149. align: 'left',
  150. field: row => row.price
  151. },
  152. {
  153. name: 'professor_info',
  154. required: true,
  155. label: 'استاد مربوطه',
  156. align: 'left',
  157. field: row => row.professor_info?.firstname + ' ' + row.professor_info?.lastname
  158. },
  159. {
  160. name: 'beginning_registration_period',
  161. required: true,
  162. label: 'تاریخ و زمان ثبت نام',
  163. align: 'left',
  164. field: row => row.beginning_registration_period ? ShamsiDate.getDateTime(row.beginning_registration_period) : '-'
  165. },
  166. {
  167. name: 'beginning_registration_period',
  168. required: true,
  169. label: 'ترم برگزاری',
  170. align: 'left',
  171. field: row => (row.beginning_registration_period) ? ShamsiDate.getTerm(row.beginning_registration_period) : '-'
  172. },
  173. {
  174. name: 'action',
  175. required: true,
  176. label: 'عملیات',
  177. align: 'left',
  178. field: ''
  179. }
  180. ],
  181. data: []
  182. },
  183. tableKeys: {
  184. data: 'results',
  185. total: 'count',
  186. currentPage: 'current',
  187. perPage: 'per_page',
  188. pageKey: 'page'
  189. }
  190. }
  191. },
  192. computed: {
  193. classroomTypeTitle () {
  194. const unitCategory = new UnitCategory({ type: this.localOptions.classroomType })
  195. return unitCategory.type_info.label
  196. },
  197. createPageRouteName () {
  198. if (this.localOptions.classroomType === 'TRAINING') {
  199. return 'Admin.Classroom.Create'
  200. }
  201. if (this.localOptions.classroomType === 'EVENT') {
  202. return 'Admin.Event.Create'
  203. }
  204. return 'Admin.Classroom.Create'
  205. },
  206. showPageRouteName () {
  207. if (this.localOptions.classroomType === 'TRAINING') {
  208. return 'Admin.Classroom.Show'
  209. }
  210. if (this.localOptions.classroomType === 'EVENT') {
  211. return 'Admin.Event.Show'
  212. }
  213. return 'Admin.Classroom.Show'
  214. }
  215. },
  216. mounted () {
  217. this.setActionBtn()
  218. this.getUnits()
  219. this.setClassroomTypeOfInputs()
  220. this.mounted = true
  221. },
  222. methods: {
  223. setClassroomTypeOfInputs () {
  224. FormBuilderAssist.setAttributeByName(this.inputs, 'status', 'label', 'وضعیت ' + this.classroomTypeTitle)
  225. FormBuilderAssist.setAttributeByName(this.inputs, 'unit__category__type', 'value', this.localOptions.classroomType)
  226. this.table.columns.forEach(col => {
  227. if (col.name === 'title') {
  228. col.label = 'نام ' + this.classroomTypeTitle
  229. }
  230. if (col.name === 'professor_info') {
  231. col.label = (this.localOptions.classroomType === 'TRAINING') ? 'استاد مربوطه' : 'برگزار کننده'
  232. }
  233. })
  234. },
  235. setActionBtn () {
  236. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.search)
  237. },
  238. search () {
  239. this.$refs.entityIndex.search()
  240. },
  241. getUnits () {
  242. APIGateway.unit.index({ per_page: 9999, category__type: this.localOptions.classroomType })
  243. .then((units) => {
  244. this.loadSelectOptions('unit', this.getSelectOptions(units.list.list, 'id', 'title'))
  245. })
  246. .catch(() => {
  247. })
  248. },
  249. loadSelectOptions (name, value) {
  250. const inputIndex = this.inputs.findIndex(input => input.name === name)
  251. this.inputs[inputIndex].options = value
  252. },
  253. getSelectOptions (result, value, label) {
  254. return result.map(item => {
  255. return {
  256. value: item[value],
  257. label: item[label]
  258. }
  259. })
  260. },
  261. getRemoveMessage (row) {
  262. return 'آیا از حذف ' + row.title + ' اطمینان دارید؟'
  263. },
  264. getClassroomHoldingTypeTitle (type) {
  265. const target = Enums.classroomHoldingTypes.find(item => item.value === type)
  266. if (!target) {
  267. return '-'
  268. }
  269. return target.label
  270. },
  271. getClassroomStatusesTitle (type) {
  272. const target = Enums.classroomStatuses.find(item => item.value === type)
  273. if (!target) {
  274. return '-'
  275. }
  276. return target.label
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="scss" scoped>
  282. .AdminClassroomIndex {
  283. .add-new-action-row {
  284. display: flex;
  285. flex-flow: row;
  286. align-items: center;
  287. justify-content: flex-end;
  288. margin-bottom: 22px;
  289. }
  290. .action-column-entity-index {
  291. display: flex;
  292. align-items: center;
  293. justify-content: flex-start;
  294. }
  295. }
  296. </style>