From b4edfb6d4e03b96a6ef5e31965a263c046db0f49 Mon Sep 17 00:00:00 2001 From: nige Date: Wed, 21 Jun 2023 17:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=BA=E5=88=B6=E5=85=B3=E6=B3=A8,=E7=94=B5?= =?UTF-8?q?=E5=BD=B1=E4=B8=8B=E5=8D=95=E9=A1=B5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/info/hotelProductInfo/index.js | 102 +- pages/info/hotelProductInfo/index.json | 4 +- pages/info/hotelProductInfo/index.wxml | 9 +- pages/info/museumInfo/index.js | 57 +- pages/info/museumInfo/index.json | 4 +- pages/info/museumInfo/index.wxml | 4 +- pages/info/postProductInfo/index.js | 1331 +++++++------- pages/info/postProductInfo/index.json | 4 +- pages/info/postProductInfo/index.wxml | 4 +- pages/info/roadInfo/index.js | 933 +++++----- pages/info/roadInfo/index.json | 4 +- pages/info/roadInfo/index.wxml | 4 +- pages/info/sceneProductInfo/index.js | 1580 +++++++++-------- pages/info/sceneProductInfo/index.json | 5 +- pages/info/sceneProductInfo/index.wxml | 4 +- pages/list/movieticket/list/ticket/index.js | 473 ++--- pages/list/movieticket/list/ticket/index.json | 3 +- pages/list/movieticket/list/ticket/index.wxml | 4 +- pages/order/components/wxqrCode/index.js | 42 + pages/order/components/wxqrCode/index.json | 4 + pages/order/components/wxqrCode/index.wxml | 13 + pages/order/components/wxqrCode/index.wxss | 70 + pages/order/movie/index.wxml | 9 +- pages/order/movie/index.wxss | 8 +- pages/user/cartlist/list.js | 688 +++---- pages/user/cartlist/list.json | 3 +- pages/user/cartlist/list.wxml | 4 +- 27 files changed, 2841 insertions(+), 2529 deletions(-) create mode 100644 pages/order/components/wxqrCode/index.js create mode 100644 pages/order/components/wxqrCode/index.json create mode 100644 pages/order/components/wxqrCode/index.wxml create mode 100644 pages/order/components/wxqrCode/index.wxss diff --git a/pages/info/hotelProductInfo/index.js b/pages/info/hotelProductInfo/index.js index b42b444..d5942c6 100644 --- a/pages/info/hotelProductInfo/index.js +++ b/pages/info/hotelProductInfo/index.js @@ -37,7 +37,9 @@ Page({ roomInfo: null, retailId: "", shareImg: null, - showShareFlag: false + showShareFlag: false, + showQrCode: false, + wxqrcode: null }, /** @@ -127,44 +129,72 @@ Page({ }) }, order: function (e) { - let item = e.currentTarget.dataset.item; - item.startDate = this.data.startDate; - item.endDate = this.data.endDate; - item.startDateText = this.data.startDateText; - item.endDateText = this.data.endDateText; - item.startDay = this.getDay(item.startDate); - item.endDay = this.getDay(item.endDate); - item.days = this.data.days; - app.globalData.product = item; - app.globalData.couponInfo = null; - wx.navigateTo({ - url: '/pages/order/hotel/index', + console.log(this.data.sceneInfo); + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/hotelProductInfo/index?id=' + this.data.id, + title: this.data.sceneInfo.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + let item = e.currentTarget.dataset.item; + item.startDate = this.data.startDate; + item.endDate = this.data.endDate; + item.startDateText = this.data.startDateText; + item.endDateText = this.data.endDateText; + item.startDay = this.getDay(item.startDate); + item.endDay = this.getDay(item.endDate); + item.days = this.data.days; + app.globalData.product = item; + app.globalData.couponInfo = null; + wx.navigateTo({ + url: '/pages/order/hotel/index', + }) + } }) }, orderMt: function (e) { - let item = e.currentTarget.dataset.item, product = e.currentTarget.dataset.product; - item.startDate = this.data.startDate; - item.endDate = this.data.endDate; - item.startDateText = this.data.startDateText; - item.endDateText = this.data.endDateText; - item.startDay = this.getDay(item.startDate); - item.endDay = this.getDay(item.endDate); - item.days = this.data.days; - item.id = item.sku_id; - // item.product_id = product.real_room_id; - item.sku_name = product.room_name; - item.sku_model = {}; - item.sku_model.area = product.useable_area + "m²"; - item.sku_model.bed_type = item.bed_type; - item.sku_model.breakfast = item.breakfast; - item.sku_model.max_room_num = item.max_room_num; - app.globalData.product = item; - app.globalData.retailId = this.data.retailId; - // return; - app.globalData.couponInfo = null; - wx.navigateTo({ - url: '/pages/order/hotel/index', - }) + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/hotelProductInfo/index?id=' + this.data.id, + title: this.data.sceneInfo.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + let item = e.currentTarget.dataset.item, product = e.currentTarget.dataset.product; + item.startDate = this.data.startDate; + item.endDate = this.data.endDate; + item.startDateText = this.data.startDateText; + item.endDateText = this.data.endDateText; + item.startDay = this.getDay(item.startDate); + item.endDay = this.getDay(item.endDate); + item.days = this.data.days; + item.id = item.sku_id; + // item.product_id = product.real_room_id; + item.sku_name = product.room_name; + item.sku_model = {}; + item.sku_model.area = product.useable_area + "m²"; + item.sku_model.bed_type = item.bed_type; + item.sku_model.breakfast = item.breakfast; + item.sku_model.max_room_num = item.max_room_num; + app.globalData.product = item; + app.globalData.retailId = this.data.retailId; + // return; + app.globalData.couponInfo = null; + wx.navigateTo({ + url: '/pages/order/hotel/index', + }) + }}) + + }, getDay: function (date) { let d = new Date(date.replace(/-/g, '/')).getDay(); diff --git a/pages/info/hotelProductInfo/index.json b/pages/info/hotelProductInfo/index.json index eb3533f..dba6e62 100644 --- a/pages/info/hotelProductInfo/index.json +++ b/pages/info/hotelProductInfo/index.json @@ -1,6 +1,8 @@ { "usingComponents": { "title":"/pages/component/TitleHeader", - "common-image":"/pages/component/commonImage/index" + "common-image":"/pages/component/commonImage/index", + "code":"../../order/components/wxqrCode/index" + } } \ No newline at end of file diff --git a/pages/info/hotelProductInfo/index.wxml b/pages/info/hotelProductInfo/index.wxml index 92fe16a..5c77760 100644 --- a/pages/info/hotelProductInfo/index.wxml +++ b/pages/info/hotelProductInfo/index.wxml @@ -53,8 +53,9 @@ {{item.room_name}} - {{item.useable_area?(item.useable_area+'m²'):''}} {{item.bedDesc}}{{item.bedType}}x{{item.bedCount}} {{item.window?item.window:''}} - {{item.low_price>0?item.low_price/100:'0'}} + + {{item.useable_area?(item.useable_area+'m²'):''}} {{item.window?item.window:''}} {{item.capacity?item.capacity+'人入住':''}} + {{item.low_price>0?item.low_price/100:'0'}} @@ -216,4 +217,6 @@ 保存到相册 - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/info/museumInfo/index.js b/pages/info/museumInfo/index.js index af26a02..a4f8e8a 100644 --- a/pages/info/museumInfo/index.js +++ b/pages/info/museumInfo/index.js @@ -26,7 +26,9 @@ Page({ retailId: "", isGroup: null, shareImg: null, - showShareFlag: false + showShareFlag: false, + showQrCode:false, + wxqrcode:null }, /** @@ -399,27 +401,38 @@ Page({ }) }, order: function () { - this.data.isGroup = null - if(this.data.product.product.flag!=1 || this.data.product.sku.flag=='off') return; - if(this.data.isGroup){ - // 如果是团队预约的话 是需要判断是否需要审核的 - commonApi.user_post("team_order/is_apply",{ - id:this.data.id - }).then(res=>{ - // 0 无需资质申请 1 需要资质申请跳转资质申请页面 - if(res && res.data==1){ - wx.navigateTo({ - url: '/pages/group/apply/index?id='+this.data.id, - }) - return; - } - this.realOrder() - }) - } - else { - this.realOrder() - } - + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/museumInfo/index?id='+this.data.id, + title:this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + this.data.isGroup = null + if(this.data.product.product.flag!=1 || this.data.product.sku.flag=='off') return; + if(this.data.isGroup){ + // 如果是团队预约的话 是需要判断是否需要审核的 + commonApi.user_post("team_order/is_apply",{ + id:this.data.id + }).then(res=>{ + // 0 无需资质申请 1 需要资质申请跳转资质申请页面 + if(res && res.data==1){ + wx.navigateTo({ + url: '/pages/group/apply/index?id='+this.data.id, + }) + return; + } + this.realOrder() + }) + } + else { + this.realOrder() + } + }}) }, order1: function () { this.data.isGroup = 1 diff --git a/pages/info/museumInfo/index.json b/pages/info/museumInfo/index.json index 5e61cff..bfbc88d 100644 --- a/pages/info/museumInfo/index.json +++ b/pages/info/museumInfo/index.json @@ -1,6 +1,8 @@ { "usingComponents": { "title":"/pages/component/TitleHeader", - "date":"/pages/order/components/date/index" + "date":"/pages/order/components/date/index", + "code":"../../order/components/wxqrCode/index" + } } \ No newline at end of file diff --git a/pages/info/museumInfo/index.wxml b/pages/info/museumInfo/index.wxml index 529faa3..0094ca3 100644 --- a/pages/info/museumInfo/index.wxml +++ b/pages/info/museumInfo/index.wxml @@ -99,4 +99,6 @@ 保存到相册 - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/info/postProductInfo/index.js b/pages/info/postProductInfo/index.js index 8bc8423..738a610 100644 --- a/pages/info/postProductInfo/index.js +++ b/pages/info/postProductInfo/index.js @@ -7,703 +7,730 @@ import util from '../../../utils/util' let app = getApp() Page({ - /** - * 页面的初始数据 - */ - data: { - autoPlay: true, - fixed: false, - type: 1, - top: 0, - isLike: 0, - commentTotal: 0, - comment: [], - info: null, - skuFlag: null, - producNum: 1, - skuIndex: 0, - aniSkuIndex: -1, - retailId: "", - cartTop: 0, - cartImgInfo: null, - cartCount: 0, - shareImg: null, - showShareFlag: false, - allowance_data: null, - showAllowance: false, - tjList: [], //推荐商品列表 - iShop:false, - supplierId:null - }, + /** + * 页面的初始数据 + */ + data: { + autoPlay: true, + fixed: false, + type: 1, + top: 0, + isLike: 0, + commentTotal: 0, + comment: [], + info: null, + skuFlag: null, + producNum: 1, + skuIndex: 0, + aniSkuIndex: -1, + retailId: "", + cartTop: 0, + cartImgInfo: null, + cartCount: 0, + shareImg: null, + showShareFlag: false, + allowance_data: null, + showAllowance: false, + tjList: [], //推荐商品列表 + iShop: false, + supplierId: null, + showQrCode: false, + wxqrcode: null + }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - //删除临时存储的联系人 - wx.removeStorageSync('linkMan') - let rect = wx.getMenuButtonBoundingClientRect(), - that = this; - let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; - this.setData({ - top: height, - id: options.id - }) - // 获取购物车按钮的位置 - wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) { - console.log(res) - that.setData({ - cartTop: res.top - }) - }).exec() + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + //删除临时存储的联系人 + wx.removeStorageSync('linkMan') + let rect = wx.getMenuButtonBoundingClientRect(), + that = this; + let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; + this.setData({ + top: height, + id: options.id + }) + // 获取购物车按钮的位置 + wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) { + console.log(res) + that.setData({ + cartTop: res.top + }) + }).exec() - if (options.retailId) { - this.setData({ - retailId: options.retailId - }) - } - commonApi._post("product/get_product_detail", { - id: options.id - }).then(res => { - res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); - if (options.skuid) { - let sku = res.data.sku.find(item => item.id == options.skuid); - res.data.sku = [sku]; - } - res.data.flag = res.data.sku.find(item => item.flag == 'on') ? res.data.flag : 0 - this.setData({ - info: res.data, - supplierId:res.data.supplier_id, - iShop:res.data.supplier_id?true:false - }) + if (options.retailId) { + this.setData({ + retailId: options.retailId + }) + } + commonApi._post("product/get_product_detail", { + id: options.id + }).then(res => { + res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); + if (options.skuid) { + let sku = res.data.sku.find(item => item.id == options.skuid); + res.data.sku = [sku]; + } + res.data.flag = res.data.sku.find(item => item.flag == 'on') ? res.data.flag : 0 + this.setData({ + info: res.data, + supplierId: res.data.supplier_id, + iShop: res.data.supplier_id ? true : false + }) - // 获取补贴 - // commonApi.user_post("product/getProductAllowancePrice", { - // product_code: res.data.product_code - // }).then(resTwo => { - // if (resTwo && resTwo.code == 1) { - // this.setData({ - // allowance_data: resTwo.data - // }) - // } - // }) - this.BroswerRecord() - }) - // 获取评价列表 - commonApi._post("product/product_comment_list", { - product_id: options.id - }).then(res => { - res.data.list.map(item => { - item.rate = Number(item.rate) - item.create_time = item.create_time.substring(0, 10) + // 获取补贴 + // commonApi.user_post("product/getProductAllowancePrice", { + // product_code: res.data.product_code + // }).then(resTwo => { + // if (resTwo && resTwo.code == 1) { + // this.setData({ + // allowance_data: resTwo.data + // }) + // } + // }) + this.BroswerRecord() + }) + // 获取评价列表 + commonApi._post("product/product_comment_list", { + product_id: options.id + }).then(res => { + res.data.list.map(item => { + item.rate = Number(item.rate) + item.create_time = item.create_time.substring(0, 10) - }) - this.setData({ - comment: res.data.list.splice(0, 2), - commentTotal: res.data.total - }) - let arr = this.data.comment - arr.map((item) => { - if (item.img_list) { - item.img_list = item.img_list.split(',') - } else { - item.img_list = [] - } - }) - this.setData({ - comment: arr - }) - }) + }) + this.setData({ + comment: res.data.list.splice(0, 2), + commentTotal: res.data.total + }) + let arr = this.data.comment + arr.map((item) => { + if (item.img_list) { + item.img_list = item.img_list.split(',') + } else { + item.img_list = [] + } + }) + this.setData({ + comment: arr + }) + }) - commonApi._post("product/get_product_by_type", { - offset: 0, - limit: 6, - rand: true, - type: 'post' - }).then(res => { - try { - this.setData({ - tjList: res.data.list + commonApi._post("product/get_product_by_type", { + offset: 0, + limit: 6, + rand: true, + type: 'post' + }).then(res => { + try { + this.setData({ + tjList: res.data.list + }) + } catch (error) { + console.log(error); + } }) - } catch (error) { - console.log(error); - } - }) - }, - changeAllowance: function () { - this.setData({ - showAllowance: !this.data.showAllowance - }) - }, - BroswerRecord: function () { - setTimeout(() => { - if (app.globalData.uuid) { - commonApi._post('browse/browse_record', { - type: "goods", - title: this.data.info.title, - drive: "mini", - source_id: this.data.info.id, - url: "/pages/info/postProductInfo/index?id=" + this.data.info.id, - uuid: app.globalData.uuid - }).then(res => {}) - } else { - this.BroswerRecord(); - } - }, 500) - }, - like: function () { - 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 => { - if (res.code == 1) { + }, + changeAllowance: function () { this.setData({ - isLike: isLike == 1 ? 0 : 1 + showAllowance: !this.data.showAllowance }) - } - }) - }, - changeMenu: function (e) { - 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({ - scrollTop: scrollTop + 4, - duration: 0 - }) - that.setData({ - type: index - }) - }) - }, - onPageScroll: function (e) { - let that = this, - height = this.data.top; - let topHeight = height; - wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) { - if (rect.top <= topHeight) { - // 此时应该把menus固定在顶部 - that.setData({ - fixed: true + }, + BroswerRecord: function () { + setTimeout(() => { + if (app.globalData.uuid) { + commonApi._post('browse/browse_record', { + type: "goods", + title: this.data.info.title, + drive: "mini", + source_id: this.data.info.id, + url: "/pages/info/postProductInfo/index?id=" + this.data.info.id, + uuid: app.globalData.uuid + }).then(res => {}) + } else { + this.BroswerRecord(); + } + }, 500) + }, + like: function () { + 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 => { + if (res.code == 1) { + this.setData({ + isLike: isLike == 1 ? 0 : 1 + }) + } }) - } else { - that.setData({ - fixed: false + }, + changeMenu: function (e) { + 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({ + scrollTop: scrollTop + 4, + duration: 0 + }) + that.setData({ + type: index + }) }) - } - // 滚动时判断滚动到哪个部分了 - 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) { - that.setData({ - type: 2 - }) - } else { - that.setData({ - type: 1 - }) - } - }) - }).exec() - - }, - showCart: function () { - if (this.data.info.sku.length == 0) { - wx.showToast({ - title: '该产品未设置规格,不能加购', - icon: 'none' - }) - return; - } - this.setData({ - skuFlag: "cart" - }) - let that = this - wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) { - console.log(res) - that.setData({ - cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' - }) - }).exec() - - }, - hideSku: function () { - this.setData({ - skuFlag: null, - cartImgInfo: null - }) - }, - minus: function () { - if (this.data.producNum == 1) return; - this.setData({ - producNum: this.data.producNum - 1 - }) - }, - add: function () { - this.setData({ - producNum: this.data.producNum + 1 - }) - }, - selectSku: function (e) { - let index = e.currentTarget.dataset.index; - this.setData({ - skuIndex: index - }) - }, - showOrder: function () { - if (this.data.info.sku.length == 0) { - wx.showToast({ - title: '该产品未设置规格,不能购买', - icon: 'none' - }) - return; - } - this.setData({ - skuFlag: 'order' - }) - }, - order: function () { - 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 + }, + onPageScroll: function (e) { + let that = this, + height = this.data.top; + let topHeight = height; + wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) { + if (rect.top <= topHeight) { + // 此时应该把menus固定在顶部 + that.setData({ + fixed: true + }) + } else { + that.setData({ + fixed: false + }) } - }, 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 => { + // 滚动时判断滚动到哪个部分了 + 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) { + that.setData({ + type: 2 + }) + } else { + that.setData({ + type: 1 + }) + } + }) + }).exec() + + }, + showCart: function () { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/postProductInfo/index?id=' + this.data.id, + title: this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { this.setData({ - cartCount: res.data.length + wxqrcode: res.data.qrcode, + showQrCode: true }) - }) - // 加动效 - this.setData({ - skuFlag: null, - aniSkuIndex: this.data.skuIndex, - cartImgInfo: null - }) - setTimeout(() => { + } else { + if (this.data.info.sku.length == 0) { + wx.showToast({ + title: '该产品未设置规格,不能加购', + icon: 'none' + }) + return; + } this.setData({ - aniSkuIndex: -1 + skuFlag: "cart" }) - wx.showModal({ - title: "提示", - content: "去购物车结算?", - success: function (res) { - if (res.confirm) { - wx.navigateTo({ - url: '/pages/user/cartlist/list', - }) - } - } + let that = this + wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) { + console.log(res) + that.setData({ + cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' + }) + }).exec() + } + }) + }, + hideSku: function () { + this.setData({ + skuFlag: null, + cartImgInfo: null + }) + }, + minus: function () { + if (this.data.producNum == 1) return; + this.setData({ + producNum: this.data.producNum - 1 + }) + }, + add: function () { + this.setData({ + producNum: this.data.producNum + 1 + }) + }, + selectSku: function (e) { + let index = e.currentTarget.dataset.index; + this.setData({ + skuIndex: index + }) + }, + showOrder: function () { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/postProductInfo/index?id=' + this.data.id, + title: this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + if (this.data.info.sku.length == 0) { + wx.showToast({ + title: '该产品未设置规格,不能购买', + icon: 'none' + }) + return; + } + this.setData({ + skuFlag: 'order' }) - }, 650) } - }) - } - } - }) - - }, - // 分享 - share: function () { - if (!wx.getStorageSync("jstrip_token")) { - util.pagePoint({ - event: 'product_share_login', - type: this.data.info.type, - id: this.data.info.id - }, 1) - commonApi.user_post("user/getMyInfo", {}).then(res => { + }) + }, + order: function () { + 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', + }) + } 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) + } + }) + } + } + }) - }) - return; - } - if (!this.data.shareImg) { - wx.showToast({ - title: '图片生成中,稍后再试', - icon: 'none' - }) - return; - } - this.setData({ - showShareFlag: !this.data.showShareFlag - }) - }, - // 保存 - save() { - let url = this.data.shareImg, - that = this; - wx.authorize({ - /* 这个就是保存相册的 */ - scope: 'scope.writePhotosAlbum', - success() { - wx.saveImageToPhotosAlbum({ - filePath: url, - success(res) { - wx.showToast({ - title: '保存成功', - icon: "success" - }) - that.setData({ - showShareFlag: !this.data.showShareFlag - }) + }, + // 分享 + share: function () { + if (!wx.getStorageSync("jstrip_token")) { util.pagePoint({ - event: 'product_share_save', - type: that.data.info.type, - id: that.data.info.id + event: 'product_share_login', + type: this.data.info.type, + id: this.data.info.id }, 1) - }, - fail(res) { + commonApi.user_post("user/getMyInfo", {}).then(res => { + + }) + return; + } + if (!this.data.shareImg) { wx.showToast({ - title: '保存失败', - icon: 'none' + title: '图片生成中,稍后再试', + icon: 'none' }) - } + return; + } + this.setData({ + showShareFlag: !this.data.showShareFlag }) - }, - complete(res) { - console.log(res); - /* 这里判断一下如果没有授权重新打开设置选项 */ - wx.getSetting({ - success(res) { - if (!res.authSetting['scope.writePhotosAlbum']) { - /* 打开设置的方法 */ - // opensit(); - wx.showToast({ - title: '请打开权限后再试', - icon: 'none' - }) + }, + // 保存 + save() { + let url = this.data.shareImg, + that = this; + wx.authorize({ + /* 这个就是保存相册的 */ + scope: 'scope.writePhotosAlbum', + success() { + wx.saveImageToPhotosAlbum({ + filePath: url, + success(res) { + wx.showToast({ + title: '保存成功', + icon: "success" + }) + that.setData({ + showShareFlag: !this.data.showShareFlag + }) + util.pagePoint({ + event: 'product_share_save', + type: that.data.info.type, + id: that.data.info.id + }, 1) + }, + fail(res) { + wx.showToast({ + title: '保存失败', + icon: 'none' + }) + } + }) + }, + complete(res) { + console.log(res); + /* 这里判断一下如果没有授权重新打开设置选项 */ + wx.getSetting({ + success(res) { + if (!res.authSetting['scope.writePhotosAlbum']) { + /* 打开设置的方法 */ + // opensit(); + wx.showToast({ + title: '请打开权限后再试', + icon: 'none' + }) + } + } + }); } - } }); - } - }); - - }, - pagePoint: function (e) { - util.pagePoint(e) - }, - // 绘制海报 - drawImg: function () { - var that = this, - userinfo = wx.getStorageSync('jstrip_userInfo'); - if (!userinfo) { - // 去登录 - return false; - } - const ctx = wx.createCanvasContext('imageCanvas'); - // const device = wx.getSystemInfoSync(); - // const ratio = device.screenWidth / 750; - // 先获取到图片信息 - let promise2 = new Promise(function (resolve, reject) { - wx.getImageInfo({ - src: that.data.info.headimg, - success: function (res) { - resolve(res); - }, - fail: function (res) { - reject(res); - } - }) - }) - let promise3 = new Promise(function (resolve, reject) { - let userid = wx.getStorageSync('jstrip_userid') - new QRCode('myQrcode', { - text: 'https://m.cloud.sz-trip.com/MailMerchandiseDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', - width: 500, - height: 500, - padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 - correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 - callback: (res) => { - resolve(res); + }, + pagePoint: function (e) { + util.pagePoint(e) + }, + // 绘制海报 + drawImg: function () { + var that = this, + userinfo = wx.getStorageSync('jstrip_userInfo'); + if (!userinfo) { + // 去登录 + return false; } - }) - }) - //成功得到图片信息后,开始绘图 - Promise.all([promise2, promise3]).then(imgs => { - ctx.save(); - ctx.beginPath(); //开始绘制 - that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') - ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 - ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); - ctx.restore(); - ctx.save(); - that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') - ctx.restore(); - // 绘制二维码 - ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); - // 开始文字绘制 - ctx.setFillStyle("#000"); - ctx.setFontSize(30 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); - // 售价 - ctx.setFillStyle("#D62828"); - ctx.setFontSize(40 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let price = "¥" + (that.data.info.price / 100); - let width = ctx.measureText(price).width; - ctx.fillText(price, 25 * ratio, 620 * ratio); - // 副标题 - ctx.setFillStyle("#999999"); - ctx.setFontSize(28 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let subtitle = that.data.info.subtitle; - if (that.data.info.subtitle.length > 10) { - subtitle = that.data.info.subtitle.substr(0, 10) + '...' - } - ctx.fillText(subtitle, 25 * ratio, 540 * ratio); - // ctx.draw(); - // 划线价 - ctx.setFillStyle("#999999"); - ctx.setFontSize(32 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let market_price = "¥" + (that.data.info.market_price / 100) - ctx.fillText(market_price, 40 * ratio + width, 620 * ratio); - let market_price_width = ctx.measureText(market_price).width; - // 划线 - ctx.beginPath() - ctx.setLineWidth(1) - ctx.moveTo(40 * ratio + width, 608 * ratio) - ctx.lineTo(45 * ratio + width + market_price_width, 608 * ratio) - ctx.stroke(); - // 长按识别二维码 - // ctx.setFillStyle("#666"); - // ctx.setFontSize(22 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); - // 长按图片转发或保存 - // ctx.setFillStyle("#000"); - // ctx.setFontSize(24 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); - ctx.draw(); - // 转为图片 - setTimeout(() => { - wx.canvasToTempFilePath({ - x: 0, - y: 0, - canvasId: 'imageCanvas', - success: function (res) { - that.setData({ - shareImg: res.tempFilePath + const ctx = wx.createCanvasContext('imageCanvas'); + // const device = wx.getSystemInfoSync(); + // const ratio = device.screenWidth / 750; + + // 先获取到图片信息 + let promise2 = new Promise(function (resolve, reject) { + wx.getImageInfo({ + src: that.data.info.headimg, + success: function (res) { + resolve(res); + }, + fail: function (res) { + reject(res); + } }) - }, - fail(err) { - console.log('agdgjgdajhg', err) - } }) - }, 500) - return false; - }).catch(err => { - console.log("this err", err) - }) - }, - // 圆角矩形 - handleBorderRect(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x + w, y + h); - ctx.lineTo(x, y + h) - // 左上角 - ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); - ctx.moveTo(x + r, y); - ctx.lineTo(x + w - r, y); - ctx.lineTo(x + w, y + r); - // 右上角 - ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); - ctx.lineTo(x + w, y + h); - ctx.lineTo(x + w - r, y + h); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - handleBorderRect2(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.lineTo(x + w, y) - // 右下角 - ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); - ctx.lineTo(x + r, y + h); - ctx.lineTo(x, y + h - r); - // 左下角 - ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); - ctx.lineTo(x, y); - ctx.lineTo(x, y); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - // 绘制两行文字 - drawText: function (ctx, str, x, y, canvasWidth, ratio) { - let row = [], - temp = "", - chr = str.split(""); - for (var a = 0; a < chr.length; a++) { - if (ctx.measureText(temp).width < canvasWidth) { - temp += chr[a]; - } else { - a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + let promise3 = new Promise(function (resolve, reject) { + let userid = wx.getStorageSync('jstrip_userid') + new QRCode('myQrcode', { + text: 'https://m.cloud.sz-trip.com/MailMerchandiseDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', + width: 500, + height: 500, + padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 + correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 + callback: (res) => { + resolve(res); + } + }) + }) + //成功得到图片信息后,开始绘图 + Promise.all([promise2, promise3]).then(imgs => { + ctx.save(); + ctx.beginPath(); //开始绘制 + that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') + ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 + ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); + ctx.restore(); + ctx.save(); + that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') + ctx.restore(); + // 绘制二维码 + ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); + // 开始文字绘制 + ctx.setFillStyle("#000"); + ctx.setFontSize(30 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); + // 售价 + ctx.setFillStyle("#D62828"); + ctx.setFontSize(40 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let price = "¥" + (that.data.info.price / 100); + let width = ctx.measureText(price).width; + ctx.fillText(price, 25 * ratio, 620 * ratio); + // 副标题 + ctx.setFillStyle("#999999"); + ctx.setFontSize(28 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let subtitle = that.data.info.subtitle; + if (that.data.info.subtitle.length > 10) { + subtitle = that.data.info.subtitle.substr(0, 10) + '...' + } + ctx.fillText(subtitle, 25 * ratio, 540 * ratio); + // ctx.draw(); + // 划线价 + ctx.setFillStyle("#999999"); + ctx.setFontSize(32 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let market_price = "¥" + (that.data.info.market_price / 100) + ctx.fillText(market_price, 40 * ratio + width, 620 * ratio); + let market_price_width = ctx.measureText(market_price).width; + // 划线 + ctx.beginPath() + ctx.setLineWidth(1) + ctx.moveTo(40 * ratio + width, 608 * ratio) + ctx.lineTo(45 * ratio + width + market_price_width, 608 * ratio) + ctx.stroke(); + // 长按识别二维码 + // ctx.setFillStyle("#666"); + // ctx.setFontSize(22 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); + // 长按图片转发或保存 + // ctx.setFillStyle("#000"); + // ctx.setFontSize(24 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); + ctx.draw(); + // 转为图片 + setTimeout(() => { + wx.canvasToTempFilePath({ + x: 0, + y: 0, + canvasId: 'imageCanvas', + success: function (res) { + that.setData({ + shareImg: res.tempFilePath + }) + }, + fail(err) { + console.log('agdgjgdajhg', err) + } + }) + }, 500) + return false; + }).catch(err => { + console.log("this err", err) + }) + }, + // 圆角矩形 + handleBorderRect(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x + w, y + h); + ctx.lineTo(x, y + h) + // 左上角 + ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); + ctx.moveTo(x + r, y); + ctx.lineTo(x + w - r, y); + ctx.lineTo(x + w, y + r); + // 右上角 + ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); + ctx.lineTo(x + w, y + h); + ctx.lineTo(x + w - r, y + h); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + handleBorderRect2(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(x + w, y) + // 右下角 + ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); + ctx.lineTo(x + r, y + h); + ctx.lineTo(x, y + h - r); + // 左下角 + ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); + ctx.lineTo(x, y); + ctx.lineTo(x, y); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + // 绘制两行文字 + drawText: function (ctx, str, x, y, canvasWidth, ratio) { + let row = [], + temp = "", + chr = str.split(""); + for (var a = 0; a < chr.length; a++) { + if (ctx.measureText(temp).width < canvasWidth) { + temp += chr[a]; + } else { + a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + row.push(temp); + temp = ""; + } + } row.push(temp); - temp = ""; - } - } - row.push(temp); - //如果数组长度大于2 则截取前两个 - if (row.length > 2) { - var rowCut = row.slice(0, 2); - var rowPart = rowCut[1]; - var test = ""; - var empty = []; - for (var a = 0; a < rowPart.length; a++) { - if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { - test += rowPart[a]; + //如果数组长度大于2 则截取前两个 + if (row.length > 2) { + var rowCut = row.slice(0, 2); + var rowPart = rowCut[1]; + var test = ""; + var empty = []; + for (var a = 0; a < rowPart.length; a++) { + if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { + test += rowPart[a]; + } else { + break; + } + } + empty.push(test); + var group = empty[0] + "..." //这里只显示两行,超出的用...表示 + rowCut.splice(1, 1, group); + row = rowCut; + } + for (var b = 0; b < row.length; b++) { + ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); + } + }, + gotoDetail: function (e) { + let item = e.currentTarget.dataset.item; + util.pagePoint({ + event: 'recommend_click', + param: { + id: item.id, + type: item.type + } + }, 1) + if (item.type == 'travels') { + // 游记做特殊处理 其他都按照原来的来 + wx.navigateTo({ + url: '/pages/info/strategyInfo/index?id=' + item.s_id, + }) } else { - break; + util.gotoDetail(item); } - } - empty.push(test); - var group = empty[0] + "..." //这里只显示两行,超出的用...表示 - rowCut.splice(1, 1, group); - row = rowCut; - } - for (var b = 0; b < row.length; b++) { - ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); - } - }, - gotoDetail: function (e) { - let item = e.currentTarget.dataset.item; - util.pagePoint({ - event: 'recommend_click', - param: { - id: item.id, - type: item.type - } - }, 1) - if (item.type == 'travels') { - // 游记做特殊处理 其他都按照原来的来 - wx.navigateTo({ - url: '/pages/info/strategyInfo/index?id=' + item.s_id, - }) - } else { - util.gotoDetail(item); - } - }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { + }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { - }, + }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - if (!wx.getStorageSync('jstrip_token')) { - return; - } - if (this.data.info && this.data.info.id) { - commonApi.user_post("product/is_product_collection", { - product_id: this.data.info.id - }).then(res => { - this.setData({ - isLike: res.data - }) - this.drawImg() - }) - commonApi.user_post('cart/get_list', {}).then(res => { + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + if (!wx.getStorageSync('jstrip_token')) { + return; + } + if (this.data.info && this.data.info.id) { + commonApi.user_post("product/is_product_collection", { + product_id: this.data.info.id + }).then(res => { + this.setData({ + isLike: res.data + }) + this.drawImg() + }) + commonApi.user_post('cart/get_list', {}).then(res => { + this.setData({ + cartCount: res.data.length + }) + }) + } else { + setTimeout(() => { + this.onShow() + }, 200) + } + }, + playVideo() { + // 播放视频需要把autoplay暂停 this.setData({ - cartCount: res.data.length + autoPlay: false }) - }) - } else { - setTimeout(() => { - this.onShow() - }, 200) - } - }, - playVideo() { - // 播放视频需要把autoplay暂停 - this.setData({ - autoPlay: false - }) - }, + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - }, + }, - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - }, + }, - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - }, + }, - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { - }, + }, - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { - } + } }) \ No newline at end of file diff --git a/pages/info/postProductInfo/index.json b/pages/info/postProductInfo/index.json index 35cf02f..ab4ec76 100644 --- a/pages/info/postProductInfo/index.json +++ b/pages/info/postProductInfo/index.json @@ -1,5 +1,7 @@ { "usingComponents": { - "title":"/pages/component/TitleHeader" + "title":"/pages/component/TitleHeader", + "code":"../../order/components/wxqrCode/index" + } } \ No newline at end of file diff --git a/pages/info/postProductInfo/index.wxml b/pages/info/postProductInfo/index.wxml index 5ef87e9..2c9a219 100644 --- a/pages/info/postProductInfo/index.wxml +++ b/pages/info/postProductInfo/index.wxml @@ -203,4 +203,6 @@ {{allowance_data.title}} - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/info/roadInfo/index.js b/pages/info/roadInfo/index.js index e65f076..18ed345 100644 --- a/pages/info/roadInfo/index.js +++ b/pages/info/roadInfo/index.js @@ -7,500 +7,515 @@ import util from '../../../utils/util' let app = getApp() Page({ - /** - * 页面的初始数据 - */ - data: { - fixed: false, - type: 1, - top: 0, - info: null, - comment: [], - commentTotal: 0, - retailId: "", - retailSkuId: "", - shareImg: null, - showShareFlag: false - }, + /** + * 页面的初始数据 + */ + data: { + fixed: false, + type: 1, + top: 0, + info: null, + comment: [], + commentTotal: 0, + retailId: "", + retailSkuId: "", + shareImg: null, + showShareFlag: false, + showQrCode: false, + wxqrcode: null + }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - let rect = wx.getMenuButtonBoundingClientRect(); - let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; - this.setData({ - top: height, - id: options.id - }) - if (options.retailId) { - this.setData({ - retailId: options.retailId - }) - } - let api = commonApi._post; - if (wx.getStorageSync("jstrip_token")) { - api = commonApi.user_post; - } - api("product/get_product_detail", { - id: options.id - }).then(res => { - res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); - - if (options.skuid) { - let sku = res.data.sku.find(item => item.id == options.skuid); - res.data.sku = [sku]; + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + let rect = wx.getMenuButtonBoundingClientRect(); + let height = (rect.top - device.statusBarHeight) * 2 + rect.height + device.statusBarHeight; this.setData({ - retailSkuId: options.skuid - }) - } - res.data.flag = res.data.sku.find(item=>item.flag=='on')?res.data.flag:0 - - this.setData({ - info: res.data - }) - this.BroswerRecord() - }) - commonApi._post("product/product_comment_list", { - product_id: options.id, - offset: 0, - limit: 3 - }).then(res => { - res.data.list.map(item => { - item.rate = Number(item.rate) - }) - this.setData({ - commentTotal: res.data.total, - comment: res.data.list - }) - }) - }, - BroswerRecord: function () { - setTimeout(() => { - if (app.globalData.uuid) { - commonApi._post('browse/browse_record', { - type: "goods", - title: this.data.info.title, - drive: "mini", - source_id: this.data.info.id, - url: "/pages/info/cardInfo/index?id=" + this.data.info.id, - uuid: app.globalData.uuid - }).then(res => { + top: height, + id: options.id }) - } - else { - this.BroswerRecord(); - } - }, 500) - }, - changeMenu: function (e) { - 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({ - scrollTop: scrollTop + 4, - duration: 0 - }) - that.setData({ - type: index - }) - }) - }, - onPageScroll: function (e) { - let that = this, height = this.data.top; - let topHeight = height; - wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) { - console.log(rect.top, topHeight) - if (rect.top <= topHeight) { - // 此时应该把menus固定在顶部 - that.setData({ - fixed: true - }) - } - else { - that.setData({ - fixed: false - }) - } - // 滚动时判断滚动到哪个部分了 - const query = wx.createSelectorQuery(); //创建节点查询器 - query.select("#box1").boundingClientRect() //选择toViewid获取位置信息 - query.select("#box2").boundingClientRect() //选择toViewid获取位置信息 - query.select("#box3").boundingClientRect() //选择toViewid获取位置信息 - query.select("#box4").boundingClientRect() //选择toViewid获取位置信息 - let minHeight = that.data.fixed ? (110 * ratio + height) : topHeight; - query.exec(function (res) { - if (res[3].top < minHeight) { - that.setData({ - type: 4 - }) - } - else if (res[2].top < minHeight) { - that.setData({ - type: 3 - }) - } - else if (res[1].top < minHeight) { - that.setData({ - type: 2 - }) + if (options.retailId) { + this.setData({ + retailId: options.retailId + }) } - else { - that.setData({ - type: 1 - }) + let api = commonApi._post; + if (wx.getStorageSync("jstrip_token")) { + api = commonApi.user_post; } - }) - }).exec() + api("product/get_product_detail", { + id: options.id + }).then(res => { + res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); - }, - order: function () { - app.globalData.couponInfo = null; - app.globalData.product = { - product: this.data.info - } - app.globalData.retailId = this.data.retailId; - 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') - wx.navigateTo({ - url: '/pages/order/road/index?id=' + this.data.info.id + (this.data.retailSkuId ? ('&skuid=' + this.data.retailSkuId) : '') - }) - }, - pagePoint:function(e){ - util.pagePoint(e) - }, - // 分享 - share: function () { - if (!wx.getStorageSync("jstrip_token")) { - util.pagePoint({ - event:'product_share_login', - param:{ - id:that.data.info.id, - type:that.data.info.type - } - },1) - commonApi.user_post("user/getMyInfo", {}).then(res => { + if (options.skuid) { + let sku = res.data.sku.find(item => item.id == options.skuid); + res.data.sku = [sku]; + this.setData({ + retailSkuId: options.skuid + }) + } + res.data.flag = res.data.sku.find(item => item.flag == 'on') ? res.data.flag : 0 - }) - return; - } - if (!this.data.shareImg) { - wx.showToast({ - title: '图片生成中,稍后再试', - icon: 'none' - }) - return; - } - this.setData({ - showShareFlag: !this.data.showShareFlag - }) - }, - // 保存 - save() { - let url = this.data.shareImg, that = this; - wx.authorize({ - /* 这个就是保存相册的 */ - scope: 'scope.writePhotosAlbum', - success() { - wx.saveImageToPhotosAlbum({ - filePath: url, - success(res) { - wx.showToast({ - title: '保存成功', - icon: "success" + this.setData({ + info: res.data + }) + this.BroswerRecord() + }) + commonApi._post("product/product_comment_list", { + product_id: options.id, + offset: 0, + limit: 3 + }).then(res => { + res.data.list.map(item => { + item.rate = Number(item.rate) + }) + this.setData({ + commentTotal: res.data.total, + comment: res.data.list + }) + }) + }, + BroswerRecord: function () { + setTimeout(() => { + if (app.globalData.uuid) { + commonApi._post('browse/browse_record', { + type: "goods", + title: this.data.info.title, + drive: "mini", + source_id: this.data.info.id, + url: "/pages/info/cardInfo/index?id=" + this.data.info.id, + uuid: app.globalData.uuid + }).then(res => {}) + } else { + this.BroswerRecord(); + } + }, 500) + }, + changeMenu: function (e) { + 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({ + scrollTop: scrollTop + 4, + duration: 0 }) that.setData({ - showShareFlag: !that.data.showShareFlag + type: index }) + }) + }, + onPageScroll: function (e) { + let that = this, + height = this.data.top; + let topHeight = height; + wx.createSelectorQuery().select('#menus').boundingClientRect(function (rect) { + console.log(rect.top, topHeight) + if (rect.top <= topHeight) { + // 此时应该把menus固定在顶部 + that.setData({ + fixed: true + }) + } else { + that.setData({ + fixed: false + }) + } + // 滚动时判断滚动到哪个部分了 + const query = wx.createSelectorQuery(); //创建节点查询器 + query.select("#box1").boundingClientRect() //选择toViewid获取位置信息 + query.select("#box2").boundingClientRect() //选择toViewid获取位置信息 + query.select("#box3").boundingClientRect() //选择toViewid获取位置信息 + query.select("#box4").boundingClientRect() //选择toViewid获取位置信息 + let minHeight = that.data.fixed ? (110 * ratio + height) : topHeight; + query.exec(function (res) { + if (res[3].top < minHeight) { + that.setData({ + type: 4 + }) + } else if (res[2].top < minHeight) { + that.setData({ + type: 3 + }) + } else if (res[1].top < minHeight) { + that.setData({ + type: 2 + }) + } else { + that.setData({ + type: 1 + }) + } + }) + }).exec() + + }, + order: function () { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/roadInfo/index?id=' + this.data.id, + title: this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + app.globalData.couponInfo = null; + app.globalData.product = { + product: this.data.info + } + app.globalData.retailId = this.data.retailId; + 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') + wx.navigateTo({ + url: '/pages/order/road/index?id=' + this.data.info.id + (this.data.retailSkuId ? ('&skuid=' + this.data.retailSkuId) : '') + }) + } + }) + + + + }, + pagePoint: function (e) { + util.pagePoint(e) + }, + // 分享 + share: function () { + if (!wx.getStorageSync("jstrip_token")) { util.pagePoint({ - event:'product_share_save', - param:{ - id:that.data.info.id, - type:that.data.info.type - } - },1) - }, - fail(res) { + event: 'product_share_login', + param: { + id: that.data.info.id, + type: that.data.info.type + } + }, 1) + commonApi.user_post("user/getMyInfo", {}).then(res => { + + }) + return; + } + if (!this.data.shareImg) { wx.showToast({ - title: '保存失败', - icon: 'none' + title: '图片生成中,稍后再试', + icon: 'none' }) - } + return; + } + this.setData({ + showShareFlag: !this.data.showShareFlag }) - }, - complete(res) { - console.log(res); - /* 这里判断一下如果没有授权重新打开设置选项 */ - wx.getSetting({ - success(res) { - if (!res.authSetting['scope.writePhotosAlbum']) { - /* 打开设置的方法 */ - // opensit(); - wx.showToast({ - title: '请打开权限后再试', - icon: 'none' - }) + }, + // 保存 + save() { + let url = this.data.shareImg, + that = this; + wx.authorize({ + /* 这个就是保存相册的 */ + scope: 'scope.writePhotosAlbum', + success() { + wx.saveImageToPhotosAlbum({ + filePath: url, + success(res) { + wx.showToast({ + title: '保存成功', + icon: "success" + }) + that.setData({ + showShareFlag: !that.data.showShareFlag + }) + util.pagePoint({ + event: 'product_share_save', + param: { + id: that.data.info.id, + type: that.data.info.type + } + }, 1) + }, + fail(res) { + wx.showToast({ + title: '保存失败', + icon: 'none' + }) + } + }) + }, + complete(res) { + console.log(res); + /* 这里判断一下如果没有授权重新打开设置选项 */ + wx.getSetting({ + success(res) { + if (!res.authSetting['scope.writePhotosAlbum']) { + /* 打开设置的方法 */ + // opensit(); + wx.showToast({ + title: '请打开权限后再试', + icon: 'none' + }) + } + } + }); } - } }); - } - }); - }, - // 绘制海报 - drawImg: function () { - var that = this, userinfo = wx.getStorageSync('jstrip_userInfo'); - if (!userinfo) { - // 去登录 - return false; - } - const ctx = wx.createCanvasContext('imageCanvas'); - // const device = wx.getSystemInfoSync(); - // const ratio = device.screenWidth / 750; - // 先获取到图片信息 - let promise2 = new Promise(function (resolve, reject) { - wx.getImageInfo({ - src: that.data.info.headimg, - success: function (res) { - resolve(res); - }, - fail: function (res) { - reject(res); - } - }) - }) - let promise3 = new Promise(function (resolve, reject) { - let userid = wx.getStorageSync('jstrip_userid') - new QRCode('myQrcode', { - text: 'https://m.cloud.sz-trip.com/LineDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', - width: 500, - height: 500, - padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 - correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 - callback: (res) => { - resolve(res); + }, + // 绘制海报 + drawImg: function () { + var that = this, + userinfo = wx.getStorageSync('jstrip_userInfo'); + if (!userinfo) { + // 去登录 + return false; } - }) - }) - //成功得到图片信息后,开始绘图 - Promise.all([promise2, promise3]).then(imgs => { - ctx.save(); - ctx.beginPath(); //开始绘制 - that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') - ctx.clip();//画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 - ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); - ctx.restore(); - ctx.save(); - that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') - ctx.restore(); - // 绘制二维码 - ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); - // 开始文字绘制 - ctx.setFillStyle("#000"); - ctx.setFontSize(30 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); - // 售价 - ctx.setFillStyle("#D62828"); - ctx.setFontSize(40 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let price = that.data.info.price ? ("¥" + (that.data.info.price / 100)) : '免费'; - let width = ctx.measureText(price).width; - ctx.fillText(price, 25 * ratio, 620 * ratio); - // 副标题 - ctx.setFillStyle("#999999"); - ctx.setFontSize(28 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let subtitle = that.data.info.display_tags[0]; - if (subtitle.length > 10) { - subtitle = subtitle.substr(0, 10) + '...' - } - ctx.fillText(subtitle, 25 * ratio, 540 * ratio); - // ctx.draw(); - // 划线价 - // ctx.setFillStyle("#999999"); - // ctx.setFontSize(32 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // let market_price = "¥" + (Number(that.data.info.market_price) / 100) - // ctx.fillText(market_price, 40 * ratio + width, 620 * ratio); - // let market_price_width = ctx.measureText(market_price).width; - // 划线 - // ctx.beginPath() - // ctx.setLineWidth(1) - // ctx.moveTo(40 * ratio + width, 608 * ratio) - // ctx.lineTo(45 * ratio + width + market_price_width, 608 * ratio) - // ctx.stroke(); - // 长按识别二维码 - // ctx.setFillStyle("#666"); - // ctx.setFontSize(22 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); - // 长按图片转发或保存 - // ctx.setFillStyle("#000"); - // ctx.setFontSize(24 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); - ctx.draw(); - // 转为图片 - setTimeout(() => { - wx.canvasToTempFilePath({ - x: 0, - y: 0, - canvasId: 'imageCanvas', - success: function (res) { - that.setData({ - shareImg: res.tempFilePath + const ctx = wx.createCanvasContext('imageCanvas'); + // const device = wx.getSystemInfoSync(); + // const ratio = device.screenWidth / 750; + // 先获取到图片信息 + let promise2 = new Promise(function (resolve, reject) { + wx.getImageInfo({ + src: that.data.info.headimg, + success: function (res) { + resolve(res); + }, + fail: function (res) { + reject(res); + } + }) + }) + let promise3 = new Promise(function (resolve, reject) { + let userid = wx.getStorageSync('jstrip_userid') + new QRCode('myQrcode', { + text: 'https://m.cloud.sz-trip.com/LineDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', + width: 500, + height: 500, + padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 + correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 + callback: (res) => { + resolve(res); + } }) - }, - fail(err) { - console.log('agdgjgdajhg', err) - } }) - }, 500) - return false; - }).catch(err => { - console.log("this err", err) - }) - }, - // 圆角矩形 - handleBorderRect(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x + w, y + h); - ctx.lineTo(x, y + h) - // 左上角 - ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); - ctx.moveTo(x + r, y); - ctx.lineTo(x + w - r, y); - ctx.lineTo(x + w, y + r); - // 右上角 - ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); - ctx.lineTo(x + w, y + h); - ctx.lineTo(x + w - r, y + h); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - handleBorderRect2(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.lineTo(x + w, y) - // 右下角 - ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); - ctx.lineTo(x + r, y + h); - ctx.lineTo(x, y + h - r); - // 左下角 - ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); - ctx.lineTo(x, y); - ctx.lineTo(x, y); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - // 绘制两行文字 - drawText: function (ctx, str, x, y, canvasWidth, ratio) { - let row = [], temp = "", chr = str.split(""); - for (var a = 0; a < chr.length; a++) { - if (ctx.measureText(temp).width < canvasWidth) { - temp += chr[a]; - } - else { - a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + //成功得到图片信息后,开始绘图 + Promise.all([promise2, promise3]).then(imgs => { + ctx.save(); + ctx.beginPath(); //开始绘制 + that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') + ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 + ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); + ctx.restore(); + ctx.save(); + that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') + ctx.restore(); + // 绘制二维码 + ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); + // 开始文字绘制 + ctx.setFillStyle("#000"); + ctx.setFontSize(30 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); + // 售价 + ctx.setFillStyle("#D62828"); + ctx.setFontSize(40 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let price = that.data.info.price ? ("¥" + (that.data.info.price / 100)) : '免费'; + let width = ctx.measureText(price).width; + ctx.fillText(price, 25 * ratio, 620 * ratio); + // 副标题 + ctx.setFillStyle("#999999"); + ctx.setFontSize(28 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let subtitle = that.data.info.display_tags[0]; + if (subtitle.length > 10) { + subtitle = subtitle.substr(0, 10) + '...' + } + ctx.fillText(subtitle, 25 * ratio, 540 * ratio); + // ctx.draw(); + // 划线价 + // ctx.setFillStyle("#999999"); + // ctx.setFontSize(32 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // let market_price = "¥" + (Number(that.data.info.market_price) / 100) + // ctx.fillText(market_price, 40 * ratio + width, 620 * ratio); + // let market_price_width = ctx.measureText(market_price).width; + // 划线 + // ctx.beginPath() + // ctx.setLineWidth(1) + // ctx.moveTo(40 * ratio + width, 608 * ratio) + // ctx.lineTo(45 * ratio + width + market_price_width, 608 * ratio) + // ctx.stroke(); + // 长按识别二维码 + // ctx.setFillStyle("#666"); + // ctx.setFontSize(22 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); + // 长按图片转发或保存 + // ctx.setFillStyle("#000"); + // ctx.setFontSize(24 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); + ctx.draw(); + // 转为图片 + setTimeout(() => { + wx.canvasToTempFilePath({ + x: 0, + y: 0, + canvasId: 'imageCanvas', + success: function (res) { + that.setData({ + shareImg: res.tempFilePath + }) + }, + fail(err) { + console.log('agdgjgdajhg', err) + } + }) + }, 500) + return false; + }).catch(err => { + console.log("this err", err) + }) + }, + // 圆角矩形 + handleBorderRect(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x + w, y + h); + ctx.lineTo(x, y + h) + // 左上角 + ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); + ctx.moveTo(x + r, y); + ctx.lineTo(x + w - r, y); + ctx.lineTo(x + w, y + r); + // 右上角 + ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); + ctx.lineTo(x + w, y + h); + ctx.lineTo(x + w - r, y + h); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + handleBorderRect2(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(x + w, y) + // 右下角 + ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); + ctx.lineTo(x + r, y + h); + ctx.lineTo(x, y + h - r); + // 左下角 + ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); + ctx.lineTo(x, y); + ctx.lineTo(x, y); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + // 绘制两行文字 + drawText: function (ctx, str, x, y, canvasWidth, ratio) { + let row = [], + temp = "", + chr = str.split(""); + for (var a = 0; a < chr.length; a++) { + if (ctx.measureText(temp).width < canvasWidth) { + temp += chr[a]; + } else { + a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + row.push(temp); + temp = ""; + } + } row.push(temp); - temp = ""; - } - } - row.push(temp); - //如果数组长度大于2 则截取前两个 - if (row.length > 2) { - var rowCut = row.slice(0, 2); - var rowPart = rowCut[1]; - var test = ""; - var empty = []; - for (var a = 0; a < rowPart.length; a++) { - if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { - test += rowPart[a]; + //如果数组长度大于2 则截取前两个 + if (row.length > 2) { + var rowCut = row.slice(0, 2); + var rowPart = rowCut[1]; + var test = ""; + var empty = []; + for (var a = 0; a < rowPart.length; a++) { + if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { + test += rowPart[a]; + } else { + break; + } + } + empty.push(test); + var group = empty[0] + "..." //这里只显示两行,超出的用...表示 + rowCut.splice(1, 1, group); + row = rowCut; } - else { - break; + for (var b = 0; b < row.length; b++) { + ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); } - } - empty.push(test); - var group = empty[0] + "..."//这里只显示两行,超出的用...表示 - rowCut.splice(1, 1, group); - row = rowCut; - } - for (var b = 0; b < row.length; b++) { - ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); - } - }, + }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { - }, + }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - if (!wx.getStorageSync('jstrip_token')) { - return; - } - if (this.data.info && this.data.info.id) { - this.drawImg() - } - else { - setTimeout(() => { - this.onShow() - }, 200) - } - }, + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + if (!wx.getStorageSync('jstrip_token')) { + return; + } + if (this.data.info && this.data.info.id) { + this.drawImg() + } else { + setTimeout(() => { + this.onShow() + }, 200) + } + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - }, + }, - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - }, + }, - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - }, + }, - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { - }, + }, - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { - } + } }) \ No newline at end of file diff --git a/pages/info/roadInfo/index.json b/pages/info/roadInfo/index.json index 35cf02f..ab4ec76 100644 --- a/pages/info/roadInfo/index.json +++ b/pages/info/roadInfo/index.json @@ -1,5 +1,7 @@ { "usingComponents": { - "title":"/pages/component/TitleHeader" + "title":"/pages/component/TitleHeader", + "code":"../../order/components/wxqrCode/index" + } } \ No newline at end of file diff --git a/pages/info/roadInfo/index.wxml b/pages/info/roadInfo/index.wxml index d4b563e..cb33ef6 100644 --- a/pages/info/roadInfo/index.wxml +++ b/pages/info/roadInfo/index.wxml @@ -118,4 +118,6 @@ 保存到相册 - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/info/sceneProductInfo/index.js b/pages/info/sceneProductInfo/index.js index ab71a71..15387b9 100644 --- a/pages/info/sceneProductInfo/index.js +++ b/pages/info/sceneProductInfo/index.js @@ -6,827 +6,861 @@ import util from "../../../utils/util" import QRCode from '../../../utils/weapp-qrcode.js' let app = getApp() Page({ - /** - * 页面的初始数据 - */ - data: { - info: null, - bookingInfo: null, - bookingInfoTitle: "", - safeBottom: app.globalData.safeBottom, - isLike: 0, - comment: [], - commentTotal: 0, - isTest: true, - retailId: "", - shareImg: null, - showShareFlag: false, - showAllowance: false, - allowance_data: null, - //购物车数量 - producNum: 1, - skuIndex: null, - aniSkuIndex: -1, - cartCount: 0, - cartImgInfo: null, - cartTop: 0, - top: 0, - skuList: [], //立即预定的列表 - sku_ids: [] - }, + /** + * 页面的初始数据 + */ + data: { + info: null, + bookingInfo: null, + bookingInfoTitle: "", + safeBottom: app.globalData.safeBottom, + isLike: 0, + comment: [], + commentTotal: 0, + isTest: true, + retailId: "", + shareImg: null, + showShareFlag: false, + showAllowance: false, + allowance_data: null, + //购物车数量 + producNum: 1, + skuIndex: null, + aniSkuIndex: -1, + cartCount: 0, + cartImgInfo: null, + cartTop: 0, + top: 0, + skuList: [], //立即预定的列表 + sku_ids: [], + showQrCode: false, + wxqrcode: null - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - console.log(options); - if (!options.id) { - util.back() - return; - } - if (options.retailId) { - this.setData({ - retailId: options.retailId - }) - } - this.setData({ - id: options.id - }) - commonApi._post("scene/detail", { - id: options.id - }).then(res => { - let flag = false - if (!res.data) { - wx.showToast({ - title: '产品已下架', - icon: 'none' - }) - setTimeout(() => { - util.back(); - }, 1000) - return; - } - res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); - // 如果是带有指定good_id的 那么取指定的 - if (options.gid) { - let pItem = res.data.product.find(item => item.id == options.gid); - if (pItem) { - res.data.product = [pItem]; - } - } - // 如果带有指定skuid的话 那么取指定的sku展示 - if (options.skuid) { - let pItem = null; - for (let i = 0; i < res.data.product.length; i++) { //3 - for (let j = 0; j < res.data.product[i].sku.length; j++) { //4 - if (res.data.product[i].sku[j].id == options.skuid) { - res.data.product[i].sku = [res.data.product[i].sku[j]]; - pItem = res.data.product[i]; - break; - } - } + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + console.log(options); + if (!options.id) { + util.back() + return; } - if (pItem) { - res.data.product = [pItem]; + if (options.retailId) { + this.setData({ + retailId: options.retailId + }) } - } else if (options.zhuanti_type) { - flag = true - commonApi._post("theme/getYihuFreeList", { - zhuanti_type: options.zhuanti_type - }).then(res1 => { - let skuArr = res1.data.sku_ids - let newArr = [] - for (let i = 0; i < res.data.product.length; i++) { //3 - for (let j = 0; j < res.data.product[i].sku.length; j++) { //4 - for (let k = 0; k < skuArr.length; k++) { - if (res.data.product[i].sku[j].id == skuArr[k]) { - newArr.push(res.data.product[i].sku[j]) - } - } + this.setData({ + id: options.id + }) + commonApi._post("scene/detail", { + id: options.id + }).then(res => { + let flag = false + if (!res.data) { + wx.showToast({ + title: '产品已下架', + icon: 'none' + }) + setTimeout(() => { + util.back(); + }, 1000) + return; } - res.data.product[i].sku = newArr; - } - res.data.product.map(product => { - product.sku.map(sku => { - sku.display_tags = (sku.display_tags ? sku.display_tags.split(",") : []).splice(0, 2); - }) - }) - this.setData({ - info: res.data - }) - var arr = [] - res.data.product.forEach((item, index) => { - item.sku.forEach(itemB => { - itemB.proIndex = index - arr.push(itemB) - }) - }); - this.setData({ - skuList: arr - }) - util.pagePoint({ - event: 'scene_view', - param: { - type: res.data.type, - id: res.data.id + res.data.display_tags = (res.data.display_tags ? res.data.display_tags.split(",") : []).splice(0, 2); + // 如果是带有指定good_id的 那么取指定的 + if (options.gid) { + let pItem = res.data.product.find(item => item.id == options.gid); + if (pItem) { + res.data.product = [pItem]; + } } - }, 1) - this.BroswerRecord() - }) + // 如果带有指定skuid的话 那么取指定的sku展示 + if (options.skuid) { + let pItem = null; + for (let i = 0; i < res.data.product.length; i++) { //3 + for (let j = 0; j < res.data.product[i].sku.length; j++) { //4 + if (res.data.product[i].sku[j].id == options.skuid) { + res.data.product[i].sku = [res.data.product[i].sku[j]]; + pItem = res.data.product[i]; + break; + } + } + } + if (pItem) { + res.data.product = [pItem]; + } + } else if (options.zhuanti_type) { + flag = true + commonApi._post("theme/getYihuFreeList", { + zhuanti_type: options.zhuanti_type + }).then(res1 => { + let skuArr = res1.data.sku_ids + let newArr = [] + for (let i = 0; i < res.data.product.length; i++) { //3 + for (let j = 0; j < res.data.product[i].sku.length; j++) { //4 + for (let k = 0; k < skuArr.length; k++) { + if (res.data.product[i].sku[j].id == skuArr[k]) { + newArr.push(res.data.product[i].sku[j]) + } + } + } + res.data.product[i].sku = newArr; + } + res.data.product.map(product => { + product.sku.map(sku => { + sku.display_tags = (sku.display_tags ? sku.display_tags.split(",") : []).splice(0, 2); + }) + }) + this.setData({ + info: res.data + }) + var arr = [] + res.data.product.forEach((item, index) => { + item.sku.forEach(itemB => { + itemB.proIndex = index + arr.push(itemB) + }) + }); + this.setData({ + skuList: arr + }) + util.pagePoint({ + event: 'scene_view', + param: { + type: res.data.type, + id: res.data.id + } + }, 1) + this.BroswerRecord() + }) - } - console.log(res.data.product); - if (flag) { - return - } + } + console.log(res.data.product); + if (flag) { + return + } - // res.data.listimg = res.data.listimg?res.data.listimg.split(","):[]; - res.data.product.map(product => { - product.sku.map(sku => { - sku.display_tags = (sku.display_tags ? sku.display_tags.split(",") : []).splice(0, 2); - }) - }) - this.setData({ - info: res.data - }) - var arr = [] - res.data.product.forEach((item, index) => { - item.sku.forEach(itemB => { - itemB.proIndex = index - arr.push(itemB) + // res.data.listimg = res.data.listimg?res.data.listimg.split(","):[]; + res.data.product.map(product => { + product.sku.map(sku => { + sku.display_tags = (sku.display_tags ? sku.display_tags.split(",") : []).splice(0, 2); + }) + }) + this.setData({ + info: res.data + }) + var arr = [] + res.data.product.forEach((item, index) => { + item.sku.forEach(itemB => { + itemB.proIndex = index + arr.push(itemB) + }) + }); + this.setData({ + skuList: arr + }) + util.pagePoint({ + event: 'scene_view', + param: { + type: res.data.type, + id: res.data.id + } + }, 1) + this.BroswerRecord() }) - }); - this.setData({ - skuList: arr - }) - util.pagePoint({ - event: 'scene_view', - param: { - type: res.data.type, - id: res.data.id + // 获取收藏的状态 + if (wx.getStorageSync("jstrip_token")) { + commonApi.user_post("scene/is_scene_collection", { + scene_id: options.id + }).then(res => { + this.setData({ + isLike: res.data + }) + }) } - }, 1) - this.BroswerRecord() - }) - // 获取收藏的状态 - if (wx.getStorageSync("jstrip_token")) { - commonApi.user_post("scene/is_scene_collection", { - scene_id: options.id - }).then(res => { - this.setData({ - isLike: res.data + commonApi._post("ask/getQuestionList", { + scene_id: options.id, + page_no: 1, + page_num: 3 + }).then(res => { + this.setData({ + ask: res.data.rows + }) }) - }) - } - commonApi._post("ask/getQuestionList", { - scene_id: options.id, - page_no: 1, - page_num: 3 - }).then(res => { - this.setData({ - ask: res.data.rows - }) - }) - // 获取评价列表 - commonApi._post("scene/get_comment", { - scene_id: options.id - }).then(res => { - res.data.list.map(item => { - item.rate = Number(item.rate) - }) - this.setData({ - comment: res.data.list.splice(0, 2), - commentTotal: res.data.total - }) - let arr = this.data.comment - arr.map((item) => { - if (item.img_list) { - let arr = item.img_list.split(',') - item.img_list = arr + // 获取评价列表 + commonApi._post("scene/get_comment", { + scene_id: options.id + }).then(res => { + res.data.list.map(item => { + item.rate = Number(item.rate) + }) + this.setData({ + comment: res.data.list.splice(0, 2), + commentTotal: res.data.total + }) + let arr = this.data.comment + arr.map((item) => { + if (item.img_list) { + let arr = item.img_list.split(',') + item.img_list = arr - } else { - item.img_list = [] - } - }) - this.setData({ - comment: arr - }) - }) - }, - changeAllowance: function () { - this.setData({ - showAllowance: !this.data.showAllowance - }) - }, - BroswerRecord: function () { - setTimeout(() => { - if (app.globalData.uuid) { - commonApi._post('browse/browse_record', { - type: "scene", - title: this.data.info.title, - drive: "mini", - source_id: this.data.info.id, - url: "/pages/info/sceneProductInfo/index?id=" + this.data.info.id, - uuid: app.globalData.uuid - }).then(res => {}) - } else { - this.BroswerRecord(); - } - }, 500) - }, - like: function () { - 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 => { - if (res.code == 1) { - wx.showToast({ - title: '操作成功', + } else { + item.img_list = [] + } + }) + this.setData({ + comment: arr + }) }) + }, + changeAllowance: function () { this.setData({ - isLike: isLike == 1 ? 0 : 1 + showAllowance: !this.data.showAllowance }) - } - }) - }, - gotolocation: function () { - let info = this.data.info; - wx.openLocation({ - latitude: Number(info.lat), - longitude: Number(info.lon) - }) - }, - audioGuide: function () { - wx.navigateToMiniProgram({ - appId: 'wx74f380bc721a0379', - path: '/pages/listen/listen?title=君到苏州' - }) - }, - showBookingInfo: function (e) { - this.setData({ - bookingInfo: e.currentTarget.dataset.item.sku_model, - bookingInfoTitle: e.currentTarget.dataset.item.sku_name - }) - util.pagePoint({ - event: "scene_notice", - param: { - type: this.data.info.type, - id: this.data.info.id - } - }, 1) - }, - closeMask: function () { - this.setData({ - bookingInfo: null - }) - }, - // 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', - // }) - // }, - selectSku: function (e) { - console.log(e.currentTarget.dataset.item); - if (e.currentTarget.dataset.item.stock == 0 && e.currentTarget.dataset.item.is_third_stock != 1) { - wx.showToast({ - title: "该商品暂无库存", - icon: 'none' - }) - return - } - let index = e.currentTarget.dataset.index; - this.setData({ - skuIndex: index - }) - }, - order: function (e) { - 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] + }, + BroswerRecord: function () { + setTimeout(() => { + if (app.globalData.uuid) { + commonApi._post('browse/browse_record', { + type: "scene", + title: this.data.info.title, + drive: "mini", + source_id: this.data.info.id, + url: "/pages/info/sceneProductInfo/index?id=" + this.data.info.id, + uuid: app.globalData.uuid + }).then(res => {}) + } else { + this.BroswerRecord(); } - app.globalData.product = { - ...sku, - ...product - } - app.globalData.index = 0 - 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 => { + }, 500) + }, + like: function () { + 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 => { if (res.code == 1) { - commonApi.user_post('cart/get_list', {}).then(res => { - this.setData({ - cartCount: res.data.length //5 + wx.showToast({ + title: '操作成功', }) - }) - // 加动效 - this.setData({ - skuFlag: null, - aniSkuIndex: this.data.skuIndex, - cartImgInfo: null - }) - setTimeout(() => { this.setData({ - aniSkuIndex: -1 + isLike: isLike == 1 ? 0 : 1 }) + } + }) + }, + gotolocation: function () { + let info = this.data.info; + wx.openLocation({ + latitude: Number(info.lat), + longitude: Number(info.lon) + }) + }, + audioGuide: function () { + wx.navigateToMiniProgram({ + appId: 'wx74f380bc721a0379', + path: '/pages/listen/listen?title=君到苏州' + }) + }, + showBookingInfo: function (e) { + this.setData({ + bookingInfo: e.currentTarget.dataset.item.sku_model, + bookingInfoTitle: e.currentTarget.dataset.item.sku_name + }) + util.pagePoint({ + event: "scene_notice", + param: { + type: this.data.info.type, + id: this.data.info.id + } + }, 1) + }, + closeMask: function () { + this.setData({ + bookingInfo: null + }) + }, + // 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', + // }) + // }, + selectSku: function (e) { + console.log(e.currentTarget.dataset.item); + if (e.currentTarget.dataset.item.stock == 0 && e.currentTarget.dataset.item.is_third_stock != 1) { + wx.showToast({ + title: "该商品暂无库存", + icon: 'none' + }) + return + } + let index = e.currentTarget.dataset.index; + this.setData({ + skuIndex: index + }) + }, + order: function (e) { + 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: "去购物车结算?", - success: function (res) { - if (res.confirm) { - wx.navigateTo({ - url: '/pages/user/cartlist/list', - }) - } - } + title: "温馨提示", + content: '商品已经被抢光啦~要不要瞧瞧别的~', + showCancel: false }) - }, 650) + 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 + } + app.globalData.index = 0 + 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 //5 + }) + }) + // 加动效 + 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({ + event: e.currentTarget.dataset.event, + param: { + type: this.data.info.type, + id: this.data.info.id } - }) + }, 1) + }, + // 分享 + share: function () { + if (!wx.getStorageSync("jstrip_token")) { + wx.setStorageSync('login_from', 'scene_share_login') + commonApi.user_post("user/getMyInfo", {}).then(res => {}).catch(err => {}) + return; } - } - }) - }, - pagePoint: function (e) { - util.pagePoint({ - event: e.currentTarget.dataset.event, - param: { - type: this.data.info.type, - id: this.data.info.id - } - }, 1) - }, - // 分享 - share: function () { - if (!wx.getStorageSync("jstrip_token")) { - wx.setStorageSync('login_from', 'scene_share_login') - commonApi.user_post("user/getMyInfo", {}).then(res => {}).catch(err => {}) - return; - } - if (!this.data.shareImg) { - wx.showToast({ - title: '图片生成中,稍后再试', - icon: 'none' - }) - return; - } - this.setData({ - showShareFlag: !this.data.showShareFlag - }) - }, - // 保存 - save() { - let url = this.data.shareImg, - that = this; - wx.authorize({ - /* 这个就是保存相册的 */ - scope: 'scope.writePhotosAlbum', - success() { - wx.saveImageToPhotosAlbum({ - filePath: url, - success(res) { - wx.showToast({ - title: '保存成功', - icon: "success" - }) - that.setData({ - showShareFlag: !that.data.showShareFlag - }) - util.pagePoint({ - event: 'scene_share_save', - param: { - type: that.data.info.type, - id: that.data.info.id - } - }, 1) - }, - fail(res) { + if (!this.data.shareImg) { wx.showToast({ - title: '保存失败', - icon: 'none' + title: '图片生成中,稍后再试', + icon: 'none' }) - } + return; + } + this.setData({ + showShareFlag: !this.data.showShareFlag }) - }, - complete(res) { - /* 这里判断一下如果没有授权重新打开设置选项 */ - wx.getSetting({ - success(res) { - if (!res.authSetting['scope.writePhotosAlbum']) { - /* 打开设置的方法 */ - // opensit(); - wx.showToast({ - title: '请打开权限后再试', - icon: 'none' - }) + }, + // 保存 + save() { + let url = this.data.shareImg, + that = this; + wx.authorize({ + /* 这个就是保存相册的 */ + scope: 'scope.writePhotosAlbum', + success() { + wx.saveImageToPhotosAlbum({ + filePath: url, + success(res) { + wx.showToast({ + title: '保存成功', + icon: "success" + }) + that.setData({ + showShareFlag: !that.data.showShareFlag + }) + util.pagePoint({ + event: 'scene_share_save', + param: { + type: that.data.info.type, + id: that.data.info.id + } + }, 1) + }, + fail(res) { + wx.showToast({ + title: '保存失败', + icon: 'none' + }) + } + }) + }, + complete(res) { + /* 这里判断一下如果没有授权重新打开设置选项 */ + wx.getSetting({ + success(res) { + if (!res.authSetting['scope.writePhotosAlbum']) { + /* 打开设置的方法 */ + // opensit(); + wx.showToast({ + title: '请打开权限后再试', + icon: 'none' + }) + } + } + }); } - } }); - } - }); - }, - // 绘制海报 - drawImg: function () { - var that = this, - userinfo = wx.getStorageSync('jstrip_userInfo'); - if (!userinfo) { - // 去登录 - return false; - } - const ctx = wx.createCanvasContext('imageCanvas'); - // const device = wx.getSystemInfoSync(); - // const ratio = device.screenWidth / 750; - // 先获取到图片信息 - let promise2 = new Promise(function (resolve, reject) { - wx.getImageInfo({ - src: that.data.info.headimg, - success: function (res) { - resolve(res); - }, - fail: function (res) { - reject(res); + }, + // 绘制海报 + drawImg: function () { + var that = this, + userinfo = wx.getStorageSync('jstrip_userInfo'); + if (!userinfo) { + // 去登录 + return false; } - }) - }) - let promise3 = new Promise(function (resolve, reject) { - let userid = wx.getStorageSync('jstrip_userid') - new QRCode('myQrcode', { - text: 'https://m.cloud.sz-trip.com/ScenicDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', - width: 500, - height: 500, - padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 - correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 - callback: (res) => { - resolve(res); - } - }) - }) - //成功得到图片信息后,开始绘图 - Promise.all([promise2, promise3]).then(imgs => { - ctx.save(); - ctx.beginPath(); //开始绘制 - that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') - ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 - ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); - ctx.restore(); - ctx.save(); - that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') - ctx.restore(); - // 绘制二维码 - ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); - // 开始文字绘制 - ctx.setFillStyle("#000"); - ctx.setFontSize(30 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); - // 售价 - ctx.setFillStyle("#D62828"); - ctx.setFontSize(40 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let price = "¥" + (that.data.info.price / 100); - let width = ctx.measureText(price).width; - ctx.fillText(price, 25 * ratio, 620 * ratio); - // 副标题 - ctx.setFillStyle("#999999"); - ctx.setFontSize(28 * ratio); //字大小 - ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - let subtitle = that.data.info.sub_title - if (subtitle && subtitle.length > 10) { - subtitle = subtitle.substr(0, 10) + '...' - } - if (subtitle) { - ctx.fillText(subtitle, 25 * ratio, 540 * ratio); - } - - // ctx.draw(); - // 划线价 - // ctx.setFillStyle("#999999"); - // ctx.setFontSize(32 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // let market_price = "¥"+(Number(that.data.info.market_price)/100) - // ctx.fillText(market_price, 40*ratio + width, 620*ratio); - // let market_price_width = ctx.measureText(market_price).width; - // 划线 - // ctx.beginPath() - // ctx.setLineWidth(1) - // ctx.moveTo(40*ratio + width, 608*ratio) - // ctx.lineTo(45*ratio + width, 608*ratio) - // ctx.stroke(); - // 长按识别二维码 - // ctx.setFillStyle("#666"); - // ctx.setFontSize(22 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); - // 长按图片转发或保存 - // ctx.setFillStyle("#000"); - // ctx.setFontSize(24 * ratio); //字大小 - // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 - // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); - ctx.draw(); - // 转为图片 - setTimeout(() => { - wx.canvasToTempFilePath({ - x: 0, - y: 0, - canvasId: 'imageCanvas', - success: function (res) { - that.setData({ - shareImg: res.tempFilePath + const ctx = wx.createCanvasContext('imageCanvas'); + // const device = wx.getSystemInfoSync(); + // const ratio = device.screenWidth / 750; + // 先获取到图片信息 + let promise2 = new Promise(function (resolve, reject) { + wx.getImageInfo({ + src: that.data.info.headimg, + success: function (res) { + resolve(res); + }, + fail: function (res) { + reject(res); + } }) - }, - fail(err) { - console.log('agdgjgdajhg', err) - } }) - }, 500) - return false; - }).catch(err => { - console.log("this err", err) - }) - }, - // 圆角矩形 - handleBorderRect(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x + w, y + h); - ctx.lineTo(x, y + h) - // 左上角 - ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); - ctx.moveTo(x + r, y); - ctx.lineTo(x + w - r, y); - ctx.lineTo(x + w, y + r); - // 右上角 - ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); - ctx.lineTo(x + w, y + h); - ctx.lineTo(x + w - r, y + h); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - handleBorderRect2(ctx, x, y, w, h, r, color) { - ctx.beginPath(); - ctx.moveTo(x, y); - ctx.lineTo(x + w, y) - // 右下角 - ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); - ctx.lineTo(x + r, y + h); - ctx.lineTo(x, y + h - r); - // 左下角 - ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); - ctx.lineTo(x, y); - ctx.lineTo(x, y); - ctx.fillStyle = color; - ctx.fill(); - ctx.closePath(); - }, - // 绘制两行文字 - drawText: function (ctx, str, x, y, canvasWidth, ratio) { - let row = [], - temp = "", - chr = str.split(""); - for (var a = 0; a < chr.length; a++) { - if (ctx.measureText(temp).width < canvasWidth) { - temp += chr[a]; - } else { - a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + let promise3 = new Promise(function (resolve, reject) { + let userid = wx.getStorageSync('jstrip_userid') + new QRCode('myQrcode', { + text: 'https://m.cloud.sz-trip.com/ScenicDetail?id=' + that.data.info.id + '&sharedUserId=' + userid + '&channel=-1', + width: 500, + height: 500, + padding: 12, // 生成二维码四周自动留边宽度,不传入默认为0 + correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 + callback: (res) => { + resolve(res); + } + }) + }) + //成功得到图片信息后,开始绘图 + Promise.all([promise2, promise3]).then(imgs => { + ctx.save(); + ctx.beginPath(); //开始绘制 + that.handleBorderRect(ctx, 0, 0, 551 * ratio, 407 * ratio, 25 * ratio, '#ccc') + ctx.clip(); //画好了圆 剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因 + ctx.drawImage(imgs[0].path, 0, 0, 551 * ratio, 407 * ratio); + ctx.restore(); + ctx.save(); + that.handleBorderRect2(ctx, 0, 407 * ratio, 551 * ratio, 236 * ratio, 25 * ratio, '#fff') + ctx.restore(); + // 绘制二维码 + ctx.drawImage(imgs[1].path, 373 * ratio, 495 * ratio, 137 * ratio, 137 * ratio); + // 开始文字绘制 + ctx.setFillStyle("#000"); + ctx.setFontSize(30 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + that.drawText(ctx, that.data.info.title, 25 * ratio, 450 * ratio, 480 * ratio, ratio); + // 售价 + ctx.setFillStyle("#D62828"); + ctx.setFontSize(40 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let price = "¥" + (that.data.info.price / 100); + let width = ctx.measureText(price).width; + ctx.fillText(price, 25 * ratio, 620 * ratio); + // 副标题 + ctx.setFillStyle("#999999"); + ctx.setFontSize(28 * ratio); //字大小 + ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + let subtitle = that.data.info.sub_title + if (subtitle && subtitle.length > 10) { + subtitle = subtitle.substr(0, 10) + '...' + } + if (subtitle) { + ctx.fillText(subtitle, 25 * ratio, 540 * ratio); + } + + // ctx.draw(); + // 划线价 + // ctx.setFillStyle("#999999"); + // ctx.setFontSize(32 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // let market_price = "¥"+(Number(that.data.info.market_price)/100) + // ctx.fillText(market_price, 40*ratio + width, 620*ratio); + // let market_price_width = ctx.measureText(market_price).width; + // 划线 + // ctx.beginPath() + // ctx.setLineWidth(1) + // ctx.moveTo(40*ratio + width, 608*ratio) + // ctx.lineTo(45*ratio + width, 608*ratio) + // ctx.stroke(); + // 长按识别二维码 + // ctx.setFillStyle("#666"); + // ctx.setFontSize(22 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按识别二维码", 404*ratio, 710*ratio); + // 长按图片转发或保存 + // ctx.setFillStyle("#000"); + // ctx.setFontSize(24 * ratio); //字大小 + // ctx.setTextAlign('left'); //是否居中显示,参考点画布中线 + // ctx.fillText("长按图片保存到本地",(592*ratio - ctx.measureText("长按图片保存到本地").width)/2, 740*ratio); + ctx.draw(); + // 转为图片 + setTimeout(() => { + wx.canvasToTempFilePath({ + x: 0, + y: 0, + canvasId: 'imageCanvas', + success: function (res) { + that.setData({ + shareImg: res.tempFilePath + }) + }, + fail(err) { + console.log('agdgjgdajhg', err) + } + }) + }, 500) + return false; + }).catch(err => { + console.log("this err", err) + }) + }, + // 圆角矩形 + handleBorderRect(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x + w, y + h); + ctx.lineTo(x, y + h) + // 左上角 + ctx.arc(x + r, y + r, r, Math.PI, 1.5 * Math.PI); + ctx.moveTo(x + r, y); + ctx.lineTo(x + w - r, y); + ctx.lineTo(x + w, y + r); + // 右上角 + ctx.arc(x + w - r, y + r, r, 1.5 * Math.PI, 2 * Math.PI); + ctx.lineTo(x + w, y + h); + ctx.lineTo(x + w - r, y + h); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + handleBorderRect2(ctx, x, y, w, h, r, color) { + ctx.beginPath(); + ctx.moveTo(x, y); + ctx.lineTo(x + w, y) + // 右下角 + ctx.arc(x + w - r, y + h - r, r, 0, 0.5 * Math.PI); + ctx.lineTo(x + r, y + h); + ctx.lineTo(x, y + h - r); + // 左下角 + ctx.arc(x + r, y + h - r, r, 0.5 * Math.PI, Math.PI); + ctx.lineTo(x, y); + ctx.lineTo(x, y); + ctx.fillStyle = color; + ctx.fill(); + ctx.closePath(); + }, + // 绘制两行文字 + drawText: function (ctx, str, x, y, canvasWidth, ratio) { + let row = [], + temp = "", + chr = str.split(""); + for (var a = 0; a < chr.length; a++) { + if (ctx.measureText(temp).width < canvasWidth) { + temp += chr[a]; + } else { + a--; //这里添加了a-- 是为了防止字符丢失,效果图中有对比 + row.push(temp); + temp = ""; + } + } row.push(temp); - temp = ""; - } - } - row.push(temp); - //如果数组长度大于2 则截取前两个 - if (row.length > 2) { - var rowCut = row.slice(0, 2); - var rowPart = rowCut[1]; - var test = ""; - var empty = []; - for (var a = 0; a < rowPart.length; a++) { - if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { - test += rowPart[a]; - } else { - break; + //如果数组长度大于2 则截取前两个 + if (row.length > 2) { + var rowCut = row.slice(0, 2); + var rowPart = rowCut[1]; + var test = ""; + var empty = []; + for (var a = 0; a < rowPart.length; a++) { + if (ctx.measureText(test).width < canvasWidth - 30 * ratio) { + test += rowPart[a]; + } else { + break; + } + } + empty.push(test); + var group = empty[0] + "..." //这里只显示两行,超出的用...表示 + rowCut.splice(1, 1, group); + row = rowCut; } - } - empty.push(test); - var group = empty[0] + "..." //这里只显示两行,超出的用...表示 - rowCut.splice(1, 1, group); - row = rowCut; - } - for (var b = 0; b < row.length; b++) { - ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); - } - }, - //加入购物车 - showCart: function () { - if (this.data.info.product[0].sku.length == 0) { - wx.showToast({ - title: '该产品未设置规格,不能加购', - icon: 'none' - }) - return; - } - this.setData({ - skuFlag: "cart" - }) - let that = this - wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) { - that.setData({ - cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' - }) - }).exec() + for (var b = 0; b < row.length; b++) { + ctx.fillText(row[b], x, y + b * 40 * ratio, canvasWidth); + } + }, + //加入购物车 + showCart: function () { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/sceneProductInfo/index?id=' + this.data.id, + title: this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + if (this.data.info.product[0].sku.length == 0) { + wx.showToast({ + title: '该产品未设置规格,不能加购', + icon: 'none' + }) + return; + } + this.setData({ + skuFlag: "cart" + }) + let that = this + wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) { + that.setData({ + cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' + }) + }).exec() + } + }) + + + + + }, + hideSku: function () { + this.setData({ + skuFlag: null, + cartImgInfo: null + }) + }, + //加减数量 + minus: function () { + if (this.data.producNum == 1) return; + this.setData({ + producNum: this.data.producNum - 1 + }) + }, + add: function () { + this.setData({ + producNum: this.data.producNum + 1 + }) + }, + //立即预定 + showOrder: function () { + console.log(this.data.id); + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/info/sceneProductInfo/index?id=' + this.data.id, + title: this.data.info.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + if (this.data.info.product[0].sku.length == 0) { + wx.showToast({ + title: '该产品未设置规格,不能购买', + icon: 'none' + }) + return; + } + if (this.data.info.product[0].type == 'line') { + wx.navigateTo({ + url: '/pages/order/road/index?id=' + this.data.info.product[0].id + }) + return + } + this.setData({ + skuFlag: 'order' + }) + } + }) - }, - hideSku: function () { - this.setData({ - skuFlag: null, - cartImgInfo: null - }) - }, - //加减数量 - minus: function () { - if (this.data.producNum == 1) return; - this.setData({ - producNum: this.data.producNum - 1 - }) - }, - add: function () { - this.setData({ - producNum: this.data.producNum + 1 - }) - }, - //立即预定 - showOrder: function () { - if (this.data.info.product[0].sku.length == 0) { - wx.showToast({ - title: '该产品未设置规格,不能购买', - icon: 'none' - }) - return; - } - if (this.data.info.product[0].type == 'line') { - wx.navigateTo({ - url: '/pages/order/road/index?id=' + this.data.info.product[0].id - }) - return - } - this.setData({ - skuFlag: 'order' - }) - }, + }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - if (app.globalData.configJson) { - this.setData({ - isTest: app.globalData.configJson.isTest - }) - } else { - setTimeout(() => { - this.onReady() - }, 300) - } - }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + if (app.globalData.configJson) { + this.setData({ + isTest: app.globalData.configJson.isTest + }) + } else { + setTimeout(() => { + this.onReady() + }, 300) + } + }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - console.log(11111); - commonApi.user_post('cart/get_list', {}).then(res => { - this.setData({ - cartCount: res.data.length //1 - }) - }) - if (!wx.getStorageSync('jstrip_token')) { - return; - } - if (this.data.info && this.data.info.id) { - this.drawImg() - //// 获取补贴 - // if (this.data.product.length == 1) { - // commonApi.user_post("product/getProductAllowancePrice", { - // product_code: this.data.product[0].product.product_code - // }).then(resTwo => { - // if (resTwo && resTwo.code == 1) { - // this.setData({ - // allowance_data: resTwo.data - // }) - // let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price) - // let sInfo = this.data.product[0].sku - // if (spread_price > 0) { - // if (spread_price < this.data.allowance_data.discount_rate / 100 * sInfo.price) { - // this.setData({ - // allowance_price: spread_price - // }) - // } else { - // this.setData({ - // allowance_price: this.data.allowance_data.discount_rate / 100 * sInfo.price - // }) - // } - // this.changePrice() - // } else { - // this.setData({ - // allowance_price: 0 - // }) - // } - // } - // }) - // } - //// 获取补贴结束 + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + console.log(11111); + commonApi.user_post('cart/get_list', {}).then(res => { + this.setData({ + cartCount: res.data.length //1 + }) + }) + if (!wx.getStorageSync('jstrip_token')) { + return; + } + if (this.data.info && this.data.info.id) { + this.drawImg() + //// 获取补贴 + // if (this.data.product.length == 1) { + // commonApi.user_post("product/getProductAllowancePrice", { + // product_code: this.data.product[0].product.product_code + // }).then(resTwo => { + // if (resTwo && resTwo.code == 1) { + // this.setData({ + // allowance_data: resTwo.data + // }) + // let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price) + // let sInfo = this.data.product[0].sku + // if (spread_price > 0) { + // if (spread_price < this.data.allowance_data.discount_rate / 100 * sInfo.price) { + // this.setData({ + // allowance_price: spread_price + // }) + // } else { + // this.setData({ + // allowance_price: this.data.allowance_data.discount_rate / 100 * sInfo.price + // }) + // } + // this.changePrice() + // } else { + // this.setData({ + // allowance_price: 0 + // }) + // } + // } + // }) + // } + //// 获取补贴结束 - } else { - console.log(2222); - setTimeout(() => { - // this.onShow() - }, 200) - } + } else { + console.log(2222); + setTimeout(() => { + // this.onShow() + }, 200) + } - }, + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - }, + }, - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - }, + }, - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - }, + }, - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { - }, + }, - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () {} + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () {} }) \ No newline at end of file diff --git a/pages/info/sceneProductInfo/index.json b/pages/info/sceneProductInfo/index.json index b5d8d8b..58e1fcb 100644 --- a/pages/info/sceneProductInfo/index.json +++ b/pages/info/sceneProductInfo/index.json @@ -1,6 +1,9 @@ { "usingComponents": { "title":"/pages/component/TitleHeader", - "notice":"/pages/component/notice/notice" + "notice":"/pages/component/notice/notice", + "code":"../../order/components/wxqrCode/index" + + } } \ No newline at end of file diff --git a/pages/info/sceneProductInfo/index.wxml b/pages/info/sceneProductInfo/index.wxml index 923f0f1..04562e2 100644 --- a/pages/info/sceneProductInfo/index.wxml +++ b/pages/info/sceneProductInfo/index.wxml @@ -251,4 +251,6 @@ {{info.allowance.title}} - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/list/movieticket/list/ticket/index.js b/pages/list/movieticket/list/ticket/index.js index 79931ff..8dacd88 100644 --- a/pages/list/movieticket/list/ticket/index.js +++ b/pages/list/movieticket/list/ticket/index.js @@ -4,252 +4,269 @@ import commonApi from "../../../../../utils/https/common" import util from "../../../../../utils/util" Page({ - /** - * 页面的初始数据 - */ - data: { - id:null, - dates:[], - days:['周日','周一','周二','周三','周四','周五','周六'], - dateIndex:0, - areas:[], - areaIndex:0, - lat:"", - lon:"", - sort:'distance', - list:[], - title:"", - page:1, - isMore:true - }, + /** + * 页面的初始数据 + */ + data: { + id: null, + dates: [], + days: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], + dateIndex: 0, + areas: [], + areaIndex: 0, + lat: "", + lon: "", + sort: 'distance', + list: [], + title: "", + page: 1, + isMore: true, + showQrCode: false, + wxqrcode: null + }, - /** - * 生命周期函数--监听页面加载 - */ - pagePoint(e) { - util.pagePoint(e) - }, - onLoad: function (options) { - this.setData({ - id:options.id, - title:options.title - }) - commonApi._post("act/get_suzhou_areas").then(res=>{ - res.data.unshift({ - area_id:"", - area_title:"苏州" - }) - this.setData({ - areas:res.data - }) - }) - this.initDate(); - wx.getLocation({ - type: 'gcj02', - success:(res)=>{ + /** + * 生命周期函数--监听页面加载 + */ + pagePoint(e) { + util.pagePoint(e) + }, + onLoad: function (options) { this.setData({ - lat:res.latitude, - lon:res.longitude + id: options.id, + title: options.title + }) + commonApi._post("act/get_suzhou_areas").then(res => { + res.data.unshift({ + area_id: "", + area_title: "苏州" + }) + this.setData({ + areas: res.data + }) + }) + this.initDate(); + wx.getLocation({ + type: 'gcj02', + success: (res) => { + this.setData({ + lat: res.latitude, + lon: res.longitude + }) + this.getList() + }, + fail: () => { + this.getList() + } + }) + }, + changeSort: function (e) { + let sort = e.currentTarget.dataset.sort; + this.setData({ + sort: this.data.sort == sort ? null : sort, + list: [], + page: 1, + isMore: true + }) + if (this.data.sort == 'distance' && !this.data.lon) { + wx.getLocation({ + type: 'gcj02', + success: (res) => { + this.setData({ + lat: res.latitude, + lon: res.longitude + }) + this.getList() + }, + fail: () => { + this.getList() + } + }) + } else { + this.getList() + } + + }, + changeDateIndex: function (e) { + this.setData({ + dateIndex: e.currentTarget.dataset.index, + list: [], + page: 1, + isMore: true }) this.getList() - }, - fail:()=>{ + }, + changeArea: function (e) { + this.setData({ + areaIndex: e.detail.value, + list: [], + page: 1, + isMore: true + }) this.getList() - } - }) - }, - changeSort:function(e){ - let sort = e.currentTarget.dataset.sort; - this.setData({ - sort:this.data.sort==sort?null:sort, - list:[], - page:1, - isMore:true - }) - if(this.data.sort=='distance' && !this.data.lon){ - wx.getLocation({ - type: 'gcj02', - success:(res)=>{ - this.setData({ - lat:res.latitude, - lon:res.longitude - }) - this.getList() - }, - fail:()=>{ - this.getList() + }, + initDate: function () { + let today = new Date(util.formatDate(new Date()).replace(/-/g, '/')).getTime(), + single = 24 * 60 * 60 * 1000, + dates = []; + for (let i = 0; i < 7; i++) { + let item = new Date(today + i * single); + let name = this.data.days[item.getDay()] + if (i == 0) { + name = "今天" + } else if (i == 1) { + name = "明天" + } + dates.push({ + date: util.formatDate(item), + dateShort: util.formatDate(item).substr(5, 5), + name: name + }) } - }) - } - else { - this.getList() - } - - }, - changeDateIndex:function(e){ - this.setData({ - dateIndex:e.currentTarget.dataset.index, - list:[], - page:1, - isMore:true - }) - this.getList() - }, - changeArea:function(e){ - this.setData({ - areaIndex:e.detail.value, - list:[], - page:1, - isMore:true - }) - this.getList() - }, - initDate:function(){ - let today = new Date(util.formatDate(new Date()).replace(/-/g,'/')).getTime(),single = 24 * 60 * 60 *1000,dates=[]; - for(let i=0;i<7;i++){ - let item = new Date(today+i * single); - let name = this.data.days[item.getDay()] - if(i==0){ - name="今天" - } - else if(i==1){ - name="明天" - } - dates.push({ - date:util.formatDate(item), - dateShort:util.formatDate(item).substr(5,5), - name:name - }) - } - this.setData({ - dates:dates - }) - console.log(dates) - }, - getList:function(){ - if(!this.data.isMore) return - commonApi._post("Cinema/getCinemaListByShowId",{ - third_id:this.data.id, - show_date:this.data.dates[this.data.dateIndex].date, - city_code:this.data.areas[this.data.areaIndex]?this.data.areas[this.data.areaIndex].area_id:"", - lon:this.data.lon, - lat:this.data.lat, - is_price_sort:this.data.sort=='price'?true:false, - is_distance_sort:this.data.sort=='distance', - page:this.data.page, - pageSize:10 - }).then(res=>{ - res.data.map(item=>{ - if(item.distance>1000){ - item.distanceText = (item.distance/1000).toFixed(2) + 'km'; - } - else if(item.distance>0){ - item.distanceText = (item.distance).toFixed(2) + 'm'; - } - }) - let list = this.data.list; - this.setData({ - list:list.concat(res.data), - page:this.data.page+1 - }) - if(res.data.length<10){ this.setData({ - isMore:false + dates: dates }) - } - console.log(res) - }) - }, - selectMovieSeat(e){ - let info = e.currentTarget.dataset.info - let index = e.currentTarget.dataset.index - console.log(index); - console.log(info.schedules); - const areaInfo = JSON.parse(info.schedules[index].schedule_area).map(item => ({...item, price:item.areaPrice,areaId:item.seatAreaId})); - let planData = { - areaInfo, - fee:info.schedules[index].service_fee, - movieName: this.data.title, - planId : info.schedules[index].schedule_id, - planTime : info.schedules[index].show_time, - type:'WECHATXCX', - remake : '' - } - let show_id = info.schedules[index].show_id - let cinema_id = info.schedules[index].cinema_id - // let schedule_id = info.schedule_id - console.log(info); - commonApi._post('Cinema/getProductAndSku',{ - show_id, - cinema_id, - }).then(res=>{ - app.globalData.product ={ - product:res.data, - info:{ - hallName:info.schedules[index].hall_name, - cinemaName:info.title, - show_date:info.schedules[index].show_date, - show_time:info.schedules[index].show_time, - close_time:info.schedules[index].close_time, - movieName:this.data.title, - start_end_time:info.schedules[index].show_time, - show_version:info.schedules[index].show_version, - selectSeatInfo:null, - schedule_id:info.schedules[index].schedule_id - } - } - console.log(planData); - wx.navigateTo({ - url:"/pages/list/movieticket/list/web/index?planData="+ JSON.stringify(planData), - }) - }) - }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { + console.log(dates) + }, + getList: function () { + if (!this.data.isMore) return + commonApi._post("Cinema/getCinemaListByShowId", { + third_id: this.data.id, + show_date: this.data.dates[this.data.dateIndex].date, + city_code: this.data.areas[this.data.areaIndex] ? this.data.areas[this.data.areaIndex].area_id : "", + lon: this.data.lon, + lat: this.data.lat, + is_price_sort: this.data.sort == 'price' ? true : false, + is_distance_sort: this.data.sort == 'distance', + page: this.data.page, + pageSize: 10 + }).then(res => { + res.data.map(item => { + if (item.distance > 1000) { + item.distanceText = (item.distance / 1000).toFixed(2) + 'km'; + } else if (item.distance > 0) { + item.distanceText = (item.distance).toFixed(2) + 'm'; + } + }) + let list = this.data.list; + this.setData({ + list: list.concat(res.data), + page: this.data.page + 1 + }) + if (res.data.length < 10) { + this.setData({ + isMore: false + }) + } + console.log(res) + }) + }, + selectMovieSeat(e) { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/list/movieticket/list/ticket/index?id=' + this.data.id, + title: this.data.title, + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + let info = e.currentTarget.dataset.info + let index = e.currentTarget.dataset.index + console.log(index); + console.log(info.schedules); + const areaInfo = JSON.parse(info.schedules[index].schedule_area).map(item => ({ + ...item, + price: item.areaPrice, + areaId: item.seatAreaId + })); + let planData = { + areaInfo, + fee: info.schedules[index].service_fee, + movieName: this.data.title, + planId: info.schedules[index].schedule_id, + planTime: info.schedules[index].show_time, + type: 'WECHATXCX', + remake: '' + } + let show_id = info.schedules[index].show_id + let cinema_id = info.schedules[index].cinema_id + // let schedule_id = info.schedule_id + console.log(info); + commonApi._post('Cinema/getProductAndSku', { + show_id, + cinema_id, + }).then(res => { + app.globalData.product = { + product: res.data, + info: { + hallName: info.schedules[index].hall_name, + cinemaName: info.title, + show_date: info.schedules[index].show_date, + show_time: info.schedules[index].show_time, + close_time: info.schedules[index].close_time, + movieName: this.data.title, + start_end_time: info.schedules[index].show_time, + show_version: info.schedules[index].show_version, + selectSeatInfo: null, + schedule_id: info.schedules[index].schedule_id + } + } + console.log(planData); + wx.navigateTo({ + url: "/pages/list/movieticket/list/web/index?planData=" + JSON.stringify(planData), + }) + }) + }}) + }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { - }, + }, - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { - }, + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - }, + }, - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - }, + }, - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - }, + }, - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - this.getList() - }, + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + this.getList() + }, - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { - } + } }) \ No newline at end of file diff --git a/pages/list/movieticket/list/ticket/index.json b/pages/list/movieticket/list/ticket/index.json index 35cf02f..321981d 100644 --- a/pages/list/movieticket/list/ticket/index.json +++ b/pages/list/movieticket/list/ticket/index.json @@ -1,5 +1,6 @@ { "usingComponents": { - "title":"/pages/component/TitleHeader" + "title":"/pages/component/TitleHeader", + "code":"../../../../order/components/wxqrCode/index" } } \ No newline at end of file diff --git a/pages/list/movieticket/list/ticket/index.wxml b/pages/list/movieticket/list/ticket/index.wxml index 3e24bca..622fdb0 100644 --- a/pages/list/movieticket/list/ticket/index.wxml +++ b/pages/list/movieticket/list/ticket/index.wxml @@ -43,4 +43,6 @@ 暂无内容 - \ No newline at end of file + + + \ No newline at end of file diff --git a/pages/order/components/wxqrCode/index.js b/pages/order/components/wxqrCode/index.js new file mode 100644 index 0000000..7cfee1b --- /dev/null +++ b/pages/order/components/wxqrCode/index.js @@ -0,0 +1,42 @@ +// pages/order/components/coupon/index.js +let app = getApp() +Component({ + /** + * 组件的属性列表 + */ + properties: { + showModel:{ + type:Boolean, + value:false + }, + qrcode:{ + type:String, + value:null + } + + }, + + /** + * 组件的初始数据 + */ + data: { + + }, + pageLifetimes: { + show: function() { + console.log(123123); + } + }, + + /** + * 组件的方法列表 + */ + methods: { + submit: function() { + this.setData({ + showModel:false + }) + } + + } +}) diff --git a/pages/order/components/wxqrCode/index.json b/pages/order/components/wxqrCode/index.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/pages/order/components/wxqrCode/index.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/order/components/wxqrCode/index.wxml b/pages/order/components/wxqrCode/index.wxml new file mode 100644 index 0000000..36bf915 --- /dev/null +++ b/pages/order/components/wxqrCode/index.wxml @@ -0,0 +1,13 @@ + + + + + + + 扫码关注【君到苏州】 微信公众号 + + + 查看更多旅游资讯 + + + \ No newline at end of file diff --git a/pages/order/components/wxqrCode/index.wxss b/pages/order/components/wxqrCode/index.wxss new file mode 100644 index 0000000..3135ada --- /dev/null +++ b/pages/order/components/wxqrCode/index.wxss @@ -0,0 +1,70 @@ +.mask{ + width: 100%; + height: 100%; + position: fixed; + top: 0; + left: 0; + background: #000; + z-index: 9000; + opacity: 0.7; +} + +.modalDlg{ + width: 500rpx; + height: 660rpx; + background-image:url('https://static.ticket.sz-trip.com/uploads/20230619/12a423ee9510a8e5c9c92696e52fcc3c.png') ; + background-size: 100% 100%; + position: fixed; + top: 50%; + left: 0; + z-index: 9999; + margin: -370rpx 125rpx; + background-color: #fff; + border-radius: 36rpx; + display: flex; + flex-direction: column; + align-items: center; +} +.img-box{ + width: 300rpx; + height: 300rpx; + background: #FFFFFF; + display: flex; + align-items: center; + justify-content: center; + margin-top: 79rpx; + + +} +.img-box image{ + width: 310rpx; + height: 310rpx; + border-radius: 10rpx; +} +.text-box{ + width: 300rpx; + font-size: 30rpx; + font-family: PingFang SC; + font-weight: bold; + color: #FFFFFF; + text-align: center; + margin-top: 40rpx; +} +.text-box text{ + color: rgba(255, 255, 85, 1); +} +.more{ + margin-top: 80rpx; +font-size: 30rpx; +font-family: PingFang SC; +font-weight: bold; +color: #0B898E; +} +.close{ + position: absolute; + bottom: -120rpx; + left: 50%; + height: 80rpx; + width: 80rpx; + transform: translate(-40rpx,0); +} diff --git a/pages/order/movie/index.wxml b/pages/order/movie/index.wxml index c39a4e0..a749339 100644 --- a/pages/order/movie/index.wxml +++ b/pages/order/movie/index.wxml @@ -11,11 +11,6 @@ {{product.info.hallName}} {{product.info.selectSeatInfo.seatInfo}} - - - 手机号码: - - @@ -32,6 +27,10 @@ + + 手机号码: + + diff --git a/pages/order/movie/index.wxss b/pages/order/movie/index.wxss index 91509b5..8b58f41 100644 --- a/pages/order/movie/index.wxss +++ b/pages/order/movie/index.wxss @@ -14,7 +14,7 @@ page { display: flex; padding-top: 30rpx; padding-bottom: 41rpx; - border-bottom: 1rpx solid #ccc; + /* border-bottom: 1rpx solid #ccc; */ font-size: 27rpx; color: #999; justify-content: space-between; @@ -42,7 +42,11 @@ page { align-items: center; height: 126rpx; font-size: 31rpx; - justify-content: space-between; + justify-content: space-between; + margin: 30rpx 25rpx; + background: white; + border-radius: 9rpx; + padding: 0 20rpx; } .tel-box>text { color: #000; diff --git a/pages/user/cartlist/list.js b/pages/user/cartlist/list.js index c51d1b1..4c7bbc2 100644 --- a/pages/user/cartlist/list.js +++ b/pages/user/cartlist/list.js @@ -1,6 +1,6 @@ // pages/user/cartlist/list.js const device = wx.getSystemInfoSync(), - rect = wx.getMenuButtonBoundingClientRect(); // 获取设备信息 + rect = wx.getMenuButtonBoundingClientRect(); // 获取设备信息 const ratio = 750 / device.windowWidth; console.log(rect) const width = device.windowWidth // 示例为一个与屏幕等宽的正方形裁剪框 @@ -10,357 +10,373 @@ import util from '../../../utils/util' let app = getApp() Page({ - /** - * 页面的初始数据 - */ - data: { - menuWidth: width - rect.right + rect.width + 6, - list: [], - allChecked: false, - allPrice: 0, - productType: '', - manageFlag: false, - flag: false, //判断订单是否同时有商品和票 - isCar:'single',//判断是否购物车 - }, + /** + * 页面的初始数据 + */ + data: { + menuWidth: width - rect.right + rect.width + 6, + list: [], + allChecked: false, + allPrice: 0, + productType: '', + manageFlag: false, + flag: false, //判断订单是否同时有商品和票 + isCar: 'single', //判断是否购物车 + showQrCode: false, + wxqrcode: null + }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - wx.removeStorageSync('linkMan') - this.getList(); - }, - manage: function () { - let list = this.data.list; - list.map(item => { - item.checked = 0; - }) - this.setData({ - manageFlag: !this.data.manageFlag, - allChecked: 0, - list: list, - allPrice: 0 - }) - }, - gotoDetail: function (e) { - console.log(e) - let item = e.currentTarget.dataset.item.product; - util.gotoDetail(item, 1); - }, - getList: function () { - commonApi.user_post("cart/get_list", { - // type: '1' - }).then(res => { - this.setData({ - list: res.data - }) - }) - }, - minus: function (e) { - let index = e.currentTarget.dataset.index, - list = this.data.list; - let num = list[index].num; - if (num <= 1) return; - num = num - 1; - list[index].num = num; - this.setData({ - list: list - }) - this.changeNumber(list[index]) - this.updatePrice() - }, - add: function (e) { - let index = e.currentTarget.dataset.index, - list = this.data.list; - let num = list[index].num + 1; - list[index].num = num; - this.setData({ - list: list - }) - this.changeNumber(list[index]) - this.updatePrice() - }, - select: function (e) { - let index = e.currentTarget.dataset.index, - list = this.data.list; - if (list[index].product.flag != 1 || list[index].sku.flag != 'on') { - if (!this.data.manageFlag) { - wx.showToast({ - title: '产品已下架', - icon: 'none' + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + wx.removeStorageSync('linkMan') + this.getList(); + }, + manage: function () { + let list = this.data.list; + list.map(item => { + item.checked = 0; }) - return; - } - } - list[index].checked = list[index].checked ? false : true; - this.setData({ - list: list - }) - let flag = true - list.forEach(item => { - if (!item.checked) { - flag = false - return - } - }); - this.setData({ - allChecked:flag - }) - this.updatePrice() - }, - selectAll: function () { - let list = this.data.list, - allChecked = this.data.allChecked ? false : true; - list.map(item => { - if (item.sku.flag == 'on' && item.product.flag == 1) { - item.checked = allChecked; - } - }) - this.setData({ - allChecked: allChecked, - list: list - }) - this.updatePrice() - }, - changeNumber(item) { - commonApi.user_post("cart/update_sku", { - sku_id: item.sku.id, - num: item.num - }).then(res => {}) - }, - updatePrice: function () { - let list = this.data.list, - price = 0; - list.map(item => { - if (item.checked) { - price = price + item.sku.price * item.num; - } - }) - this.setData({ - allPrice: price - }) - }, - order: function () { - app.globalData.couponInfo = null; - util.pagePoint({ - event: 'cart_order' - }, 1) - let list = this.data.list, - price = 0, - product = [], - product1 = [] - list.map(item => { - if (item.checked) { - // item.product.type="post"; - if (item.product.type == 'post') { - product.push({ - product: item.product, - sku: item.sku, - productNum: item.num - }) - } else { - product1.push(item) - app.globalData.list = product1 - } - if (item.product.type.includes('post')) { - this.data.productType = 'post' - } - } - }) - if (product.length == 0 && product1.length == 0) { - wx.showToast({ - title: '请先选择产品', - icon: 'none' - }) - return; - } - if (product.length > 0 && product1.length > 0) { - this.setData({ - flag: 'mix', - isCar:'multiple' - }) - } - if ( product1.length > 1) { - this.setData({ - isCar:'multiple' - }) - }else{ - this.setData({ - isCar:'single' - }) - } - console.log(product1); - app.globalData.postProduct = product; - if (app.globalData.list) { - app.globalData.product = app.globalData.list[app.globalData.index] - } - if (this.data.productType == 'post') { - console.log(this.data.flag); - wx.navigateTo({ - url: '/pages/order/postOrder/index?from=cart&flag=' + this.data.flag, - }) - } else { - wx.navigateTo({ - url: '/pages/order/scene/index?isCar=' + this.data.isCar, - }) - } - }, - touchStart(e) { //移动前点击的位置 - console.log(e) - // 在开始触摸时将所有startTouchMove设置为flase,对当前的为true - this.data.list.forEach(cart => { - if (cart.isTouchMove) //当istouchMove为true - cart.isTouchMove = false; //其它的对象都为false - }) - this.setData({ - startX: e.changedTouches[0].clientX, - startY: e.changedTouches[0].clientY, - list: this.data.list - }) - }, - touchmove(e) { //移动的位置,用于计算用户滑动的弧度向左还是向右,移动了多少,可以确定删除功能的显示和隐藏 - let index = e.currentTarget.dataset.index; - // 获取开始的x,y坐标 - let startX = this.data.startX, - startY = this.data.startY; - // 获取移动的x,x坐标 - let touchMoveX = e.changedTouches[0].clientX, - touchMoveY = e.changedTouches[0].clientY; - // 调用计算角度的方法,获取角度 - var angel = this.angel({ - X: startX, - Y: startY - }, { - X: touchMoveX, - Y: touchMoveY - }) - // 遍历cartArray - this.data.list.forEach((cart, i) => { - cart.isTouchMove = false; - // 滑动角度大于30,直接return 视为非滑动意思 - if (Math.abs(angel) > 30) return; - // 匹配当前所点击的list和滑动的list - if (i == index) { - // 匹配上后判断滑动方向 - if (touchMoveX > startX) { //左滑动隐藏删除 - cart.isTouchMove = false; - } else { - cart.isTouchMove = true; + this.setData({ + manageFlag: !this.data.manageFlag, + allChecked: 0, + list: list, + allPrice: 0 + }) + }, + gotoDetail: function (e) { + console.log(e) + let item = e.currentTarget.dataset.item.product; + util.gotoDetail(item, 1); + }, + getList: function () { + commonApi.user_post("cart/get_list", { + // type: '1' + }).then(res => { + this.setData({ + list: res.data + }) + }) + }, + minus: function (e) { + let index = e.currentTarget.dataset.index, + list = this.data.list; + let num = list[index].num; + if (num <= 1) return; + num = num - 1; + list[index].num = num; + this.setData({ + list: list + }) + this.changeNumber(list[index]) + this.updatePrice() + }, + add: function (e) { + let index = e.currentTarget.dataset.index, + list = this.data.list; + let num = list[index].num + 1; + list[index].num = num; + this.setData({ + list: list + }) + this.changeNumber(list[index]) + this.updatePrice() + }, + select: function (e) { + let index = e.currentTarget.dataset.index, + list = this.data.list; + if (list[index].product.flag != 1 || list[index].sku.flag != 'on') { + if (!this.data.manageFlag) { + wx.showToast({ + title: '产品已下架', + icon: 'none' + }) + return; + } } - } - }) - // 更新数据 - this.setData({ - list: this.data.list - }) - }, - angel(start, end) { //计算滑动的角度 - // console.log(start,end) - // 移动坐标减去对应的开始坐标 - var _X = end.X - start.X, - _Y = end.Y - start.Y; - // 返回角度 Math.atan() 返回数字的正切值 - return 360 * Math.atan(_Y / _X) / (2 * Math.PI) - }, - del: function (e) { - let index = e.currentTarget.dataset.index, - list = this.data.list; - commonApi.user_post("cart/del_sku", { - sku_id: list[index].sku_id - }).then(res => { - if (res.code == 1) { - wx.showToast({ - title: '删除成功', - icon: "success" + list[index].checked = list[index].checked ? false : true; + this.setData({ + list: list + }) + let flag = true + list.forEach(item => { + if (!item.checked) { + flag = false + return + } + }); + this.setData({ + allChecked: flag + }) + this.updatePrice() + }, + selectAll: function () { + let list = this.data.list, + allChecked = this.data.allChecked ? false : true; + list.map(item => { + if (item.sku.flag == 'on' && item.product.flag == 1) { + item.checked = allChecked; + } + }) + this.setData({ + allChecked: allChecked, + list: list + }) + this.updatePrice() + }, + changeNumber(item) { + commonApi.user_post("cart/update_sku", { + sku_id: item.sku.id, + num: item.num + }).then(res => { }) + }, + updatePrice: function () { + let list = this.data.list, + price = 0; + list.map(item => { + if (item.checked) { + price = price + item.sku.price * item.num; + } }) - list.splice(index, 1); this.setData({ - list: list + allPrice: price }) - } - }) - }, - delM() { - let that = this - let arr = this.data.list - let suid = [] - arr.forEach(item => { - if (item.checked) { - suid.push(item.sku_id) - } - }); - let skuids = suid.join(',') - wx.showModal({ - title: '提示', - content: '确定要删除选定的产品?', - success: function (res) { - if (res.confirm) { - commonApi.user_post("cart/del_sku", { - sku_id:skuids - }).then(res => { + }, + order: function () { + commonApi.user_post('wx/get_user_keep', { + jumpurl: '/pages/user/cartlist/list', + title: '购物车', + type: 'mini' + }).then(res => { + if (res.data.subscribe == 0) { + this.setData({ + wxqrcode: res.data.qrcode, + showQrCode: true + }) + } else { + app.globalData.couponInfo = null; + util.pagePoint({ + event: 'cart_order' + }, 1) + let list = this.data.list, + price = 0, + product = [], + product1 = [] + list.map(item => { + if (item.checked) { + // item.product.type="post"; + if (item.product.type == 'post') { + product.push({ + product: item.product, + sku: item.sku, + productNum: item.num + }) + } else { + product1.push(item) + app.globalData.list = product1 + } + if (item.product.type.includes('post')) { + this.data.productType = 'post' + } + } + }) + if (product.length == 0 && product1.length == 0) { + wx.showToast({ + title: '请先选择产品', + icon: 'none' + }) + return; + } + if (product.length > 0 && product1.length > 0) { + this.setData({ + flag: 'mix', + isCar: 'multiple' + }) + } + if (product1.length > 1) { + this.setData({ + isCar: 'multiple' + }) + } else { + this.setData({ + isCar: 'single' + }) + } + console.log(product1); + app.globalData.postProduct = product; + if (app.globalData.list) { + app.globalData.product = app.globalData.list[app.globalData.index] + } + if (this.data.productType == 'post') { + console.log(this.data.flag); + wx.navigateTo({ + url: '/pages/order/postOrder/index?from=cart&flag=' + this.data.flag, + }) + } else { + wx.navigateTo({ + url: '/pages/order/scene/index?isCar=' + this.data.isCar, + }) + } + } + }) + + }, + touchStart(e) { //移动前点击的位置 + console.log(e) + // 在开始触摸时将所有startTouchMove设置为flase,对当前的为true + this.data.list.forEach(cart => { + if (cart.isTouchMove) //当istouchMove为true + cart.isTouchMove = false; //其它的对象都为false + }) + this.setData({ + startX: e.changedTouches[0].clientX, + startY: e.changedTouches[0].clientY, + list: this.data.list + }) + }, + touchmove(e) { //移动的位置,用于计算用户滑动的弧度向左还是向右,移动了多少,可以确定删除功能的显示和隐藏 + let index = e.currentTarget.dataset.index; + // 获取开始的x,y坐标 + let startX = this.data.startX, + startY = this.data.startY; + // 获取移动的x,x坐标 + let touchMoveX = e.changedTouches[0].clientX, + touchMoveY = e.changedTouches[0].clientY; + // 调用计算角度的方法,获取角度 + var angel = this.angel({ + X: startX, + Y: startY + }, { + X: touchMoveX, + Y: touchMoveY + }) + // 遍历cartArray + this.data.list.forEach((cart, i) => { + cart.isTouchMove = false; + // 滑动角度大于30,直接return 视为非滑动意思 + if (Math.abs(angel) > 30) return; + // 匹配当前所点击的list和滑动的list + if (i == index) { + // 匹配上后判断滑动方向 + if (touchMoveX > startX) { //左滑动隐藏删除 + cart.isTouchMove = false; + } else { + cart.isTouchMove = true; + } + } + }) + // 更新数据 + this.setData({ + list: this.data.list + }) + }, + angel(start, end) { //计算滑动的角度 + // console.log(start,end) + // 移动坐标减去对应的开始坐标 + var _X = end.X - start.X, + _Y = end.Y - start.Y; + // 返回角度 Math.atan() 返回数字的正切值 + return 360 * Math.atan(_Y / _X) / (2 * Math.PI) + }, + del: function (e) { + let index = e.currentTarget.dataset.index, + list = this.data.list; + commonApi.user_post("cart/del_sku", { + sku_id: list[index].sku_id + }).then(res => { if (res.code == 1) { - wx.showToast({ - title: '删除成功', - icon: "success" - }) - that.getList(); + wx.showToast({ + title: '删除成功', + icon: "success" + }) + list.splice(index, 1); + this.setData({ + list: list + }) } - }) - - } else { - console.log('取消') - } - } - }) - }, - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { + }) + }, + delM() { + let that = this + let arr = this.data.list + let suid = [] + arr.forEach(item => { + if (item.checked) { + suid.push(item.sku_id) + } + }); + let skuids = suid.join(',') + wx.showModal({ + title: '提示', + content: '确定要删除选定的产品?', + success: function (res) { + if (res.confirm) { + commonApi.user_post("cart/del_sku", { + sku_id: skuids + }).then(res => { + if (res.code == 1) { + wx.showToast({ + title: '删除成功', + icon: "success" + }) + that.getList(); + } + }) - }, + } else { + console.log('取消') + } + } + }) + }, + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - util.pagePoint({ - event: 'cart_view' - }, 1) - app.globalData.list = null - app.globalData.createDate = null - app.globalData.index = 0 - app.globalData.productPrice = 0 - app.globalData.ticketPrice = 0 - this.data.productType = '' - }, + }, - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + util.pagePoint({ + event: 'cart_view' + }, 1) + app.globalData.list = null + app.globalData.createDate = null + app.globalData.index = 0 + app.globalData.productPrice = 0 + app.globalData.ticketPrice = 0 + this.data.productType = '' + }, - }, + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { + }, - }, + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { + }, - }, + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { + }, - } + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + } }) \ No newline at end of file diff --git a/pages/user/cartlist/list.json b/pages/user/cartlist/list.json index 18a9446..58d0c51 100644 --- a/pages/user/cartlist/list.json +++ b/pages/user/cartlist/list.json @@ -1,5 +1,6 @@ { "usingComponents": { - "title": "/pages/component/TitleHeader" + "title": "/pages/component/TitleHeader", + "code":"../../order/components/wxqrCode/index" } } \ No newline at end of file diff --git a/pages/user/cartlist/list.wxml b/pages/user/cartlist/list.wxml index 970316e..c8478c6 100644 --- a/pages/user/cartlist/list.wxml +++ b/pages/user/cartlist/list.wxml @@ -41,4 +41,6 @@ 全选 删除 - \ No newline at end of file + + + \ No newline at end of file