Commit 4db5b92d by 谢中龙

广告弹出框

parent c7971084
......@@ -3,30 +3,182 @@ var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
const utilLink = require('../../utils/currentLinkRouter')
Component({
/**
* 组件的属性列表
*/
properties: {
showDialog : {
type: Boolean,
value: false
pageInfo : {
type: Object,
value: {}
},
currentHasUserInfo: {
type: Boolean,
type: false
},
},
observers:{
pageInfo(val){
this.handleAdDialog(val);
}
},
/**
* 组件的初始数据
*/
data: {
showDialog : false,
imageUrl : '',
needAuth : false,
dialogInfo : {},
},
lifetimes:{
attached(){
// console.log(this.data.pageInfo)
},
created(){
}
},
/**
* 组件的方法列表
*/
methods: {
_getUserInfo(res = {}) {
this.triggerEvent('getAuth', res);
},
//处理广告弹出层
handleAdDialog(page){
if(!page){
this.data.showDialog = false;
this.setData({
showDialog : this.data.showDialog
});
return ;
}
if(!page.hasDialog){
this.data.showDialog = false;
this.setData({
showDialog : this.data.showDialog
});
return ;
}
//有弹框
this.data.showDialog = true;
let dialogInfo = page.dialogInfo ? JSON.parse(page.dialogInfo) : null;
if(dialogInfo){
this.data.imageUrl = dialogInfo.imageUrl;
if (dialogInfo.link) {
if (dialogInfo.link.type == 2) {
// 父组件 更新
const urls = getCurrentPages()
const currentPath = urls[0]
const pageId = dialogInfo.link.url
dialogInfo.link.newPath = `/${currentPath.route}`
}
} else if (dialogInfo.row) {
newRow = JSON.parse(dialogInfo.row)
if (newRow.type == 8) {
newRow.newPath = '/pages/productDetail/productDetail'
} else if (newRow.type == 9) {
newRow.newPath = '/subPackage/page/pages/categoryPro/categoryPro'
}
dialogInfo.row = newRow
}
let checkUrl = '';
if (dialogInfo.link) {
checkUrl = dialogInfo.link.newPath ? dialogInfo.link.newPath : dialogInfo.link.url
} else if (dialogInfo.row) {
checkUrl = dialogInfo.row.newPath ? dialogInfo.row.newPath : dialogInfo.row.url
}
dialogInfo.needAuth = false;
wxService.NoLoginPage(checkUrl).then(res => {
if(checkUrl) {
dialogInfo.needAuth = res.needAuth;
this.setData({
dialogInfo : dialogInfo,
});
}
});
}
this.setData({
imageUrl : this.data.imageUrl,
showDialog : this.data.showDialog && !this.todayHasDialog(),
dialogInfo : dialogInfo,
});
},
//预览
preview(event) {
if(!this.data.pageInfo.hasDialog){
return ;
}
utilLink.currentLinkRouter(event, this);
},
//设置弹出框本地弹出状态 //每天都弹出
setLocalDialogStatus(){
let currentRouter = getCurrentPages()[getCurrentPages().length - 1].route;
let dialogInfo = wx.getStorageSync('dialogInfo');
let key = `${currentRouter}_d_${this.getCurrentYearMonDay()}`;
if(!dialogInfo){
dialogInfo = {};
dialogInfo[key] = true;
wx.setStorageSync('dialogInfo',dialogInfo);
}
else{
//先设置进去
dialogInfo[key] = true;
wx.setStorageSync('dialogInfo',dialogInfo);
//获取今天的当前也的key
let expiredAllKey = [];
for(let k in dialogInfo){
let expiredKey = k.split('_d_')[1];
if(parseInt(expiredKey) < parseInt(this.getCurrentYearMonDay())){
expiredAllKey.push(k);
}
}
//移除今天一起的过期key
expiredAllKey.forEach(item => {
delete dialogInfo[item];
});
}
},
//获取今天是否已经弹出了
todayHasDialog(){
let currentRouter = getCurrentPages()[getCurrentPages().length - 1].route;
let dialogInfo = wx.getStorageSync('dialogInfo');
let key = `${currentRouter}_d_${this.getCurrentYearMonDay()}`;
if(!dialogInfo){
return false;
}
if(dialogInfo[key]){
return true
}
return false;
},
//获取当前年月日
getCurrentYearMonDay(){
let da = new Date();
return `${da.getFullYear()}${da.getMonth()}${da.getDate()}`;
},
//关闭
onTapClose(){
this.setLocalDialogStatus();
this.setData({
showDialog :false
});
......
<!--component/adDialog/adDialog.wxml-->
<view class="ad-modal-bg" wx:if="{{showDialog}}">
<view class="ad-modal-body">
<image mode="widthFix" src="https://hwimagecdn.ihotwind.cn/hotwind-activity/home_get_coupon.png"></image>
<view class="show-img">
<!-- 是否需要授权 -->
<view class="positionRe" wx:if="{{dialogInfo.needAuth}}">
<button
wx:if="{{!currentHasUserInfo}}"
bindgetuserinfo="_getUserInfo"
data-jflag="false"
open-type='getUserInfo'
class='positionAbs clear-btn'
hover-class="btn-hover">
<image mode="widthFix"
data-appid="{{dialogInfo.link.appid}}"
data-path="{{dialogInfo.link.url}}"
data-link="{{dialogInfo.link}}"
data-item="{{dialogInfo}}"
src="{{imageUrl}}"></image>
</button>
<!-- 已授权 -->
<image mode="widthFix"
wx:if="{{currentHasUserInfo}}"
data-appid="{{dialogInfo.link.appid}}"
data-path="{{dialogInfo.link.url}}"
data-link="{{dialogInfo.link}}"
data-item="{{dialogInfo}}"
bindtap='preview'
src="{{imageUrl}}"></image>
</view>
<!-- 不需要授权 -->
<image mode="widthFix"
wx:if="{{!dialogInfo.needAuth}}"
data-appid="{{dialogInfo.link.appid}}"
data-path="{{dialogInfo.link.url}}"
data-link="{{dialogInfo.link}}"
data-item="{{dialogInfo}}"
bindtap='preview'
src="{{imageUrl}}"></image>
</view>
<view class="close-dia">
<image src="/assets/imgs/close.png" mode="aspectFit" bindtap="onTapClose"></image>
</view>
......
......@@ -22,8 +22,15 @@
justify-content: center;
}
.ad-modal-bg .ad-modal-body image{
.ad-modal-bg .ad-modal-body .show-img{
width: 100%;
height: auto;
}
.ad-modal-bg .ad-modal-body .show-img image{
width: 100%;
height: auto;
}
.ad-modal-bg .ad-modal-body .close-dia{
......
......@@ -258,37 +258,7 @@ wxService.page({
// 直接调支付
// this.handleGoBuy(skuIds)
},
handleGoBuy(parmas) {
// 下单
wx.showLoading({
title: '加载中'
})
// 获取支付参数
wxService.post(`/sale/trade/buyer/create`,parmas).then(res => {
if (!res) return false;
const { result, data } = res && res.data || res && res.result
if (result == 0) {
delete data.appId
let amount = data.amount || 0
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
// wx.showToast({
// title: '支付成功',
// icon: 'none',
// mask: true
// })
// 支付成功页面
wxService.router(`/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}`)
},
fail(res) {
wx.hideLoading()
wxService.router('/subPackage/page/pages/paymentStatus/paymentStatus?status=F')
}
}, data))
}
})
},
// 调整商品 /trolley/add
editOk(cartPro) {
// count skuId
......
......@@ -885,7 +885,7 @@ wxService.page({
let tempArr = res.data.data ? res.data.data : [];
let currentType = _this.data.currentType;
if (tempArr.length == 0) {
wx.redirectTo({
wx.reLaunch({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
return;
......@@ -909,14 +909,14 @@ wxService.page({
}
},
complete: (res) => {
wx.redirectTo({
wx.reLaunch({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
}
})
}).catch(err => {
let currentType = _this.data.currentType;
wx.redirectTo({
wx.reLaunch({
url: `/subPackage/page/pages/paymentStatus/paymentStatus?status=S&amount=${amount}&type=${currentType}`,
});
})
......@@ -928,11 +928,11 @@ wxService.page({
icon: 'none'
});
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
wx.reLaunch({
url: '/pages/order/order',
});
} else {
wx.redirectTo({
wx.reLaunch({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
......@@ -940,11 +940,11 @@ wxService.page({
}, data.wxParams));
} else {
if (_this.data.currentType == 'delivery') {
wx.redirectTo({
wx.reLaunch({
url: '/pages/order/order',
});
} else {
wx.redirectTo({
wx.reLaunch({
url: '/subPackage/page/pages/selfPickUpOrderList/selfPickUpOrderList',
});
}
......
......@@ -32,7 +32,9 @@ wxService.page({
currHomePageId: '',
skuVOList: [],
isQiye: false,
contactUsModal: false
contactUsModal: false,
//显示广告
pageInfo : null,
},
/**
* 生命周期函数--监听页面加载
......@@ -234,12 +236,14 @@ wxService.page({
// 动态设置title
wx.setNavigationBarTitle({
title: data.page.title
})
});
this.data.pageInfo = data.page;
// 首页 pageId
// data.page.pageId
this.setData({
currHomePageId: data.page.pageId
})
currHomePageId: data.page.pageId,
pageInfo : this.data.pageInfo
});
// 段落
const products = data.paragraphs
......
......@@ -15,6 +15,7 @@
"authorization-modal": "/component/authorization-modal/authorization-modal",
"plus": "/component/plus/plus",
"cell": "plugin://contactPlugin/cell",
"ad-dialog": "/component/adDialog/adDialog",
"contact-us-modal": "/component/contactUsModal/contactUsModal"
}
}
\ No newline at end of file
......@@ -51,3 +51,6 @@
<!-- 联系我点击成功之后的回调 -->
<contact-us-modal contactShow="{{contactUsModal}}"/>
<!-- 广告 -->
<ad-dialog pageInfo="{{pageInfo}}" currentHasUserInfo="{{currentHasUserInfo}}" bind:getAuth="_getUserInfo"/>
\ No newline at end of file
......@@ -41,7 +41,7 @@ wxService.page({
contactUsModal : false,
apiIsOk : true,
//显示广告
showDialog : true,
pageInfo : null,
},
/**
* 生命周期函数--监听页面加载
......@@ -285,6 +285,8 @@ wxService.page({
//把页面信息缓存到本地
//获取tabs
let tabs = data.paragraphs.filter(item => item.type == 5);
this.data.pageInfo = data.page;
if(tabs.length > 0){
wx.setStorageSync('navBars', tabs[0]);
}
......@@ -302,8 +304,9 @@ wxService.page({
// 首页 pageId
// data.page.pageId
this.setData({
currHomePageId: data.page.pageId
})
currHomePageId: data.page.pageId,
pageInfo : this.data.pageInfo
});
// 段落
const products = data.paragraphs
......
......@@ -81,4 +81,4 @@
<exception wx:if="{{!apiIsOk}}" bind:reCall="onTapReCall"/>
<!-- 广告 -->
<!-- <ad-dialog showDialog="{{showDialog}}"/> -->
<ad-dialog pageInfo="{{pageInfo}}" currentHasUserInfo="{{currentHasUserInfo}}" bind:getAuth="_getUserInfo"/>
......@@ -32,7 +32,9 @@ wxService.page({
pageBackgroundColor: 0,
guidePageModalShow: false,
currHomePageId: '',
skuVOList:[]
skuVOList:[],
//显示广告
pageInfo : null,
},
/**
* 生命周期函数--监听页面加载
......@@ -225,23 +227,25 @@ wxService.page({
wxService.post(`/merchant/modelPage/getDetailById?pageId=${pageId}&brandId=${app.globalData.brandId}`).then(res => {
// wxService.post(`/merchant/modelPage/mainSetting/mall?brandId=${app.globalData.brandId}`).then(res => {
if (!res) return false
const { result, data } = res.data
console.log(data.page.backgroundColor)
const { result, data } = res.data;
this.data.pageBackgroundColor = data.page.backgroundColor ? data.page.backgroundColor : 0;
if (result == 0) {
this.setData({
pageBackgroundColor: this.data.pageBackgroundColor
})
});
// 动态设置title
wx.setNavigationBarTitle({
title: data.page.title
})
});
this.data.pageInfo = data.page;
// 首页 pageId
// data.page.pageId
this.setData({
currHomePageId: data.page.pageId
})
currHomePageId: data.page.pageId,
pageInfo : this.data.pageInfo
});
// 段落
const products = data.paragraphs
const filterResult = products.map((res, index) => {
......@@ -262,7 +266,6 @@ wxService.page({
let tabbar = products.filter(item => item.type == 5);
let plus = products.filter(item => item.type == 9);
console.log(this.data.outoHeigth)
if (plus.length != 0) {
this.setData({
paddingBottom: '96rpx',
......
......@@ -14,6 +14,7 @@
"guide-page-modal": "/component/guidePageModal/guidePageModal",
"bottom-tabs": "/component/bottomTabs/bottomTabs",
"authorization-modal": "/component/authorization-modal/authorization-modal",
"ad-dialog": "/component/adDialog/adDialog",
"plus": "/component/plus/plus"
}
}
\ No newline at end of file
......@@ -35,4 +35,7 @@
<guide-page-modal show="{{guidePageModalShow}}" />
<!-- 底部补充高度 防止被遮盖 -->
<view class="bottom-fixed" style="padding-bottom:{{paddingBottom}}"></view>
<go-guid/>
\ No newline at end of file
<go-guid/>
<!-- 广告 -->
<ad-dialog pageInfo="{{pageInfo}}" currentHasUserInfo="{{currentHasUserInfo}}" bind:getAuth="_getUserInfo"/>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment