You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
11 KiB

// pages/make_order/choose_sit/choose_sit.js
import {
httpUtil,
http
} from '../../../utils/util'
import MinaTouch from 'mina-touch'; // 1. 引入mina-touch
Page({
/**
* 页面的初始数据
*/
data: {
selected_seats: [],
max_select: 6,
baseSpace: {
x: 10,
y: 10
}, //座位间的距离
baseSize: {
x: 22,
y: 20
}, //图片默认尺寸
scaleNum: 1, //默认缩放比例(画布宽度适应屏幕)
newScale: 1, //手动缩放比例
move: {
x: 0,
y: 0
}, //手动挪动偏移距离
},
select_grade(e) {
if (e.currentTarget.dataset.num !== 0) {
if (this.data.select_grade == e.currentTarget.dataset.select_grade) {
this.setData({
select_grade: ''
})
} else {
this.setData({
select_grade: e.currentTarget.dataset.select_grade
})
}
}
this.init1()
},
// 计算票总价 '含多买折扣'
price_cac(selected_seats) {
const p = []
const grade_price = []
grade_price.push(this.data.data1.grade_price)
// Object.prototype.fun = () => {};
// console.log(Object.values(grade_price[0]))
for (var x in grade_price[0]) {
let a = 0
let arr = []
for (let i of selected_seats) {
if (i.grade == x) {
a++
arr.push({
row: i.row,
col: i.col,
floor: i.floor
})
}
}
if (grade_price[0][x][a]) {
p.push({
tkt_grade: x,
tkt_num: a,
tkt_pirce: grade_price[0][x][a],
tkt_loc: arr
})
}
}
let ii = 0
for (let i in p) {
ii += parseInt(p[i].tkt_pirce)
}
this.setData({
total_price_list: p,
total_price: ii
})
},
tap(e){
console.log('选座',e);
let _this = this
let seat_list = _this.data.data1.seat_list
let selected_seats = _this.data.selected_seats
let scaleNum = _this.data.scaleNum
let newScale = _this.data.newScale
this.setData({newScale:2.5})
let move = _this.data.move
let maxCanvasW = _this.data.maxCanvasW
let maxCanvasH = _this.data.maxCanvasH
let baseSize = _this.data.baseSize
let baseSpace = _this.data.baseSpace
let max_select = _this.data.max_select
let select_position = {
x: e.detail.x,
y: e.detail.y
}
let x = (select_position.x - move.x) / scaleNum/newScale
let y = (select_position.y - move.y - 200) / scaleNum/newScale
let cur_seat = {
x: Math.floor(x / (baseSize.x + baseSpace.x)),
y: Math.floor(y / (baseSize.y + baseSpace.y))
}
/* 选座 */
// 判断是否已选中
let a = 0
selected_seats.forEach((v, k) => {
if (cur_seat.x == v.x && cur_seat.y == v.y) {
selected_seats.splice(k, 1)
v.select = 0
a = 1
return
}
})
if (a == 0) {
// 将坐标放入选中座位的数组中
seat_list.forEach((v, k) => {
if (cur_seat.x == v.x && cur_seat.y == v.y && v.ticket_status == 0) {
// 判断是否超过最大可选
if (selected_seats.length >= max_select) {
selected_seats.splice(max_select)
wx.showToast({
title: '单次最多选座6个',
icon: 'error',
duration: 1000
})
} else {
selected_seats.push(v)
v.select = 1
}
return
}
})
}
_this.price_cac(selected_seats)
_this.init1()
},
scroll(e){
console.log("滑动",e)
this.setData({move:{x:-e.detail.scrollLeft,y:-e.detail.scrollTop}})
},
// init2(){
// const baseSpace = this.data.baseSpace
// const baseSize = this.data.baseSize
// const ctx = wx.createCanvasContext('myCanvas');
// ctx.drawImage(this.data.canvasTemImg)
// ctx.scale(this.data.scaleNum, this.data.scaleNum)
// this.data.selected_seats.forEach((item) => {
// ctx.rect( item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y),baseSize.x, baseSize.y)
// ctx.drawImage('/images/seats/01.png', 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y),
// baseSize.x, baseSize.y);
// })
// ctx.draw()
// },
init1() {
let _this = this
const ctx = wx.createCanvasContext('myCanvas');
const baseSpace = this.data.baseSpace
const baseSize = this.data.baseSize
const maxCanvasW = (baseSize.x + baseSpace.x) * (this.data.data1.max_x + 1); //画布最大宽度
const maxCanvasH = (baseSize.y + baseSpace.y) * (this.data.data1.max_y + 1); //画布最大高度
this.setData({
maxCanvasW,
maxCanvasH
})
if (this.screenWidth < maxCanvasW) {
var scaleNum = this.screenWidth / maxCanvasW //缩放比例
this.setData({
scaleNum
})
ctx.scale(scaleNum, scaleNum)
}
const img = {
"00": {
name: 'default',
url: '/images/seats/00.png'
},
"01": {
name: 'checked',
url: '/images/seats/01.png'
},
"A": {
name: 'A',
url: '/images/seats/A.png'
},
"B": {
name: 'B',
url: '/images/seats/B.png'
},
"C": {
name: 'C',
url: '/images/seats/C.png'
},
"D": {
name: 'D',
url: '/images/seats/D.png'
},
"E": {
name: 'E',
url: '/images/seats/E.png'
},
"F": {
name: 'F',
url: '/images/seats/F.png'
},
"G": {
name: 'G',
url: '/images/seats/G.png'
},
"H": {
name: 'H',
url: '/images/seats/H.png'
},
"I": {
name: 'I',
url: '/images/seats/I.png'
},
"J": {
name: 'J',
url: '/images/seats/J.png'
},
"K": {
name: 'K',
url: '/images/seats/K.png'
},
"L": {
name: 'L',
url: '/images/seats/L.png'
},
"M": {
name: 'M',
url: '/images/seats/M.png'
},
"N": {
name: 'N',
url: '/images/seats/N.png'
},
"O": {
name: 'O',
url: '/images/seats/O.png'
},
"P": {
name: 'P',
url: '/images/seats/P.png'
},
"Q": {
name: 'Q',
url: '/images/seats/Q.png'
},
"R": {
name: 'R',
url: '/images/seats/R.png'
},
"S": {
name: 'S',
url: '/images/seats/S.png'
},
"T": {
name: 'T',
url: '/images/seats/T.png'
},
"U": {
name: 'U',
url: '/images/seats/U.png'
},
"V": {
name: 'V',
url: '/images/seats/V.png'
},
"W": {
name: 'W',
url: '/images/seats/W.png'
},
"X": {
name: 'X',
url: '/images/seats/X.png'
},
"Y": {
name: 'Y',
url: '/images/seats/Y.png'
},
"Z": {
name: 'Z',
url: '/images/seats/Z.png'
},
} //默认图片
this.data.data1.seat_list.forEach((item) => {
// 可售座位颜色处理
if (this.data.select_grade) {
if (item.select == 1) {
ctx.drawImage(img["01"].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y),
baseSize.x, baseSize.y);
} else if (item.grade == this.data.select_grade) {
if (item.ticket_status === 0) {
ctx.drawImage(img[item.grade].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y), baseSize.x, baseSize.y);
} else {
ctx.drawImage(img["00"].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y), baseSize.x, baseSize.y);
}
}
} else {
if (item.select == 1) {
ctx.drawImage(img["01"].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y),
baseSize.x, baseSize.y);
} else {
if (item.ticket_status === 0) {
ctx.drawImage(img[item.grade].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y), baseSize.x, baseSize.y);
} else {
ctx.drawImage(img["00"].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x), item.y * (baseSize.y + baseSpace.y), baseSize.x, baseSize.y);
}
}
}
/* if (this.data.selected_seats) {
this.data.selected_seats.forEach((item) => {
ctx.drawImage(img["01"].url, 0, 0, baseSize.x, baseSize.y, item.x * (baseSize.x + baseSpace.x) - maxCanvasW / 2, item.y * (baseSize.y + baseSpace.y) - maxCanvasH / 2,
baseSize.x, baseSize.y);
// ( Math.floor( item.x / ( baseSize.x + baseSpace.x ) ) + Math.floor( maxCanvasW / 2 * ( 1 - 1 / this.data.newScale ) / ( baseSize.x + baseSpace.x ) ) ) *(baseSize.x+baseSpace.x)-maxCanvasW/2
})
} */
})
ctx.draw(false,(e)=>{
wx.canvasToTempFilePath({
canvasId: 'myCanvas',
success: res => {
this.setData({
canvasTemImg: res.tempFilePath
})
}
}, this);
})
},
make_order() {
var selected_seats = this.data.selected_seats
var tid = ""
selected_seats.forEach((v, k) => {
tid = tid + ',' + String(v.ticket_id)
})
tid = tid.substring(1)
wx.navigateTo({
url: '../make_order/make_order?tid=' + tid + '&drama_id=' + this.data.drama_id
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let drama_id = options.drama_id
let _this = this;
wx.getSystemInfo({
success(res) {
//获取屏幕的宽成功
_this.screenWidth = res.screenWidth
_this.screenHeight = res.screenHeight
}
})
this.setData({
drama_id
})
httpUtil("/api/v1/seat-list", "get", {
drama_id: 76165
}).then(res => {
this.setData({
data1: res
})
this.init1()
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})