index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <app-layout>
  3. <app-swiper :height="280" :list="banner_list" name="pic_url" :autoplay="true"></app-swiper>
  4. <view @click="qrcode" v-if="setting.cs_status ===1 && setting.cs_prompt_pic" class="lottery-share">
  5. <image :src="setting.cs_prompt_pic" mode="aspectFit" load-lazy></image>
  6. </view>
  7. <view class="dir-top-nowrap bottom">
  8. <view class="lottery cross-center" v-for="(v,k) in list" :key="k">
  9. <view class="lottery-image box-grow-0">
  10. <view>{{v.lottery_log_count}}人参与</view>
  11. <image :src="v.cover_pic" load-lazy></image>
  12. </view>
  13. <view class="dir-top-nowrap lottery-desc box-grow-1" @click="goods(v)">
  14. <view class="box-grow-0 goods-name t-omit-two">{{v.goods_name}}</view>
  15. <view class="box-grow-1 dir-left cross-center activity">
  16. <icon class="activity-icon"></icon>
  17. <text v-if="v.new_status == 2">距活动开始:</text>
  18. <text v-else>距活动结束:</text>
  19. <text v-if="times[k].day>0 || times[k].hour>0">
  20. <text class="red">{{times[k].day}}</text>
  21. <text>天</text>
  22. <text class="red">{{times[k].hour}}</text>
  23. <text>小时</text>
  24. </text>
  25. <text v-if="times[k].day==0 && times[k].hour==0">
  26. <text class="red">{{times[k].minute}}</text>
  27. <text>分</text>
  28. <text class="red">{{times[k].second}}</text>
  29. <text>秒</text>
  30. </text>
  31. </view>
  32. <view class="stock box-grow-0">共{{v.stock}}份</view>
  33. <view class="dir-left-nowrap cross-center box-grow-0 end">
  34. <view class="price box-grow-1 dir-left-nowrap">
  35. <view class="currency">免费</view>
  36. <view class="original">原价¥{{v.price}}</view>
  37. </view>
  38. <view class="price box-grow-0">
  39. <view v-if="v.new_status == 2" @click.stop>
  40. <app-button height="56" font-size="28" color="#FFFFFF" round
  41. background="#cdcdcd" width="164" disabled>尚未开始
  42. </app-button>
  43. </view>
  44. <app-button v-else-if="v.new_status == 1" height="56" font-size="28" color="#FFFFFF" round
  45. background="#cdcdcd" width="164" disabled>已参与
  46. </app-button>
  47. <view v-else @click.stop="detail(v.id)">
  48. <app-button height="56" font-size="28" color="#FFFFFF" background="#ff4544" width="164"
  49. round>立即抽奖
  50. </app-button>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <app-load-text v-if="load"></app-load-text>
  57. </view>
  58. <common-buttom status="index"></common-buttom>
  59. </app-layout>
  60. </template>
  61. <script>
  62. import appSwiper from "../../../components/page-component/app-swiper/app-swiper.vue";
  63. import commonButtom from "../common-buttom.vue";
  64. export default {
  65. name: "index",
  66. components: {appSwiper, commonButtom},
  67. data() {
  68. let integral;
  69. return {
  70. integral,
  71. args: false,
  72. load: false,
  73. page: 1,
  74. list: null,
  75. times: null,
  76. title: '幸运抽奖',
  77. banner_list: null,
  78. setting: null,
  79. template_message: null,
  80. }
  81. },
  82. onHide: function () {
  83. clearInterval(this.integral);
  84. },
  85. onUnload: function () {
  86. clearInterval(this.integral);
  87. },
  88. onLoad: function (options) {
  89. const self = this;
  90. self.$request({
  91. url: self.$api.lottery.setting,
  92. }).then(info => {
  93. if (info.code === 0) {
  94. self.setting = info.data.setting;
  95. uni.setNavigationBarTitle({
  96. title: self.setting.title,
  97. });
  98. self.title = self.setting.title;
  99. }
  100. })
  101. },
  102. onReachBottom: function () {
  103. const self = this;
  104. if (self.args || self.load)
  105. return;
  106. self.load = true;
  107. let page = self.page + 1;
  108. self.$request({
  109. url: self.$api.lottery.index,
  110. data: {
  111. page: page,
  112. }
  113. }).then(info => {
  114. if (info.code === 0) {
  115. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(info.data.list)];
  116. let time = self.list.map(v => {
  117. return v.new_status == 2 ? v.start_at : v.end_at;
  118. })
  119. self.setTimeStart(time);
  120. }
  121. self.load = false;
  122. });
  123. },
  124. onShow: function () {
  125. const self = this;
  126. self.$showLoading({title: '加载中'});
  127. self.$request({
  128. url: self.$api.lottery.index,
  129. }).then(info => {
  130. self.$hideLoading();
  131. if (info.code === 0) {
  132. [
  133. self.banner_list,
  134. self.list,
  135. self.banner_list,
  136. self.template_message
  137. ] = [
  138. info.data.banner_list,
  139. info.data.list,
  140. info.data.banner_list,
  141. info.data.template_message
  142. ];
  143. [self.page, self.args] = [1, false];
  144. let time = self.list.map(v => {
  145. return v.new_status == 2 ? v.start_at : v.end_at;
  146. })
  147. self.setTimeStart(time);
  148. }
  149. }).catch(e => {
  150. self.$hideLoading();
  151. })
  152. },
  153. //
  154. onShareAppMessage: function () {
  155. return this.$shareAppMessage({
  156. title: this.title,
  157. path: '/plugins/lottery/index/index',
  158. params: {},
  159. });
  160. },
  161. methods: {
  162. qrcode() {
  163. uni.navigateTo({url: `/plugins/lottery/qrcode/qrcode`})
  164. },
  165. goods(data) {
  166. uni.navigateTo({
  167. url: `/plugins/lottery/goods/goods?lottery_id=${data.id}`
  168. });
  169. },
  170. detail(id) {
  171. uni.navigateTo({
  172. url: `/plugins/lottery/goods/goods?lottery_id=`+id
  173. });
  174. // this.$subscribe(this.template_message).then(res => {
  175. // uni.navigateTo({url: `/plugins/lottery/detail/detail?lottery_id=` + id});
  176. // }).catch(res => {
  177. // uni.navigateTo({url: `/plugins/lottery/detail/detail?lottery_id=` + id});
  178. // });
  179. },
  180. setTimeStart(info) {
  181. const self = this;
  182. clearInterval(self.integral);
  183. let func = function (info) {
  184. let times = [];
  185. info.map((item, index, array) => {
  186. let time = item.replace(/-/g, '/');
  187. let diff_time = parseInt((new Date(time).getTime() - new Date().getTime()) / 1000)
  188. let day = 0, hour = 0, minute = 0, second = 0;
  189. if (diff_time > 0) {
  190. day = Math.floor(diff_time / (60 * 60 * 24));
  191. hour = Math.floor(diff_time / (60 * 60)) - (day * 24);
  192. minute = Math.floor(diff_time / 60) - (day * 24 * 60) - (hour * 60);
  193. second = Math.floor(diff_time) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
  194. }
  195. times[index] = {day, hour, minute, second}
  196. })
  197. self.times = times;
  198. }
  199. func(info);
  200. self.integral = setInterval(() => {
  201. func(info)
  202. }, 1000)
  203. }
  204. }
  205. }
  206. </script>
  207. <style scoped lang="scss">
  208. .lottery-share {
  209. margin-top: #{20rpx};
  210. image {
  211. height: #{150rpx};
  212. width: 100%;
  213. display: block;
  214. }
  215. }
  216. .bottom {
  217. //margin-bottom: #{96rpx}
  218. }
  219. .lottery {
  220. margin-top: #{20rpx};
  221. width: 100%;
  222. height: #{268rpx};
  223. background: #FFFFFF;
  224. .lottery-image {
  225. padding-left: #{24rpx};
  226. position: relative;
  227. margin: #{24rpx} 0;
  228. view {
  229. position: absolute;
  230. top: 0;
  231. left: #{24rpx};
  232. color: #ff4544;
  233. background: #ffe4e7;
  234. line-height: #{40rpx};
  235. padding: 0 #{12rpx};
  236. border-radius: 0 #{25rpx} #{25rpx} 0;
  237. font-size: #{24rpx};
  238. }
  239. image {
  240. width: #{220rpx};
  241. height: #{220rpx};
  242. display: block;
  243. }
  244. }
  245. .lottery-desc {
  246. align-self: flex-start;
  247. margin: #{24rpx};
  248. height: #{220rpx};
  249. .goods-name {
  250. color: #353535;
  251. font-size: #{28rpx};
  252. margin-bottom: #{10rpx};
  253. }
  254. .activity-icon {
  255. background-image: url('./../image/lottery_time.png');
  256. background-repeat: no-repeat;
  257. background-size: 100% 100%;
  258. height: #{24rpx};
  259. width: #{24rpx};
  260. margin-right: #{12rpx};
  261. }
  262. .activity {
  263. font-size: #{26rpx};
  264. color: #999999;
  265. .red {
  266. color: #ff4544;
  267. }
  268. }
  269. .stock {
  270. font-size: #{26rpx};
  271. color: #999999;
  272. margin-top: #{10rpx};
  273. }
  274. .end {
  275. width: 100%;
  276. }
  277. .price {
  278. font-size: #{28rpx};
  279. .currency {
  280. color: #ff4544;
  281. }
  282. .original {
  283. margin-left: #{12rpx};
  284. text-decoration: line-through;
  285. color: #999999;
  286. }
  287. }
  288. }
  289. }
  290. </style>