index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. const BtnControlComp = shallowRef(BtnControl)
  60. export default {
  61. name: 'Admin.User.Index',
  62. components: {
  63. DeleteBtn,
  64. EntityIndex
  65. },
  66. data () {
  67. return {
  68. mounted: false,
  69. exportReportLoading: false,
  70. inputs: [
  71. { type: 'input', name: 'id', value: null, label: 'شناسه', placeholder: ' ', col: 'col-md-4 col-12' },
  72. { type: 'input', name: 'national_code', value: null, label: 'کد ملی', placeholder: ' ', col: 'col-md-4 col-12' },
  73. { type: 'input', name: 'mobile_number', value: null, label: 'شماره همراه', placeholder: ' ', col: 'col-md-4 col-12' },
  74. { type: 'input', name: 'email', value: null, label: 'ایمیل', placeholder: ' ', col: 'col-md-3 col-12' },
  75. { type: 'input', name: 'firstname', value: null, label: 'نام', placeholder: ' ', col: 'col-md-3 col-12' },
  76. { type: 'input', name: 'lastname', value: null, label: 'نام خانوادگی', placeholder: ' ', col: 'col-md-3 col-12' },
  77. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'جستجو', placeholder: ' ', atClick: () => {}, col: 'col-md-3 col-12' }
  78. ],
  79. api: APIGateway.user.APIAdresses.base,
  80. table: {
  81. columns: [
  82. {
  83. name: 'number',
  84. required: true,
  85. label: 'شماره',
  86. align: 'left',
  87. field: () => ''
  88. },
  89. {
  90. name: 'id',
  91. required: true,
  92. label: 'شناسه',
  93. align: 'left',
  94. field: row => row.id
  95. },
  96. {
  97. name: 'fullname',
  98. required: true,
  99. label: 'نام و نام خانوادگی',
  100. align: 'left',
  101. field: row => row.firstname + ' ' + row.lastname
  102. },
  103. {
  104. name: 'national_code',
  105. required: true,
  106. label: 'کد ملی',
  107. align: 'left',
  108. field: row => row.national_code
  109. },
  110. {
  111. name: 'mobile_number',
  112. required: true,
  113. label: 'شماره همراه',
  114. align: 'left',
  115. field: row => row.mobile_number
  116. },
  117. {
  118. name: 'email',
  119. required: true,
  120. label: 'ایمیل',
  121. align: 'left',
  122. field: row => row.email
  123. },
  124. {
  125. name: 'roles',
  126. required: true,
  127. label: 'نقش',
  128. align: 'left',
  129. field: row => row.roles.join(', ')
  130. },
  131. {
  132. name: 'is_active',
  133. required: true,
  134. label: 'وضعیت',
  135. align: 'left',
  136. field: row => row.is_active ? 'فعال' : 'غیر فعال'
  137. },
  138. {
  139. name: 'action',
  140. required: true,
  141. label: '',
  142. align: 'left',
  143. field: ''
  144. }
  145. ],
  146. data: []
  147. },
  148. tableKeys: {
  149. data: 'results',
  150. total: 'count',
  151. currentPage: 'current',
  152. perPage: 'per_page',
  153. pageKey: 'page'
  154. }
  155. }
  156. },
  157. mounted() {
  158. this.setActionBtn()
  159. this.mounted = true
  160. },
  161. methods: {
  162. exportExcel () {
  163. const params = this.$refs.entityIndex.createParams()
  164. this.exportReportLoading = true
  165. delete params.btn
  166. params.type = 'users'
  167. APIGateway.user.exportReport(params)
  168. .then((xlsxData) => {
  169. Assist.saveXlsx(xlsxData, 'لیست کاربران')
  170. this.exportReportLoading = false
  171. })
  172. .catch(() => {
  173. this.exportReportLoading = false
  174. })
  175. },
  176. setActionBtn () {
  177. this.inputs.forEach((item, index) => {
  178. if (item.name === 'btn') {
  179. this.inputs[index].atClick = this.search
  180. }
  181. })
  182. },
  183. search () {
  184. this.$refs.entityIndex.search()
  185. },
  186. changeUserActiveStatus (user) {
  187. APIGateway.user.updateByAdmin(user)
  188. .then(() => {
  189. this.search()
  190. })
  191. .catch(() => {
  192. this.search()
  193. })
  194. },
  195. getRemoveMessage (row) {
  196. return 'آیا از حذف ' + row.firstname + row.lastname + ' اطمینان دارید؟'
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss">
  202. .AdminUserIndex {
  203. .action-column-entity-index {
  204. display: flex;
  205. align-items: center;
  206. justify-content: flex-start;
  207. }
  208. }
  209. </style>