adWindow.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view v-if="visible">
  3. <view v-if="adInfo.jumpType === 3 && couponList && couponList.length> 0" class="mask mask-coupon ad-coupons"
  4. @touchmove.stop.prevent="moveHandle">
  5. <view class="ad-box-warp">
  6. <view class="ad-boxs">
  7. <image class="img" :src="adInfo.popupImg" mode="widthFix"></image>
  8. <view class="coupon-list">
  9. <scroll-view :scroll-top="0" class="scrollBox" scroll-y="true">
  10. <view class="item" v-for="(item, index) in couponList" :key="index">
  11. <view class="money">
  12. <text class="num"
  13. :class="[item.discountMode ===1?'num-minus':'num-discount']">{{ item.reduceMoney }}</text>
  14. <text class="text">
  15. 满{{ item.fullMoney }}元可用
  16. </text>
  17. </view>
  18. <view class="text">
  19. <text>
  20. {{item.activityName}}
  21. </text>
  22. </view>
  23. </view>
  24. </scroll-view>
  25. </view>
  26. <WxSendCoupon v-if="couponList && couponList.length > 0" :couponList="couponList" @closeAd="close">
  27. <view class="btn-receive">一键领取</view>
  28. </WxSendCoupon>
  29. </view>
  30. <view class="close-btn">
  31. <image :src="adInfo.closeImg" class='btn' mode="widthFix" @click="close()"></image>
  32. </view>
  33. </view>
  34. </view>
  35. <view v-else-if="adInfo.jumpType !== 3" class="mask mask-coupon ad-link">
  36. <view class="ad-box-warp">
  37. <view class="ad-boxs" @click="goRoll()">
  38. <image class="img" :src="adInfo.popupImg" mode="widthFix"></image>
  39. </view>
  40. <view class="close-btn">
  41. <image :src="adInfo.closeImg" class='btn' mode="widthFix" @click="close()"></image>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import WxSendCoupon from "./wx/wxSendCoupon";
  49. const NET = require('../utils/request')
  50. const API = require('../config/api')
  51. export default {
  52. name: "adWindow",
  53. components: {
  54. WxSendCoupon
  55. },
  56. props: {
  57. triggerCondition: {
  58. type: Number,
  59. default: 1
  60. }
  61. },
  62. data() {
  63. return {
  64. visible: false,
  65. adInfo: {},
  66. jumpContent: {},
  67. couponList: [],
  68. isLogin: false,
  69. buyerUserId: 0,
  70. cParams: {}
  71. };
  72. },
  73. methods: {
  74. // 阻止滑动
  75. moveHandle() {
  76. return
  77. },
  78. // 获取广告信息
  79. getAd() {
  80. const res = uni.getStorageSync('storage_key'),
  81. token = res.token;
  82. this.buyerUserId = res.buyerUserId
  83. this.isLogin = !!token
  84. NET.request(API.GetAd, {
  85. triggerCondition: this.triggerCondition
  86. }, 'POST').then(res => {
  87. if (res.data) {
  88. this.adInfo = res.data[0]
  89. if (this.adInfo.jumpContent) {
  90. this.jumpContent = JSON.parse(this.adInfo.jumpContent)
  91. }
  92. this.visible = true
  93. if (this.adInfo.jumpType === 3) {
  94. this.getCoupons()
  95. }
  96. }
  97. }).catch(res => {
  98. })
  99. },
  100. // 查询优惠券
  101. getCoupons() {
  102. if (this.isLogin) {
  103. const _items = this.jumpContent.items
  104. if (_items) {
  105. NET.request(API.getCoupons, {
  106. page: 1,
  107. pageSize: 99,
  108. ids: _items
  109. }, 'GET').then(res => {
  110. if (res.data) {
  111. this.couponList = res.data.list
  112. }
  113. }).catch(res => {
  114. })
  115. }
  116. } else {
  117. uni.showToast({
  118. title: '登录之后领取更多优惠',
  119. icon: "none"
  120. })
  121. // uni.navigateTo({
  122. // url: '/pages_category_page2/userModule/login'
  123. // })
  124. }
  125. },
  126. // 关闭弹窗
  127. close() {
  128. this.visible = false
  129. var params = {}
  130. if (this.isLogin) {
  131. params.buyerUserId = this.buyerUserId
  132. } else {
  133. uni.getSystemInfo({
  134. success: function(res) {
  135. params.deviceId = res.deviceId
  136. }
  137. })
  138. }
  139. NET.request(API.adClose, params, 'POST').then(res => {}).catch(res => {})
  140. },
  141. goRoll() {
  142. this.visible = false
  143. switch (this.adInfo.jumpType) {
  144. case 1:
  145. uni.navigateTo({
  146. url: '/pages_category_page1/goodsModule/goodsDetails?shopId=' + this.jumpContent
  147. .shopId + '&productId=' + this.jumpContent.productId + '&skuId=' + this.jumpContent
  148. .skuId
  149. })
  150. break
  151. case 2:
  152. uni.navigateTo({
  153. url: `/pages_category_page1/goodsModule/goodsList?category3Id=${this.jumpContent.id}`
  154. })
  155. break
  156. case 4:
  157. uni.navigateToMiniProgram({
  158. appId: this.jumpContent.appId,
  159. path: this.jumpContent.id,
  160. success(res) {
  161. // 打开成功
  162. }
  163. })
  164. case 5:
  165. uni.navigateTo({
  166. path: this.jumpContent.link
  167. })
  168. break
  169. }
  170. },
  171. }
  172. };
  173. </script>
  174. <style scoped lang="scss">
  175. .mask {
  176. position: fixed;
  177. top: 0;
  178. left: 0;
  179. right: 0;
  180. bottom: 0;
  181. z-index: 55;
  182. background-color: rgba(0, 0, 0, 0.5);
  183. }
  184. .mask-coupon {
  185. z-index: 9999;
  186. background: rgba(39, 38, 39, .15);
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. .ad-box-warp {
  191. width: 100%;
  192. position: relative;
  193. }
  194. flex-direction: column;
  195. .ad-boxs {
  196. position: relative;
  197. width: 100%;
  198. .img {
  199. width: 100%;
  200. }
  201. }
  202. .btn-receive {
  203. width: 446rpx;
  204. height: 84rpx;
  205. background: #EC6F43;
  206. border-radius: 42rpx;
  207. display: block;
  208. text-align: center;
  209. font-size: 28rpx;
  210. line-height: 84rpx;
  211. color: #fff;
  212. position: absolute;
  213. bottom: 32rpx;
  214. left: 50%;
  215. margin-left: -223rpx;
  216. }
  217. .close-btn {
  218. position: absolute;
  219. bottom: -70rpx;
  220. left: 50%;
  221. margin-left: -25rpx;
  222. .btn {
  223. width: 50rpx;
  224. height: 50rpx;
  225. }
  226. }
  227. }
  228. .ad-coupons {
  229. .ad-box-warp {
  230. width: 510rpx;
  231. }
  232. .coupon-list {
  233. width: 446rpx;
  234. height: 295rpx;
  235. overflow: auto;
  236. position: absolute;
  237. top: 308rpx;
  238. left: 50%;
  239. margin-left: -223rpx;
  240. .scrollBox {
  241. height: 294upx;
  242. }
  243. .item {
  244. width: 100%;
  245. height: 140rpx;
  246. background-color: #fff;
  247. margin-top: 15rpx;
  248. border-radius: 8rpx;
  249. display: flex;
  250. position: relative;
  251. align-items: center;
  252. &:first-child {
  253. margin-top: 0px;
  254. }
  255. &:before,
  256. &:after {
  257. content: '';
  258. width: 32rpx;
  259. height: 32rpx;
  260. background: #000;
  261. border-radius: 50%;
  262. display: block;
  263. position: absolute;
  264. top: 50%;
  265. margin-top: -16rpx;
  266. }
  267. &:before {
  268. left: -16rpx;
  269. }
  270. &:after {
  271. right: -16rpx;
  272. }
  273. .money {
  274. width: 190rpx;
  275. text-align: center;
  276. .num {
  277. font-size: 48rpx;
  278. color: #EC6F43;
  279. display: block;
  280. &.num-minus::before {
  281. content: '¥';
  282. font-size: 36rpx;
  283. }
  284. &.num-discount::after {
  285. content: '折';
  286. font-size: 36rpx;
  287. }
  288. }
  289. .text {
  290. font-size: 24rpx;
  291. color: #999;
  292. }
  293. }
  294. .text {
  295. flex: 1;
  296. padding-right: 16rpx;
  297. width: 0;
  298. text {
  299. font-size: 32rpx;
  300. color: #333;
  301. display: block;
  302. overflow: hidden;
  303. text-overflow: ellipsis;
  304. white-space: nowrap;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. </style>