userList.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="mainBox">
  3. <!--搜索功能 start------------------------------------------------------------>
  4. <div class="layerBox_search">
  5. <div class="layerBoxLine">
  6. <el-row>
  7. <el-col :span="8">
  8. <div class="searchBox">
  9. <div class="searchTitle">用户账号:</div>
  10. <el-input placeholder="请输入用户账号" autocomplete="off" v-model="getApiData.keyword"/>
  11. </div>
  12. </el-col>
  13. <el-col :span="8">
  14. <div class="searchBox">
  15. <div class="searchTitle">用户类型:</div>
  16. <el-select placeholder="请选择用户类型" v-model="getApiData.type_id">
  17. <el-option label="个人会员" value="1"></el-option>
  18. <el-option label="政务会员" value="2"></el-option>
  19. <el-option label="企业会员" value="3"></el-option>
  20. <el-option label="调研员" value="4"></el-option>
  21. <el-option label="管理员" value="10000"></el-option>
  22. <el-option label="游客" value="20000"></el-option>
  23. </el-select>
  24. </div>
  25. </el-col>
  26. <el-col :span="8">
  27. <div class="searchBox">
  28. <div class="searchTitle">账号状态:</div>
  29. <el-select placeholder="请选择用户类型" v-model="getApiData.status">
  30. <el-option label="启用" value="1"></el-option>
  31. <el-option label="停用" value="0"></el-option>
  32. </el-select>
  33. </div>
  34. </el-col>
  35. </el-row>
  36. </div>
  37. </div>
  38. <div class="layerBoxNoBg">
  39. <div>
  40. <el-button type="primary" @click="goCreat">添加用户</el-button>
  41. </div>
  42. <div>
  43. <el-button @click="clearSearchList">重置</el-button>
  44. <el-button type="primary" @click="getData">搜索</el-button>
  45. </div>
  46. </div>
  47. <!--搜索功能 end------------------------------------------------------------>
  48. <!--表格内容 start------------------------------------------------------------>
  49. <div class="layerBox">
  50. <tableTitle :name="tableDivTitle"/>
  51. <el-row>
  52. <template>
  53. <el-table :data="tableData" style="width: 100%">
  54. <el-table-column fixed prop="id" label="编号" width="50"></el-table-column>
  55. <el-table-column prop="real_name" label="用户姓名" width=""></el-table-column>
  56. <el-table-column prop="type_name" label="用户类型" width=""></el-table-column>
  57. <el-table-column prop="mobile" label="联系电话" width=""></el-table-column>
  58. <el-table-column prop="created_at" label="创建时间" width=""></el-table-column>
  59. <el-table-column prop="status" label="账号状态" width="">
  60. <template slot-scope="scope">
  61. <el-switch
  62. v-model="scope.row.status"
  63. :active-value="1"
  64. :inactive-value="0"
  65. @change="upRow(scope.row.id,scope.row.status)"
  66. ></el-switch>
  67. </template>
  68. </el-table-column>
  69. <el-table-column fixed="right" label="操作" width="200" header-align="center">
  70. <template slot-scope="scope">
  71. <div class="listBtnBox">
  72. <div class="listEditBtn" @click="goEdit(scope.row.id)"><i class="el-icon-edit-outline"></i>编辑</div>
  73. </div>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. </template>
  78. </el-row>
  79. </div>
  80. <!--分页 start------------------------------------------------------------>
  81. <div class="alignBox">
  82. <el-row>
  83. <el-col :span="24">
  84. <el-pagination :current-page="getApiData.page" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper" :total="allCount"></el-pagination>
  85. </el-col>
  86. </el-row>
  87. </div>
  88. <!--分页 end------------------------------------------------------------>
  89. <!--表格内容 end------------------------------------------------------------>
  90. </div>
  91. </template>
  92. <script>
  93. //表格标题
  94. import tableTitle from './components/tableTitle';
  95. //引入公用样式
  96. import '@/styles/global.less';
  97. export default {
  98. components: {
  99. tableTitle,//表格标题
  100. },
  101. data() {
  102. return {
  103. //1.列表和分页相关 start ------------------------------------------------------------>
  104. tableDivTitle:"用户列表",
  105. tableData:[],//内容
  106. editId:0,//要修改的网站id
  107. getApiData:{
  108. type_id:"",//用户类型
  109. keyword:"",//用户账号
  110. status:"",//用户状态
  111. page:1,//当前是第几页
  112. pageSize:10,//一共多少条
  113. },
  114. allCount:0,//总条数
  115. //分页相关 end ------------------------------------------------------------>
  116. }
  117. },
  118. methods: {
  119. //1.列表和分页相关 start ------------------------------------------------------------>
  120. //1.1 开始请求列表信息方法
  121. getData(){
  122. this.$store.dispatch('userMember/getUserList',this.getApiData).then(res=> {
  123. this.tableData = res.data.rows; //给与内容
  124. this.allCount = res.data.count; //给与总条数
  125. }).catch(() => {
  126. this.$message({
  127. type: 'warning',
  128. message: '网络错误,请重试!'
  129. });
  130. })
  131. },
  132. //1.2 删除内容
  133. // deleteRow(id){
  134. // this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
  135. // confirmButtonText: '确定',
  136. // cancelButtonText: '取消',
  137. // type: 'warning'
  138. // }).then(() => {
  139. // console.log("当前删除:" + id)
  140. // this.$store.dispatch('',{id:id}).then(res=> {
  141. // this.getData();
  142. // this.$message({
  143. // type: 'success',
  144. // message: '删除成功!'
  145. // });
  146. // }).catch(() => {
  147. // this.$message({
  148. // type: 'warning',
  149. // message: '网络错误,请重试!'
  150. // });
  151. // })
  152. // }).catch(() => {
  153. // this.$message({
  154. // type: 'warning',
  155. // message: '已取消删除'
  156. // });
  157. // });
  158. // },
  159. //1.3 修改用户状态
  160. upRow(id,status){
  161. let data = {
  162. id:id,
  163. status:status
  164. }
  165. this.$store.dispatch('userMember/upUserStatus',data).then(res=> {
  166. if(res.code==200){
  167. this.$message({
  168. type: 'success',
  169. message: '用户状态已修改!'
  170. });
  171. }
  172. }).catch(() => {
  173. this.$message({
  174. type: 'warning',
  175. message: '已取消删除'
  176. });
  177. });
  178. },
  179. //1.4 列表内容分页
  180. //直接跳转
  181. handleSizeChange(val) {
  182. this.getApiData.page = val;
  183. this.getData();
  184. },
  185. //1.5 点击分页
  186. handleCurrentChange(val) {
  187. this.getApiData.page = val;
  188. this.getData();
  189. },
  190. //1.6 重置按钮
  191. clearSearchList(){
  192. this.tableData = [];
  193. this.getApiData.type_id = "";
  194. this.getApiData.keyword = "";
  195. this.getApiData.status = "";
  196. this.getApiData.page = 1;
  197. this.getApiData.pageSize = 10;
  198. this.getData();
  199. },
  200. //列表和分页相关 end ------------------------------------------------------------>
  201. //2.添加新闻 start ------------------------------------------------------------>
  202. //跳转到资讯发布页面
  203. goCreat(){
  204. this.$router.push({
  205. path: '/creatUser',
  206. });
  207. },
  208. goEdit(id){
  209. let data = {
  210. id:id
  211. }
  212. this.$router.push({
  213. path: '/creatUser',
  214. query: data
  215. });
  216. }
  217. //添加新闻 end ------------------------------------------------------------>
  218. },
  219. mounted(){
  220. //1.获得初始数据
  221. this.getData();
  222. }
  223. }
  224. </script>
  225. <style scoped lang="less">
  226. </style>