微信

index.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <style>
  2. .van-dialog__message--has-title {
  3. color: #000 !important;
  4. }
  5. </style>
  6. <template>
  7. <div v-if="showPage">
  8. <model1 v-if="model === 1" @run='run' :prizeData='prizeData' :prizeNum='prizeNum' :data='data' :bg='bg1' :activityStatus='activityStatus' :residue='residue'></model1>
  9. <model2 v-if="model === 2" @run='run' :prizeData='prizeData' :prizeNum='prizeNum' :data='data' :bg='bg2' :activityStatus='activityStatus' :residue='residue'></model2>
  10. <model3 v-if="model === 3" @run='run' :prizeData='prizeData' :prizeNum='prizeNum' :data='data' :bg='bg3' :activityStatus='activityStatus' :residue='residue'></model3>
  11. </div>
  12. </template>
  13. <script>
  14. // import { getToLogin } from '@/util/util'
  15. import bg1 from '@/assets/bg1.png'
  16. import bg2 from '@/assets/bg2.jpg'
  17. import bg3 from '@/assets/bg3.jpg'
  18. import wxsdk from '@/util/share'
  19. import model1 from '@/components/model1'
  20. import model2 from '@/components/model2'
  21. import model3 from '@/components/model3'
  22. import { mapState, createNamespacedHelpers } from 'vuex'
  23. const { mapActions: mapAppActions } = createNamespacedHelpers('app')
  24. export default {
  25. data () {
  26. return {
  27. bg1,
  28. bg2,
  29. bg3,
  30. round: false,
  31. showDialog: false,
  32. data: {
  33. userInfo: {},
  34. prize: {},
  35. prizeList: [],
  36. list: [],
  37. hasTitle: true
  38. },
  39. prizeData: {},
  40. prizeNum: false,
  41. winning: '',
  42. showBtn: false,
  43. jump: '',
  44. model: 0,
  45. showPage: false,
  46. activityStatus: 1,
  47. residue: 1
  48. }
  49. },
  50. components: {
  51. model1,
  52. model2,
  53. model3
  54. },
  55. created () {
  56. this.LotteryId(this.$route.query.lotteryId)
  57. // this.showPage = true
  58. // this.model = 3 // 模板
  59. if (location.search && this.toolClass.UrlSearch(location.search).code) {
  60. this.code = this.toolClass.UrlSearch(location.search).code
  61. } else {
  62. this.code = null
  63. }
  64. this.getUserInfo({ code: this.code, luckdrawid: this.lotteryId }).then((res) => {
  65. if (typeof (res) === 'object') {
  66. if (res.appid && res.appid !== '') {
  67. this.toolClass.getCode(res.appid)
  68. } else {
  69. this.data.userInfo = this.userInfo
  70. this.residue = this.data.userInfo.set.SurplusNum
  71. this.getData()
  72. }
  73. }
  74. }).catch((err) => {
  75. console.log(err)
  76. })
  77. },
  78. computed: {
  79. ...mapState({
  80. userInfo: x => x.app.userInfo,
  81. prize: x => x.app.prize,
  82. list: x => x.app.record,
  83. lotteryId: x => x.app.lotteryId,
  84. isRun: x => x.app.runState
  85. })
  86. },
  87. methods: {
  88. ...mapAppActions(['getUserInfo', 'getPrize', 'setPrize', 'getRecord', 'setUser', 'setRunState', 'LotteryId']),
  89. getData () {
  90. this.getPrize({ id: this.lotteryId }).then((res) => {
  91. this.showPage = true
  92. this.data.prize = this.prize
  93. this.data.prizeList = this.data.prize.Prizes
  94. for (let i = 0; i < this.data.prizeList.length; i++) {
  95. this.data.prizeList[i].PrizeName = this.data.prizeList[i].PrizeName ? this.data.prizeList[i].PrizeName : '谢谢参与'
  96. }
  97. this.model = res.TplId ? Math.floor(res.TplId) : 3 // 模板
  98. if (this.model === 1) {
  99. this.bg1 = res.Imgs ? res.Imgs[0].ImgUrl : this.bg1
  100. } else if (this.model === 2) {
  101. this.bg2 = res.Imgs ? res.Imgs[0].ImgUrl : this.bg2
  102. } else if (this.model === 3) {
  103. this.bg3 = res.Imgs ? res.Imgs[0].ImgUrl : this.bg3
  104. }
  105. this.data.hasTitle = res.Imgs ? 0 : 1
  106. this.activityStatus = this.data.prize.Status
  107. let now = new Date().getTime()
  108. let start = new Date(this.data.prize.BeginDate).getTime()
  109. let end = new Date(this.data.prize.EndDate).getTime()
  110. if (this.activityStatus === 1) {
  111. if (now < start) {
  112. this.activityStatus = 0
  113. } else if (now > start && now < end) {
  114. this.activityStatus = this.data.prize.Status
  115. } else if (now > end) {
  116. this.activityStatus = 9
  117. }
  118. } else if (this.activityStatus === -1) {
  119. } else {
  120. this.activityStatus = 9
  121. }
  122. wxsdk({ url: encodeURIComponent(window.location.href.split('#')[0]) }, { // 随模板变动
  123. title: res.Name,
  124. desc: '精美礼品免费抽取,机会有限,速来参与',
  125. link: `${window.location.origin}${window.location.pathname}#/from/${this.data.userInfo.user.CustomerId}?lotteryId=${this.lotteryId}`,
  126. thu_image: `https://spaceofcheng.oss-cn-beijing.aliyuncs.com/indexlogo.jpg?x-oss-process=style/wxicon`
  127. })
  128. })
  129. this.getRecord({ id: this.lotteryId }).then((res) => {
  130. this.data.list = this.list
  131. })
  132. },
  133. start () {
  134. return new Promise((resolve, reject) => {
  135. if (this.isRun) {
  136. } else {
  137. this.setRunState(1)
  138. this.setPrize({ id: this.lotteryId }).then((res) => {
  139. for (let i = 0; i < this.data.prizeList.length; i++) {
  140. if (this.data.prizeList[i].Id === res.prize.Id) {
  141. this.prizeData = res // 中奖数据
  142. this.prizeNum = i // 奖品位于奖品列表的第几条
  143. }
  144. }
  145. resolve(res)
  146. }).catch((err) => {
  147. console.log(err)
  148. reject(err)
  149. this.setRunState(0)
  150. })
  151. }
  152. })
  153. },
  154. run () {
  155. if (this.data.userInfo.user.Phone === '') {
  156. this.$dialog.confirm({
  157. title: '提示',
  158. message: '您不是城的空间会员,前往注册免费获取抽奖机会',
  159. confirmButtonText: '立即前往',
  160. cancelButtonText: '放弃机会',
  161. overlay: true,
  162. lockScroll: true
  163. }).then(() => {
  164. const luckshare = this.$route.params.id ? `&luckshare=${this.$route.params.id}` : ''
  165. window.location.href = `${window.location.origin}/wechat/user.html#/bindMobile?isLottery=1${luckshare}&lotteryId=${this.lotteryId}`
  166. }).catch(() => {
  167. return false
  168. })
  169. } else {
  170. if (this.activityStatus === -1) {
  171. this.$toast('当前活动已不存在')
  172. return
  173. }
  174. this.start().then((res) => {
  175. if (this.$route.params.id) {
  176. if (this.$route.query.isnew) {
  177. this.setUser({ toId: this.lotteryId, fromId: this.$route.params.id, isnew: this.$route.query.isnew })
  178. } else {
  179. this.setUser({ toId: this.lotteryId, fromId: this.$route.params.id })
  180. }
  181. } else {
  182. if (this.$route.query.isnew) {
  183. this.setUser({ toId: this.lotteryId, isnew: this.$route.query.isnew })
  184. }
  185. }
  186. this.getUserInfo({ code: this.code, luckdrawid: this.lotteryId }).then((res) => {
  187. if (typeof (res) === 'object') {
  188. if (res.appid && res.appid !== '') {
  189. this.toolClass.getCode(res.appid)
  190. } else {
  191. this.data.userInfo = this.userInfo
  192. this.residue = this.data.userInfo.set.SurplusNum
  193. }
  194. }
  195. }).catch((err) => {
  196. console.log(err)
  197. })
  198. }).catch(() => {
  199. this.setRunState(0)
  200. })
  201. }
  202. }
  203. },
  204. watch: {
  205. isRun: {
  206. handler (cur, old) {
  207. if (cur === 2) {
  208. this.setRunState(0)
  209. this.getRecord({ id: this.lotteryId }).then((res) => {
  210. this.data.list = this.list
  211. })
  212. }
  213. },
  214. immediate: false,
  215. deep: false
  216. }
  217. }
  218. }
  219. </script>