Honghe.vue 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="index-box">
  3. <bg-music />
  4. <popup
  5. :show="showPopup"
  6. @cancel="cancelFrom"
  7. :current-month="currentMonth"
  8. :is-prize="myPrize"
  9. :PrizeState="PrizeState"
  10. :prizeList="prizeList"
  11. />
  12. <WinningPopup
  13. :show="showMyWinning"
  14. @cancel="canclMyWinning"
  15. :current-person="person"
  16. :prize="myPrize"
  17. />
  18. <!-- 奖品没了 -->
  19. <img class="topImage" src="../assets/indexImg/indexBgctop.jpg" alt />
  20. <div class="outer6-wrapper">
  21. <div class="outer6 flex-col">
  22. <div v-for="month in list" :key="month.id" class="section-item">
  23. <div @click="handleMonthClick(month)">
  24. <ImgBox :prize="month"></ImgBox>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { useModel } from '@/store'
  33. import { drawLottery, getPrizeList } from '@/services/person'
  34. import { rand, shuffle } from '@/utils/math'
  35. import { hideLoading } from '@/utils'
  36. import { share } from '@/utils/wx'
  37. /**
  38. * 月份信息
  39. * posterImg关闭的图片
  40. * popImg 打开的图片
  41. * shareImg分享图片
  42. * screenImg屏保
  43. * calendarImg日历图片
  44. */
  45. const monthList = [
  46. {
  47. id: 1,
  48. posterImg: require('../assets/indexImg/imgex_MEW/1.jpg'),
  49. popImg: require('../assets/luckyImg/1.jpg'),
  50. shareImg: require('../assets/sharePagesImg/1.jpg'),
  51. screenImg: require('../assets/screenImg/1.jpg'),
  52. calendarImg: require('../assets/monthImg/January1.jpg'),
  53. mode: 1
  54. },
  55. {
  56. id: 2,
  57. posterImg: require('../assets/indexImg/imgex_MEW/2.jpg'),
  58. popImg: require('../assets/luckyImg/2.jpg'),
  59. shareImg: require('../assets/sharePagesImg/2.jpg'),
  60. screenImg: require('../assets/screenImg/2.jpg'),
  61. calendarImg: require('../assets/monthImg/February2.jpg'),
  62. mode: 1
  63. },
  64. {
  65. id: 3,
  66. posterImg: require('../assets/indexImg/imgex_MEW/3.jpg'),
  67. popImg: require('../assets/luckyImg/3.jpg'),
  68. shareImg: require('../assets/sharePagesImg/3.jpg'),
  69. screenImg: require('../assets/screenImg/3.jpg'),
  70. calendarImg: require('../assets/monthImg/March3.jpg'),
  71. mode: 1
  72. },
  73. {
  74. id: 4,
  75. posterImg: require('../assets/indexImg/imgex_MEW/4.jpg'),
  76. popImg: require('../assets/luckyImg/4.jpg'),
  77. shareImg: require('../assets/sharePagesImg/4.jpg'),
  78. screenImg: require('../assets/screenImg/4.jpg'),
  79. calendarImg: require('../assets/monthImg/April4.jpg'),
  80. mode: 1
  81. },
  82. {
  83. id: 5,
  84. posterImg: require('../assets/indexImg/imgex_MEW/5.jpg'),
  85. popImg: require('../assets/luckyImg/5.jpg'),
  86. shareImg: require('../assets/sharePagesImg/5.jpg'),
  87. screenImg: require('../assets/screenImg/5.jpg'),
  88. calendarImg: require('../assets/monthImg/May5.jpg'),
  89. mode: 1
  90. },
  91. {
  92. id: 6,
  93. posterImg: require('../assets/indexImg/imgex_MEW/6.jpg'),
  94. popImg: require('../assets/luckyImg/6.jpg'),
  95. shareImg: require('../assets/sharePagesImg/6.jpg'),
  96. screenImg: require('../assets/screenImg/6.jpg'),
  97. calendarImg: require('../assets/monthImg/June6.jpg'),
  98. mode: 1
  99. },
  100. {
  101. id: 7,
  102. posterImg: require('../assets/indexImg/imgex_MEW/7.jpg'),
  103. popImg: require('../assets/luckyImg/7.jpg'),
  104. shareImg: require('../assets/sharePagesImg/7.jpg'),
  105. screenImg: require('../assets/screenImg/7.jpg'),
  106. calendarImg: require('../assets/monthImg/July7.jpg'),
  107. mode: 1
  108. },
  109. {
  110. id: 8,
  111. posterImg: require('../assets/indexImg/imgex_MEW/8.jpg'),
  112. popImg: require('../assets/luckyImg/8.jpg'),
  113. shareImg: require('../assets/sharePagesImg/8.jpg'),
  114. screenImg: require('../assets/screenImg/8.jpg'),
  115. calendarImg: require('../assets/monthImg/August8.jpg'),
  116. mode: 1
  117. },
  118. {
  119. id: 9,
  120. posterImg: require('../assets/indexImg/imgex_MEW/9.jpg'),
  121. popImg: require('../assets/luckyImg/9.jpg'),
  122. shareImg: require('../assets/sharePagesImg/9.jpg'),
  123. screenImg: require('../assets/screenImg/9.jpg'),
  124. calendarImg: require('../assets/monthImg/September9.jpg'),
  125. mode: 1
  126. },
  127. {
  128. id: 10,
  129. posterImg: require('../assets/indexImg/imgex_MEW/10.jpg'),
  130. popImg: require('../assets/luckyImg/10.jpg'),
  131. shareImg: require('../assets/sharePagesImg/10.jpg'),
  132. screenImg: require('../assets/screenImg/10.jpg'),
  133. calendarImg: require('../assets/monthImg/October10.jpg'),
  134. mode: 1
  135. },
  136. {
  137. id: 11,
  138. posterImg: require('../assets/indexImg/imgex_MEW/11.jpg'),
  139. popImg: require('../assets/luckyImg/11.jpg'),
  140. shareImg: require('../assets/sharePagesImg/11.jpg'),
  141. screenImg: require('../assets/screenImg/11.jpg'),
  142. calendarImg: require('../assets/monthImg/December12.jpg'),
  143. mode: 1
  144. },
  145. {
  146. id: 12,
  147. posterImg: require('../assets/indexImg/imgex_MEW/12.jpg'),
  148. popImg: require('../assets/luckyImg/12.jpg'),
  149. shareImg: require('../assets/sharePagesImg/12.jpg'),
  150. screenImg: require('../assets/screenImg/12.jpg'),
  151. calendarImg: require('../assets/monthImg/December12.jpg'),
  152. mode: 1
  153. }
  154. ]
  155. export default {
  156. name: 'Honghe',
  157. components: {
  158. Popup: () => import('@/components/Popup.vue'),
  159. WinningPopup: () => import('@/components/WinningPopup.vue'),
  160. ImgBox: () => import('@/components/imgbox.vue'),
  161. BgMusic: () => import('@/components/BgMusic.vue')
  162. // MyWinning: () => import('@/components/MyWinning.vue')
  163. },
  164. data() {
  165. return {
  166. list: shuffle(monthList),
  167. currentMonth: null,
  168. showPopup: false,
  169. showMyWinning: false,
  170. prizeList: [],
  171. bingoId: rand(0, 12) + 1, // 可以抽奖的月份
  172. NOMyWinningShow: true,
  173. PrizeState: null
  174. }
  175. },
  176. computed: {
  177. person: {
  178. get() {
  179. return useModel('person')[0]
  180. },
  181. set(val) {
  182. useModel('person')[1](val)
  183. }
  184. },
  185. myPrize() {
  186. if (this.prizeList.length && this.person.prizeId) {
  187. return this.prizeList.filter(
  188. (x) => x.prizeId === this.person.prizeId
  189. )[0]
  190. }
  191. return undefined
  192. },
  193. noPrize() {
  194. if (this.prizeList.length) {
  195. return this.prizeList.reduce((sum, x) => x.exitsNum + sum, 0) <= 0
  196. }
  197. return true
  198. }
  199. },
  200. created() {
  201. this.getPrizes()
  202. this.noShowMy()
  203. // 设置微信分享
  204. share({ title: '抽取幸运签,解锁隐藏福利', desc: '每月都有欢乐发生' })
  205. },
  206. watch: {
  207. showMyWinning(newValue, oldValue) {
  208. // 微信分享
  209. // 1、正常情况下, 分享主题是 抽取幸运签,解锁隐藏福利
  210. // 2、中奖弹出情况下, 分享主题是 我中奖啦! 来试试你的运气吧
  211. if (newValue && !oldValue) {
  212. share({
  213. title: '我中奖啦! 来试试你的运气吧',
  214. desc: '抽取幸运签,解锁隐藏福利'
  215. })
  216. } else if (newValue !== oldValue) {
  217. share({ title: '抽取幸运签,解锁隐藏福利', desc: '每月都有欢乐发生' })
  218. }
  219. }
  220. },
  221. methods: {
  222. noShowMy() {
  223. if (this.person.prizeId !== '' && this.noPrize) {
  224. console.log('有奖品')
  225. } else {
  226. this.PrizeState = true
  227. console.log('没有奖品')
  228. }
  229. },
  230. //关闭
  231. cancelFrom() {
  232. this.showPopup = false
  233. this.list.map((item) => {
  234. if (item.id == this.currentMonth.id) {
  235. item.mode = 3
  236. }
  237. })
  238. },
  239. canclMyWinning() {
  240. this.showMyWinning = false
  241. this.list.map((item) => {
  242. if (item.id == this.currentMonth.id) {
  243. item.mode = 3
  244. }
  245. })
  246. },
  247. handleMonthClick(month) {
  248. this.list.map((item) => {
  249. if (item.id == month.id) {
  250. item.mode = 2
  251. }
  252. })
  253. this.currentMonth = month
  254. console.log(
  255. '🚀 ~ file: Honghe.vue ~ line 193 ~ handleMonthClick ~ month',
  256. month
  257. )
  258. // 如果点击可以抽奖
  259. if (month.id === this.bingoId && !this.noPrize) {
  260. // if (!this.noPrize) {
  261. // this.PrizeState = 2
  262. // }
  263. if (!this.person.personId) {
  264. // 报错, 提示刷新页面
  265. } else {
  266. // 如果还没有参与
  267. if (!this.person.isJoined) {
  268. this.drawLots()
  269. } else {
  270. this.showPopup = true
  271. }
  272. }
  273. } else {
  274. this.showPopup = true
  275. this.PrizeState = 2
  276. }
  277. },
  278. // 抽奖
  279. drawLots() {
  280. drawLottery(this.person)
  281. .then((res) => {
  282. // 更新人员信息
  283. this.person = res
  284. this.showMyWinning = true
  285. // this.PrizeState = 0
  286. console.log('showMyWinning-----------')
  287. // 其他动作
  288. })
  289. .catch((err) => {
  290. if (err && err.code === 9999) {
  291. this.PrizeState = 2
  292. // 奖品没了
  293. } else {
  294. // 其他错误
  295. const errMsg = err.message || err
  296. console.log('🚀 ~ file: Honghe.vue ~errMsg errMsg', errMsg)
  297. alert('请刷新重试')
  298. }
  299. })
  300. },
  301. // 获取奖品列表
  302. getPrizes() {
  303. getPrizeList().then((list) => {
  304. this.prizeList = list
  305. console.log(
  306. '🚀 ~ file: Honghe.vue ~ line 227 ~ getPrizeList ~ list',
  307. list
  308. )
  309. const t = setTimeout(() => {
  310. hideLoading()
  311. clearTimeout(t)
  312. }, 1000)
  313. })
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="less" scoped>
  319. .flex-col {
  320. display: flex;
  321. flex-direction: column;
  322. }
  323. .index-box {
  324. background-color: #b12b32;
  325. width: 100vw;
  326. height: 100vh;
  327. position: relative;
  328. top: 0;
  329. left: 0;
  330. right: 0;
  331. bottom: 0;
  332. overflow: auto;
  333. .dialog {
  334. z-index: 2;
  335. }
  336. .topImage {
  337. padding-top: 2em;
  338. width: 100vw;
  339. }
  340. .outer6-wrapper {
  341. width: 92vw;
  342. border: 1px solid #d0b69a;
  343. margin: 0 auto 2em;
  344. .outer6 {
  345. flex-flow: row wrap;
  346. align-content: flex-start;
  347. z-index: 2;
  348. background-color: #b12b32;
  349. align-self: center;
  350. width: 90vw;
  351. margin: 3px auto;
  352. border-right: 1px solid #d0b69a;
  353. border-bottom: 1px solid #d0b69a;
  354. overflow: hidden;
  355. .section-item {
  356. width: 22vw;
  357. border-left: 1px solid #d0b69a;
  358. border-top: 1px solid #d0b69a;
  359. display: inline-flex;
  360. overflow: hidden;
  361. }
  362. }
  363. }
  364. }
  365. </style>