reportList.vue 8.6 KB

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