adWindow.vue 9.4 KB

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