get-redpick.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <view>
  3. <view class="mask">
  4. <view class="redpick-close" @click="closeMask">
  5. <image src="../static/close.png" mode="widthFix"></image>
  6. </view>
  7. <view class="bag" >
  8. <view class="redpick-info">
  9. <view class="redpick-info-avatar">
  10. <view >
  11. <image :src="image_cache(item.sender.avatar)" style="border-radius: 12upx;" />
  12. <view class="redpick-info-nickname">{{item.sender.nickname}}</view>
  13. <view class="redpick-info-nickname">的红包</view>
  14. </view>
  15. </view>
  16. <view class="redpick-info-title" >
  17. <block v-if="isopen==0">
  18. {{item.message.content.title || '恭喜发财,大吉大利'}}
  19. </block>
  20. <block v-else>
  21. <view v-if="money>0" class="money">
  22. <span style='font-size: 16px;'>¥</span><span style='font-size: 52px;font-weight: 600;'>{{money}}</span>
  23. </view>
  24. <block v-else>
  25. 手慢了,红包派完了
  26. </block>
  27. </block>
  28. </view>
  29. </view>
  30. <view v-if="isopen==0" :class="{'stick':true,'opening':opening}" @click="goDetail" >
  31. <span class="rmb">開</span>
  32. </view>
  33. <view v-else class="error-text" @tap="opendetail()">
  34. 看看大家的手气
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import http from "../library/http.js"
  42. export default {
  43. data() {
  44. return {
  45. user: uni.getStorageSync('userInfo'),
  46. status:1,
  47. opening:false,
  48. timer:null,
  49. isopen:false,
  50. isget:false,
  51. msg:'',
  52. money:0,
  53. id:0,
  54. }
  55. },
  56. props: {
  57. item:{
  58. },
  59. },
  60. methods: {
  61. closeMask() {
  62. this.$emit('closePick')
  63. },
  64. goDetail() {
  65. if(this.user.banknum<1){
  66. uni.showModal({
  67. title: '提示',
  68. content: "绑定银行卡后才可以枪红包",
  69. showCancel: true,
  70. cancelText: '关闭',
  71. confirmText: '立即绑定',
  72. success: res => {
  73. if(res.confirm) {
  74. uni.navigateTo({
  75. url:"/pages/mine/bank"
  76. })
  77. }
  78. }
  79. });
  80. return false;
  81. }
  82. this.opening=true;
  83. var that=this;
  84. clearInterval(this.timer)
  85. this.timer= setInterval(function(){
  86. that.opening=!that.opening;
  87. },500)
  88. var postdata={userid:this.user.id,id:this.id}
  89. http.setWait(false).get('group.php?act=get_redpacket',postdata).then(res=>{
  90. if(res.code==200){
  91. this.getover(res.data);
  92. }
  93. else{
  94. clearInterval(this.timer)
  95. uni.showToast({
  96. title:'网络异常,请稍后再试',
  97. icon:'none'
  98. })
  99. }
  100. })
  101. },
  102. getover(money){
  103. clearInterval(this.timer)
  104. this.status=2;
  105. this.money=money;
  106. this.isopen=true;
  107. this.updatemsg(money);
  108. if(money>0){
  109. if( this.item.sender.id!=this.user.id){
  110. if(this.item.message.content.isgroup==1){
  111. var data = {
  112. user_id: this.item.sender.id,
  113. tip_uid: this.item.sender.id,
  114. type: 'sendtips',
  115. group_id: this.item.group_id,
  116. content: this.user.nickname+'领取了您的红包',
  117. };
  118. }else{
  119. var data = {
  120. fromid: this.user.id,
  121. touid: this.item.sender.id,
  122. tip_uid: this.item.sender.id,
  123. type: 'sendtips',
  124. content: this.user.nickname+'领取了您的红包',
  125. };
  126. }
  127. this.$socket.send(data);
  128. }
  129. }
  130. },
  131. updatemsg(money){
  132. //更新聊天记录中的红包打开状态
  133. var msgkey=this.user.id+"_chat_"+this.item.cache_key;
  134. var msglist=uni.getStorageSync(msgkey);
  135. for(var i=0;i<msglist.length;i++){
  136. var msg=msglist[i];
  137. if(msg.msg_id==this.item.msg_id){
  138. try{
  139. msglist[i].message.content=JSON.parse(msglist[i].message.content);
  140. }catch(e){
  141. //TODO handle the exception
  142. }
  143. msglist[i].message.content.isopen=1;
  144. msglist[i].message.content.money=money;
  145. msglist[i].message.content=JSON.stringify(msglist[i].message.content);
  146. uni.setStorageSync(msgkey,msglist);
  147. this.$emit('fresmsg',msglist[i]);
  148. break;
  149. }
  150. }
  151. },
  152. opendetail(){
  153. uni.navigateTo({
  154. url:'../friend/redpacket_detail?msg_id='+this.item.msg_id+'&storekey='+this.item.cache_key
  155. })
  156. }
  157. },
  158. created() {
  159. this.status=this.item.message.content.status;
  160. this.id=this.item.message.content.id;
  161. this.money=this.item.message.content.money;
  162. this.isopen=this.item.message.content.isopen;
  163. // uni.getStorageSync(this.userid+"_chat_"+this.storeKey)
  164. }
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .mask {
  169. width: 100%;
  170. height: 100vh;
  171. overflow: hidden;
  172. z-index: 10;
  173. position: fixed;
  174. background: rgba(255,255,255,0.5);
  175. left: 0;
  176. top: 0;
  177. }
  178. .bag {
  179. position: absolute;
  180. top: 50%;
  181. left: 50%;
  182. width: 500upx;
  183. height: 800upx;
  184. margin: 0 auto;
  185. overflow: hidden;
  186. text-align: center;
  187. background-color: #F25542;
  188. border-radius: 12upx;
  189. transform: translate(-50%,-50%);
  190. }
  191. .redpick-close {
  192. position: absolute;
  193. left: 50%;
  194. bottom: 10%;
  195. width: 60upx;
  196. height: 60upx;
  197. z-index: 100;
  198. transform: translateX(-50%);
  199. image {
  200. width: 60upx;
  201. height: 60upx;
  202. }
  203. }
  204. .bag:before {
  205. content: '';
  206. position: absolute;
  207. top: -20%;
  208. left: 50%;
  209. z-index: 0;
  210. width: 200%;
  211. height: 100%;
  212. border-radius: 100%;
  213. background-color: #F45E4D;
  214. box-shadow: 0px 4upx 10upx 0px rgba(0,0,0,0.2);
  215. transform: translateX(-50%);
  216. }
  217. .bag .header {
  218. position: absolute;
  219. left: 0;
  220. top: 45%;
  221. width: 100%;
  222. text-align: center;
  223. z-index: 1;
  224. color: #fff;
  225. font-size: 80upx;
  226. opacity: .9;
  227. }
  228. .bag .header .subtitle {
  229. font-size: 32upx;
  230. }
  231. .bag .header .num {
  232. color: #FEED4C;
  233. }
  234. .bag .stick {
  235. position: relative;
  236. z-index: 1;
  237. width: 140upx;
  238. height: 140upx;
  239. margin: 0 auto;
  240. margin-top: 112%;
  241. border-radius: 9999px;
  242. background-color: #EBCD99;
  243. box-shadow: 0 0 10upx 0 rgba(0,0,0,0.4);
  244. }
  245. .bag .stick .rmb {
  246. font-size: 70upx;
  247. line-height: 150upx;
  248. color: #3B3A37;
  249. }
  250. .bag .detail-btn {
  251. display: block;
  252. font-size: 32upx;
  253. color: #fff;
  254. }
  255. .message {
  256. font-size: 28upx;
  257. text-align: center;
  258. color: #eee;
  259. }
  260. .bag .money{
  261. color:#fff;
  262. }
  263. .error-text{
  264. position: absolute;
  265. left: 50%;
  266. bottom: 4%;
  267. transform: translateX(-50%);
  268. color: #f4e4ae;
  269. font-size: 28upx;
  270. width: 100%;
  271. }
  272. .opening {
  273. animation: openboom 0.5s;
  274. }
  275. @keyframes openboom {
  276. /*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/
  277. 0% {
  278. transform: rotateY(0deg);
  279. }
  280. 100% {
  281. transform: rotateY(360deg);
  282. }
  283. }
  284. .redpick-info{
  285. position: absolute;
  286. left:0;
  287. top: 0;
  288. width: 100%;
  289. color: #F4E4AE;
  290. &-avatar{
  291. display: block;
  292. align-items: center;
  293. justify-content: center;
  294. margin-top: 25%;
  295. font-size: 28upx;
  296. image{
  297. width: 60upx;
  298. height:60upx;
  299. vertical-align: middle;
  300. }
  301. }
  302. &-nickname{
  303. display: inline-block;
  304. max-width: 100px;
  305. max-width: 80%;
  306. text-overflow: ellipsis;
  307. white-space: nowrap;
  308. overflow: hidden;
  309. vertical-align: middle;
  310. }
  311. &-title{
  312. margin-top:30px;
  313. font-size: 40upx;
  314. }
  315. }
  316. .redpick-over{
  317. max-width: 80%;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. overflow: hidden;
  321. display: block;
  322. margin: 0px auto;
  323. }
  324. </style>