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

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