AdminTeamShow.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div class="AdminTeamShow"
  3. :style="localOptions.style">
  4. <div class="flex justify-end">
  5. <q-btn flat
  6. color="grey"
  7. @click="$router.go(-1)">
  8. بازگشت
  9. >
  10. </q-btn>
  11. </div>
  12. <entity-edit v-if="mounted"
  13. ref="entityEdit"
  14. v-model:value="inputs"
  15. title="اطلاعات گروه"
  16. :api="api"
  17. :entity-id-key="entityIdKey"
  18. :entity-param-key="entityParamKey"
  19. :show-close-button="false"
  20. :show-edit-button="false"
  21. :show-expand-button="false"
  22. :show-save-button="false"
  23. :show-reload-button="false"
  24. :redirect-after-edit="false"
  25. :after-load-input-data="afterLoadInputData" />
  26. <q-separator class="q-my-lg" />
  27. <entity-index v-if="mounted"
  28. ref="teamRegistrationList"
  29. v-model:value="teamRegistrationListInputs"
  30. title="لیست اعضای گروه"
  31. :api="teamRegistrationListApi"
  32. :table="teamRegistrationListTable"
  33. :table-keys="teamRegistrationListTableKeys"
  34. :show-search-button="false"
  35. :show-reload-button="false"
  36. :show-expand-button="false">
  37. <template #toolbar>
  38. <form-builder ref="formBuilder"
  39. :key="addTeamRegistrationKey"
  40. v-model:value="addTeamRegistrationInputs"
  41. :loading="addNewTeamRegistrationLoading" />
  42. </template>
  43. <template v-slot:entity-index-table-cell="{inputData, showConfirmRemoveDialog}">
  44. <template v-if="inputData.col.name === 'number'">
  45. {{ inputData.rowNumber }}
  46. </template>
  47. <template v-else-if="inputData.col.name === 'actions'">
  48. <div class="action-column-entity-index">
  49. <delete-btn @click="showConfirmRemoveDialog(inputData.props.row, 'id', getRemoveMessage(inputData.props.row))" />
  50. </div>
  51. </template>
  52. <template v-else>
  53. {{ inputData.col.value }}
  54. </template>
  55. </template>
  56. </entity-index>
  57. </div>
  58. </template>
  59. <script>
  60. import { shallowRef } from 'vue'
  61. import { Team } from 'src/models/Team.js'
  62. import { mixinWidget } from 'src/mixin/Mixins.js'
  63. import { APIGateway } from 'src/api/APIGateway.js'
  64. import { EntityEdit, EntityIndex } from 'quasar-crud'
  65. import BtnControl from 'src/components/Control/btn.vue'
  66. import DeleteBtn from 'src/components/Control/DeleteBtn.vue'
  67. import { FormBuilder, inputMixin, FormBuilderAssist } from 'quasar-form-builder'
  68. import EntityInput from 'quasar-crud/src/components/Entity/Attachment/EntityInput.vue'
  69. import FormBuilderInputEditor from 'src/components/FormBuilderCustumComponents/FormBuilderInputEditor.vue'
  70. const BtnControlComp = shallowRef(BtnControl)
  71. const EntityInputComp = shallowRef(EntityInput)
  72. const FormBuilderInputEditorComp = shallowRef(FormBuilderInputEditor)
  73. export default {
  74. name: 'AdminTeamShow',
  75. components: {
  76. DeleteBtn,
  77. EntityEdit,
  78. EntityIndex,
  79. FormBuilder
  80. },
  81. mixins: [mixinWidget, inputMixin],
  82. data () {
  83. const teamId = this.$route.params.team_id
  84. const classroomId = this.$route.params.classroom_id
  85. return {
  86. mounted: false,
  87. team: new Team(),
  88. entityLoading: true,
  89. api: APIGateway.team.APIAdresses.byId(teamId),
  90. entityIdKey: 'id',
  91. entityParamKey: 'id',
  92. inputs: [
  93. { type: 'input', name: 'title', responseKey: 'title', label: 'عنوان گروه', placeholder: ' ', col: 'col-md-3 col-12' },
  94. { type: 'input', name: 'capacity', responseKey: 'capacity', label: 'ظرفیت', placeholder: ' ', col: 'col-md-3 col-12' },
  95. { type: 'checkbox', name: 'is_joinable', responseKey: 'is_joinable', label: 'قابل پیوستن', placeholder: ' ', value: false, col: 'col-md-3 col-12' },
  96. { type: 'separator', name: 'space', label: 'مشخصات سرگروه', className: 'custom-separator', col: 'col-12' },
  97. { type: 'input', name: 'leader_info.firstname', responseKey: 'leader_info.firstname', label: 'نام سرگروه', placeholder: ' ', readonly: true, ignoreValue: true, col: 'col-md-3 col-12' },
  98. { type: 'input', name: 'leader_info.lastname', responseKey: 'leader_info.lastname', label: 'نام خانوادگی سرگروه', placeholder: ' ', readonly: true, ignoreValue: true, col: 'col-md-3 col-12' },
  99. { type: 'separator', name: 'space', size: '0', col: 'col-12' },
  100. {
  101. type: 'entity',
  102. name: 'leader',
  103. responseKey: 'leader_info',
  104. selectionMode: 'single',
  105. popUpButtonConfig: {
  106. label: 'انتخاب سرگروه',
  107. outline: true,
  108. buttonColor: 'deep-purple',
  109. buttonTextColor: 'white',
  110. buttonBadgeColor: 'pink'
  111. },
  112. dialogConfirmButtonConfig: {
  113. label: 'تایید',
  114. buttonColor: 'deep-purple',
  115. buttonTextColor: 'white',
  116. buttonBadgeColor: 'pink'
  117. },
  118. apiAddress: APIGateway.classroomLeaders.APIAdresses.base,
  119. tableTitle: 'لیست کل سرگروه ها',
  120. showTableItemsRouteName: 'Admin.BlockManagement.Show',
  121. tableKeys: {
  122. data: 'results',
  123. total: 'count',
  124. currentPage: 'current',
  125. perPage: 'per_page',
  126. pageKey: 'page'
  127. },
  128. table: {
  129. columns: [
  130. {
  131. name: 'leader',
  132. required: true,
  133. label: 'شناسه',
  134. align: 'left',
  135. field: row => row.leader
  136. },
  137. {
  138. name: 'leader_info.gender',
  139. required: true,
  140. label: 'جنسیت',
  141. align: 'left',
  142. field: row => (row.leader_info.gender === 1) ? 'مذکر' : ((row.leader_info.gender === 2) ? 'مونث' : '-')
  143. },
  144. {
  145. name: 'leader_info.full_name',
  146. required: true,
  147. label: 'نام و نام خانوادگی',
  148. align: 'left',
  149. field: row => row.leader_info.firstname + ' ' + row.leader_info.lastname
  150. },
  151. {
  152. name: 'leader_info.national_code',
  153. required: true,
  154. label: 'کدملی',
  155. align: 'left',
  156. field: row => row.leader_info.national_code
  157. },
  158. {
  159. name: 'leader_info.mobile_number',
  160. required: true,
  161. label: 'شماره تلفن',
  162. align: 'left',
  163. field: row => row.leader_info.mobile_number
  164. },
  165. {
  166. name: 'leader_info.last_academy_name',
  167. required: true,
  168. label: 'دانشگاه',
  169. align: 'left',
  170. field: row => row.leader_info.last_academy_name
  171. },
  172. {
  173. name: 'leader_info.living_city',
  174. required: true,
  175. label: 'شهر',
  176. align: 'left',
  177. field: row => row.leader_info.living_city
  178. }
  179. ]
  180. },
  181. inputs: [
  182. { type: 'hidden', name: 'classroom', value: classroomId }
  183. ],
  184. // itemIndicatorKey: row => row.firstname + ' ' + row.lastname,
  185. itemIndicatorKey: 'leader_info.id',
  186. // itemIndicatorKey: 'firstname',
  187. itemIdentifyKey: 'leader_info.id',
  188. itemIdentifyKeyOfIndexTable: 'leader',
  189. indexConfig: {
  190. itemIndicatorKey: row => row.leader_info.firstname + ' ' + row.leader_info.lastname,
  191. itemIdentifyKey: 'leader'
  192. // itemIdentifyKey: 'id'
  193. },
  194. value: null,
  195. selected: null,
  196. col: 'col-md-3 col-12'
  197. },
  198. { type: FormBuilderInputEditorComp, name: 'description', responseKey: 'description', label: 'توضیحات', col: 'col-12' },
  199. { type: 'hidden', name: 'classroom', value: classroomId },
  200. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'ویرایش گروه', placeholder: ' ', atClick: () => {}, col: 'col-md-6' }
  201. ],
  202. addNewTeamRegistrationLoading: false,
  203. addTeamRegistrationKey: Date.now(),
  204. addTeamRegistrationInputs: [
  205. {
  206. type: EntityInputComp,
  207. name: 'leaders',
  208. selectionMode: 'multiple',
  209. popUpButtonConfig: {
  210. label: 'اختصاص عضو جدید',
  211. outline: true,
  212. buttonColor: 'deep-purple',
  213. buttonTextColor: 'white',
  214. buttonBadgeColor: 'pink'
  215. },
  216. dialogConfirmButtonConfig: {
  217. label: 'تایید',
  218. buttonColor: 'deep-purple',
  219. buttonTextColor: 'white',
  220. buttonBadgeColor: 'pink'
  221. },
  222. apiAddress: APIGateway.registration.APIAdresses.base,
  223. tableTitle: 'لیست کاربران',
  224. showTableItemsRouteName: 'Admin.BlockManagement.Show',
  225. tableKeys: {
  226. data: 'results',
  227. total: 'count',
  228. currentPage: 'current',
  229. perPage: 'per_page',
  230. pageKey: 'page'
  231. },
  232. table: {
  233. columns: [
  234. {
  235. name: 'id',
  236. required: true,
  237. label: 'شناسه',
  238. align: 'left',
  239. field: row => row.owner_info.id
  240. },
  241. {
  242. name: 'fullname',
  243. required: true,
  244. label: 'نام و نام خانوادگی',
  245. align: 'left',
  246. field: row => row.owner_info.firstname + ' ' + row.owner_info.lastname
  247. },
  248. {
  249. name: 'national_code',
  250. required: true,
  251. label: 'کد ملی',
  252. align: 'left',
  253. field: row => row.owner_info.national_code
  254. },
  255. {
  256. name: 'mobile_number',
  257. required: true,
  258. label: 'شماره همراه',
  259. align: 'left',
  260. field: row => row.owner_info.mobile_number
  261. }
  262. ]
  263. },
  264. inputs: [
  265. { type: 'hidden', name: 'teams__isnull', value: true },
  266. { type: 'hidden', name: 'classroom', value: classroomId }
  267. ],
  268. itemIndicatorKey: row => row.owner_info.firstname + ' ' + row.owner_info.lastname,
  269. // itemIndicatorKey: 'firstname',
  270. itemIdentifyKey: 'id',
  271. onConfirmed: this.onConfirmedSelectedRegistrations,
  272. value: [],
  273. selected: [],
  274. col: 'col-md-12 col-12'
  275. }
  276. ],
  277. teamRegistrationListInputs: [
  278. { type: 'hidden', name: 'team', value: teamId }
  279. ],
  280. teamRegistrationListApi: APIGateway.teamRegistrations.APIAdresses.base,
  281. teamRegistrationListTable: {
  282. columns: [
  283. {
  284. name: 'number',
  285. required: true,
  286. label: 'شماره',
  287. align: 'left',
  288. field: () => ''
  289. },
  290. {
  291. name: 'id',
  292. required: true,
  293. label: 'شناسه',
  294. align: 'left',
  295. field: row => row.registration_info.owner_info.id
  296. },
  297. {
  298. name: 'title',
  299. required: true,
  300. label: 'جنسیت',
  301. align: 'left',
  302. field: row => (row.registration_info.owner_info.gender === 1) ? 'مذکر' : ((row.registration_info.owner_info.gender === 2) ? 'مونث' : '-')
  303. },
  304. {
  305. name: 'creation_time',
  306. required: true,
  307. label: 'نام و نام خانوادگی',
  308. align: 'left',
  309. field: row => row.registration_info.owner_info.firstname + ' ' + row.registration_info.owner_info.lastname
  310. },
  311. {
  312. name: 'creation_time',
  313. required: true,
  314. label: 'کدملی',
  315. align: 'left',
  316. field: row => row.registration_info.owner_info.national_code
  317. },
  318. {
  319. name: 'creation_time',
  320. required: true,
  321. label: 'شماره تلفن',
  322. align: 'left',
  323. field: row => row.registration_info.owner_info.mobile_number
  324. },
  325. {
  326. name: 'creation_time',
  327. required: true,
  328. label: 'دانشگاه',
  329. align: 'left',
  330. field: row => row.registration_info.owner_info.last_academy_name
  331. },
  332. {
  333. name: 'creation_time',
  334. required: true,
  335. label: 'شهر',
  336. align: 'left',
  337. field: row => row.registration_info.owner_info.living_city
  338. },
  339. {
  340. name: 'actions',
  341. required: true,
  342. label: 'عملیات',
  343. align: 'left',
  344. field: ''
  345. }
  346. ]
  347. },
  348. teamRegistrationListTableKeys: {
  349. data: 'results',
  350. total: 'count',
  351. currentPage: 'current',
  352. perPage: 'per_page',
  353. pageKey: 'page'
  354. }
  355. }
  356. },
  357. mounted() {
  358. this.setActionBtn()
  359. this.mounted = true
  360. },
  361. methods: {
  362. onConfirmedSelectedRegistrations (data) {
  363. const registrations = data.map(item => item.id)
  364. this.addNewLeaderLoading = true
  365. APIGateway.team.appendRegistrations({ teamId: this.$route.params.team_id, registrations })
  366. .then(() => {
  367. this.$refs.teamRegistrationList.search()
  368. this.addTeamRegistrationInputs[0].value = []
  369. this.addTeamRegistrationInputs[0].selected = []
  370. this.addTeamRegistrationKey = Date.now()
  371. this.addNewLeaderLoading = false
  372. })
  373. .catch(() => {
  374. this.addTeamRegistrationInputs[0].value = []
  375. this.addTeamRegistrationInputs[0].selected = []
  376. this.addTeamRegistrationKey = Date.now()
  377. this.addNewLeaderLoading = false
  378. })
  379. },
  380. setActionBtn () {
  381. FormBuilderAssist.setAttributeByName(this.inputs, 'btn', 'atClick', this.edit)
  382. },
  383. afterLoadInputData (responseData) {
  384. this.team = new Team(responseData)
  385. this.entityLoading = false
  386. FormBuilderAssist.setAttributeByName(this.inputs, 'leader', 'value', this.team.leader)
  387. FormBuilderAssist.setAttributeByName(this.inputs, 'leader', 'selected', this.team.leader_info)
  388. },
  389. edit() {
  390. this.entityLoading = true
  391. this.$refs.entityEdit.editEntity(false)
  392. .then(() => {
  393. this.$refs.entityEdit.getData()
  394. this.entityLoading = false
  395. })
  396. .catch(() => {
  397. this.$refs.entityEdit.getData()
  398. this.entityLoading = false
  399. })
  400. },
  401. getRemoveMessage (row) {
  402. return 'آیا از حذف ' + row.registration_info.owner_info.firstname + ' ' + row.registration_info.owner_info.lastname + ' اطمینان دارید؟'
  403. }
  404. }
  405. }
  406. </script>
  407. <style scoped lang="scss">
  408. .AdminTeamShow {
  409. .title {
  410. font-style: normal;
  411. font-weight: 700;
  412. font-size: 24px;
  413. line-height: 140%;
  414. color: #424242;
  415. margin-bottom: 27px;
  416. display: flex;
  417. flex-flow: row;
  418. position: relative;
  419. .static-title {
  420. }
  421. .dynamic-title {
  422. }
  423. .back-action {
  424. position: absolute;
  425. right: 0;
  426. top: 0;
  427. }
  428. }
  429. :deep(.form) {
  430. padding: 24px;
  431. }
  432. }
  433. </style>