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

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