index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 && 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" type></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="27" color="#FFFFFF" round
  45. background="#cdcdcd" width="164" disabled>已参与
  46. </app-button>
  47. <view v-else @click.stop="validateIntegral(v)">
  48. <app-button height="56" font-size="27" 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. <integral-model ref="integralModel" :text="deplete_integral_num + '积分'" @next="detail"></integral-model>
  60. </app-layout>
  61. </template>
  62. <script>
  63. import appSwiper from "../../../components/page-component/app-swiper/app-swiper.vue";
  64. import integralModel from "../integral-model.vue";
  65. import commonButtom from "../common-buttom.vue";
  66. import {mapGetters} from "vuex";
  67. export default {
  68. name: "index",
  69. components: {appSwiper, commonButtom, integralModel},
  70. data() {
  71. let integral;
  72. return {
  73. integral,
  74. args: false,
  75. load: false,
  76. page: 1,
  77. list: null,
  78. times: null,
  79. title: '幸运抽奖',
  80. banner_list: [],
  81. setting: null,
  82. template_message: null,
  83. deplete_integral_num: 0,
  84. }
  85. },
  86. computed: {
  87. ...mapGetters({
  88. userInfo: 'user/info',
  89. })
  90. },
  91. onHide: function () {
  92. clearInterval(this.integral);
  93. },
  94. onUnload: function () {
  95. clearInterval(this.integral);
  96. },
  97. onLoad(options) { this.$commonLoad.onload(options);
  98. const self = this;
  99. self.$request({
  100. url: self.$api.lottery.setting,
  101. }).then(info => {
  102. if (info.code === 0) {
  103. self.setting = info.data.setting;
  104. uni.setNavigationBarTitle({
  105. title: self.setting.title,
  106. });
  107. self.title = self.setting.title;
  108. }
  109. })
  110. // #ifdef MP-WEIXIN
  111. wx.showShareMenu({
  112. withShareTicket: true,
  113. menus: ['shareAppMessage', 'shareTimeline']
  114. })
  115. // #endif
  116. },
  117. // #ifdef MP-WEIXIN
  118. onShareTimeline() {
  119. return this.$shareTimeline({
  120. title: this.title,
  121. query: {}
  122. });
  123. },
  124. // #endif
  125. onReachBottom: function () {
  126. const self = this;
  127. if (self.args || self.load)
  128. return;
  129. self.load = true;
  130. let page = self.page + 1;
  131. self.$request({
  132. url: self.$api.lottery.index,
  133. data: {
  134. page: page,
  135. }
  136. }).then(info => {
  137. if (info.code === 0) {
  138. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(info.data.list)];
  139. let time = self.list.map(v => {
  140. return v.new_status == 2 ? v.start_at : v.end_at;
  141. })
  142. self.setTimeStart(time);
  143. }
  144. self.load = false;
  145. });
  146. },
  147. onShow: function () {
  148. const self = this;
  149. self.$showLoading({title: '加载中'});
  150. self.$request({
  151. url: self.$api.lottery.index,
  152. }).then(info => {
  153. self.$hideLoading();
  154. if (info.code === 0) {
  155. [
  156. self.banner_list,
  157. self.list,
  158. self.banner_list,
  159. self.template_message
  160. ] = [
  161. info.data.banner_list,
  162. info.data.list,
  163. info.data.banner_list,
  164. info.data.template_message
  165. ];
  166. [self.page, self.args] = [1, false];
  167. let time = self.list.map(v => {
  168. return v.new_status == 2 ? v.start_at : v.end_at;
  169. })
  170. self.setTimeStart(time);
  171. }
  172. }).catch(() => {
  173. self.$hideLoading();
  174. })
  175. },
  176. // #ifdef MP
  177. onShareAppMessage () {
  178. return this.$shareAppMessage({
  179. title: this.title,
  180. path: '/plugins/lottery/index/index',
  181. params: {},
  182. });
  183. },
  184. // #endif
  185. methods: {
  186. qrcode() {
  187. uni.navigateTo({url: `/plugins/lottery/qrcode/qrcode`})
  188. },
  189. goods(data) {
  190. uni.navigateTo({
  191. url: `/plugins/lottery/goods/goods?lottery_id=${data.id}`
  192. });
  193. },
  194. validateIntegral(column){
  195. let deplete_integral_num = Number(column.deplete_integral_num);
  196. if (deplete_integral_num > 0) {
  197. this.deplete_integral_num = deplete_integral_num;
  198. this.$refs.integralModel.showModel(column.id);
  199. } else {
  200. this.detail(column.id);
  201. }
  202. },
  203. detail(id) {
  204. this.$subscribe(this.template_message).then(res => {
  205. uni.navigateTo({url: `/plugins/lottery/detail/detail?lottery_id=` + id});
  206. }).catch(res => {
  207. uni.navigateTo({url: `/plugins/lottery/detail/detail?lottery_id=` + id});
  208. });
  209. },
  210. setTimeStart(info) {
  211. const self = this;
  212. clearInterval(self.integral);
  213. let func = function (info) {
  214. let times = [];
  215. info.map((item, index, array) => {
  216. let time = item.replace(/-/g, '/');
  217. let diff_time = parseInt((new Date(time).getTime() - new Date().getTime()) / 1000)
  218. let day = 0, hour = 0, minute = 0, second = 0;
  219. if (diff_time > 0) {
  220. day = Math.floor(diff_time / (60 * 60 * 24));
  221. hour = Math.floor(diff_time / (60 * 60)) - (day * 24);
  222. minute = Math.floor(diff_time / 60) - (day * 24 * 60) - (hour * 60);
  223. second = Math.floor(diff_time) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
  224. }
  225. times[index] = {day, hour, minute, second}
  226. })
  227. self.times = times;
  228. }
  229. func(info);
  230. self.integral = setInterval(() => {
  231. func(info)
  232. }, 1000)
  233. }
  234. }
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. .lottery-share {
  239. margin-top: #{20rpx};
  240. image {
  241. height: #{150rpx};
  242. width: 100%;
  243. display: block;
  244. }
  245. }
  246. .bottom {
  247. //margin-bottom: #{96rpx}
  248. }
  249. .lottery {
  250. margin-top: #{20rpx};
  251. width: 100%;
  252. height: #{268rpx};
  253. background: #FFFFFF;
  254. .lottery-image {
  255. padding-left: #{24rpx};
  256. position: relative;
  257. margin: #{24rpx} 0;
  258. view {
  259. position: absolute;
  260. top: 0;
  261. left: #{24rpx};
  262. color: #ff4544;
  263. background: #ffe4e7;
  264. line-height: #{40rpx};
  265. padding: 0 #{12rpx};
  266. border-radius: 0 #{25rpx} #{25rpx} 0;
  267. font-size: #{24rpx};
  268. }
  269. image {
  270. width: #{220rpx};
  271. height: #{220rpx};
  272. display: block;
  273. }
  274. }
  275. .lottery-desc {
  276. align-self: flex-start;
  277. margin: #{24rpx};
  278. height: #{220rpx};
  279. .goods-name {
  280. color: #353535;
  281. font-size: #{28rpx};
  282. margin-bottom: #{10rpx};
  283. }
  284. .activity-icon {
  285. background-image: url('./../image/lottery_time.png');
  286. background-repeat: no-repeat;
  287. background-size: 100% 100%;
  288. height: #{24rpx};
  289. width: #{24rpx};
  290. margin-right: #{12rpx};
  291. }
  292. .activity {
  293. font-size: #{26rpx};
  294. color: #999999;
  295. .red {
  296. color: #ff4544;
  297. }
  298. }
  299. .stock {
  300. font-size: #{26rpx};
  301. color: #999999;
  302. margin-top: #{10rpx};
  303. }
  304. .end {
  305. width: 100%;
  306. }
  307. .price {
  308. font-size: #{28rpx};
  309. .currency {
  310. color: #ff4544;
  311. }
  312. .original {
  313. margin-left: #{12rpx};
  314. text-decoration: line-through;
  315. color: #999999;
  316. }
  317. }
  318. }
  319. }
  320. </style>