You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
2.6 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. <template>
  2. <view class="main">
  3. <view class="top_row">
  4. <view class="row selectAll" @click="chooseAll">
  5. <view class="icon ">
  6. <image src="@/static/images/icon (22).png" mode="" v-if="isAll"></image>
  7. <image src="@/static/images/icon (20).png" mode="" v-else></image>
  8. </view>
  9. <view class="txt">全选</view>
  10. </view>
  11. <view class="searchBox">
  12. <searchRow placeholder="名称/IP过滤" @searchFn="searchFn"/>
  13. </view>
  14. </view>
  15. <view class="card">
  16. <view class="row" v-for="(item,index) in list" :key="index" @click="chooseItem(item)">
  17. <view class="icon">
  18. <image src="@/static/images/icon (20).png" mode="" v-if="(listId.findIndex((val)=>item.id==val))==-1"></image>
  19. <image src="@/static/images/icon (22).png" mode="" v-else></image>
  20. </view>
  21. <view class="txt">{{item.name}}</view>
  22. </view>
  23. </view>
  24. <view class="btnPoz">
  25. <view class="btnBg" @click="chooseMachine"> </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { machineList } from '@/config/api.js'
  31. export default {
  32. data() {
  33. return {
  34. list: [],
  35. listId: [],
  36. list2: []
  37. }
  38. },
  39. onLoad() {
  40. this.machineListFn()
  41. },
  42. computed: {
  43. isAll() {
  44. if(!this.listId.length) return false
  45. if(this.listId.length==this.list2.length) return true
  46. return false
  47. }
  48. },
  49. methods: {
  50. async machineListFn() {
  51. let obj = {
  52. limit: 10000,
  53. status: 1
  54. }
  55. const {data: res} = await machineList(obj)
  56. this.list = res.rows||[]
  57. this.list2 = res.rows||[]
  58. console.log(res)
  59. },
  60. searchFn(val) {
  61. this.list = this.list2.filter(item=>{
  62. return item.name.includes(val)
  63. })
  64. },
  65. chooseAll() {
  66. if(this.isAll) {
  67. this.listId = []
  68. }else {
  69. this.listId = this.list2.map(item=>item.id)
  70. }
  71. },
  72. chooseItem(val) {
  73. let index = this.listId.findIndex((item)=>item==val.id)
  74. if(index==-1) {
  75. this.listId.push(val.id)
  76. }else {
  77. this.listId.splice(index, 1)
  78. }
  79. console.log(index)
  80. console.log(this.listId)
  81. },
  82. chooseMachine() {
  83. uni.$emit('chooseMachine', this.listId)
  84. uni.navigateBack()
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .btnPoz {
  91. position: fixed;
  92. bottom: 30rpx;
  93. left: 0;
  94. width: 100%;
  95. padding: 0 32rpx;
  96. }
  97. .top_row {
  98. display: flex;
  99. align-items: center;
  100. padding: 14rpx 30rpx;
  101. background-color: #fff;
  102. font-size: 26rpx;
  103. .selectAll {
  104. width: 130rpx;
  105. }
  106. .searchBox {
  107. flex: 1;
  108. }
  109. }
  110. .row {
  111. align-items: center;
  112. display: flex;
  113. padding: 24rpx 0;
  114. .icon {
  115. width: 32rpx;
  116. height: 32rpx;
  117. }
  118. .txt {
  119. padding: 0 16rpx;
  120. font-size: 26rpx;
  121. }
  122. }
  123. .card {
  124. margin-top: 8rpx;
  125. padding: 30rpx;
  126. }
  127. </style>