userList.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <a-card size="small" :bordered="false">
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline">
  5. <a-row :gutter="15">
  6. <a-col :md="6" :sm="24">
  7. <a-form-item label="用户名称">
  8. <a-input allowClear v-model="queryParam.name" placeholder="请输入用户名称"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="6" :sm="24">
  12. <a-form-item label="手机号码">
  13. <a-input allowClear v-model="queryParam.phone" placeholder="请输入手机号码"/>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="6" :sm="24">
  17. <a-form-item label="状态">
  18. <v-select code="CHECK_ENABLE_STATE" v-model="queryParam.loginFlag" allowClear placeholder="请选择状态"></v-select>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="4" :sm="24">
  22. <a-button type="primary" @click="$refs.table.refresh(true)" style="margin-right: 10px;">查询</a-button>
  23. <a-button type="" @click="reset" id="roleList-reset">重置</a-button>
  24. </a-col>
  25. </a-row>
  26. </a-form>
  27. </div>
  28. <div class="table-operator">
  29. <a-button v-if="$hasPermissions('B_powerMD_user_add')" type="primary" class="button-error" @click="openModal">新增</a-button>
  30. </div>
  31. <s-table
  32. ref="table"
  33. size="default"
  34. rowKey="id"
  35. :columns="columns"
  36. :data="loadData"
  37. style="word-break: break-all;"
  38. bordered
  39. >
  40. <span slot="status" slot-scope="text, record">
  41. <a-switch v-if="$hasPermissions('B_powerMD_user_enable')" checkedChildren="启用" unCheckedChildren="禁用" v-model="record.loginFlag" @change="changeFlagHandle(text, record)"/>
  42. <span v-else>{{ record.loginFlag==1?'已启用':'已禁用' }}</span>
  43. </span>
  44. <span slot="action" slot-scope="text, record">
  45. <a-icon
  46. type="edit"
  47. title="编辑"
  48. :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}"
  49. v-if="$hasPermissions('B_powerMD_user_edit')"
  50. @click="handleEdit(record)"
  51. />
  52. <a-icon
  53. type="unlock"
  54. title="重置密码"
  55. v-if="record.loginFlag==1 && $hasPermissions('B_powerMD_user_restPwd')"
  56. :style="{fontSize: '20px',color:' #ffaa00',padding: '0 10px'}"
  57. @click="resetPassword(record)" />
  58. <a-icon
  59. type="delete"
  60. title="删除"
  61. :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
  62. v-if="record.loginFlag==0 && $hasPermissions('B_powerMD_user_del')"
  63. @click="delect(record)"/>
  64. </span>
  65. </s-table>
  66. <userModal :visible="showModal" @refresh="$refs.table.refresh(true)" :data="itemData" @close="showModal = false"></userModal>
  67. </a-card>
  68. </template>
  69. <script>
  70. import { STable, VSelect } from '@/components'
  71. import userModal from './userModal.vue'
  72. import { resetPSD, updateEnableStatus, getPowerUserList, delectUserPower } from '@/api/power-user.js'
  73. export default {
  74. name: 'UserList',
  75. components: {
  76. STable, VSelect, userModal
  77. },
  78. data () {
  79. return {
  80. // 查询参数
  81. queryParam: {
  82. name: '',
  83. phone: '',
  84. loginFlag: ''
  85. },
  86. showModal: false,
  87. itemData: {}, // 编辑行数据
  88. // 表头
  89. columns: [
  90. {
  91. title: '序号',
  92. dataIndex: 'no',
  93. width: 60,
  94. align: 'center'
  95. },
  96. {
  97. title: '创建时间',
  98. dataIndex: 'createDate',
  99. width: 150,
  100. align: 'center'
  101. },
  102. {
  103. title: '用户名称',
  104. dataIndex: 'name',
  105. width: 150,
  106. align: 'center'
  107. },
  108. {
  109. title: '手机号码',
  110. dataIndex: 'phone',
  111. width: 150,
  112. align: 'center'
  113. },
  114. {
  115. title: '角色',
  116. width: 200,
  117. align: 'center',
  118. dataIndex: 'roleNames'
  119. },
  120. {
  121. title: '状态',
  122. width: 150,
  123. align: 'center',
  124. scopedSlots: { customRender: 'status' }
  125. },
  126. {
  127. title: '操作',
  128. width: 150,
  129. align: 'center',
  130. scopedSlots: { customRender: 'action' }
  131. }
  132. ],
  133. // 加载数据方法 必须为 Promise 对象
  134. loadData: parameter => {
  135. return getPowerUserList(Object.assign(parameter, this.queryParam)).then(res => {
  136. const no = (res.data.pageNo - 1) * res.data.pageSize
  137. for (let i = 0; i < res.data.list.length; i++) {
  138. const _item = res.data.list[i]
  139. _item.no = no + i + 1
  140. _item.loginFlag = _item.loginFlag + '' === '1'
  141. }
  142. return res.data
  143. })
  144. },
  145. optionAlertShow: false
  146. }
  147. },
  148. methods: {
  149. // 刷新列表
  150. refreshTable () {
  151. this.$refs.table.refresh(true)
  152. },
  153. // 新增
  154. openModal () {
  155. this.showModal = true
  156. this.itemData = {}
  157. },
  158. // 重置
  159. reset () {
  160. this.queryParam.name = ''
  161. this.queryParam.phone = ''
  162. this.queryParam.loginFlag = ''
  163. this.refreshTable()
  164. },
  165. // 重置密码
  166. resetPassword (row) {
  167. const _this = this
  168. this.$confirm({
  169. title: '提示',
  170. content: '确认重置密码吗?',
  171. centered: true,
  172. onOk () {
  173. resetPSD({
  174. id: row.id
  175. }).then(res => {
  176. if (res.status == 200) {
  177. this.$message.success(res.message)
  178. } else {
  179. this.$message.error(res.message)
  180. }
  181. }).catch(() => {
  182. this.$message.success(res.message)
  183. })
  184. }
  185. })
  186. },
  187. // 删除
  188. delect (row) {
  189. const _this = this
  190. this.$confirm({
  191. title: '警告',
  192. content: '删除后无法恢复,确认删除?',
  193. centered: true,
  194. onOk () {
  195. delectUserPower({
  196. id: row.id
  197. }).then(res => {
  198. if (res.status == 200) {
  199. _this.$message.success(res.message)
  200. _this.$refs.table.refresh()
  201. } else {
  202. _this.$message.error(res.message)
  203. }
  204. }).catch(() => {
  205. _this.$message.success(res.message)
  206. })
  207. }
  208. })
  209. },
  210. getBizStr (storeBizList) {
  211. const str = []
  212. storeBizList.forEach(item => {
  213. str.push(item.bizTypeName)
  214. })
  215. return str.join(',')
  216. },
  217. handleEdit (row) {
  218. console.log(row, 'row')
  219. this.showModal = true
  220. this.itemData = row
  221. },
  222. // 修改状态
  223. changeFlagHandle (text, record) {
  224. const _data = {
  225. id: record.id,
  226. flag: record.loginFlag ? '1' : '0'
  227. }
  228. updateEnableStatus(_data).then(res => {
  229. if (res.status + '' === '200') {
  230. this.$message.success(res.message)
  231. } else {
  232. record.loginFlag = !record.loginFlag
  233. }
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style scoped>
  240. .action-button{
  241. line-height: 40px;
  242. white-space: nowrap;
  243. padding: 5px 10px;
  244. background-color: #1890ff;
  245. border-radius: 4px;
  246. color: #fff;
  247. margin-right: 5px;
  248. }
  249. .red-text{
  250. background-color: red;
  251. }
  252. .reset-text {
  253. background-color: #31b50b;
  254. }
  255. </style>