userList.vue 7.3 KB

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