project-list.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="list">
  3. <u-swipe-action>
  4. <u-swipe-action-item @click="(e)=>{click(e,item)}" :options="options1" v-for="(item,index) in list"
  5. :key="item.id">
  6. <view class="list-item">
  7. <view class="left">
  8. {{item.description}}
  9. </view>
  10. <view class="right">
  11. {{item.gatewayDeviceId}}
  12. </view>
  13. </view>
  14. </u-swipe-action-item>
  15. </u-swipe-action>
  16. <u-toast ref="uToast"></u-toast>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. },
  23. data() {
  24. return {
  25. msg: {
  26. userId: uni.getStorageSync('userId'),
  27. pageNo: 1,
  28. pageSize: 10
  29. },
  30. options1: [{
  31. text: '修改',
  32. style: {
  33. backgroundColor: '#3c9cff'
  34. }
  35. }, {
  36. text: '删除',
  37. style: {
  38. backgroundColor: '#f56c6c'
  39. }
  40. }],
  41. list: []
  42. }
  43. },
  44. // 触底事件
  45. onReachBottom() {
  46. console.log('触底了');
  47. },
  48. onLoad() {
  49. this.getList()
  50. },
  51. methods: {
  52. async getList() {
  53. uni.showLoading({
  54. title: '数据加载中...'
  55. })
  56. const {
  57. data: res
  58. } = await uni.$http.post('/api/v1/test/testProject/queryByCondition', this.msg)
  59. console.log(res);
  60. if(res.code===200){
  61. uni.hideLoading()
  62. this.list = res.data.records
  63. }else{
  64. this.$u.toast(`修改失败`)
  65. }
  66. },
  67. async click(e, item) {
  68. console.log(item);
  69. if (e.index == 0) {
  70. this.$u.toast(`点击了更改`);
  71. let detail = JSON.stringify(item)
  72. uni.navigateTo({
  73. url: "/pages/add-project/add-project?item=" + detail
  74. })
  75. } else {
  76. uni.showLoading({
  77. title:"正在删除中"
  78. })
  79. const {
  80. data: res
  81. } = await uni.$http.delete(`/api/v1/test/testProject/${item.id}`)
  82. if(res.code==200){
  83. uni.hideLoading()
  84. this.getList()
  85. }else{
  86. this.$u.toast(`删除失败,请重新删除`)
  87. }
  88. }
  89. }
  90. },
  91. onPullDownRefresh() {
  92. console.log('refresh');
  93. this.getList()
  94. setTimeout(function() {
  95. uni.stopPullDownRefresh();
  96. }, 1000);
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .list {
  102. width: calc(100vw - 40rpx);
  103. margin: 10rpx 20rpx;
  104. overflow: hidden;
  105. .list-item {
  106. padding: 20rpx;
  107. height: 100rpx;
  108. border-bottom: 1px solid #535353;
  109. display: flex;
  110. justify-content: space-between;
  111. align-items: center;
  112. // margin-bottom: 20rpx;
  113. .left {
  114. // background-color: red;
  115. // flex: 1;
  116. }
  117. .right {
  118. // background-color: blue;
  119. // flex: 1;
  120. }
  121. }
  122. }
  123. </style>