reportList.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="container">
  3. <view class="header-box">
  4. <view class="search-box">
  5. <u-search v-model="searchForm.keyword" :clearabled="true" bg-color="#E5E5E5"
  6. :input-style="searchInputStyle" placeholder="搜索您想要的内容" @search="toSearch"></u-search>
  7. </view>
  8. <view class="tab-box">
  9. <u-tabs name="label" :list="searchType" :is-scroll="true" v-model="searchForm.type"
  10. @change="onSearchTypeChange" font-size="24" :bold="false" inactive-color="#000000"
  11. active-color="#000000" :bar-style="{'background-color': '#2979ff'}" :gutter="25"
  12. height="45"></u-tabs>
  13. </view>
  14. </view>
  15. <view class="list-box">
  16. <view class="list-item-box" v-for="item in list" :key="item.id" @click="onClickReport(item)">
  17. <view class="image-box">
  18. <image :src="item.imgUrl" mode="aspectFill"></image>
  19. </view>
  20. <view class="info-box">
  21. <view class="title">
  22. {{item.title}}
  23. </view>
  24. <view class="type">
  25. <span>{{item.type}}</span>
  26. </view>
  27. <view class="func">
  28. <view class="" v-if="item.free > 0"></view>
  29. <view class="price" v-if="item.price">
  30. ¥{{item.price}}元
  31. </view>
  32. <view class="member-free" v-if="item.price == null && item.free < 1">
  33. {{item.memberFree > 0 ? '会员免费' : `会员:${item.memberPrice}元`}}
  34. </view>
  35. <view class="not-member-price" v-if="item.price == null && item.free < 1">
  36. 非会员:¥{{item.notMemberPrice}}元
  37. </view>
  38. <view v-if="item.free > 0" class="button free">免费</view>
  39. <view v-else-if="item.memberFree > 0" class="button member-free">会员免费</view>
  40. <view v-else :class="['button', item.status > 0 ? 'free' : 'buy']">
  41. {{item.status > 0 ? '已购买' : '立即购买'}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <u-loadmore :status="status" margin-top="20" margin-bottom="20" @loadmore="loadmore"/>
  48. </view>
  49. </template>
  50. <script setup>
  51. import {
  52. ref,
  53. computed
  54. } from 'vue'
  55. import {
  56. onLoad
  57. } from '@dcloudio/uni-app'
  58. import {
  59. loadReportList
  60. } from '@/api/report.js'
  61. import { useReportStore } from '@/store/reportStore.js'
  62. const reportStore = useReportStore();
  63. const customButtonStyle = {
  64. height: '40rpx',
  65. lineHeight: '40rpx',
  66. padding: '0 30rpx'
  67. }
  68. const searchInputStyle = {
  69. backgroundColor: '#E5E5E5'
  70. }
  71. const categoryList = ref({});
  72. const pageNum = ref(1);
  73. const pageSize = ref(10);
  74. const count = ref(0);
  75. const model = ref(null);
  76. const status = ref('loadmore');
  77. const searchType = ref([{
  78. label: '全部',
  79. value: ' '
  80. }
  81. ])
  82. // 对应tab的code
  83. const currentType = ref(null);
  84. function onSearchTypeChange(val) {
  85. currentType.value = searchType.value[val].value;
  86. pageNum.value = 1;
  87. search(searchForm.value.keyword, 1, model.value, currentType.value);
  88. }
  89. const searchForm = ref({
  90. keyword: '',
  91. type: 0
  92. })
  93. const modelName = ref()
  94. const list = ref([])
  95. const listFilter = ref([])
  96. function onClickReport(report) {
  97. uni.navigateTo({
  98. url: `/pages/reportDetail/reportDetail?id=${report.id}&title=${report.title}`
  99. })
  100. }
  101. function init(){
  102. searchForm.value.keyword = '';
  103. pageNum.value = 1
  104. search('', 1, model.value, currentType.value)
  105. }
  106. function search(keyword, pageNumber, model, type, pageSize) {
  107. status.value = 'loading'
  108. const form = {
  109. keyword,
  110. model,
  111. type,
  112. pageNumber,
  113. pageSize: pageSize ? pageSize : 10
  114. }
  115. loadReportList(form).then(res => {
  116. if (res.code === 0) {
  117. if (pageNumber === 1) {
  118. list.value = res.data
  119. } else {
  120. list.value = [...list.value, ...res.data];
  121. }
  122. pageNum.value = pageNumber + 1;
  123. count.value = res.count;
  124. if(list.value.length===count.value){
  125. status.value = 'nomore'
  126. }else{
  127. status.value ='loadmore'
  128. }
  129. }
  130. }).catch(()=>{
  131. status.value ='loadmore'
  132. })
  133. }
  134. function loadmore(){
  135. search(searchForm.value.keyword, pageNum.value, model.value, currentType.value);
  136. }
  137. function toSearch(){
  138. search(searchForm.value.keyword, 1, model.value, currentType.value);
  139. }
  140. onLoad((load) => {
  141. if (load.model) {
  142. // console.log(load, reportStore.reportCate , "传过来的值")
  143. searchType.value = reportStore.reportCate[load.model].child;
  144. modelName.value = load.model
  145. model.value = load.value
  146. currentType.value = searchType.value[0].value;
  147. uni.setNavigationBarTitle({
  148. title: modelName.value
  149. })
  150. init()
  151. }
  152. })
  153. </script>
  154. <style lang="scss">
  155. $image-width: 230rpx;
  156. .container {
  157. height: 100vh;
  158. width: 100vw;
  159. background-color: $uni-text-color-inverse;
  160. .header-box {
  161. padding: 0 20rpx;
  162. background-color: $uni-text-color-inverse;
  163. @include topMagnet();
  164. }
  165. .search-box {
  166. margin-bottom: 20rpx;
  167. ::v-deep(.u-search) {
  168. background-color: #e5e5e5;
  169. border-radius: 50rpx;
  170. .u-action {
  171. width: 18%;
  172. background-color: $uni-color-primary;
  173. border-radius: 50rpx;
  174. color: $uni-text-color-inverse;
  175. margin-right: 8rpx;
  176. font-size: 28rpx;
  177. line-height: 50rpx;
  178. letter-spacing: 3rpx;
  179. text-align: center;
  180. }
  181. }
  182. }
  183. .list-box {
  184. padding: 0 20rpx;
  185. .list-item-box {
  186. padding: 30rpx 20rpx;
  187. display: flex;
  188. gap: 20rpx;
  189. height: 210rpx;
  190. border-bottom: 5rpx solid #E6E6E6;
  191. &:active {
  192. background-color: $uni-bg-color-hover;
  193. }
  194. .image-box {
  195. width: $image-width;
  196. image {
  197. width: $image-width;
  198. flex: 0 0 $image-width;
  199. height: 100%;
  200. border-radius: $uni-card-border-radius;
  201. }
  202. }
  203. .info-box {
  204. .title {
  205. font-size: $uni-title-font-size-2;
  206. font-weight: bold;
  207. line-height: 40rpx;
  208. margin-bottom: 15rpx;
  209. @include text-line-overflow(2);
  210. }
  211. .type {
  212. font-size: $uni-font-size-2;
  213. .iconfont {
  214. font-size: $uni-font-size-2;
  215. padding-right: 10rpx;
  216. }
  217. }
  218. .func {
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: flex-end;
  222. font-size: $uni-font-size-2;
  223. font-weight: bold;
  224. .button {
  225. text-align: center;
  226. width: 130rpx;
  227. }
  228. .price {
  229. color: $uni-color-error;
  230. font-size: $uni-title-font-size-3;
  231. }
  232. .not-member-price {
  233. font-size: $uni-font-size-4;
  234. color: $uni-text-color-grey;
  235. text-align: end;
  236. }
  237. .buy {
  238. padding: 6rpx 25rpx;
  239. background-color: $uni-color-error;
  240. border-radius: $uni-card-border-radius;
  241. color: $uni-text-color-inverse;
  242. }
  243. .free {
  244. padding: 6rpx 25rpx;
  245. background-color: $uni-color-primary;
  246. border-radius: $uni-card-border-radius;
  247. color: $uni-text-color-inverse;
  248. }
  249. .member-free {
  250. padding: 10rpx 20rpx;
  251. @include backgroundImg('https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/bg-label.png');
  252. color: $uni-text-color;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. </style>