content.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="page" v-if="fetch && fetch.top">
  3. <use-tabbar :tabbar="false"></use-tabbar>
  4. <view class="use-header dflex padding-lr-sm w-full bg-drak" >
  5. <!-- 头部组件 -->
  6. <view class="use-search dflex-b border-radius-lg padding-lr w-full">
  7. <u-input
  8. :placeholder="searchTip"
  9. border="none"
  10. v-model="searchValue"
  11. ></u-input>
  12. <view class="iconfont iconsousuo-01" @click="search"></view>
  13. </view>
  14. </view>
  15. <view class="category">
  16. <!-- 左侧滚动分类 -->
  17. <scroll-view class="left" scroll-y>
  18. <u-sidebar v-model="top" @change="loadTop" :activeBold="true" lineColor="#ff6b6b" activeColor="#ff6b6b"
  19. activeBgColor="#ffffff00">
  20. <u-sidebar-item v-for="(item, index) in fetch.top" :key="index" :label="item.name"
  21. :value="item.id"></u-sidebar-item>
  22. </u-sidebar>
  23. </scroll-view>
  24. <!-- 右侧商品区域 -->
  25. <view class="right">
  26. <!-- tabs 固定 -->
  27. <view class="small-tabs-wrapper bg-main border-radius margin-bottom-sm padding-8">
  28. <u-tabs lineColor="#ff6b6b" activeColor="#ff6b6b" :list="fetch.top[top].cate" :activeStyle="{
  29. color: '#303133',
  30. fontWeight: 'bold',
  31. transform: 'scale(1.05)'
  32. }" :inactiveStyle="{
  33. color: '#606266',
  34. transform: 'scale(1)'
  35. }" @click="loadCate" scrollable></u-tabs>
  36. </view>
  37. <!-- 商品列表滚动 -->
  38. <scroll-view class="goods-list" scroll-y v-if="fetch.list && fetch.list.length > 0">
  39. <view class="use-hover" v-for="(item, index) in fetch.list" :key="index">
  40. <view class="goods border-radius padding bg-main"
  41. @click="goContentInfo(item)">
  42. <view class="margin-left-sm pos-r flex-1">
  43. <view class="name-wrap">
  44. <text class="clamp-2">{{ item.name }}</text>
  45. <u-icon v-if="item.look == 2" name="lock" size="18"></u-icon>
  46. <u-icon v-else-if="item.look >= 3" name="integral" size="18"></u-icon>
  47. </view>
  48. <!-- ✅ 价格行 -->
  49. <view class="price-box">
  50. <u--text type="info" v-if="item.info" :lines="2" :size="12" :text="item.info"></u--text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </scroll-view>
  56. <view v-else>
  57. <u-empty mode="data" :marginTop="100"></u-empty>
  58. </view>
  59. </view>
  60. </view>
  61. <use-copyright :title="fetch.channel.name" :desc="fetch.channel.desc"
  62. v-if="fetch && fetch.channel"></use-copyright>
  63. </view>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. searchTip: "请输入搜索关键字",
  70. searchValue: '',
  71. id: 0,
  72. cid: 0,
  73. fetch: {},
  74. top: 0,
  75. cate: 0
  76. };
  77. },
  78. onLoad(options) {
  79. this.id = options.id;
  80. this.cid = options.cid;
  81. this.loadData();
  82. },
  83. //下拉刷新
  84. onPullDownRefresh() {
  85. this.loadList(1);
  86. },
  87. //加载更多
  88. onReachBottom() {
  89. this.loadList(2);
  90. },
  91. methods: {
  92. // 加载数据
  93. loadData() {
  94. this.DeverApi.get(this, "source.content", {
  95. id: this.id,
  96. cid: this.cid,
  97. }, res => {
  98. this.loadList(1);
  99. });
  100. },
  101. search() {
  102. if (!this.searchValue) {
  103. return this.Dever.alert('请输入关键词');
  104. }
  105. this.loadList(1, this.searchValue);
  106. },
  107. loadTop(index) {
  108. this.top = index.index;
  109. this.loadList(1);
  110. },
  111. loadCate(tab) {
  112. this.cate = tab.index;
  113. this.loadList(1);
  114. },
  115. loadList(page, search) {
  116. if (!search) {
  117. search = ''
  118. }
  119. var id = this.fetch.top[this.top].id;
  120. if (id >= 0) {
  121. this.DeverApi.page([page, "list"], this, "source.contentList", {
  122. id: this.id,
  123. cid: this.cid,
  124. cate_id: id,
  125. search: search,
  126. });
  127. }
  128. },
  129. goContentInfo(item) {
  130. if (item.look == 2) {
  131. // 购买规格
  132. this.Dever.confirm(item.buy, () => {
  133. this.buy(item)
  134. });
  135. } else if (item.look >= 3) {
  136. this.Dever.confirm(item.score, () => {
  137. this.DeverApi.post('source.contentBuy', {id:item.id}, r => {
  138. this.Dever.success('付费成功', () => {
  139. this.Dever.location('source/content_info?id=' + item.id + '&title=' + item.name)
  140. })
  141. });
  142. });
  143. } else {
  144. this.Dever.location('source/content_info?id=' + item.id + '&title=' + item.name)
  145. }
  146. },
  147. buy(item) {
  148. if (!this.DeverApi.getToken()) {
  149. this.Dever.confirm('您需要登录才能继续操作', () => {
  150. this.Dever.goLogin();
  151. })
  152. return;
  153. }
  154. var detail = [{
  155. id: item.info_id,
  156. sku_id: item.sku_id,
  157. num: 1
  158. }]
  159. this.Dever.data('detail', {
  160. type: 'source',
  161. type_id: item.cate_id,
  162. detail: detail,
  163. //jump: 'source/content?id=' + item.info_id,
  164. jump: 'source/content_info?id=' + item.id + '&title=' + item.name,
  165. });
  166. this.Dever.location('order/create');
  167. },
  168. }
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .page {
  173. display: flex;
  174. flex-direction: column;
  175. height: 100vh;
  176. overflow: hidden;
  177. background: #f5f5f5;
  178. }
  179. .use-header {
  180. height: 96rpx;
  181. }
  182. .category {
  183. flex: 1;
  184. display: flex;
  185. overflow: hidden;
  186. }
  187. .left {
  188. width: 198rpx;
  189. overflow-y: auto;
  190. -webkit-overflow-scrolling: touch;
  191. background-color: #f5f5f5;
  192. }
  193. .right {
  194. flex: 1;
  195. display: flex;
  196. flex-direction: column;
  197. overflow: hidden;
  198. background-color: #fff;
  199. }
  200. .small-tabs-wrapper {
  201. padding: 8rpx;
  202. margin-bottom: 12rpx;
  203. background: #fff;
  204. }
  205. .goods-list {
  206. flex: 1;
  207. overflow-y: auto;
  208. -webkit-overflow-scrolling: touch;
  209. padding-left: 4rpx;
  210. padding-right: 18rpx;
  211. }
  212. .goods {
  213. display: flex;
  214. padding-bottom: 14rpx;
  215. }
  216. .goods .goods-left image {
  217. width: 120rpx;
  218. height: 120rpx;
  219. }
  220. .use-tag {
  221. border-top-left-radius: 8rpx;
  222. border-bottom-right-radius: 8rpx;
  223. line-height: 1;
  224. padding: 8rpx 12rpx;
  225. font-size: 20rpx;
  226. background-color: #ff6b6c;
  227. color: #fff;
  228. }
  229. .price-box {
  230. margin-top: 20rpx;
  231. }
  232. .price {
  233. font-size: 32rpx;
  234. font-weight: bold;
  235. color: #ff6b6b;
  236. line-height: 1;
  237. flex-shrink: 0;
  238. /* 不让价格被挤压 */
  239. }
  240. .m-price {
  241. font-size: 24rpx;
  242. color: #999;
  243. text-decoration: line-through;
  244. line-height: 1;
  245. flex-shrink: 0;
  246. /* 不让原价被挤压 */
  247. }
  248. .price-desc {
  249. font-size: 24rpx;
  250. color: #666;
  251. }
  252. /* 免费标签 */
  253. .free-tag {
  254. color: #4caf50;
  255. background-color: #e6f5ea;
  256. padding: 4rpx 10rpx;
  257. border-radius: 6rpx;
  258. font-size: 24rpx;
  259. line-height: 1;
  260. }
  261. .name-wrap {
  262. display: flex;
  263. align-items: center; /* 垂直居中 */
  264. }
  265. .use-header {
  266. height: 100rpx;
  267. }
  268. .use-search {
  269. height: 70rpx;
  270. line-height: 70rpx;
  271. background-color: #fff;
  272. text {
  273. color: #c0c0c0;
  274. }
  275. .iconfont {
  276. font-size: $font-base + 6upx;
  277. color: #c0c0c0;
  278. }
  279. }
  280. </style>