payLottery.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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="" :lotteryNum="lottery_num" :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. this.orderId = newV.order_id;
  125. this.totalPrice = newV.totalPrice;
  126. this.type = newV.type
  127. this.getLotteryData(newV.type)
  128. },
  129. deep: true
  130. }
  131. },
  132. created(options) {
  133. // #ifdef H5 || APP-PLUS
  134. this.orderId = this.options.order_id;
  135. this.totalPrice = this.options.totalPrice;
  136. this.type = this.options.type;
  137. // #endif
  138. if (this.isLogin) {
  139. this.getLotteryData(this.type)
  140. } else {
  141. toLogin();
  142. }
  143. },
  144. methods: {
  145. openTap() {
  146. this.$set(this, 'couponsHidden', !this.couponsHidden);
  147. },
  148. orderDetails() {
  149. this.$emit('orderDetails')
  150. },
  151. getWiningIndex(callback) {
  152. this.aleartType = 0
  153. startLottery({
  154. id: this.id
  155. }).then(res => {
  156. this.prize.forEach((item, index) => {
  157. if (res.data.id === item.id) {
  158. this.alData = res.data
  159. this.lottery_draw_param.winingIndex = index;
  160. callback(this.lottery_draw_param);
  161. }
  162. })
  163. }).catch(err => {
  164. this.$util.Tips({
  165. title: err
  166. });
  167. })
  168. // //props修改在小程序和APP端不成功,所以在这里使用回调函数传参,
  169. },
  170. /**
  171. * 去首页关闭当前所有页面
  172. */
  173. goIndex: function(e) {
  174. uni.switchTab({
  175. url: '/pages/index/index'
  176. });
  177. },
  178. /**
  179. *
  180. * 去订单详情页面
  181. */
  182. goOrderDetails: function(e) {
  183. // #ifdef MP
  184. uni.showLoading({
  185. title: this.$t(`正在加载中`),
  186. })
  187. openOrderSubscribe().then(res => {
  188. uni.hideLoading();
  189. uni.navigateTo({
  190. url: '/pages/goods/order_details/index?order_id=' + this.orderId
  191. });
  192. }).catch(() => {
  193. nui.hideLoading();
  194. });
  195. // #endif
  196. },
  197. getLotteryData(type) {
  198. getLotteryData(type).then(res => {
  199. this.factor_num = res.data.lottery.factor_num
  200. this.id = res.data.lottery.id
  201. this.prize = res.data.lottery.prize
  202. this.lottery_num = res.data.lottery_num
  203. this.prize.push({
  204. a: 1
  205. })
  206. this.$emit('lotteryShow', true)
  207. this.lotteryShow = true
  208. }).catch(err => {
  209. this.$emit('lotteryShow', false)
  210. this.lotteryShow = false
  211. })
  212. },
  213. closeLottery(status) {
  214. this.aleartStatus = false
  215. this.getLotteryData(this.type)
  216. if (this.alData.type === 6) {
  217. this.addressModel = true
  218. }
  219. },
  220. getAddress(data) {
  221. let addData = data
  222. addData.id = this.alData.lottery_record_id
  223. addData.address = data.address.province + data.address.city + data.address.district + data.detail
  224. receiveLottery(addData).then(res => {
  225. this.$util.Tips({
  226. title: this.$t(`领取成功`)
  227. });
  228. this.addressModel = false
  229. }).catch(err => {
  230. this.$util.Tips({
  231. title: err
  232. });
  233. })
  234. },
  235. getWiningIndex(callback) {
  236. this.aleartType = 0
  237. startLottery({
  238. id: this.id
  239. }).then(res => {
  240. this.prize.forEach((item, index) => {
  241. if (res.data.id === item.id) {
  242. this.alData = res.data
  243. this.lottery_draw_param.winingIndex = index;
  244. callback(this.lottery_draw_param);
  245. }
  246. })
  247. }).catch(err => {
  248. this.$util.Tips({
  249. title: err
  250. });
  251. })
  252. // //props修改在小程序和APP端不成功,所以在这里使用回调函数传参,
  253. },
  254. // 抽奖完成
  255. luck_draw_finish(param) {
  256. this.aleartType = 2
  257. this.aleartStatus = true
  258. },
  259. }
  260. }
  261. </script>
  262. <style lang="scss" scoped>
  263. .header {
  264. color: #fff;
  265. background-color: var(--view-theme);
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. flex-direction: column;
  270. padding: 80rpx 0;
  271. .pay-status {
  272. display: flex;
  273. align-items: center;
  274. .iconfont {
  275. font-size: 74rpx;
  276. background: rgba(#000, 0.08);
  277. border-radius: 50%;
  278. margin-right: 30rpx;
  279. padding: 9rpx;
  280. }
  281. .pay-status-r {
  282. display: flex;
  283. flex-direction: column;
  284. .pay-status-text {
  285. font-size: 38rpx;
  286. font-weight: bold;
  287. padding-bottom: 10rpx;
  288. }
  289. }
  290. }
  291. .grids /deep/ .grid_wrap .lottery_wrap .lottery_grid li:nth-of-type(9) {
  292. background: rgba(#fff, 0.2) !important;
  293. }
  294. .jump {
  295. display: flex;
  296. padding-top: 40rpx;
  297. .jump-det {
  298. background: #FFFFFF;
  299. opacity: 1;
  300. border-radius: 22px;
  301. color: #E93323;
  302. padding: 10rpx 38rpx;
  303. margin-right: 30rpx;
  304. }
  305. .jump-index {
  306. border: 1px solid #FEFFFF;
  307. opacity: 1;
  308. padding: 10rpx 38rpx;
  309. border-radius: 22px;
  310. }
  311. }
  312. }
  313. .grids-top {
  314. display: flex;
  315. justify-content: center;
  316. padding: 30rpx 0 0 0;
  317. image {
  318. width: 40rpx;
  319. height: 40rpx;
  320. }
  321. .grids-title {
  322. display: flex;
  323. justify-content: center;
  324. font-size: 20px;
  325. color: #E93323;
  326. z-index: 999;
  327. padding: 0 14rpx;
  328. font-weight: bold;
  329. .grids-frequency {}
  330. }
  331. }
  332. /deep/ .lottery_grid {
  333. background-color: #E93323;
  334. border-radius: 12rpx;
  335. }
  336. .grids {
  337. width: 100%;
  338. // height: 800rpx;
  339. display: flex;
  340. flex-direction: column;
  341. justify-content: center;
  342. align-items: center;
  343. margin-top: 20rpx;
  344. position: relative;
  345. padding: 30rpx;
  346. .grids-bag {
  347. position: absolute;
  348. top: 0;
  349. left: 0;
  350. // #ifdef MP
  351. width: 95%;
  352. height: 95%;
  353. // #endif
  354. // #ifdef H5 || APP-PLUS
  355. width: 750rpx;
  356. height: 750rpx;
  357. // #endif
  358. padding: 20rpx;
  359. display: flex;
  360. justify-content: center;
  361. align-items: center;
  362. }
  363. .grids-box {
  364. width: 700rpx;
  365. height: 700rpx;
  366. // z-index: 10000;
  367. padding: 20rpx;
  368. background-color: #E74435;
  369. }
  370. .winning-tips-list {
  371. display: flex;
  372. align-items: center;
  373. justify-content: center;
  374. width: 50%;
  375. font-size: 20rpx;
  376. line-height: 40rpx;
  377. height: 40rpx;
  378. font-weight: 400;
  379. color: #FFF8F8;
  380. margin: 30rpx 0;
  381. z-index: 999;
  382. background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.3) 51%, rgba(255, 255, 255, 0) 100%);
  383. .iconfont {
  384. font-size: 20rpx;
  385. margin-right: 10rpx;
  386. }
  387. }
  388. }
  389. .mask {
  390. position: fixed;
  391. top: 0;
  392. left: 0;
  393. right: 0;
  394. bottom: 0;
  395. background-color: rgba(0, 0, 0, 0.8);
  396. z-index: 9;
  397. }
  398. </style>