时空网前端
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.

323 lines
8.9 KiB

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