reportList.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. <u-empty
  16. mode="data"
  17. v-if="list.length === 0"
  18. iconSize="120"
  19. textSize="58"
  20. text="暂无数据"
  21. margin-top="50"
  22. >
  23. </u-empty>
  24. <view class="list-box">
  25. <view class="list-item-box" v-for="item in list" :key="item.id" @click="onClickReport(item)">
  26. <view class="image-box">
  27. <image :src="item.imgUrl" mode="aspectFill"></image>
  28. </view>
  29. <view class="info-box">
  30. <view class="title">
  31. {{item.title}}
  32. </view>
  33. <view class="type">
  34. <span>{{item.type}}</span>
  35. </view>
  36. <view class="func">
  37. <!-- 如果是免费,直接显示免费 -->
  38. <view v-if="item.viewMode==='1'" class="func-box" style="justify-content: flex-end;">
  39. <view class="button free" >免费</view>
  40. </view>
  41. <view v-else-if="item.viewMode==='2' && isMember" class="func-box">
  42. <view class="price">¥{{ item.price }}元</view>
  43. <view class="button member-free">会员免费</view>
  44. </view>
  45. <view v-else-if="item.viewMode==='2' && !isMember" class="func-box">
  46. <view style="flex: 0 0 auto;display: flex;align-items: center;">
  47. <view class="member-free">
  48. 会员免费
  49. </view>
  50. <view class="not-member-price">
  51. 非会员:¥{{item.price}}元
  52. </view>
  53. </view>
  54. <view :class="['button', item.hasBuy ? 'free' : 'buy']">
  55. {{item.hasBuy ? '已购买' : '立即购买'}}
  56. </view>
  57. </view>
  58. <view v-else-if="item.viewMode==='3' && item.price===item.priceMember" class="func-box">
  59. <view class="price">¥{{ item.price }}元</view>
  60. <view :class="['button', item.hasBuy ? 'free' : 'buy']">
  61. {{item.hasBuy ? '已购买' : '立即购买'}}
  62. </view>
  63. </view>
  64. <view v-else-if="item.viewMode==='3' && item.price!==item.priceMember" class="func-box">
  65. <view style="flex: 0 0 auto;display: flex;align-items: center;">
  66. <view class="member-free">
  67. {{`会员:${item.priceMember}元`}}
  68. </view>
  69. <view class="not-member-price">
  70. 非会员:¥{{item.price}}元
  71. </view>
  72. </view>
  73. <view :class="['button', item.hasBuy ? 'free' : 'buy']">
  74. {{item.hasBuy ? '已购买' : '立即购买'}}
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <u-loadmore v-if="list.length !==0 && status !== 'nomore'"
  82. :status="status" margin-top="20" margin-bottom="20"
  83. @loadmore="loadmore" />
  84. </view>
  85. </template>
  86. <script setup>
  87. import {
  88. ref,
  89. computed
  90. } from 'vue'
  91. import {
  92. onLoad, onReachBottom
  93. } from '@dcloudio/uni-app'
  94. import {
  95. loadReportList
  96. } from '@/api/report.js'
  97. import {
  98. useReportStore
  99. } from '@/store/reportStore.js'
  100. import {
  101. useAuthStore
  102. } from '@/store/authStore.js'
  103. const reportStore = useReportStore();
  104. const authStore = useAuthStore();
  105. const customButtonStyle = {
  106. height: '40rpx',
  107. lineHeight: '40rpx',
  108. padding: '0 30rpx'
  109. }
  110. const searchInputStyle = {
  111. backgroundColor: '#E5E5E5'
  112. }
  113. const isMember = ref(false);
  114. const categoryList = ref({});
  115. const pageNum = ref(1);
  116. const pageSize = ref(10);
  117. const count = ref(0);
  118. const model = ref(null);
  119. const status = ref('loadmore');
  120. const searchType = ref([{
  121. label: '全部',
  122. value: ' '
  123. }])
  124. // 对应tab的code
  125. const currentType = ref(null);
  126. function onSearchTypeChange(val) {
  127. currentType.value = searchType.value[val].value;
  128. pageNum.value = 1;
  129. search(searchForm.value.keyword, 1, model.value, currentType.value);
  130. }
  131. const searchForm = ref({
  132. keyword: '',
  133. type: 0
  134. })
  135. const modelName = ref()
  136. const list = ref([])
  137. const listFilter = ref([])
  138. function onClickReport(report) {
  139. uni.navigateTo({
  140. url: `/pages/reportDetail/reportDetail?id=${report.id}&title=${report.title}`
  141. })
  142. }
  143. function init() {
  144. searchForm.value.keyword = '';
  145. pageNum.value = 1
  146. search('', 1, model.value, currentType.value)
  147. }
  148. function search(keyword, pageNumber, model, type, pageSize) {
  149. status.value = 'loading'
  150. const form = {
  151. keyword,
  152. model,
  153. type,
  154. pageNumber,
  155. pageSize: pageSize ? pageSize : 10
  156. }
  157. loadReportList(form).then(res => {
  158. // console.log(res)
  159. if (res.code === 0) {
  160. if (pageNumber === 1) {
  161. list.value = res.data
  162. } else {
  163. list.value = [...list.value, ...res.data];
  164. }
  165. pageNum.value = pageNumber + 1;
  166. count.value = res.count;
  167. if(list.value.length===count.value){
  168. status.value = 'nomore'
  169. }else{
  170. status.value ='loadmore'
  171. }
  172. }
  173. }).catch(() => {
  174. status.value = 'loadmore'
  175. })
  176. }
  177. function loadmore() {
  178. if(list.value.length === count.value){
  179. return
  180. }
  181. search(searchForm.value.keyword, pageNum.value, model.value, currentType.value);
  182. }
  183. function toSearch() {
  184. search(searchForm.value.keyword, 1, model.value, currentType.value);
  185. }
  186. onReachBottom(()=>{
  187. loadmore()
  188. })
  189. onLoad((load) => {
  190. isMember.value = authStore.userInfo.isMember === '0' ? false : true;
  191. if (load.model) {
  192. // console.log(load, reportStore.reportCate , "传过来的值")
  193. searchType.value = reportStore.reportCate[load.model].child;
  194. modelName.value = load.model
  195. model.value = load.value
  196. currentType.value = searchType.value[0].value;
  197. uni.setNavigationBarTitle({
  198. title: modelName.value
  199. })
  200. init()
  201. }
  202. })
  203. </script>
  204. <style lang="scss">
  205. $image-width: 230rpx;
  206. .container {
  207. // height: 100vh;
  208. width: 100vw;
  209. background-color: $uni-text-color-inverse;
  210. .header-box {
  211. padding: 0 20rpx;
  212. background-color: $uni-text-color-inverse;
  213. @include topMagnet();
  214. }
  215. .search-box {
  216. margin-bottom: 20rpx;
  217. ::v-deep(.u-search) {
  218. background-color: #e5e5e5;
  219. border-radius: 50rpx;
  220. .u-action {
  221. width: 18%;
  222. background-color: $uni-color-primary;
  223. border-radius: 50rpx;
  224. color: $uni-text-color-inverse;
  225. margin-right: 8rpx;
  226. font-size: 28rpx;
  227. line-height: 50rpx;
  228. letter-spacing: 3rpx;
  229. text-align: center;
  230. }
  231. }
  232. }
  233. .list-box {
  234. padding: 0 20rpx;
  235. .list-item-box {
  236. padding: 30rpx 20rpx;
  237. display: flex;
  238. gap: 20rpx;
  239. // height: 210rpx;
  240. border-bottom: 5rpx solid #E6E6E6;
  241. &:active {
  242. background-color: $uni-bg-color-hover;
  243. }
  244. .image-box {
  245. width: $image-width;
  246. image {
  247. width: $image-width;
  248. flex: 0 0 $image-width;
  249. height: 100%;
  250. border-radius: $uni-card-border-radius;
  251. }
  252. }
  253. .info-box {
  254. .title {
  255. font-size: $uni-title-font-size-2;
  256. font-weight: bold;
  257. line-height: 40rpx;
  258. margin-bottom: 15rpx;
  259. @include text-line-overflow(2);
  260. }
  261. .type {
  262. font-size: $uni-font-size-2;
  263. .iconfont {
  264. font-size: $uni-font-size-2;
  265. padding-right: 10rpx;
  266. }
  267. }
  268. .func {
  269. display: flex;
  270. justify-content: space-between;
  271. align-items: flex-end;
  272. font-size: $uni-font-size-2;
  273. font-weight: bold;
  274. margin-top: 10rpx;
  275. .func-box {
  276. display: flex;
  277. justify-content: space-between;
  278. width: 100%;
  279. align-items: center;
  280. }
  281. .button {
  282. text-align: center;
  283. width: 130rpx;
  284. }
  285. .price {
  286. color: $uni-color-error;
  287. font-size: $uni-title-font-size-3;
  288. }
  289. .not-member-price {
  290. font-size: $uni-font-size-4;
  291. color: $uni-text-color-grey;
  292. text-align: end;
  293. }
  294. .buy {
  295. padding: 6rpx 25rpx;
  296. background-color: $uni-color-error;
  297. border-radius: $uni-card-border-radius;
  298. color: $uni-text-color-inverse;
  299. }
  300. .free {
  301. padding: 6rpx 25rpx;
  302. background-color: $uni-color-primary;
  303. border-radius: $uni-card-border-radius;
  304. color: $uni-text-color-inverse;
  305. }
  306. .member-free {
  307. padding: 10rpx 20rpx;
  308. @include backgroundImg('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  309. color: $uni-text-color;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. </style>