Преглед на файлове

Merge branch 'master' of http://svn.ouj.com:3000/FED/dw_lotter_draw

PC-20180523CIYM\Administrator преди 5 години
родител
ревизия
1943159ad7

+ 4 - 0
components/iview/alert/index.js

@@ -21,6 +21,10 @@ Component({
             type: Boolean,
             default: false
         },
+        fixMargin: {
+          type: Boolean,
+          default: false
+        }
     },
     data: {
         closed: false

+ 2 - 1
components/iview/alert/index.wxml

@@ -1,4 +1,5 @@
-<view class="i-class i-alert {{'i-alert-'+type}} {{showIcon?'i-alert-with-icon':''}} {{desc?'i-alert-with-desc':''}}" wx:if="{{!closed}}">
+<view class="i-class i-alert {{'i-alert-'+type}} {{showIcon?'i-alert-with-icon':''}} {{desc?'i-alert-with-desc':''}}" wx:if="{{!closed}}" 
+  style="margin: {{fixMargin ? '0px' : '10px'}}">
     <view wx:if="{{ showIcon }}" class="i-alert-icon">
         <i-icon type="prompt" wx:if="{{ type === 'info' }}" size="{{desc?24:16}}"></i-icon>
         <i-icon type="success" wx:if="{{ type === 'success' }}" size="{{desc?24:16}}"></i-icon>

+ 6 - 6
lib/events/events.js

@@ -1,5 +1,5 @@
 /*!
- * awsome-events v1.0.13
+ * awsome-events v1.0.15
  * (c) ghostratel
  * Released under the MIT License.
  */
@@ -228,14 +228,14 @@
 
   Events.prototype.rawListeners = function (eventName) {
     var instance = this;
-    var listenrs = this._events[eventName] ? this._events[eventName].slice() : [];
-    listenrs.length && (listenrs = listenrs.map(function (listener, _i) {
+    var listeners = this._events[eventName] ? this._events[eventName].slice() : [];
+    listeners.length && (listeners = listeners.map(function (listener, _i) {
       var f = function f() {
         if (listener.once) {
           instance.removeListener(eventName, listener);
-          listenrs.splice(_i, 1);
+          listeners.splice(_i, 1);
 
-          if (listenrs.length === 0) {
+          if (listeners.length === 0) {
             delete instance._events[eventName];
           }
         }
@@ -253,7 +253,7 @@
 
       return f;
     }));
-    return listenrs;
+    return listeners;
   };
 
   return Events;

+ 23 - 9
pages/award-detail/award-detail.js

@@ -1,6 +1,7 @@
 const WP = require('../../lib/wxParse/wxParse.js')
 const { getLotteryDetail, drawLottery, invite } = require('../../utils/API.js')
 const USER_INFO = wx.getStorageSync('USER_INFO')
+const bus = require('../../utils/bus.js')
 const NOTICE = `Lucky Maker作为提供抽奖服务的平台, 不对第三方发起人行为承担任何责任。活动奖品均由发起人提供并派发,Lucky Maker会在法律范围内尽可能地规范实行抽奖活动,感谢支持。`
 
 Page({
@@ -20,14 +21,15 @@ Page({
     download_url:'',  // 下载链接
 		invited_user_avatars: [], //  我邀请的队友
     lottery_user_count: 0, // 抽奖参与总人数
-    lottery_user_avatars: 0, // 参与抽奖的用户头像
+    lottery_user_avatars: [], // 参与抽奖的用户头像
 		user_lottery_codes: [], //  用户的抽奖码
     recommend_lottery: {}, //  推荐的抽奖
     visit_count: 0, // 浏览数
 		user_draw_state: 0, // 用户抽奖状态
-		isFold: true,
+    isFold: false, // 当前内容折叠状态
+    needFold: false, // 当前内容高度是否需要折叠
 		modalVisiable: false,
-		notice: NOTICE
+    notice: NOTICE
 	},
 	swipeTo(ev) {
 		const { index } = ev.target.dataset
@@ -43,15 +45,25 @@ Page({
 	toggleFold() {
 		this.setData({ isFold: !this.data.isFold })
   },
+  // 根据抽奖内容多少判断是否需要折叠
+  _judgeContentHeight(){
+    wx.createSelectorQuery().select('.award-article').boundingClientRect(nodeRef => {
+      nodeRef.height > 1000 ? this.setData({needFold: true}) : this.setData({needFold: false})
+    }).exec()
+  },
   // 点击抽奖按钮事件处理函数
 	handleDrawLottery() {
 		const { id } = this.data
 		drawLottery(id)
 			.then(data => {
+        const {user_lottery_codes, avatar_url} = data.data
 				wx.showToast({ title: data.msg })
 				this.setData({
-					user_draw_state: 1
-				})
+          user_draw_state: 1,
+          user_lottery_codes,
+          lottery_user_avatars: this.data.lottery_user_avatars.concat(avatar_url)
+        })
+        bus.emit('user_draw_lottery', id)
 			})
 			.catch(err => {
 				wx.showToast({ title: err.msg })
@@ -97,7 +109,7 @@ Page({
         visit_count,
         download_url,
         lottery_user_avatars
-			} = data.data
+      } = data.data
 			this.setData({
 				cover_images,
 				title,
@@ -108,8 +120,9 @@ Page({
 				winner_codes,
 				state,
 				invited_user_avatars: invited_user_avatars.slice(0, 24),
-				lottery_user_count,
-				user_lottery_codes,
+        lottery_user_count,
+        // 抽奖结束时判断用户是否中奖
+				user_lottery_codes: state === '2' ? user_lottery_codes.map(code => ({code, isWin: winner_codes.includes(code)})) : user_lottery_codes.map(code => ({code, isWin: false})),
         recommend_lottery,
         user_draw_state,
         id,
@@ -118,7 +131,8 @@ Page({
         download_url,
         lottery_user_avatars
 			})
-			WP.wxParse('article', 'html', body, this, 5)
+      WP.wxParse('article', 'html', body, this, 5)
+      this._judgeContentHeight()
 		})
 	},
 	seeAll() {

+ 1 - 0
pages/award-detail/award-detail.json

@@ -9,6 +9,7 @@
     "i-avatar": "../../components/iview/avatar/index",
     "i-modal": "../../components/iview/modal/index",
     "i-divider": "../../components/iview/divider/index",
+    "i-tag": "../../components/iview/tag/index",
     "recommend-award": "../../components/recommend-award/recommend-award",
     "share-btns": "../../components/share-btns/share-btns"
   }

+ 14 - 13
pages/award-detail/award-detail.wxml

@@ -32,7 +32,7 @@
 
   <view class="award-article {{isFold ? 'fold': ''}}">
     <template is="wxParse" data="{{wxParseData:article.nodes}}"></template>
-    <button class="fold" bind:tap="toggleFold">
+    <button class="fold" bind:tap="toggleFold" wx:if="{{needFold}}">
       {{isFold ? '展开' : '收起'}}
       <i-icon type="unfold" color="#64a8d1" size="26" class="{{!isFold ?'hide' : ''}}"></i-icon>
       <i-icon type="packup" color="#64a8d1" size="26" class="{{isFold ? 'hide' : ''}}"></i-icon>
@@ -86,9 +86,11 @@
   <view class="my-code">
  
     <i-alert wx:if="{{user_lottery_codes.length !== 0}}">
-        我的奖码:
+        我的奖码:
       <block wx:for="{{user_lottery_codes}}" wx:key="{{item}}">
-        <view slot="desc" class="award-code">{{item}}</view>
+        <view slot="desc" class="award-code">
+          {{item.code}}
+        <i-tag class="i-tags" type="dot" color="{{item.isWin ? 'green' : 'yellow'}}">{{item.isWin ? '已' : '未'}}中奖</i-tag></view>
       </block>
     </i-alert>
   </view>
@@ -104,18 +106,17 @@
     </view>
   </view>
 
-  <view class="results" wx:if="{{winner_codes.length !== 0}}">
+  <view class="results" wx:if="{{winner_codes.length !== 0 && state === '2'}}">
     <view class="title">
-      中奖列表
+      本期中奖码 
     </view>
-    <block wx:for="{{winner_codes}}" wx:key="{{item}}">
-     <view class="winner">
-        <image src="https://i.loli.net/2017/08/21/599a521472424.jpg" alt=""></image>
-        <view class="winner-code">
-          {{item}}
-        </view>
-    </view>
-    </block>
+
+      <i-alert type="success" class="i-class" fixMargin="{{true}}">
+        <block wx:for="{{winner_codes}}" wx:key="{{item}}">
+          <view class="winner-code">{{item}}</view>
+        </block>
+      </i-alert>
+
 
   </view>
 

+ 8 - 0
pages/award-detail/award-detail.wxss

@@ -246,6 +246,9 @@ button.fold::after{
 .award-code{
   font-size: 40rpx;
   font-weight: bolder;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
 }
 
 .invited-users{
@@ -349,4 +352,9 @@ button.fold::after{
 }
 .all-users .view-count view:last-child{
   text-decoration: underline;
+}
+
+.winner-code{
+  font-size: 40rpx;
+  font-weight: bolder;
 }

+ 8 - 0
pages/index/index.js

@@ -1,4 +1,5 @@
 const {getLotteries} =  require('../../utils/API.js')
+const bus = require('../../utils/bus.js')
 let cur_page = 1
 Page({
   data: {
@@ -30,6 +31,13 @@ Page({
         recommend: data.data.recommend_lottery
       })
     })
+    bus.on('user_draw_lottery', (id) => {
+      let _index = this.data.lotteries.findIndex(item => item.id === id)
+      let key = `lotteries[${_index}].user_draw_state`
+      this.setData({
+        [key]: 1
+      })
+    })
   },
 })
 

+ 3 - 0
utils/bus.js

@@ -0,0 +1,3 @@
+const Events = require('../lib/events/events.js')
+
+module.exports = new Events()