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. 72
      pages/info/postProductInfo/index.js
  5. 116
      pages/info/sceneProductInfo/index.js

5
pages/index/index.js

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

4
pages/index/index.wxss

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

72
pages/info/postProductInfo/index.js

@ -37,7 +37,8 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { 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; let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight;
this.setData({ this.setData({
top: height, top: height,
@ -87,7 +88,7 @@ Page({
}).then(res => { }).then(res => {
res.data.list.map(item => { res.data.list.map(item => {
item.rate = Number(item.rate) 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({ this.setData({
@ -95,15 +96,15 @@ Page({
commentTotal: res.data.total commentTotal: res.data.total
}) })
let arr = this.data.comment let arr = this.data.comment
arr.map((item)=>{ arr.map((item) => {
if (item.img_list) { if (item.img_list) {
item.img_list = item.img_list.split(',') item.img_list = item.img_list.split(',')
}else{ } else {
item.img_list=[] item.img_list = []
} }
}) })
this.setData({ this.setData({
comment:arr comment: arr
}) })
}) })
@ -123,16 +124,15 @@ Page({
source_id: this.data.info.id, source_id: this.data.info.id,
url: "/pages/info/postProductInfo/index?id=" + this.data.info.id, url: "/pages/info/postProductInfo/index?id=" + this.data.info.id,
uuid: app.globalData.uuid uuid: app.globalData.uuid
}).then(res => { }).then(res => {})
}) } else {
}
else {
this.BroswerRecord(); this.BroswerRecord();
} }
}, 500) }, 500)
}, },
like: function () { 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"), { commonApi.user_post("product/" + (isLike == 1 ? "product_cancel_collection" : "product_collection"), {
product_id: id product_id: id
}).then(res => { }).then(res => {
@ -144,7 +144,8 @@ Page({
}) })
}, },
changeMenu: function (e) { changeMenu: function (e) {
let index = e.currentTarget.dataset.index, that = this; let index = e.currentTarget.dataset.index,
that = this;
const query = wx.createSelectorQuery(); //创建节点查询器 const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息 query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息
query.selectViewport().scrollOffset() //获取页面查询位置的 query.selectViewport().scrollOffset() //获取页面查询位置的
@ -160,7 +161,8 @@ Page({
}) })
}, },
onPageScroll: function (e) { onPageScroll: function (e) {
let that = this, height = this.data.top; let that = this,
height = this.data.top;
let topHeight = height; let topHeight = height;
wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) { wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) {
if (rect.top <= topHeight) { if (rect.top <= topHeight) {
@ -168,8 +170,7 @@ Page({
that.setData({ that.setData({
fixed: true fixed: true
}) })
} } else {
else {
that.setData({ that.setData({
fixed: false fixed: false
}) })
@ -185,13 +186,11 @@ Page({
that.setData({ that.setData({
type: 3 type: 3
}) })
} } else if (res[1].top < minHeight) {
else if (res[1].top < minHeight) {
that.setData({ that.setData({
type: 2 type: 2
}) })
} } else {
else {
that.setData({ that.setData({
type: 1 type: 1
}) })
@ -258,6 +257,12 @@ Page({
order: function () { order: function () {
app.globalData.postProduct = null app.globalData.postProduct = null
app.globalData.list = [] 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') { if (this.data.skuFlag == 'order') {
util.pagePoint({ util.pagePoint({
event: 'product_order', event: 'product_order',
@ -280,8 +285,7 @@ Page({
wx.navigateTo({ wx.navigateTo({
url: '/pages/order/postOrder/index', url: '/pages/order/postOrder/index',
}) })
} } else {
else {
commonApi.user_post("cart/add_sku", { commonApi.user_post("cart/add_sku", {
sku_id: this.data.info.sku[this.data.skuIndex].id, sku_id: this.data.info.sku[this.data.skuIndex].id,
num: this.data.producNum num: this.data.producNum
@ -317,6 +321,9 @@ Page({
} }
}) })
} }
// }
// })
}, },
// 分享 // 分享
share: function () { share: function () {
@ -344,7 +351,8 @@ Page({
}, },
// 保存 // 保存
save() { save() {
let url = this.data.shareImg, that = this; let url = this.data.shareImg,
that = this;
wx.authorize({ wx.authorize({
/* 这个就是保存相册的 */ /* 这个就是保存相册的 */
scope: 'scope.writePhotosAlbum', scope: 'scope.writePhotosAlbum',
@ -397,7 +405,8 @@ Page({
}, },
// 绘制海报 // 绘制海报
drawImg: function () { drawImg: function () {
var that = this, userinfo = wx.getStorageSync('jstrip_userInfo'); var that = this,
userinfo = wx.getStorageSync('jstrip_userInfo');
if (!userinfo) { if (!userinfo) {
// 去登录 // 去登录
return false; return false;
@ -436,7 +445,7 @@ Page({
ctx.save(); ctx.save();
ctx.beginPath(); //开始绘制 ctx.beginPath(); //开始绘制
that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') 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.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio);
ctx.restore(); ctx.restore();
ctx.save(); ctx.save();
@ -547,12 +556,13 @@ Page({
}, },
// 绘制两行文字 // 绘制两行文字
drawText: function (ctx, str, x, y, canvasWidth, ratio) { 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++) { for (var a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < canvasWidth) { if (ctx.measureText(temp).width < canvasWidth) {
temp += chr[a]; temp += chr[a];
} } else {
else {
a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比
row.push(temp); row.push(temp);
temp = ""; temp = "";
@ -569,13 +579,12 @@ Page({
for (var a = 0; a < rowPart.length; a++) { for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { if (ctx.measureText(test).width < canvasWidth - 30 * ratio) {
test += rowPart[a]; test += rowPart[a];
} } else {
else {
break; break;
} }
} }
empty.push(test); empty.push(test);
var group = empty[0] + "..."//这里只显示两行,超出的用...表示 var group = empty[0] + "..." //这里只显示两行,超出的用...表示
rowCut.splice(1, 1, group); rowCut.splice(1, 1, group);
row = rowCut; row = rowCut;
} }
@ -611,8 +620,7 @@ Page({
cartCount: res.data.length cartCount: res.data.length
}) })
}) })
} } else {
else {
setTimeout(() => { setTimeout(() => {
this.onShow() this.onShow()
}, 200) }, 200)

116
pages/info/sceneProductInfo/index.js

@ -6,7 +6,6 @@ import util from "../../../utils/util"
import QRCode from '../../../utils/weapp-qrcode.js' import QRCode from '../../../utils/weapp-qrcode.js'
let app = getApp() let app = getApp()
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
@ -23,7 +22,7 @@ Page({
shareImg: null, shareImg: null,
showShareFlag: false, showShareFlag: false,
showAllowance: false, showAllowance: false,
allowance_data:null, allowance_data: null,
//购物车数量 //购物车数量
producNum: 1, producNum: 1,
skuIndex: 0, skuIndex: 0,
@ -32,7 +31,7 @@ Page({
cartImgInfo: null, cartImgInfo: null,
cartTop: 0, cartTop: 0,
top: 0, top: 0,
skuList:[],//立即预定的列表 skuList: [], //立即预定的列表
}, },
/** /**
@ -98,16 +97,22 @@ Page({
info: res.data info: res.data
}) })
var arr = [] var arr = []
res.data.product.forEach((item,index) => { res.data.product.forEach((item, index) => {
item.sku.forEach(itemB=>{ item.sku.forEach(itemB => {
itemB.proIndex = index itemB.proIndex = index
arr.push(itemB) arr.push(itemB)
}) })
}); });
this.setData({ 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() this.BroswerRecord()
}) })
// 获取收藏的状态 // 获取收藏的状态
@ -141,17 +146,17 @@ Page({
commentTotal: res.data.total commentTotal: res.data.total
}) })
let arr = this.data.comment let arr = this.data.comment
arr.map((item)=>{ arr.map((item) => {
if (item.img_list) { if (item.img_list) {
let arr = item.img_list.split(',') let arr = item.img_list.split(',')
item.img_list = arr item.img_list = arr
}else{ } else {
item.img_list=[] item.img_list = []
} }
}) })
this.setData({ this.setData({
comment:arr comment: arr
}) })
}) })
}, },
@ -170,16 +175,15 @@ Page({
source_id: this.data.info.id, source_id: this.data.info.id,
url: "/pages/info/sceneProductInfo/index?id=" + this.data.info.id, url: "/pages/info/sceneProductInfo/index?id=" + this.data.info.id,
uuid: app.globalData.uuid uuid: app.globalData.uuid
}).then(res => { }).then(res => {})
}) } else {
}
else {
this.BroswerRecord(); this.BroswerRecord();
} }
}, 500) }, 500)
}, },
like: function () { 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", { commonApi.user_post(isLike != 1 ? "scene/scene_collection" : "scene/scene_cancel_collection", {
scene_id: id scene_id: id
}).then(res => { }).then(res => {
@ -251,17 +255,20 @@ Page({
}) })
}, },
order: function (e) { order: function (e) {
commonApi.user_post("/product/checkStock",{ // commonApi.user_post("/product/checkStock", {
sku_id: this.data.skuList[this.data.skuIndex].id, // sku_id: this.data.skuList[this.data.skuIndex].id,
}).then(res => { // }).then(res => {
console.log(res) // if (res && res.code != 1) {
if(res && res.code != 1){ // wx.showModal({
return; // title: "温馨提示",
}else{ // content: '商品已经被抢光啦~要不要瞧瞧别的~',
// console.log(this.data.info,this.data.skuFlag) // showCancel: false
// })
// return;
// } else {
app.globalData.postProduct = [] app.globalData.postProduct = []
app.globalData.list = [] app.globalData.list = []
if (this.data.skuFlag == 'order'){ if (this.data.skuFlag == 'order') {
if (e.currentTarget.dataset.disable == 1) return; if (e.currentTarget.dataset.disable == 1) return;
util.pagePoint({ util.pagePoint({
event: 'scene_order', event: 'scene_order',
@ -276,12 +283,20 @@ Page({
app.globalData.retailId = this.data.retailId; app.globalData.retailId = this.data.retailId;
// let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product; // 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: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]} let sku = {
app.globalData.product = {...sku,...product} 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({ wx.navigateTo({
url: '/pages/order/scene/index', url: '/pages/order/scene/index',
}) })
}else { } else {
commonApi.user_post("cart/add_sku", { commonApi.user_post("cart/add_sku", {
sku_id: this.data.skuList[this.data.skuIndex].id, sku_id: this.data.skuList[this.data.skuIndex].id,
num: this.data.producNum num: this.data.producNum
@ -317,8 +332,8 @@ Page({
} }
}) })
} }
} // }
}) // })
}, },
pagePoint: function (e) { pagePoint: function (e) {
util.pagePoint({ util.pagePoint({
@ -333,9 +348,7 @@ Page({
share: function () { share: function () {
if (!wx.getStorageSync("jstrip_token")) { if (!wx.getStorageSync("jstrip_token")) {
wx.setStorageSync('login_from', 'scene_share_login') wx.setStorageSync('login_from', 'scene_share_login')
commonApi.user_post("user/getMyInfo", {}).then(res => { commonApi.user_post("user/getMyInfo", {}).then(res => {}).catch(err => {})
}).catch(err => {
})
return; return;
} }
if (!this.data.shareImg) { if (!this.data.shareImg) {
@ -351,7 +364,8 @@ Page({
}, },
// 保存 // 保存
save() { save() {
let url = this.data.shareImg, that = this; let url = this.data.shareImg,
that = this;
wx.authorize({ wx.authorize({
/* 这个就是保存相册的 */ /* 这个就是保存相册的 */
scope: 'scope.writePhotosAlbum', scope: 'scope.writePhotosAlbum',
@ -366,7 +380,13 @@ Page({
that.setData({ that.setData({
showShareFlag: !that.data.showShareFlag 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) { fail(res) {
wx.showToast({ wx.showToast({
@ -396,7 +416,8 @@ Page({
}, },
// 绘制海报 // 绘制海报
drawImg: function () { drawImg: function () {
var that = this, userinfo = wx.getStorageSync('jstrip_userInfo'); var that = this,
userinfo = wx.getStorageSync('jstrip_userInfo');
if (!userinfo) { if (!userinfo) {
// 去登录 // 去登录
return false; return false;
@ -434,7 +455,7 @@ Page({
ctx.save(); ctx.save();
ctx.beginPath(); //开始绘制 ctx.beginPath(); //开始绘制
that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') 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.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio);
ctx.restore(); ctx.restore();
ctx.save(); ctx.save();
@ -548,12 +569,13 @@ Page({
}, },
// 绘制两行文字 // 绘制两行文字
drawText: function (ctx, str, x, y, canvasWidth, ratio) { 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++) { for (var a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < canvasWidth) { if (ctx.measureText(temp).width < canvasWidth) {
temp += chr[a]; temp += chr[a];
} } else {
else {
a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比
row.push(temp); row.push(temp);
temp = ""; temp = "";
@ -570,13 +592,12 @@ Page({
for (var a = 0; a < rowPart.length; a++) { for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { if (ctx.measureText(test).width < canvasWidth - 30 * ratio) {
test += rowPart[a]; test += rowPart[a];
} } else {
else {
break; break;
} }
} }
empty.push(test); empty.push(test);
var group = empty[0] + "..."//这里只显示两行,超出的用...表示 var group = empty[0] + "..." //这里只显示两行,超出的用...表示
rowCut.splice(1, 1, group); rowCut.splice(1, 1, group);
row = rowCut; row = rowCut;
} }
@ -644,8 +665,7 @@ Page({
this.setData({ this.setData({
isTest: app.globalData.configJson.isTest isTest: app.globalData.configJson.isTest
}) })
} } else {
else {
setTimeout(() => { setTimeout(() => {
this.onReady() this.onReady()
}, 300) }, 300)
@ -696,8 +716,7 @@ Page({
} }
}) })
} }
} } else {
else {
setTimeout(() => { setTimeout(() => {
this.onShow() this.onShow()
}, 200) }, 200)
@ -736,6 +755,5 @@ Page({
/** /**
* 用户点击右上角分享 * 用户点击右上角分享
*/ */
onShareAppMessage: function () { onShareAppMessage: function () {}
}
}) })
Loading…
Cancel
Save