index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <app-layout>
  3. <view class="index">
  4. <view class="search-input">
  5. <search-input :theme="getTheme"></search-input>
  6. </view>
  7. <view class="index-swipe" v-if="picture_list.length > 0">
  8. <index-swipe :pictures="picture_list"></index-swipe>
  9. </view>
  10. <view class="index-product-list">
  11. <product-list :theme="themeObject" :product="product_list" ></product-list>
  12. </view>
  13. </view>
  14. </app-layout>
  15. </template>
  16. <script>
  17. import searchInput from '../components/search-input.vue';
  18. import indexSwipe from '../components/index-swipe.vue';
  19. import indexProductList from '../components/index-product-list.vue';
  20. import {mapGetters} from "vuex";
  21. export default {
  22. name: 'index',
  23. data() {
  24. return {
  25. product_list: [],
  26. picture_list: [],
  27. page_count: 1,
  28. interval: null,
  29. page: 1,
  30. }
  31. },
  32. onHide() {
  33. clearInterval(this.interval);
  34. },
  35. onUnload() {
  36. clearInterval(this.interval);
  37. },
  38. onLoad() {
  39. this.requestBanner().then(() => {
  40. this.requestList();
  41. });
  42. // #ifdef MP-WEIXIN
  43. wx.showShareMenu({
  44. menus: ['shareAppMessage', 'shareTimeline']
  45. })
  46. // #endif
  47. },
  48. methods: {
  49. cutoffTime(product_list) {
  50. let now = (new Date()).getTime();
  51. product_list.map((item, index) => {
  52. let end_time = new Date(item.advanceGoods.end_prepayment_at.replace(/-/g, '/')).getTime();
  53. let timing = end_time - now;
  54. if (timing > 0) {
  55. let day = parseInt(timing/1000/60/60/24);
  56. let hou = parseInt((timing/1000/60/60)%24);
  57. let min = parseInt((timing/1000/60)%60);
  58. let sec = parseInt((timing/1000)%60);
  59. if (day > 0) {
  60. this.$set(product_list[index], 'html', `${day}天${hou}:${(min<10?"0"+min:min)}:${(sec<10?"0"+sec:sec)}`);
  61. } else {
  62. this.$set(product_list[index], 'html', `${hou}:${(min<10?"0"+min:min)}:${(sec<10?"0"+sec:sec)}`);
  63. }
  64. } else {
  65. this.$delete(product_list, index);
  66. if (this.product_list.length < 10 && this.page_count > 1) {
  67. this.product_list = [];
  68. this.requestList();
  69. }
  70. }
  71. })
  72. },
  73. set_interval() {
  74. clearInterval(this.interval);
  75. this.cutoffTime(this.product_list);
  76. this.interval = setInterval(() => {
  77. this.cutoffTime(this.product_list);
  78. }, 1000);
  79. },
  80. async requestList() {
  81. const res = await this.$request({
  82. url: this.$api.advance.goods,
  83. method: 'get',
  84. data: {
  85. page: this.page,
  86. }
  87. });
  88. if (res.code === 0) {
  89. this.product_list.push(...res.data.list);
  90. this.page_count = res.data.pagination.page_count;
  91. this.set_interval();
  92. }
  93. },
  94. async requestBanner() {
  95. this.$request({
  96. url: this.$api.advance.banner,
  97. method: 'get',
  98. }).then(res => {
  99. if (res.code === 0) {
  100. this.picture_list = res.data.list;
  101. }
  102. })
  103. }
  104. },
  105. components: {
  106. 'search-input': searchInput,
  107. 'index-swipe' : indexSwipe,
  108. 'product-list': indexProductList,
  109. },
  110. onShareAppMessage() {
  111. return this.$shareAppMessage({
  112. path: '/plugins/advance/index/index',
  113. title: this.$children[0].navigationBarTitle,
  114. });
  115. },
  116. // #ifdef MP-WEIXIN
  117. onShareTimeline() {
  118. // 分享朋友圈beta
  119. return this.$shareTimeline({
  120. title: this.$children[0].navigationBarTitle,
  121. query: {
  122. } // 此处填写页面的参数
  123. });
  124. },
  125. // #endif
  126. computed: {
  127. ...mapGetters('mallConfig', {
  128. getTheme: 'getTheme',
  129. }),
  130. themeObject:function() {
  131. return {
  132. back: this.getTheme + '-m-back ' + this.getTheme,
  133. backQ: this.getTheme + '-m-back-q ' + this.getTheme,
  134. theme: this.getTheme,
  135. color: this.getTheme + '-m-text ' + this.getTheme,
  136. sBack: this.getTheme + '-s-back ' + this.getTheme
  137. }
  138. }
  139. },
  140. onReachBottom() {
  141. if (this.page < this.page_count) {
  142. this.page++;
  143. this.requestList();
  144. }
  145. },
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. .index {
  150. position: absolute;
  151. width: 100%;
  152. height: 100%;
  153. background-color: #f7f7f7;
  154. padding-top: #{88upx};
  155. }
  156. .index-product-list {
  157. margin-top: #{20rpx};
  158. }
  159. </style>