userList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <a-card size="small" :bordered="false">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="用户名称">
  9. <a-input allowClear v-model.trim="queryParam.name" placeholder="请输入用户名称"/>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="手机号码">
  14. <a-input allowClear v-model.trim="queryParam.phone" placeholder="请输入手机号码"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-form-item label="状态">
  19. <v-select code="ENABLE_FLAG" v-model="queryParam.loginFlag" allowClear placeholder="请选择状态"></v-select>
  20. </a-form-item>
  21. </a-col>
  22. <a-col :md="4" :sm="24">
  23. <a-button type="primary" @click="$refs.table.refresh(true)" style="margin-right: 10px;">查询</a-button>
  24. <a-button type="" @click="reset" id="roleList-reset">重置</a-button>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </div>
  29. <div class="table-operator">
  30. <a-button type="primary" v-if="$hasPermissions('B_power_user_add')" class="button-error" @click="openModal">新增</a-button>
  31. </div>
  32. <s-table
  33. class="sTable fixPagination"
  34. ref="table"
  35. size="small"
  36. :style="{ height: tableHeight+84.5+'px' }"
  37. rowKey="id"
  38. :columns="columns"
  39. :data="loadData"
  40. :scroll="{ y: tableHeight }"
  41. style="word-break: break-all;"
  42. :defaultLoadData="false"
  43. bordered
  44. >
  45. <span slot="status" slot-scope="text, record">
  46. <!-- 超级管理员不可删除不可编辑不可启禁用 -->
  47. <a-switch v-if="record.superAdmin!=1 && $hasPermissions('B_power_user_enable')" checkedChildren="启用" unCheckedChildren="禁用" v-model="record.loginFlag" @change="changeFlagHandle(text, record)"/>
  48. <span v-else>{{ record.loginFlag==1?'已启用':'已禁用' }}</span>
  49. </span>
  50. <span slot="action" slot-scope="text, record">
  51. <a-button
  52. size="small"
  53. type="link"
  54. class="button-info"
  55. v-if="record.superAdmin!=1 &&$hasPermissions('B_power_user_edit')"
  56. @click="handleEdit(record)"
  57. >
  58. 编辑
  59. </a-button>
  60. <a-button
  61. size="small"
  62. type="link"
  63. class="button-info"
  64. v-if="record.loginFlag==1 && record.superAdmin!=1 &&$hasPermissions('B_power_user_resetPsd')"
  65. @click="resetPassword(record)"
  66. >
  67. 重置密码
  68. </a-button>
  69. <a-button
  70. size="small"
  71. type="link"
  72. class="button-info"
  73. v-if="$hasPermissions('B_power_user_set')"
  74. @click="handleSetting(record)"
  75. >
  76. 分区设置
  77. </a-button>
  78. <a-button
  79. size="small"
  80. type="link"
  81. class="button-error"
  82. v-if="record.loginFlag==0 && record.superAdmin!=1 &&$hasPermissions('B_power_user_del')"
  83. @click="delect(record)"
  84. >
  85. 删除
  86. </a-button>
  87. </span>
  88. </s-table>
  89. </a-spin>
  90. <userModal :visible="showModal" @refresh="$refs.table.refresh(true)" :nowData="itemData" @close="closeModal"></userModal>
  91. <!-- 分区设置 -->
  92. <UpdateArea ref="UpdateArea" :openUdModal="openUdModal" @ok="$refs.table.refresh(true)" @close="openUdModal=false"></UpdateArea>
  93. </a-card>
  94. </template>
  95. <script>
  96. import { commonMixin } from '@/utils/mixin'
  97. import { STable, VSelect } from '@/components'
  98. import userModal from './userModal.vue'
  99. import { resetPSD, updateEnableStatus, getPowerUserList, delectUserPower } from '@/api/power-user.js'
  100. import UpdateArea from './updateAreal.vue'
  101. export default {
  102. name: 'PowerUserList',
  103. mixins: [commonMixin],
  104. components: {
  105. STable, VSelect, userModal, UpdateArea
  106. },
  107. data () {
  108. return {
  109. spinning: false,
  110. tableHeight: 0,
  111. // 查询参数
  112. queryParam: {
  113. name: '',
  114. phone: '',
  115. loginFlag: undefined
  116. },
  117. showModal: false,
  118. openUdModal: false,
  119. itemData: null, // 编辑行数据
  120. // 表头
  121. columns: [
  122. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  123. { title: '创建时间', dataIndex: 'createDate', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  124. { title: '用户名称', dataIndex: 'name', align: 'center', width: '18%', customRender: function (text) { return text || '--' }, ellipsis: true },
  125. { title: '手机号码', dataIndex: 'phone', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  126. { title: '用户账号', dataIndex: 'loginName', width: '12%', align: 'center', customRender: function (text) { return text || '--' } },
  127. { title: '所属分区', dataIndex: 'allSubareaName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  128. { title: '角色', dataIndex: 'roleNames', width: '18%', align: 'center', customRender: function (text) { return text || '--' } },
  129. { title: '状态', width: '6%', align: 'center', scopedSlots: { customRender: 'status' } },
  130. { title: '操作', width: '20%', align: 'center', scopedSlots: { customRender: 'action' } }
  131. ],
  132. // 加载数据方法 必须为 Promise 对象
  133. loadData: parameter => {
  134. this.spinning = true
  135. return getPowerUserList(Object.assign(parameter, this.queryParam)).then(res => {
  136. let data
  137. if (res.status == 200) {
  138. data = res.data
  139. const no = (data.pageNo - 1) * data.pageSize
  140. for (let i = 0; i < data.list.length; i++) {
  141. const _item = data.list[i]
  142. _item.no = no + i + 1
  143. _item.loginFlag = _item.loginFlag + '' === '1'
  144. }
  145. }
  146. this.spinning = false
  147. return data
  148. })
  149. },
  150. optionAlertShow: false
  151. }
  152. },
  153. methods: {
  154. // 新增
  155. openModal () {
  156. this.showModal = true
  157. this.itemData = null
  158. },
  159. closeModal () {
  160. this.showModal = false
  161. this.itemData = null
  162. },
  163. // 重置
  164. reset () {
  165. this.queryParam.name = ''
  166. this.queryParam.phone = ''
  167. this.queryParam.loginFlag = undefined
  168. this.$refs.table.refresh(true)
  169. },
  170. // 分区设置
  171. handleSetting (row) {
  172. this.openUdModal = true
  173. this.$refs.UpdateArea.setData(row)
  174. },
  175. // 重置密码
  176. resetPassword (row) {
  177. const _this = this
  178. this.$confirm({
  179. title: '提示',
  180. content: '确认重置密码吗?',
  181. centered: true,
  182. onOk () {
  183. _this.spinning = true
  184. resetPSD({
  185. id: row.id
  186. }).then(res => {
  187. if (res.status == 200) {
  188. _this.$message.success(res.message)
  189. _this.$refs.table.refresh()
  190. _this.spinning = false
  191. } else {
  192. _this.spinning = false
  193. }
  194. })
  195. }
  196. })
  197. },
  198. // 删除
  199. delect (row) {
  200. const _this = this
  201. this.$confirm({
  202. title: '警告',
  203. content: '删除后无法恢复,确认删除?',
  204. centered: true,
  205. onOk () {
  206. _this.spinning = true
  207. delectUserPower({
  208. id: row.id
  209. }).then(res => {
  210. if (res.status == 200) {
  211. _this.$message.success(res.message)
  212. _this.$refs.table.refresh()
  213. _this.spinning = false
  214. } else {
  215. _this.$message.error(res.message)
  216. _this.spinning = false
  217. }
  218. })
  219. }
  220. })
  221. },
  222. handleEdit (row) {
  223. this.showModal = true
  224. this.itemData = row
  225. },
  226. // 修改状态
  227. changeFlagHandle (text, record) {
  228. const _data = {
  229. id: record.id,
  230. flag: record.loginFlag ? '1' : '0'
  231. }
  232. this.spinning = true
  233. updateEnableStatus(_data).then(res => {
  234. if (res.status == 200) {
  235. this.$message.success(res.message)
  236. this.$refs.table.refresh()
  237. this.spinning = false
  238. } else {
  239. this.$refs.table.refresh()
  240. this.spinning = false
  241. }
  242. })
  243. },
  244. pageInit () {
  245. const _this = this
  246. this.$nextTick(() => { // 页面渲染完成后的回调
  247. _this.setTableH()
  248. })
  249. },
  250. setTableH () {
  251. const tableSearchH = this.$refs.tableSearch.offsetHeight
  252. this.tableHeight = window.innerHeight - tableSearchH - 245
  253. }
  254. },
  255. watch: {
  256. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  257. this.setTableH()
  258. }
  259. },
  260. mounted () {
  261. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  262. this.pageInit()
  263. this.reset()
  264. }
  265. },
  266. activated () {
  267. // 如果是新页签打开,则重置当前页面
  268. if (this.$store.state.app.isNewTab) {
  269. this.pageInit()
  270. this.reset()
  271. }
  272. // 仅刷新列表,不重置页面
  273. if (this.$store.state.app.updateList) {
  274. this.pageInit()
  275. this.$refs.table.refresh()
  276. }
  277. }
  278. }
  279. </script>