list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="house-list">
  3. <tables
  4. :data-api="dataApi"
  5. :columns="columns"
  6. @toEdit="toEdit"
  7. placeholder="账号名称"
  8. ref="table"
  9. />
  10. <CModal :show="show" title="用户信息" :width="420" @submit="changeUser" @close="closeModal">
  11. <Form :label-width="75">
  12. <FormItem label="用户名称">
  13. <Input size="large" v-model="form.name" disabled />
  14. </FormItem>
  15. <FormItem label="用户角色">
  16. <Select v-model="form.type" size="large">
  17. <Option :value="-1">未分配</Option>
  18. <Option :value="item.roleType" v-for="item in roleList" :key="item.roleId">{{ item.remark }}</Option>
  19. </Select>
  20. </FormItem>
  21. <FormItem label="手机号码">
  22. <Input size="large" v-model="form.phone" disabled />
  23. </FormItem>
  24. </Form>
  25. </CModal>
  26. </div>
  27. </template>
  28. <script>
  29. import tables from 'components/tables'
  30. import { fetchUserList, updateUser, fetchRoleList } from 'api/'
  31. import CModal from 'components/Modal'
  32. const roleMap = {
  33. 0: '超级管理员',
  34. 1: '普通管理员',
  35. 2: '经纪人',
  36. }
  37. export default {
  38. data() {
  39. return {
  40. show: false,
  41. form: {},
  42. // 传递给tables的表格列数据
  43. dataApi: fetchUserList,
  44. roleList: [],
  45. columns: [
  46. {
  47. type: 'index',
  48. title: '序号',
  49. align: 'center',
  50. width: 80
  51. },
  52. {
  53. title: '账号ID',
  54. key: 'admin_id',
  55. align: 'center'
  56. },
  57. {
  58. title: '账号名称',
  59. key: 'name',
  60. align: 'center'
  61. },
  62. {
  63. title: '角色',
  64. key: 'type',
  65. align: 'center',
  66. render: (h, params) => {
  67. return h('span', roleMap[params.row.type])
  68. }
  69. },
  70. {
  71. title: '联系方式',
  72. key: 'phone',
  73. align: 'center'
  74. },
  75. {
  76. title: '启动状态',
  77. key: 'name',
  78. align: 'center',
  79. render: (h, params) => {
  80. return h('i-switch', {
  81. props: {
  82. trueValue: 1,
  83. falseValue: 0,
  84. value: params.row.enable,
  85. // disabled: params.row.roleKey === 'admin'
  86. },
  87. on: {
  88. 'on-change': (val) => {
  89. updateUser(Object.assign(params.row, {enable: val})).catch (err => {
  90. params.row.enable = !val ? 1 : 0
  91. })
  92. }
  93. }
  94. })
  95. }
  96. },
  97. {
  98. title: '创建时间',
  99. key: 'createTime',
  100. align: 'center'
  101. },
  102. {
  103. title: '操作',
  104. slot: 'action',
  105. tools: ['edit' ],
  106. align: 'center'
  107. }
  108. ],
  109. }
  110. },
  111. components: {
  112. tables,
  113. CModal
  114. },
  115. mounted () {
  116. this.fetchRoleList()
  117. },
  118. methods: {
  119. fetchRoleList () {
  120. fetchRoleList().then(res => {
  121. this.roleList = res.data
  122. })
  123. },
  124. async changeUser () {
  125. await updateUser(this.form)
  126. this.closeModal()
  127. this.$Message.success({
  128. content: '修改成功'
  129. })
  130. this.$refs['table'].handleTableData()
  131. },
  132. toEdit (row) {
  133. this.form = JSON.parse(JSON.stringify(row))
  134. this.show = true
  135. },
  136. closeModal () {
  137. this.show = false
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="less" scoped>
  143. .house-list {
  144. padding: 20px;
  145. background: #252828;
  146. }
  147. </style>