payLottery.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="header" v-show="lotteryShow">
  4. <view class="pay-status">
  5. <text class="iconfont icon-gou"></text>
  6. <view class="pay-status-r">
  7. <text class="pay-status-text">
  8. {{$t(`支付成功`)}}
  9. </text>
  10. <text>
  11. {{$t(`支付金额`)}}:{{$t(`¥`)}}{{totalPrice}}
  12. </text>
  13. </view>
  14. </view>
  15. <view class="jump">
  16. <view class="jump-det" @click="orderDetails">
  17. {{$t(`查看订单`)}}
  18. </view>
  19. <view class="jump-index" @click="goIndex">
  20. {{$t(`返回首页`)}}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="grids-top" v-show="lotteryShow">
  25. <image src="../static/pay-lottery-l.png" mode=""></image>
  26. <view class="grids-title">
  27. <view>{{$t(`恭喜您`)}},{{$t(`获得`)}} {{lottery_num}} {{$t(`机会`)}}</view>
  28. </view>
  29. <image src="../static/pay-lottery-r.png" mode=""></image>
  30. </view>
  31. <view class="grids" v-show="lotteryShow">
  32. <image class="grids-bag" src="../static/pay-lottery-bag.png" mode=""></image>
  33. <view class="grids-box">
  34. <gridsLottery class="" :prizeData="prize" @get_winingIndex='getWiningIndex'
  35. @luck_draw_finish='luck_draw_finish'>
  36. </gridsLottery>
  37. </view>
  38. </view>
  39. <lotteryAleart :aleartStatus="aleartStatus" @close="closeLottery" :alData="alData" :aleartType="aleartType">
  40. </lotteryAleart>
  41. <view class="mask" v-if="aleartStatus || addressModel"></view>
  42. <userAddress :aleartStatus="addressModel" @getAddress="getAddress" @close="()=>{addressModel = false}">
  43. </userAddress>
  44. </view>
  45. </template>
  46. <script>
  47. import gridsLottery from '../components/lottery/index.vue'
  48. import lotteryAleart from './components/lotteryAleart.vue'
  49. import userAddress from './components/userAddress.vue'
  50. import {
  51. getOrderDetail
  52. } from '@/api/order.js';
  53. import {
  54. openOrderSubscribe
  55. } from '@/utils/SubscribeMessage.js';
  56. import {
  57. toLogin
  58. } from '@/libs/login.js';
  59. import {
  60. getLotteryData,
  61. startLottery,
  62. receiveLottery
  63. } from '@/api/lottery.js'
  64. import {
  65. mapGetters
  66. } from "vuex";
  67. // #ifdef MP
  68. import authorize from '@/components/Authorize';
  69. // #endif
  70. import colors from "@/mixins/color";
  71. export default {
  72. components: {
  73. // #ifdef MP
  74. authorize,
  75. // #endif
  76. gridsLottery,
  77. lotteryAleart,
  78. userAddress
  79. },
  80. mixins:[colors],
  81. props: {
  82. options: {
  83. type: Object
  84. }
  85. },
  86. data() {
  87. return {
  88. lotteryShow: false,
  89. addressModel: false,
  90. lottery_num: 0,
  91. aleartType: 0,
  92. aleartStatus: false,
  93. lottery_draw_param: {
  94. startIndex: 3, //开始抽奖位置,从0开始
  95. totalCount: 3, //一共要转的圈数
  96. winingIndex: 1, //中奖的位置,从0开始
  97. speed: 100 //抽奖动画的速度 [数字越大越慢,默认100]
  98. },
  99. alData: {},
  100. type: '',
  101. prize: [],
  102. orderId: '',
  103. order_pay_info: {
  104. paid: 1,
  105. _status: {}
  106. },
  107. isAuto: false, //没有授权的不会自动授权
  108. isShowAuth: false, //是否隐藏授权
  109. couponsHidden: true,
  110. couponList: [],
  111. totalPrice: 0
  112. };
  113. },
  114. computed: mapGetters(['isLogin']),
  115. watch: {
  116. isLogin: {
  117. handler: function(newV, oldV) {
  118. if (newV) {}
  119. },
  120. deep: true
  121. },
  122. options: {
  123. handler: function(newV, oldV) {
  124. if (newV) {
  125. this.orderId = newV.order_id;
  126. this.totalPrice = newV.totalPrice;
  127. this.type = newV.type
  128. this.getLotteryData(newV.type)
  129. }
  130. },
  131. deep: true
  132. }
  133. },
  134. created(options) {
  135. // #ifdef H5 || APP-PLUS
  136. this.orderId = this.options.order_id;
  137. this.totalPrice = this.options.totalPrice;
  138. this.type = this.options.type;
  139. // #endif
  140. if (this.isLogin) {
  141. this.getLotteryData(this.type)
  142. } else {
  143. toLogin();
  144. }
  145. },
  146. methods: {
  147. openTap() {
  148. this.$set(this, 'couponsHidden', !this.couponsHidden);
  149. },
  150. orderDetails() {
  151. this.$emit('orderDetails')
  152. },
  153. getWiningIndex(callback) {
  154. this.aleartType = 0
  155. startLottery({
  156. id: this.id
  157. }).then(res => {
  158. this.prize.forEach((item, index) => {
  159. if (res.data.id === item.id) {
  160. this.alData = res.data
  161. this.lottery_draw_param.winingIndex = index;
  162. callback(this.lottery_draw_param);
  163. }
  164. })
  165. }).catch(err => {
  166. this.$util.Tips({
  167. title: err
  168. });
  169. })
  170. // //props修改在小程序和APP端不成功,所以在这里使用回调函数传参,
  171. },
  172. /**
  173. * 去首页关闭当前所有页面
  174. */
  175. goIndex: function(e) {
  176. uni.switchTab({
  177. url: '/pages/index/index'
  178. });
  179. },
  180. /**
  181. *
  182. * 去订单详情页面
  183. */
  184. goOrderDetails: function(e) {
  185. // #ifdef MP
  186. uni.showLoading({
  187. title: this.$t(`正在加载中`),
  188. })
  189. openOrderSubscribe().then(res => {
  190. uni.hideLoading();
  191. uni.navigateTo({
  192. url: '/pages/goods/order_details/index?order_id=' + this.orderId
  193. });
  194. }).catch(() => {
  195. nui.hideLoading();
  196. });
  197. // #endif
  198. },
  199. getLotteryData(type) {
  200. getLotteryData(type).then(res => {
  201. this.factor_num = res.data.lottery.factor_num
  202. this.id = res.data.lottery.id
  203. this.prize = res.data.lottery.prize
  204. this.lottery_num = res.data.lottery_num
  205. this.prize.push({
  206. a: 1
  207. })
  208. this.$emit('lotteryShow', true)
  209. this.lotteryShow = true
  210. }).catch(err => {
  211. this.$emit('lotteryShow', false)
  212. this.lotteryShow = false
  213. })
  214. },
  215. closeLottery(status) {
  216. this.aleartStatus = false
  217. this.getLotteryData(this.type)
  218. if (this.alData.type === 6) {
  219. this.addressModel = true
  220. }
  221. },
  222. getAddress(data) {
  223. let addData = data
  224. addData.id = this.alData.lottery_record_id
  225. addData.address = data.address.province + data.address.city + data.address.district + data.detail
  226. receiveLottery(addData).then(res => {
  227. this.$util.Tips({
  228. title: this.$t(`领取成功`)
  229. });
  230. this.addressModel = false
  231. }).catch(err => {
  232. this.$util.Tips({
  233. title: err
  234. });
  235. })
  236. },
  237. getWiningIndex(callback) {
  238. this.aleartType = 0
  239. startLottery({
  240. id: this.id
  241. }).then(res => {
  242. this.prize.forEach((item, index) => {
  243. if (res.data.id === item.id) {
  244. this.alData = res.data
  245. this.lottery_draw_param.winingIndex = index;
  246. callback(this.lottery_draw_param);
  247. }
  248. })
  249. }).catch(err => {
  250. this.$util.Tips({
  251. title: err
  252. });
  253. })
  254. // //props修改在小程序和APP端不成功,所以在这里使用回调函数传参,
  255. },
  256. // 抽奖完成
  257. luck_draw_finish(param) {
  258. this.aleartType = 2
  259. this.aleartStatus = true
  260. },
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. .header {
  266. color: #fff;
  267. background-color: var(--view-theme);
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. flex-direction: column;
  272. padding: 80rpx 0;
  273. .pay-status {
  274. display: flex;
  275. align-items: center;
  276. .iconfont {
  277. font-size: 74rpx;
  278. background: rgba(#000, 0.08);
  279. border-radius: 50%;
  280. margin-right: 30rpx;
  281. padding: 9rpx;
  282. }
  283. .pay-status-r {
  284. display: flex;
  285. flex-direction: column;
  286. .pay-status-text {
  287. font-size: 38rpx;
  288. font-weight: bold;
  289. padding-bottom: 10rpx;
  290. }
  291. }
  292. }
  293. .grids /deep/ .grid_wrap .lottery_wrap .lottery_grid li:nth-of-type(9) {
  294. background: rgba(#fff, 0.2) !important;
  295. }
  296. .jump {
  297. display: flex;
  298. padding-top: 40rpx;
  299. .jump-det {
  300. background: #FFFFFF;
  301. opacity: 1;
  302. border-radius: 22px;
  303. color: #E93323;
  304. padding: 10rpx 38rpx;
  305. margin-right: 30rpx;
  306. }
  307. .jump-index {
  308. border: 1px solid #FEFFFF;
  309. opacity: 1;
  310. padding: 10rpx 38rpx;
  311. border-radius: 22px;
  312. }
  313. }
  314. }
  315. .grids-top {
  316. display: flex;
  317. justify-content: center;
  318. padding: 30rpx 0 0 0;
  319. image {
  320. width: 40rpx;
  321. height: 40rpx;
  322. }
  323. .grids-title {
  324. display: flex;
  325. justify-content: center;
  326. font-size: 20px;
  327. color: #E93323;
  328. z-index: 999;
  329. padding: 0 14rpx;
  330. font-weight: bold;
  331. .grids-frequency {}
  332. }
  333. }
  334. /deep/ .lottery_grid {
  335. background-color: #E93323;
  336. border-radius: 12rpx;
  337. }
  338. .grids {
  339. width: 100%;
  340. // height: 800rpx;
  341. display: flex;
  342. flex-direction: column;
  343. justify-content: center;
  344. align-items: center;
  345. margin-top: 20rpx;
  346. position: relative;
  347. padding: 30rpx;
  348. .grids-bag {
  349. position: absolute;
  350. top: 0;
  351. left: 0;
  352. // #ifdef MP
  353. width: 95%;
  354. height: 95%;
  355. // #endif
  356. // #ifdef H5 || APP-PLUS
  357. width: 750rpx;
  358. height: 750rpx;
  359. // #endif
  360. padding: 20rpx;
  361. display: flex;
  362. justify-content: center;
  363. align-items: center;
  364. }
  365. .grids-box {
  366. width: 700rpx;
  367. height: 700rpx;
  368. // z-index: 10000;
  369. padding: 20rpx;
  370. background-color: #E74435;
  371. }
  372. .winning-tips-list {
  373. display: flex;
  374. align-items: center;
  375. justify-content: center;
  376. width: 50%;
  377. font-size: 20rpx;
  378. line-height: 40rpx;
  379. height: 40rpx;
  380. font-weight: 400;
  381. color: #FFF8F8;
  382. margin: 30rpx 0;
  383. z-index: 999;
  384. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.3) 51%, rgba(255, 255, 255, 0) 100%);
  385. .iconfont {
  386. font-size: 20rpx;
  387. margin-right: 10rpx;
  388. }
  389. }
  390. }
  391. .mask {
  392. position: fixed;
  393. top: 0;
  394. left: 0;
  395. right: 0;
  396. bottom: 0;
  397. background-color: rgba(0, 0, 0, 0.8);
  398. z-index: 9;
  399. }
  400. </style>