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() //这里隐藏了底部导航栏 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;
} }

200
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,
@ -45,7 +46,7 @@ Page({
}) })
// 获取购物车按钮的位置 // 获取购物车按钮的位置
wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) { wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) {
console.log(res) console.log(res)
that.setData({ that.setData({
cartTop: res.top cartTop: res.top
}) })
@ -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,10 +144,11 @@ Page({
}) })
}, },
changeMenu: function (e) { changeMenu: function (e) {
let index = e.currentTarget.dataset.index, that = this; let index = e.currentTarget.dataset.index,
const query = wx.createSelectorQuery(); //创建节点查询器 that = this;
query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息 const query = wx.createSelectorQuery(); //创建节点查询器
query.selectViewport().scrollOffset() //获取页面查询位置的 query.select("#box" + index).boundingClientRect() //选择toViewid获取位置信息
query.selectViewport().scrollOffset() //获取页面查询位置的
query.exec(function (res) { query.exec(function (res) {
let scrollTop = res[0].top + res[1].scrollTop - 110 * ratio - that.data.top; let scrollTop = res[0].top + res[1].scrollTop - 110 * ratio - that.data.top;
wx.pageScrollTo({ wx.pageScrollTo({
@ -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,30 +170,27 @@ Page({
that.setData({ that.setData({
fixed: true fixed: true
}) })
} } else {
else {
that.setData({ that.setData({
fixed: false fixed: false
}) })
} }
// 滚动时判断滚动到哪个部分了 // 滚动时判断滚动到哪个部分了
const query = wx.createSelectorQuery(); //创建节点查询器 const query = wx.createSelectorQuery(); //创建节点查询器
query.select("#box1").boundingClientRect() //选择toViewid获取位置信息 query.select("#box1").boundingClientRect() //选择toViewid获取位置信息
query.select("#box2").boundingClientRect() //选择toViewid获取位置信息 query.select("#box2").boundingClientRect() //选择toViewid获取位置信息
query.select("#box3").boundingClientRect() //选择toViewid获取位置信息 query.select("#box3").boundingClientRect() //选择toViewid获取位置信息
let minHeight = that.data.fixed ? (110 * ratio + height) : topHeight; let minHeight = that.data.fixed ? (110 * ratio + height) : topHeight;
query.exec(function (res) { query.exec(function (res) {
if (res[2].top < minHeight) { if (res[2].top < minHeight) {
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
}) })
@ -256,67 +255,75 @@ Page({
}) })
}, },
order: function () { order: function () {
app.globalData.postProduct = null app.globalData.postProduct = null
app.globalData.list = [] app.globalData.list = []
if (this.data.skuFlag == 'order') { // commonApi.user_post("/product/checkStock", {
util.pagePoint({ // sku_id: this.data.info.sku[this.data.skuIndex].id,
event: 'product_order', // }).then(res => {
param: { // if (res && res.code != 1) {
id: this.data.info.id, // return;
type: this.data.info.type // } else {
} if (this.data.skuFlag == 'order') {
}, 1) util.pagePoint({
wx.setStorageSync('login_from', 'product_order_login') event: 'product_order',
wx.setStorageSync('order_from', 'product_order_submit') param: {
app.globalData.couponInfo = null; id: this.data.info.id,
// 购买 type: this.data.info.type
let product = [{ }
product: this.data.info, }, 1)
sku: this.data.info.sku[this.data.skuIndex], wx.setStorageSync('login_from', 'product_order_login')
productNum: this.data.producNum wx.setStorageSync('order_from', 'product_order_submit')
}]; app.globalData.couponInfo = null;
app.globalData.postProduct = product; // 购买
app.globalData.retailId = this.data.retailId; let product = [{
wx.navigateTo({ product: this.data.info,
url: '/pages/order/postOrder/index', sku: this.data.info.sku[this.data.skuIndex],
}) productNum: this.data.producNum
} }];
else { app.globalData.postProduct = product;
commonApi.user_post("cart/add_sku", { app.globalData.retailId = this.data.retailId;
sku_id: this.data.info.sku[this.data.skuIndex].id, wx.navigateTo({
num: this.data.producNum url: '/pages/order/postOrder/index',
}).then(res => {
if (res.code == 1) {
commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({
cartCount: res.data.length
})
}) })
// 加动效 } else {
this.setData({ commonApi.user_post("cart/add_sku", {
skuFlag: null, sku_id: this.data.info.sku[this.data.skuIndex].id,
aniSkuIndex: this.data.skuIndex, num: this.data.producNum
cartImgInfo: null }).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 () { 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)

284
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,8 +22,8 @@ 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,
aniSkuIndex: -1, aniSkuIndex: -1,
@ -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 => {
@ -225,24 +229,24 @@ Page({
}) })
}, },
// order: function(e){ // order: function(e){
// console.log(e) // console.log(e)
// if (e.currentTarget.dataset.disable == 1) return; // if (e.currentTarget.dataset.disable == 1) return;
// util.pagePoint({ // util.pagePoint({
// event: 'scene_order', // event: 'scene_order',
// param: { // param: {
// type: this.data.info.type, // type: this.data.info.type,
// id: this.data.info.id // id: this.data.info.id
// } // }
// }, 1) // }, 1)
// wx.setStorageSync('login_from', 'scene_order_login') // wx.setStorageSync('login_from', 'scene_order_login')
// wx.setStorageSync('order_from', 'scene_order_submit') // wx.setStorageSync('order_from', 'scene_order_submit')
// app.globalData.couponInfo = null; // app.globalData.couponInfo = null;
// 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;
// app.globalData.product = e.currentTarget.dataset; // app.globalData.product = e.currentTarget.dataset;
// wx.navigateTo({ // wx.navigateTo({
// url: '/pages/order/scene/index', // url: '/pages/order/scene/index',
// }) // })
// }, // },
selectSku: function (e) { selectSku: function (e) {
let index = e.currentTarget.dataset.index; let index = e.currentTarget.dataset.index;
@ -251,74 +255,85 @@ 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
app.globalData.postProduct = [] // })
app.globalData.list = [] // return;
if (this.data.skuFlag == 'order'){ // } else {
if (e.currentTarget.dataset.disable == 1) return; app.globalData.postProduct = []
util.pagePoint({ app.globalData.list = []
event: 'scene_order', if (this.data.skuFlag == 'order') {
param: { if (e.currentTarget.dataset.disable == 1) return;
type: this.data.info.type, util.pagePoint({
id: this.data.info.id event: 'scene_order',
} param: {
}, 1) type: this.data.info.type,
wx.setStorageSync('login_from', 'scene_order_login') id: this.data.info.id
wx.setStorageSync('order_from', 'scene_order_submit') }
app.globalData.couponInfo = null; }, 1)
app.globalData.retailId = this.data.retailId; wx.setStorageSync('login_from', 'scene_order_login')
// let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product; wx.setStorageSync('order_from', 'scene_order_submit')
// let sku = {sku:e.currentTarget.dataset.product.sku[this.data.skuIndex]},product = {product: e.currentTarget.dataset.product} app.globalData.couponInfo = null;
let sku = {sku:this.data.skuList[this.data.skuIndex]},product = {product:this.data.info.product[this.data.skuList[this.data.skuIndex].proIndex]} app.globalData.retailId = this.data.retailId;
app.globalData.product = {...sku,...product} // let sku = e.currentTarget.dataset.sku,product = e.currentTarget.dataset.product;
wx.navigateTo({ // let sku = {sku:e.currentTarget.dataset.product.sku[this.data.skuIndex]},product = {product: e.currentTarget.dataset.product}
url: '/pages/order/scene/index', let sku = {
}) sku: this.data.skuList[this.data.skuIndex]
}else { },
commonApi.user_post("cart/add_sku", { product = {
sku_id: this.data.skuList[this.data.skuIndex].id, product: this.data.info.product[this.data.skuList[this.data.skuIndex].proIndex]
num: this.data.producNum }
}).then(res => { app.globalData.product = {
if (res.code == 1) { ...sku,
commonApi.user_post('cart/get_list', {}).then(res => { ...product
this.setData({ }
cartCount: res.data.length wx.navigateTo({
}) url: '/pages/order/scene/index',
}) })
// 加动效 } else {
this.setData({ commonApi.user_post("cart/add_sku", {
skuFlag: null, sku_id: this.data.skuList[this.data.skuIndex].id,
aniSkuIndex: this.data.skuIndex, num: this.data.producNum
cartImgInfo: null }).then(res => {
}) if (res.code == 1) {
setTimeout(() => { commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({ this.setData({
aniSkuIndex: -1 cartCount: res.data.length
}) })
wx.showModal({ })
title: "提示", // 加动效
content: "去购物车结算?", this.setData({
success: function (res) { skuFlag: null,
if (res.confirm) { aniSkuIndex: this.data.skuIndex,
wx.navigateTo({ cartImgInfo: null
url: '/pages/user/cartlist/list', })
}) setTimeout(() => {
} this.setData({
} aniSkuIndex: -1
}) })
}, 650) wx.showModal({
} title: "提示",
}) content: "去购物车结算?",
} success: function (res) {
} if (res.confirm) {
}) wx.navigateTo({
url: '/pages/user/cartlist/list',
})
}
}
})
}, 650)
}
})
}
// }
// })
}, },
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;
} }
@ -602,7 +623,7 @@ Page({
cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;'
}) })
}).exec() }).exec()
}, },
hideSku: function () { hideSku: function () {
this.setData({ this.setData({
@ -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)
@ -656,11 +676,11 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
commonApi.user_post('cart/get_list', {}).then(res => { commonApi.user_post('cart/get_list', {}).then(res => {
this.setData({ this.setData({
cartCount: res.data.length cartCount: res.data.length
}) })
}) })
if (!wx.getStorageSync('jstrip_token')) { if (!wx.getStorageSync('jstrip_token')) {
return; return;
} }
@ -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