时空网前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
8.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <template>
  2. <view class="lf-row-center lf-flex-column">
  3. <block v-if="tab_list.length">
  4. <view class="ctab">
  5. <u-tabs :list="tab_list" :is-scroll="true" :show-bar="false" :current="current" @change="change"></u-tabs>
  6. </view>
  7. <swiper :style="{height: 'calc('+ windowHeight +'px - 110rpx)', width: '750rpx'}" :current="current" @change="swiperChange">
  8. <swiper-item v-for="(tab, tabIndex) in tab_list" :key="tabIndex">
  9. <scroll-view class="com" :scroll-y="true" :refresher-enabled="true" :refresher-triggered="isRefresher" @scrolltolower="onScrolltolower" @refresherrefresh="onRefresherrefresh">
  10. <view class="lf-row-between list" v-for="(item, index) in tab.list" :key="item.id" @click="toDetail(item)">
  11. <view class="left">
  12. <image :src="item.cover" mode="aspectFill"></image>
  13. </view>
  14. <view class="right">
  15. <view class="lf-line-2 title">{{ item.name }}</view>
  16. <view class="lf-flex tips">
  17. <view class="lf-row-between lf-flex-1" v-if="item.specs[0]">
  18. <view class="lf-flex">
  19. <view class="u-line-progress">
  20. <u-line-progress :percent="item.specs[0].sold_percent" height="20" :striped="true" active-color="#FE9903" :show-percent="false" inactive-color="#F5F5F5"></u-line-progress>
  21. </view>
  22. <text class="progress lf-m-r-10">{{ item.specs[0].sold_percent_text }}</text>
  23. </view>
  24. <view>
  25. <text class="bought">{{ item.specs[0].sold_stock_text }}</text>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="lf-row-between price">
  30. <lf-price :price="item.specs[0].selling_price" v-if="item.specs[0]"></lf-price>
  31. <text class="lf-font-24 original-price" v-if="item.specs[0]">{{ item.specs[0].original_price }}</text>
  32. <text v-else></text>
  33. <button>立即抢购</button>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 空数据的情况 -->
  38. <view class="loading-more">
  39. <text v-if="tab.list.length" :class="{'loading-more-text': tab.loadingClass}">{{ tab.loadingText }}</text>
  40. <my-nocontent v-else></my-nocontent>
  41. </view>
  42. <!-- 回到顶部 -->
  43. <u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
  44. </scroll-view>
  45. </swiper-item>
  46. </swiper>
  47. </block>
  48. <block v-else>
  49. <my-nocontent></my-nocontent>
  50. </block>
  51. </view>
  52. </template>
  53. <script>
  54. let SparkMD5 = require("@/common/SparkMD5.js"); // 签名加密js文件
  55. export default {
  56. data() {
  57. return {
  58. tab_list: [],
  59. current: 0, // tab下表
  60. pageSize: 10,
  61. shareInfo: {},
  62. windowHeight: 0, // 屏幕可用高度
  63. isRefresher: false ,// scroll-view下拉刷新状态,当前默认没有触发
  64. pt: 1
  65. }
  66. },
  67. onLoad(options) {
  68. this.pt = options.pt || 1;
  69. this.windowHeight = getApp().globalData.windowHeight;
  70. this.getCategoryList();
  71. this.getShareInfo();
  72. if(this.pt == 2) {
  73. this.bindUsders()
  74. }
  75. },
  76. methods: {
  77. //用户绑定
  78. bindUsders() {
  79. var _this = this;
  80. let yy = new Date().getFullYear();
  81. let mm = new Date().getMonth()+1;
  82. let dd = new Date().getDate();
  83. let hh = new Date().getHours();
  84. let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
  85. let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
  86. let gettime = yy+'-'+mm+'-'+dd+' '+hh+':'+mf+':'+ss;
  87. let userInfo = uni.getStorageSync('userinfo') || {};
  88. let timeDate = Math.round(new Date().getTime() / 1000).toString();
  89. let md5TimeDate = SparkMD5.hash(timeDate)
  90. let nowTime = new Date().toLocaleString();
  91. _this.$http(_this.API.API_BINDSALES, {
  92. deed: md5TimeDate,
  93. sid: userInfo.id,
  94. t: gettime
  95. }).then(res => {
  96. _this.$msg('提交审核成功');
  97. }).catch(err => {
  98. console.log(err)
  99. })
  100. },
  101. // 获取分享信息
  102. getShareInfo(){
  103. this.$http(this.API.API_SHARE_HOME).then(res => {
  104. this.shareInfo = res.data;
  105. });
  106. },
  107. // 切换tab
  108. change(index) {
  109. this.current = index;
  110. if(this.tab_list[index].list.length <= 0){
  111. this.getGoodsList(); // tab下没有数据,请求第一页
  112. }
  113. },
  114. // 滑块下标值变化
  115. swiperChange(event){
  116. this.current = event.detail.current;
  117. if(event.detail.source == '') return; // 如果是被动出发,没有事件类型则不做处理
  118. if(this.tab_list[event.detail.current].list.length <= 0){
  119. this.getGoodsList(); // tab下没有数据,请求第一页
  120. }
  121. },
  122. // 获取分类tab
  123. getCategoryList(options = {}){
  124. this.$http(this.API.API_CATEGORY_LIST).then(res => {
  125. let res_list = res.data || [];
  126. let tab_list = res_list.map(item => {
  127. return {
  128. id: item.id,
  129. name: item.name,
  130. type: item.type,
  131. list: [],
  132. loadingClass: true,
  133. loadingText: '正在加载中',
  134. page: 1,
  135. isPage: true
  136. }
  137. });
  138. if(options.type == 'pageRefresh'){
  139. uni.stopPullDownRefresh();
  140. }else if(options.type == 'scrollRefresh'){
  141. this.isRefresher = false;
  142. }
  143. this.tab_list = tab_list;
  144. this.getGoodsList();
  145. })
  146. },
  147. // 获取分类下的商品列表
  148. getGoodsList(){
  149. let per_page = this.pageSize;
  150. let tab_item = this.tab_list[this.current];
  151. this.$http(this.API.API_GOODS_LIST, {
  152. category_id: tab_item.id,
  153. type: tab_item.type,
  154. page: tab_item.page,
  155. per_page
  156. }).then(res => {
  157. let isPage = res.data.has_more_page;
  158. tab_item.isPage = isPage;
  159. if(!isPage){
  160. tab_item.loadingClass = false;
  161. tab_item.loadingText = '没有更多数据啦~';
  162. }
  163. if(tab_item.page == 1){
  164. tab_item.list = res.data.items;
  165. }else{
  166. tab_item.list.push(...res.data.items);
  167. }
  168. })
  169. },
  170. // 去到详情页
  171. toDetail(item){
  172. this.$url('/pages/goodsDetail/index?id='+ item.id);
  173. },
  174. // 页面触底,加载下一页
  175. onScrolltolower(){
  176. let tab_item = this.tab_list[this.current];
  177. if(tab_item.isPage){
  178. tab_item.page = tab_item.page + 1;
  179. this.getGoodsList();
  180. }
  181. },
  182. // scroll-view 下拉刷新
  183. onRefresherrefresh(){
  184. this.isRefresher = true;
  185. this.getCategoryList({type: 'scrollRefresh'});
  186. }
  187. },
  188. // page 下拉刷新
  189. onPullDownRefresh(){
  190. // 新版逻辑,刷新则整个数据全部重新获取
  191. this.getCategoryList({type: 'pageRefresh'});
  192. // 旧版逻辑,刷新只刷tab下的商品列表
  193. // let tab_item = this.tab_list[this.current];
  194. // tab_item.page = 1;
  195. // tab_item.isPage = true;
  196. // tab_item.loadingClass = true;
  197. // tab_item.loadingText = '正在加载中';
  198. // this.getGoodsList();
  199. },
  200. onShareAppMessage(){
  201. let shareInfo = {
  202. title: this.shareInfo.title || '欢迎使用时空网小程序',
  203. path: '/pages/route/index?route=home'
  204. }
  205. if(this.shareInfo.cover){
  206. shareInfo.imageUrl = this.shareInfo.cover;
  207. }
  208. return shareInfo;
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .title {
  214. font-size: 28rpx;
  215. color: $u-content-color;
  216. height: 88rpx;
  217. }
  218. // tab
  219. .ctab{
  220. width: 100%;
  221. margin: 20rpx 0 0rpx 0rpx;
  222. padding: 0 22rpx;
  223. }
  224. // 商品列表
  225. .com{
  226. width: 100%;
  227. height: 100%;
  228. overflow: hidden;
  229. .list{
  230. border-radius: 10rpx;
  231. overflow: hidden;
  232. margin: 20rpx 32rpx;
  233. background-color: #FFFFFF;
  234. box-shadow: 0 10rpx 20rpx 0 rgba(0, 0, 0, 0.1);
  235. align-items: flex-start;
  236. .left{
  237. overflow: hidden;
  238. image{
  239. width: 204rpx;
  240. height: 204rpx;
  241. margin: 20rpx;
  242. border-radius: 10rpx;
  243. }
  244. }
  245. .right{
  246. overflow: hidden;
  247. width: 64%;
  248. .title{
  249. margin: 18rpx 20rpx 0 0;
  250. color: #222222;
  251. font-size: 32rpx;
  252. }
  253. .tips{
  254. margin: 16rpx 0;
  255. overflow: hidden;
  256. .u-line-progress{
  257. width: 112rpx;
  258. overflow: hidden;
  259. margin-right:20rpx ;
  260. }
  261. .progress{
  262. color: #777777;
  263. font-size: 24rpx;
  264. }
  265. .bought{
  266. color: #777777;
  267. font-size: 24rpx;
  268. margin-right: 20rpx;
  269. }
  270. }
  271. .price{
  272. overflow: hidden;
  273. color:#FF0000;
  274. .original-price{
  275. text-decoration: line-through;
  276. color: #777777;
  277. }
  278. // text{
  279. // font-size: 48rpx;
  280. // color:#FF0000;
  281. // font-weight: 500;
  282. // }
  283. // text:nth-child(1){
  284. // color: #FF0000;
  285. // font-size: 28rpx;
  286. // }
  287. // text:nth-child(2){
  288. // color: #FF0000;
  289. // font-size: 48rpx;
  290. // }
  291. // text:nth-child(3){
  292. // color: #FF0000;
  293. // font-size: 28rpx;
  294. // }
  295. // text:nth-child(4){
  296. // color: #777777;
  297. // font-size: 28rpx;
  298. // text-decoration:line-through;
  299. // font-weight: 400;
  300. // }
  301. button{
  302. width: 160rpx;
  303. height: 60rpx;
  304. background: #FE9903;
  305. border-radius: 50px;
  306. font-size: 24rpx;
  307. color: #FFFFFF;
  308. margin: 0rpx 20rpx 0rpx 20rpx;
  309. border: none;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. </style>