<template>
	<view class="movie">
		<anil-seat
		ref="anilSeat"
		  :title="info.movieName"
		  :info="info.showTime.substring(5)+' '+ info.version"
		  :day="info.showTime"
		  :room-name="info.hall"
		  :seat-data="seatData" 
		  :max="6" 
		  @confirm="onConfirmSeat">
		</anil-seat>
	</view>
</template>

<script>
	import {
		seatData
	} from '@/utils/seat-data.js';
	import {getSeat} from '@/api/movie'
	export default {
		data() {
			return {
				info:{
					movieName:'',
					showTime:'',
					version:'',
					hall:'',
				},
				list:[],
				query:{
					sessionId:'',
					cinemaId:'',
					movieId:'',
				}
			}
		},
		methods: {
			onConfirmSeat (items) {
			  console.log(items)
			  let seatArr = items.map(item=>{
				  return item.SeatName
			  })
			  let seatIdArr = items.map(item=>{
			  	  return item.SeatCode
			  })
			  
			  let originPriceArr = items.map(item=>{
			  	  return item.originPrice
			  })
			  let priceArr = items.map(item=>{
			  	  return item.Price
			  })
			  console.log(originPriceArr,priceArr);
			  let that = this
			  uni.navigateTo({
			  	url:`/pay/pay1`,
				success: function(res) {
					let info = {
						sessionId:that.query.sessionId,
						cityId:uni.getStorageSync('movieCityId'),
						cinemaId:that.query.cinemaId,
						movieId:that.query.movieId,
						movieCode:that.query.movieCode,
						cityName:uni.getStorageSync('city'),
						cinemaName:that.info.cinemaName,
						cinemaCode:that.info.cinemaCode,
						hallName:that.info.hall,
						movieName:that.info.movieName,
						seatNames:seatArr.toString(),
						cinemaAddress:that.info.cinemaAddress,
						sessionBeginTime:that.info.sessionBeginTime,
						sessionEndTime:that.info.sessionEndTime,
						originalSeatIds:seatIdArr.toString(),
						postImageUrl:that.info.postImageUrl,
						originPrice:originPriceArr,
						price:priceArr,
						// originPrice:Array.from(new Set(originPriceArr)),
						// price:Array.from(new Set(priceArr)),
						
					}
				  // 通过eventChannel向被打开页面传送数据
				  res.eventChannel.emit('pay', info)
				}
			  })
			},
			getSeat(){
				getSeat(this.query).then(res=>{
					if(res.state == 'Success'){
						res.content.data.seatSection.seatRows.map(item=>{
							item.columns.map(i=>{
								if(i.colId){
									let price = res.content.data.sellPrice
									let originPrice = res.content.data.originPrice
									if(res.content.data.areaPriceList.length){
										res.content.data.areaPriceList.map(pItem=>{
											if(pItem.areaId == i.areaId){
												price = pItem.price
												originPrice = pItem.originPrice
											}
										})
									}
									let obj = {
										"YCoord": item.rowsNum,
										"XCoord": i.colNum,
										"SeatCode": i.originSeatID,
										"RowNum": item.rowsNum,
										"ColumnNum": i.colNum,
										"SeatName":i.seatName,
										"areaId":i.areaId,
										"originPrice": originPrice,
										"Price": price
									}
									
									if(i.type == 2){
										obj.flag = 1
									}else if(i.type == 3){
										obj.flag = 2
									}
									
									if(i.state == 0){//非座位
										obj.Status = -1
									}else if(i.state == 1||i.state == 10||i.state == 11){//可选
										obj.Status = 0
									}else if(i.state == 2 || i.state == 3){//不可选
										obj.Status = 2
									}
									
									this.list.push(obj)
								}
							})
						})
						this.$nextTick(()=>{
							console.log(222222,this.list);
						this.$refs['anilSeat'].initData(this.list)
						})
						this.info = {
							
							movieCode:res.content.data.movieCode,
							postImageUrl:res.content.data.postImageUrl,
							sessionBeginTime:res.content.data.showTime,
							sessionEndTime:res.content.data.endTime,
							cinemaAddress:res.content.data.cinemaAddress,
							cinemaName:res.content.data.cinemaName,
							cinemaCode:res.content.data.cinemaCode,
							movieName:res.content.data.movieName,
							showTime:  uni.$u.timeFormat(new Date(res.content.data.showTime).getTime(), 'yyyy-mm-dd hh:MM'),
							version:res.content.data.version,
							hall:res.content.data.hall,
						}
					}
				})
			}
		},
		onLoad(options) {
			this.query.sessionId = options.sessionId
			this.query.cinemaId = options.cinemaId
			this.query.movieId = options.movieId
			this.getSeat()
			
			console.log(1111,this.list);
			 // 座位图初始化 - seatData座位数据
		}
	}
</script>

<style lang="scss" scoped>
.movie{
	
}
</style>