index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="content">
  3. <view class="content-bg flex-y-center" v-for="(item,index) of list" :key='index' @click="choice" :data-index='index'>
  4. <view class="main-icon" v-if="is_check!=2">
  5. <i class="iconfont iconxuanzhong" v-if="item.checked"></i>
  6. <i class="iconfont iconweixuanzhong" v-else style="color:#bfbfbf"></i>
  7. </view>
  8. <view class="">
  9. <view class="">
  10. {{item.name}}
  11. </view>
  12. <view class="content-bg-time">
  13. {{item.update_time}}
  14. </view>
  15. </view>
  16. </view>
  17. <view style="height: 100px;"></view>
  18. <view class="bottom-bars ">
  19. <button @click="save" v-if="is_check!=2" class="flex-center ft28" style="margin-bottom: 20rpx;">选择记录</button>
  20. <button @click="nav" class="flex-center ft28">添加{{$test.$test}}池</button>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. $test: this.$test.$test,
  29. list: [],
  30. page: 1,
  31. type: 1,
  32. is_check:1,
  33. }
  34. },
  35. onLoad(e) {
  36. this.type = e.type;
  37. this.is_check=e.is_check||1;
  38. },
  39. onShow(e) {
  40. this.page = 1;
  41. this.list = [];
  42. this.http();
  43. },
  44. onReachBottom(e) {
  45. this.http();
  46. },
  47. methods: {
  48. choice(e) {
  49. if(this.is_check==2){
  50. let index = e.currentTarget.dataset.index;
  51. let id= this.list[index].id;
  52. uni.navigateTo({
  53. url:"add-way?id="+id
  54. })
  55. return
  56. }
  57. let index = e.currentTarget.dataset.index;
  58. if (this.type == 2) {
  59. for(let i of this.list){
  60. i.checked=false
  61. }
  62. this.list[index].checked =true;
  63. } else {
  64. this.list[index].checked = !this.list[index].checked;
  65. }
  66. },
  67. nav(e) {
  68. uni.navigateTo({
  69. url: "./add-way"
  70. })
  71. },
  72. save() {
  73. let hasGoodStudentType = this.list.some((v, i) => v.checked )
  74. if(!hasGoodStudentType){
  75. uni.showToast({
  76. title: "请选择记录",
  77. icon: 'none'
  78. })
  79. return
  80. }
  81. uni.setStorageSync("list_way", this.list);
  82. uni.navigateBack();
  83. return;
  84. var pages = getCurrentPages();
  85. var currPage = pages[pages.length - 1]; //当前页面
  86. var prevPage = pages[pages.length - 2]; //上一个页面
  87. //可以打印prevPage看看
  88. console.log(prevPage)
  89. //h5的写法
  90. // #ifdef H5
  91. prevPage.powerpool_id = way_id;
  92. // #endif
  93. // #ifdef MP-WEIXIN
  94. //小程序的写法 具体要怎么写可以打印一下prevPage看一下
  95. prevPage.$vm.powerpool_id = way_id;;
  96. // #endif
  97. },
  98. http() {
  99. this.request({
  100. url: "powerpool/poollists",
  101. data: {
  102. page: this.page,
  103. token: uni.getStorageSync("token"),
  104. },
  105. }).then(res => {
  106. console.log(res, "res")
  107. if (res.code === '200') {
  108. for (var i of res.data) {
  109. i.checked = false;
  110. }
  111. this.list = this.list.concat(res.data);
  112. this.page = this.page + 1;
  113. }
  114. })
  115. },
  116. },
  117. }
  118. </script>
  119. <style>
  120. .content {
  121. padding: 20rpx 0;
  122. }
  123. .content-bg {
  124. background: #FAFAFA;
  125. width: 670rpx;
  126. margin: 0 auto;
  127. margin-bottom: 20rpx;
  128. padding: 20rpx;
  129. border-radius: 8rpx;
  130. }
  131. .content-bg-time {
  132. font-size: 26rpx;
  133. color: 999;
  134. }
  135. .main-icon {
  136. margin-right: 33rpx;
  137. }
  138. .main-icon .iconfont {
  139. font-size: 38rpx;
  140. }
  141. .iconxuanzhong {
  142. color: #007AFF;
  143. }
  144. </style>