reportList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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: 20rpx 0 10rpx;">
  10. <u-tabs name="label" :list="searchType" :is-scroll="true" v-model="searchForm.type"
  11. @change="onSearchTypeChange" font-size="28" :bold="false" inactive-color="#000000"
  12. :bar-style="{'background-color': '#2979ff'}" :gutter="35" :show-bar="false"
  13. duration="0" height="45" 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 lang="scss">
  200. $image-width: 230rpx;
  201. .container {
  202. // height: 100vh;
  203. width: 100vw;
  204. background-color: $uni-text-color-inverse;
  205. .header-box {
  206. padding: 0 20rpx;
  207. background-color: $uni-text-color-inverse;
  208. @include topMagnet();
  209. }
  210. .search-box {
  211. margin-bottom: 20rpx;
  212. ::v-deep(.u-search) {
  213. background-color: #e5e5e5;
  214. border-radius: 50rpx;
  215. .u-action {
  216. width: 18%;
  217. background-color: $uni-color-primary;
  218. border-radius: 50rpx;
  219. color: $uni-text-color-inverse;
  220. margin-right: 8rpx;
  221. font-size: 28rpx;
  222. line-height: 50rpx;
  223. letter-spacing: 3rpx;
  224. text-align: center;
  225. }
  226. }
  227. }
  228. .list-box {
  229. padding: 0 20rpx;
  230. .list-item-box {
  231. padding: 30rpx 20rpx;
  232. display: flex;
  233. gap: 20rpx;
  234. // height: 210rpx;
  235. border-bottom: 5rpx solid #E6E6E6;
  236. &:active {
  237. background-color: $uni-bg-color-hover;
  238. }
  239. .image-box {
  240. width: $image-width;
  241. image {
  242. width: $image-width;
  243. flex: 0 0 $image-width;
  244. height: 100%;
  245. border-radius: $uni-card-border-radius;
  246. }
  247. }
  248. .info-box {
  249. .title {
  250. font-size: $uni-title-font-size-2;
  251. font-weight: bold;
  252. line-height: 40rpx;
  253. margin-bottom: 15rpx;
  254. @include text-line-overflow(2);
  255. }
  256. .type {
  257. font-size: $uni-font-size-2;
  258. .iconfont {
  259. font-size: $uni-font-size-2;
  260. padding-right: 10rpx;
  261. }
  262. }
  263. .func {
  264. display: flex;
  265. justify-content: space-between;
  266. align-items: flex-end;
  267. font-size: $uni-font-size-2;
  268. font-weight: bold;
  269. margin-top: 10rpx;
  270. .func-box {
  271. display: flex;
  272. justify-content: space-between;
  273. width: 100%;
  274. align-items: center;
  275. }
  276. .button {
  277. text-align: center;
  278. width: 130rpx;
  279. }
  280. .price {
  281. color: $uni-color-error;
  282. font-size: $uni-title-font-size-3;
  283. }
  284. .not-member-price {
  285. font-size: $uni-font-size-4;
  286. color: $uni-text-color-grey;
  287. text-align: end;
  288. }
  289. .buy {
  290. padding: 6rpx 25rpx;
  291. background-color: $uni-color-error;
  292. border-radius: $uni-card-border-radius;
  293. color: $uni-text-color-inverse;
  294. }
  295. .free {
  296. padding: 6rpx 25rpx;
  297. background-color: $uni-color-primary;
  298. border-radius: $uni-card-border-radius;
  299. color: $uni-text-color-inverse;
  300. }
  301. .member-free {
  302. padding: 10rpx 20rpx;
  303. @include backgroundImg('https://www.gzrea.cn/wxmp/static/icon/bg-label.png');
  304. color: $uni-text-color;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. </style>