list.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view>
  3. <scroll-view :scroll-y="true">
  4. <view class="cu-bar bg-white solid-bottom">
  5. <view class="action">
  6. <text class="cuIcon-title text-orange "></text> 用户列表
  7. </view>
  8. </view>
  9. <view class="cu-list menu">
  10. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
  11. v-for="(item,index) in userList" :key="index" @touchstart="ListTouchStart"
  12. @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index">
  13. <view class="content">
  14. <view class="text-gray" style="width: 30%;">{{item.account}}</view>
  15. </view>
  16. <view class="text-gray" style="margin-left: auto;">{{item.name}}</view>
  17. <view class="move">
  18. <view class="bg-grey" @click="editUserInfo(item)">修改</view>
  19. <view class="bg-red" @click="deleteUserInfo(item)">删除</view>
  20. </view>
  21. </view>
  22. </view>
  23. <u-toast ref="uToast"></u-toast>
  24. </scroll-view>
  25. </view>
  26. </template>
  27. <script>
  28. import {list,deleteUser} from '@/api/system/user.js'
  29. export default {
  30. data() {
  31. return {
  32. userList: [],
  33. modalName: null,
  34. }
  35. },
  36. methods: {
  37. addClick() {
  38. uni.navigateTo({
  39. url: '/pages/user/add'
  40. })
  41. },
  42. // ListTouch触摸开始
  43. ListTouchStart(e) {
  44. this.listTouchStart = e.touches[0].pageX
  45. },
  46. // ListTouch计算方向
  47. ListTouchMove(e) {
  48. this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
  49. },
  50. // ListTouch计算滚动
  51. ListTouchEnd(e) {
  52. if (this.listTouchDirection == 'left') {
  53. this.modalName = e.currentTarget.dataset.target
  54. } else {
  55. this.modalName = null
  56. }
  57. this.listTouchDirection = null
  58. },
  59. editUserInfo(item) {
  60. uni.navigateTo({
  61. url: '/pages/user/edit?userInfo=' + encodeURIComponent(JSON.stringify(item))
  62. })
  63. },
  64. deleteUserInfo(item) {
  65. const arr = []
  66. arr.push(item)
  67. deleteUser(arr).then(res=>{
  68. if(res.success){
  69. this.$refs.uToast.show({
  70. type: 'success',
  71. message: "删除用户成功",
  72. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  73. })
  74. this.removeUserInfo(item)
  75. }else{
  76. }
  77. })
  78. },
  79. removeUserInfo(item) {
  80. const index = this.userList.findIndex(ele => {
  81. return ele.id == item.id
  82. })
  83. this.userList.splice(index, 1)
  84. },
  85. loadData() {
  86. list().then(res => {
  87. if (res.success) {
  88. this.userList = res.data
  89. } else {}
  90. })
  91. }
  92. },
  93. onLoad() {
  94. this.loadData()
  95. uni.$on('loadData', () => {
  96. this.loadData();
  97. })
  98. }
  99. }
  100. </script>
  101. <style>
  102. </style>