index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <div class="AdminUserIndex">
  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. :show-expand-button="false"
  11. :show-reload-button="false"
  12. :show-search-button="false">
  13. <template #toolbar>
  14. <q-btn color="primary"
  15. :loading="exportReportLoading"
  16. @click="exportExcel">
  17. خروجی اکسل
  18. </q-btn>
  19. </template>
  20. <template v-slot:entity-index-table-cell="{inputData, showConfirmRemoveDialog}">
  21. <template v-if="inputData.col.name === 'number'">
  22. {{ inputData.rowNumber }}
  23. </template>
  24. <template v-else-if="inputData.col.name === 'action'">
  25. <div class="action-column-entity-index">
  26. <q-btn size="md"
  27. color="primary"
  28. label="جزییات"
  29. :to="{name: 'Admin.User.Show', params: {id: inputData.props.row.id}}"
  30. class="q-mr-md" />
  31. <delete-btn @click="showConfirmRemoveDialog(inputData.props.row, 'id', getRemoveMessage(inputData.props.row))">
  32. <q-tooltip>
  33. حذف
  34. </q-tooltip>
  35. </delete-btn>
  36. </div>
  37. </template>
  38. <template v-else-if="inputData.col.name === 'status'">
  39. <div class="action-column-entity-index">
  40. <q-toggle v-model="inputData.props.row.is_active"
  41. label="فعال/غیر فعال"
  42. @update:model-value="changeUserActiveStatus(inputData.props.row)" />
  43. </div>
  44. </template>
  45. <template v-else>
  46. {{ inputData.col.value }}
  47. </template>
  48. </template>
  49. </entity-index>
  50. </div>
  51. </template>
  52. <script>
  53. import { shallowRef } from 'vue'
  54. import { EntityIndex } from 'quasar-crud'
  55. import Assist from 'src/assets/js/Assist.js'
  56. import { APIGateway } from 'src/api/APIGateway.js'
  57. import BtnControl from 'src/components/Control/btn.vue'
  58. import DeleteBtn from 'src/components/Control/DeleteBtn.vue'
  59. import Enums from 'assets/Enums/Enums'
  60. const BtnControlComp = shallowRef(BtnControl)
  61. export default {
  62. name: 'Admin.User.Index',
  63. components: {
  64. DeleteBtn,
  65. EntityIndex
  66. },
  67. data () {
  68. return {
  69. mounted: false,
  70. exportReportLoading: false,
  71. inputs: [
  72. { type: 'input', name: 'id', value: null, label: 'شناسه', placeholder: ' ', col: 'col-md-3 col-12' },
  73. { type: 'input', name: 'firstname', value: null, label: 'نام', placeholder: ' ', col: 'col-md-3 col-12' },
  74. { type: 'input', name: 'lastname', value: null, label: 'نام خانوادگی', placeholder: ' ', col: 'col-md-3 col-12' },
  75. { type: 'input', name: 'national_code', value: null, label: 'کد ملی', placeholder: ' ', col: 'col-md-3 col-12' },
  76. { type: 'input', name: 'mobile_number', value: null, label: 'شماره همراه', placeholder: ' ', col: 'col-md-3 col-12' },
  77. { type: 'input', name: 'email', value: null, label: 'ایمیل', placeholder: ' ', col: 'col-md-3 col-12' },
  78. { type: 'input', name: 'search', label: 'جست جو', placeholder: ' ', col: 'col-md-3 col-12' },
  79. { type: 'select', name: 'role', value: null, label: 'نقش', placeholder: ' ', options: Enums.groups, col: 'col-md-3 col-12' },
  80. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-2 col-12' }
  81. ],
  82. api: APIGateway.user.APIAdresses.base,
  83. table: {
  84. columns: [
  85. {
  86. name: 'number',
  87. required: true,
  88. label: 'شماره',
  89. align: 'left',
  90. field: () => ''
  91. },
  92. {
  93. name: 'id',
  94. required: true,
  95. label: 'شناسه',
  96. align: 'left',
  97. field: row => row.id
  98. },
  99. {
  100. name: 'fullname',
  101. required: true,
  102. label: 'نام و نام خانوادگی',
  103. align: 'left',
  104. field: row => row.firstname + ' ' + row.lastname
  105. },
  106. {
  107. name: 'national_code',
  108. required: true,
  109. label: 'کد ملی',
  110. align: 'left',
  111. field: row => row.national_code
  112. },
  113. {
  114. name: 'mobile_number',
  115. required: true,
  116. label: 'شماره همراه',
  117. align: 'left',
  118. field: row => row.mobile_number
  119. },
  120. {
  121. name: 'email',
  122. required: true,
  123. label: 'ایمیل',
  124. align: 'left',
  125. field: row => row.email
  126. },
  127. {
  128. name: 'roles',
  129. required: true,
  130. label: 'نقش',
  131. align: 'left',
  132. field: row => row.roles.join(', ')
  133. },
  134. {
  135. name: 'is_active',
  136. required: true,
  137. label: 'وضعیت',
  138. align: 'left',
  139. field: row => row.is_active ? 'فعال' : 'غیر فعال'
  140. },
  141. {
  142. name: 'action',
  143. required: true,
  144. label: '',
  145. align: 'left',
  146. field: ''
  147. }
  148. ]
  149. },
  150. tableKeys: {
  151. data: 'results',
  152. total: 'count',
  153. currentPage: 'current',
  154. perPage: 'per_page',
  155. pageKey: 'page'
  156. }
  157. }
  158. },
  159. mounted() {
  160. this.setActionBtn()
  161. this.mounted = true
  162. },
  163. methods: {
  164. exportExcel () {
  165. const params = this.$refs.entityIndex.createParams()
  166. this.exportReportLoading = true
  167. delete params.btn
  168. params.type = 'users'
  169. APIGateway.user.exportReport(params)
  170. .then((xlsxData) => {
  171. Assist.saveXlsx(xlsxData, 'لیست کاربران')
  172. this.exportReportLoading = false
  173. })
  174. .catch(() => {
  175. this.exportReportLoading = false
  176. })
  177. },
  178. setActionBtn () {
  179. this.inputs.forEach((item, index) => {
  180. if (item.name === 'btn') {
  181. this.inputs[index].atClick = this.search
  182. }
  183. })
  184. },
  185. search () {
  186. this.$refs.entityIndex.search()
  187. },
  188. changeUserActiveStatus (user) {
  189. APIGateway.user.updateByAdmin(user)
  190. .then(() => {
  191. this.search()
  192. })
  193. .catch(() => {
  194. this.search()
  195. })
  196. },
  197. getRemoveMessage (row) {
  198. return 'آیا از حذف ' + row.firstname + row.lastname + ' اطمینان دارید؟'
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. .AdminUserIndex {
  205. .action-column-entity-index {
  206. display: flex;
  207. align-items: center;
  208. justify-content: flex-start;
  209. }
  210. }
  211. </style>