adWindow.vue 8.1 KB

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