Browse Source

库存判断 首页广告

master
caichunsheng 4 years ago
parent
commit
e0142ba7c6
  1. 5
      pages/index/index.js
  2. 2
      pages/index/index.wxml
  3. 4
      pages/index/index.wxss
  4. 200
      pages/info/postProductInfo/index.js
  5. 284
      pages/info/sceneProductInfo/index.js

5
pages/index/index.js

@ -46,7 +46,7 @@ Page({
wx.hideTabBar() //这里隐藏了底部导航栏
commonApi._post("adv/getAdv", {
position: 2,
type_id: 5
type_id: 3
}).then(res => {
if (res.data.length > 0) {
this.setData({
@ -191,7 +191,7 @@ Page({
//弹窗广告
commonApi._post("adv/getAdv", {
position: 3,
type_id: 5
type_id: 3
}).then(res => {
if (res.data.length > 0) {
this.setData({
@ -631,7 +631,6 @@ Page({
})
},
bannerJumpNew(item) {
let that = this
item = item.currentTarget.dataset.item
if (item.tdata == '') return

2
pages/index/index.wxml

@ -433,7 +433,7 @@
<swiper class="alertsp" indicator-dots='{{true}}' indicator-color="rgba(255,255,255,0.5)" autoplay="{{true}}" interval="{{3000}}" duration="{{300}}" indicator-active-color="white">
<block wx:for="{{alertSwipeList}}" wx:key="*this">
<swiper-item data-item="{{item}}" bindtap="bannerJumpNew" >
<image src="{{item.head_img}}" style="width: 100%;height: 100%;" mode="widthFix"></image>
<image src="{{item.head_img}}" style="width: 100%; height:100%; border-radius: 10rpx;" mode="aspectFill"></image>
</swiper-item>
</block>
</swiper>

4
pages/index/index.wxss

@ -684,11 +684,11 @@
}
.alertavd{
width: 500rpx;
height: 500rpx;
height: 700rpx;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-250rpx,-150rpx);
transform: translate(-250rpx,-300rpx);
z-index: 999;
}

200
pages/info/postProductInfo/index.js

@ -37,7 +37,8 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let rect = wx.getMenuButtonBoundingClientRect(), that = this;
let rect = wx.getMenuButtonBoundingClientRect(),
that = this;
let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight;
this.setData({
top: height,
@ -45,7 +46,7 @@ Page({
})
// 获取购物车按钮的位置
wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) {
console.log(res)
console.log(res)
that.setData({
cartTop: res.top
})
@ -87,7 +88,7 @@ Page({
}).then(res => {
res.data.list.map(item => {
item.rate = Number(item.rate)
item.create_time = item.create_time.substring(0,10)
item.create_time = item.create_time.substring(0, 10)
})
this.setData({
@ -95,15 +96,15 @@ Page({
commentTotal: res.data.total
})
let arr = this.data.comment
arr.map((item)=>{
arr.map((item) => {
if (item.img_list) {
item.img_list = item.img_list.split(',')
}else{
item.img_list=[]
} else {
item.img_list = []
}
})
this.setData({
comment:arr
comment: arr
})
})
@ -123,16 +124,15 @@ Page({
source_id: this.data.info.id,
url: "/pages/info/postProductInfo/index?id=" + this.data.info.id,
uuid: app.globalData.uuid
}).then(res => {
})
}
else {
}).then(res => {})
} else {
this.BroswerRecord();
}
}, 500)
},
like: function () {
let id = this.data.id, isLike = this.data.isLike;
let id = this.data.id,
isLike = this.data.isLike;
commonApi.user_post("product/" + (isLike == 1 ? "product_cancel_collection" : "product_collection"), {
product_id: id
}).then(res => {
@ -144,10 +144,11 @@ Page({
})
},
changeMenu: function (e) {
let index = e.currentTarget.dataset.index, that = this;
const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息
query.selectViewport().scrollOffset() //获取页面查询位置的
let index = e.currentTarget.dataset.index,
that = this;
const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息
query.selectViewport().scrollOffset() //获取页面查询位置的
query.exec(function (res) {
let scrollTop = res[0].top + res[1].scrollTop - 110 * ratio - that.data.top;
wx.pageScrollTo({
@ -160,7 +161,8 @@ Page({
})
},
onPageScroll: function (e) {
let that = this, height = this.data.top;
let that = this,
height = this.data.top;
let topHeight = height;
wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) {
if (rect.top <= topHeight) {
@ -168,30 +170,27 @@ Page({
that.setData({
fixed: true
})
}
else {
} else {
that.setData({
fixed: false
})
}
// 滚动时判断滚动到哪个部分了
const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box1").boundingClientRect() //选择toViewid获取位置信息
query.select("#box2").boundingClientRect() //选择toViewid获取位置信息
query.select("#box3").boundingClientRect() //选择toViewid获取位置信息
const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box1").boundingClientRect() //选择toViewid获取位置信息
query.select("#box2").boundingClientRect() //选择toViewid获取位置信息
query.select("#box3").boundingClientRect() //选择toViewid获取位置信息
let minHeight = that.data.fixed ? (110 * ratio + height) : topHeight;
query.exec(function (res) {
if (res[2].top < minHeight) {
that.setData({
type: 3
})
}
else if (res[1].top < minHeight) {
} else if (res[1].top < minHeight) {
that.setData({
type: 2
})
}
else {
} else {
that.setData({
type: 1
})
@ -256,67 +255,75 @@ Page({
})
},
order: function () {
app.globalData.postProduct = null
app.globalData.list = []
if (this.data.skuFlag == 'order') {
util.pagePoint({
event: 'product_order',
param: {
id: this.data.info.id,
type: this.data.info.type
}
}, 1)
wx.setStorageSync('login_from', 'product_order_login')
wx.setStorageSync('order_from', 'product_order_submit')
app.globalData.couponInfo = null;
// 购买
let product = [{
product: this.data.info,
sku: this.data.info.sku[this.data.skuIndex],
productNum: this.data.producNum
}];
app.globalData.postProduct = product;
app.globalData.retailId = this.data.retailId;
wx.navigateTo({
url: '/pages/order/postOrder/index',
})
}
else {
commonApi.user_post("cart/add_sku", {
sku_id: this.data.info.sku[this.data.skuIndex].id,
num: this.data.producNum
}).then(res => {
if (res.code == 1) {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
app.globalData.postProduct = null
app.globalData.list = []
// commonApi.user_post("/product/checkStock", {
// sku_id: this.data.info.sku[this.data.skuIndex].id,
// }).then(res => {
// if (res && res.code != 1) {
// return;
// } else {
if (this.data.skuFlag == 'order') {
util.pagePoint({
event: 'product_order',
param: {
id: this.data.info.id,
type: this.data.info.type
}
}, 1)
wx.setStorageSync('login_from', 'product_order_login')
wx.setStorageSync('order_from', 'product_order_submit')
app.globalData.couponInfo = null;
// 购买
let product = [{
product: this.data.info,
sku: this.data.info.sku[this.data.skuIndex],
productNum: this.data.producNum
}];
app.globalData.postProduct = product;
app.globalData.retailId = this.data.retailId;
wx.navigateTo({
url: '/pages/order/postOrder/index',
})
// 加动效
this.setData({
skuFlag: null,
aniSkuIndex: this.data.skuIndex,
cartImgInfo: null
} else {
commonApi.user_post("cart/add_sku", {
sku_id: this.data.info.sku[this.data.skuIndex].id,
num: this.data.producNum
}).then(res => {
if (res.code == 1) {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
})
// 加动效
this.setData({
skuFlag: null,
aniSkuIndex: this.data.skuIndex,
cartImgInfo: null
})
setTimeout(() => {
this.setData({
aniSkuIndex: -1
})
wx.showModal({
title: "提示",
content: "去购物车结算?",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/user/cartlist/list',
})
}
}
})
}, 650)
}
})
setTimeout(() => {
this.setData({
aniSkuIndex: -1
})
wx.showModal({
title: "提示",
content: "去购物车结算?",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/user/cartlist/list',
})
}
}
})
}, 650)
}
})
}
// }
// })
},
// 分享
share: function () {
@ -344,7 +351,8 @@ Page({
},
// 保存
save() {
let url = this.data.shareImg, that = this;
let url = this.data.shareImg,
that = this;
wx.authorize({
/* 这个就是保存相册的 */
scope: 'scope.writePhotosAlbum',
@ -397,7 +405,8 @@ Page({
},
// 绘制海报
drawImg: function () {
var that = this, userinfo = wx.getStorageSync('jstrip_userInfo');
var that = this,
userinfo = wx.getStorageSync('jstrip_userInfo');
if (!userinfo) {
// 去登录
return false;
@ -436,7 +445,7 @@ Page({
ctx.save();
ctx.beginPath(); //开始绘制
that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc')
ctx.clip();//画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio);
ctx.restore();
ctx.save();
@ -547,12 +556,13 @@ Page({
},
// 绘制两行文字
drawText: function (ctx, str, x, y, canvasWidth, ratio) {
let row = [], temp = "", chr = str.split("");
let row = [],
temp = "",
chr = str.split("");
for (var a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < canvasWidth) {
temp += chr[a];
}
else {
} else {
a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比
row.push(temp);
temp = "";
@ -569,13 +579,12 @@ Page({
for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < canvasWidth - 30 * ratio) {
test += rowPart[a];
}
else {
} else {
break;
}
}
empty.push(test);
var group = empty[0] + "..."//这里只显示两行,超出的用...表示
var group = empty[0] + "..." //这里只显示两行,超出的用...表示
rowCut.splice(1, 1, group);
row = rowCut;
}
@ -611,8 +620,7 @@ Page({
cartCount: res.data.length
})
})
}
else {
} else {
setTimeout(() => {
this.onShow()
}, 200)

284
pages/info/sceneProductInfo/index.js

@ -6,7 +6,6 @@ import util from "../../../utils/util"
import QRCode from '../../../utils/weapp-qrcode.js'
let app = getApp()
Page({
/**
* 页面的初始数据
*/
@ -23,8 +22,8 @@ Page({
shareImg: null,
showShareFlag: false,
showAllowance: false,
allowance_data:null,
//购物车数量
allowance_data: null,
//购物车数量
producNum: 1,
skuIndex: 0,
aniSkuIndex: -1,
@ -32,7 +31,7 @@ Page({
cartImgInfo: null,
cartTop: 0,
top: 0,
skuList:[],//立即预定的列表
skuList: [], //立即预定的列表
},
/**
@ -98,16 +97,22 @@ Page({
info: res.data
})
var arr = []
res.data.product.forEach((item,index) => {
item.sku.forEach(itemB=>{
itemB.proIndex = index
arr.push(itemB)
})
res.data.product.forEach((item, index) => {
item.sku.forEach(itemB => {
itemB.proIndex = index
arr.push(itemB)
})
});
this.setData({
skuList:arr
skuList: arr
})
util.pagePoint({ event: 'scene_view', param: { type: res.data.type, id: res.data.id } }, 1)
util.pagePoint({
event: 'scene_view',
param: {
type: res.data.type,
id: res.data.id
}
}, 1)
this.BroswerRecord()
})
// 获取收藏的状态
@ -141,17 +146,17 @@ Page({
commentTotal: res.data.total
})
let arr = this.data.comment
arr.map((item)=>{
arr.map((item) => {
if (item.img_list) {
let arr = item.img_list.split(',')
let arr = item.img_list.split(',')
item.img_list = arr
}else{
item.img_list=[]
} else {
item.img_list = []
}
})
this.setData({
comment:arr
comment: arr
})
})
},
@ -170,16 +175,15 @@ Page({
source_id: this.data.info.id,
url: "/pages/info/sceneProductInfo/index?id=" + this.data.info.id,
uuid: app.globalData.uuid
}).then(res => {
})
}
else {
}).then(res => {})
} else {
this.BroswerRecord();
}
}, 500)
},
like: function () {
let id = this.data.id, isLike = Number(this.data.isLike);
let id = this.data.id,
isLike = Number(this.data.isLike);
commonApi.user_post(isLike != 1 ? "scene/scene_collection" : "scene/scene_cancel_collection", {
scene_id: id
}).then(res => {
@ -225,24 +229,24 @@ Page({
})
},
// order: function(e){
// console.log(e)
// if (e.currentTarget.dataset.disable == 1) return;
// util.pagePoint({
// event: 'scene_order',
// param: {
// type: this.data.info.type,
// id: this.data.info.id
// }
// }, 1)
// wx.setStorageSync('login_from', 'scene_order_login')
// wx.setStorageSync('order_from', 'scene_order_submit')
// app.globalData.couponInfo = null;
// app.globalData.retailId = this.data.retailId;
// // let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product;
// app.globalData.product = e.currentTarget.dataset;
// wx.navigateTo({
// url: '/pages/order/scene/index',
// })
// console.log(e)
// if (e.currentTarget.dataset.disable == 1) return;
// util.pagePoint({
// event: 'scene_order',
// param: {
// type: this.data.info.type,
// id: this.data.info.id
// }
// }, 1)
// wx.setStorageSync('login_from', 'scene_order_login')
// wx.setStorageSync('order_from', 'scene_order_submit')
// app.globalData.couponInfo = null;
// app.globalData.retailId = this.data.retailId;
// // let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product;
// app.globalData.product = e.currentTarget.dataset;
// wx.navigateTo({
// url: '/pages/order/scene/index',
// })
// },
selectSku: function (e) {
let index = e.currentTarget.dataset.index;
@ -251,74 +255,85 @@ Page({
})
},
order: function (e) {
commonApi.user_post("/product/checkStock",{
sku_id: this.data.skuList[this.data.skuIndex].id,
}).then(res => {
console.log(res)
if(res && res.code != 1){
return;
}else{
// console.log(this.data.info,this.data.skuFlag)
app.globalData.postProduct = []
app.globalData.list = []
if (this.data.skuFlag == 'order'){
if (e.currentTarget.dataset.disable == 1) return;
util.pagePoint({
event: 'scene_order',
param: {
type: this.data.info.type,
id: this.data.info.id
}
}, 1)
wx.setStorageSync('login_from', 'scene_order_login')
wx.setStorageSync('order_from', 'scene_order_submit')
app.globalData.couponInfo = null;
app.globalData.retailId = this.data.retailId;
// let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product;
// let sku = {sku:e.currentTarget.dataset.product.sku[this.data.skuIndex]},product = {product: e.currentTarget.dataset.product}
let sku = {sku:this.data.skuList[this.data.skuIndex]},product = {product:this.data.info.product[this.data.skuList[this.data.skuIndex].proIndex]}
app.globalData.product = {...sku,...product}
wx.navigateTo({
url: '/pages/order/scene/index',
})
}else {
commonApi.user_post("cart/add_sku", {
sku_id: this.data.skuList[this.data.skuIndex].id,
num: this.data.producNum
}).then(res => {
if (res.code == 1) {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
})
// 加动效
this.setData({
skuFlag: null,
aniSkuIndex: this.data.skuIndex,
cartImgInfo: null
})
setTimeout(() => {
this.setData({
aniSkuIndex: -1
})
wx.showModal({
title: "提示",
content: "去购物车结算?",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/user/cartlist/list',
})
}
}
})
}, 650)
}
})
}
}
})
// commonApi.user_post("/product/checkStock", {
// sku_id: this.data.skuList[this.data.skuIndex].id,
// }).then(res => {
// if (res && res.code != 1) {
// wx.showModal({
// title: "温馨提示",
// content: '商品已经被抢光啦~要不要瞧瞧别的~',
// showCancel: false
// })
// return;
// } else {
app.globalData.postProduct = []
app.globalData.list = []
if (this.data.skuFlag == 'order') {
if (e.currentTarget.dataset.disable == 1) return;
util.pagePoint({
event: 'scene_order',
param: {
type: this.data.info.type,
id: this.data.info.id
}
}, 1)
wx.setStorageSync('login_from', 'scene_order_login')
wx.setStorageSync('order_from', 'scene_order_submit')
app.globalData.couponInfo = null;
app.globalData.retailId = this.data.retailId;
// let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product;
// let sku = {sku:e.currentTarget.dataset.product.sku[this.data.skuIndex]},product = {product: e.currentTarget.dataset.product}
let sku = {
sku: this.data.skuList[this.data.skuIndex]
},
product = {
product: this.data.info.product[this.data.skuList[this.data.skuIndex].proIndex]
}
app.globalData.product = {
...sku,
...product
}
wx.navigateTo({
url: '/pages/order/scene/index',
})
} else {
commonApi.user_post("cart/add_sku", {
sku_id: this.data.skuList[this.data.skuIndex].id,
num: this.data.producNum
}).then(res => {
if (res.code == 1) {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
})
// 加动效
this.setData({
skuFlag: null,
aniSkuIndex: this.data.skuIndex,
cartImgInfo: null
})
setTimeout(() => {
this.setData({
aniSkuIndex: -1
})
wx.showModal({
title: "提示",
content: "去购物车结算?",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/user/cartlist/list',
})
}
}
})
}, 650)
}
})
}
// }
// })
},
pagePoint: function (e) {
util.pagePoint({
@ -333,9 +348,7 @@ Page({
share: function () {
if (!wx.getStorageSync("jstrip_token")) {
wx.setStorageSync('login_from', 'scene_share_login')
commonApi.user_post("user/getMyInfo", {}).then(res => {
}).catch(err => {
})
commonApi.user_post("user/getMyInfo", {}).then(res => {}).catch(err => {})
return;
}
if (!this.data.shareImg) {
@ -351,7 +364,8 @@ Page({
},
// 保存
save() {
let url = this.data.shareImg, that = this;
let url = this.data.shareImg,
that = this;
wx.authorize({
/* 这个就是保存相册的 */
scope: 'scope.writePhotosAlbum',
@ -366,7 +380,13 @@ Page({
that.setData({
showShareFlag: !that.data.showShareFlag
})
util.pagePoint({ event: 'scene_share_save', param: { type: that.data.info.type, id: that.data.info.id } }, 1)
util.pagePoint({
event: 'scene_share_save',
param: {
type: that.data.info.type,
id: that.data.info.id
}
}, 1)
},
fail(res) {
wx.showToast({
@ -396,7 +416,8 @@ Page({
},
// 绘制海报
drawImg: function () {
var that = this, userinfo = wx.getStorageSync('jstrip_userInfo');
var that = this,
userinfo = wx.getStorageSync('jstrip_userInfo');
if (!userinfo) {
// 去登录
return false;
@ -434,7 +455,7 @@ Page({
ctx.save();
ctx.beginPath(); //开始绘制
that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc')
ctx.clip();//画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio);
ctx.restore();
ctx.save();
@ -548,12 +569,13 @@ Page({
},
// 绘制两行文字
drawText: function (ctx, str, x, y, canvasWidth, ratio) {
let row = [], temp = "", chr = str.split("");
let row = [],
temp = "",
chr = str.split("");
for (var a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < canvasWidth) {
temp += chr[a];
}
else {
} else {
a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比
row.push(temp);
temp = "";
@ -570,13 +592,12 @@ Page({
for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < canvasWidth - 30 * ratio) {
test += rowPart[a];
}
else {
} else {
break;
}
}
empty.push(test);
var group = empty[0] + "..."//这里只显示两行,超出的用...表示
var group = empty[0] + "..." //这里只显示两行,超出的用...表示
rowCut.splice(1, 1, group);
row = rowCut;
}
@ -602,7 +623,7 @@ Page({
cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;'
})
}).exec()
},
hideSku: function () {
this.setData({
@ -644,8 +665,7 @@ Page({
this.setData({
isTest: app.globalData.configJson.isTest
})
}
else {
} else {
setTimeout(() => {
this.onReady()
}, 300)
@ -656,11 +676,11 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
})
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
})
if (!wx.getStorageSync('jstrip_token')) {
return;
}
@ -696,8 +716,7 @@ Page({
}
})
}
}
else {
} else {
setTimeout(() => {
this.onShow()
}, 200)
@ -736,6 +755,5 @@ Page({
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
onShareAppMessage: function () {}
})
Loading…
Cancel
Save