<template>
	<view class="appointList">
		<!-- <view v-for="item in appointList" :key="item.id" class="appoint">
      <view class="fl-flex fl-justify-between">
        <view>
          {{ item.mobile }}
          <text class="f-s-22" style="color: #999999"> (预留手机) </text>
        </view>
        <u-icon name="phone" color="#2979ff" size="24" @click="handlerMakePhone(item.mobile)" />
      </view>
      <view class="line"></view>
      <view class="fl-flex fl-align-center">
        <image
          :src="item.simpleMerchantVO.logo"
          mode="scaleToFill"
          style="width: 200rpx; height: 200rpx"
          v-if="item.simpleMerchantVO.logo"
        />
        <image
          src="/static/QR57a.jpg"
          v-else
          mode="scaleToFill"
          style="width: 200rpx; height: 200rpx"
        />

        <view class="u-p-l-10">
          <view class="f-s-32" style="font-weight: bold">服务名称服务</view>
          <view style="margin: 10rpx 0">{{ $u.timeFormat(item.appointTime) || '--' }}</view>
          <view>{{ item.simpleMerchantVO.address || '--' }}</view>
        </view>
      </view>
    </view> -->

		<view class="content">
			<ren-calendar ref='ren' :markDays='markDays' :headerBar='true' :open="false"
				@onDayClick='onDayClick'></ren-calendar>
		</view>

		<!-- 订单 -->
		<view class="order">
			<view class="order-box">
				<view class="order-item" v-for="(item, index) of appointList" :key="index">

					<view class="item-allnumb-box">
						<view class="allnumb-left">
							<image class="img" :src="item.avatar  "
								style="width: 50rpx; height: 50rpx" />
							<span style="margin-left:20rpx">{{item.memberUsername}}</span>
						</view>
						<view class="allnumb-right" :style="{color: getStatusColor(item.status)}">
							{{ getStatusText(item.status) }}
						</view>
					</view>

					<u-line margin="20rpx 0"></u-line>

					<view class="item-center" :key="idx" v-for="(itm, idx) of item.goodsInfo">
						<view class="center-left">
							<image :src="itm.goodsPic" class="img"></image>
						</view>
						<view class="center-right">
							<view class="r-l">
								<view class="right-name"> {{ itm.goodsName }} </view>
								<!-- <view class="right-descript"> 测试商品描述111 </view> -->
								<view class="l-box">
									<view class="right-price"> ￥{{ itm.goodsPrice }} </view>
									<view class="right-numb"> ×{{ itm.goodsQuantity }} </view>
								</view>
							</view>
						</view>
					</view>

					<view class="item-allnumb-box">
						<view class="allnumb-left"></view>
						<view class="allnumb-right">
							<span class="r-text">实付款</span>￥{{ item.payAmount }}
						</view>
					</view>

					<u-line margin="20rpx 0" dashed="true"></u-line>

					<view class="item-top">
						<view class="top-left gray-color">订单编号 : {{ item.id }}</view>
						<view class="top-right">{{ type_name }}</view>
					</view>
					<view class="item-top">
						<view class="top-left gray-color">下单时间 : {{formatTime1(item.createTime)  }}</view>
						<view class="top-right"></view>
					</view>
					<view class="item-top">
						<view class="top-left gray-color">预约时间: {{ formatTime1(item.appointTime) }}</view>

					</view>
				</view>
			</view>
			<view style="margin-top: 40rpx" v-if="appointList.length === 0">
				<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
			</view>

		</view>

	</view>
</template>

<script>
	import {
		// getAppointListApi,
		getMerchantListApi
	} from '@/api/merchant/order';
	export default {
		data() {
			return {
				// params: {
				// 	offset: 1,
				// 	size: 10,
				// },
				appointList: [],
				list: {},
				curDate: '',
				markDays: [],
				params: {
					pageNum: 1,
					pageSize: 10,
				},
			};
		},
		// created() {
		// 	let {
		// 		merchant
		// 	} = this.$store.state.data.merchantInfo;
		// 	this.list = merchant;
		// 	let today = this.$refs.ren.getToday().date;
		// 	this.curDate = today;
		// 	this.markDays.push(today);
		// 	console.log(this.curDate)
		// },
		// mounted() {
		// 	this.getMerchantList();
		// },
		onReady() {

		},
		onShow() {
			let {
				merchant
			} = this.$store.state.data.merchantInfo;
			this.list = merchant;
			let today = this.$refs.ren.getToday().date;
			this.curDate = today;
			this.markDays.push(today);
			console.log(this.curDate)
			
			this.getMerchantList();
			
		},
		methods: {
			onDayClick(data) {
				console.log(data.date)
				this.curDate = data.date;
			},
			async getMerchantList() {
				let result = Object.assign({}, {
					paging: `${this.params.pageNum},${this.params.pageSize}`
				}, {
					merchantId: this.list.id,
					status: 'PENDING',
					date: this.curDate
				});
				let res = await getMerchantListApi({
					...result
				});
				console.log(res, "sdaasdsas")
			},
			getStatusColor(status) {
				switch (status) {
					case 1:
						return 'blue';
					case 2:
						return 'red';
					case 3:
						return 'orange';
					default:
						return 'black';
				}
			},
			getStatusText(status) {
				switch (status) {
					case 1:
						return '待处理';
					case 2:
						return '已取消';
					case 3:
						return '已完成';
					default:
						return '';
				}
			},
			formatTime1(timestamp) {
				const date = new Date(timestamp ); // 转换为毫秒
				const year = date.getFullYear();
				const month = ('0' + (date.getMonth() + 1)).slice(-2);
				const day = ('0' + date.getDate()).slice(-2);
				const hour = ('0' + date.getHours()).slice(-2);
				const minute = ('0' + date.getMinutes()).slice(-2);
				const second = ('0' + date.getSeconds()).slice(-2);

				return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
			}


			// async getAppointList() {
			//   let result = Object.assign({}, { ...this.params }, { merchantId: this.list.id });
			//   let res = await getAppointListApi({ ...result });

			//   if (res.code === 'OK') {
			//     this.appointList = res.data;
			//   }
			// },
		},
	};
</script>

<style lang="scss" scoped>
	.order {
		margin-top: 10px;
		padding: 10rpx 20rpx 20rpx;
		box-sizing: border-box;

		.order-box {
			.order-item {
				margin-bottom: 20rpx;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx;
				box-shadow: 0 8rpx 15rpx 0 rgba(0, 0, 0, 0.08);

				.item-top {
					display: flex;
					justify-content: space-between;
					margin-bottom: 10rpx;
				}

				.item-center {
					display: flex;
					align-items: center;
					margin-bottom: 10rpx;

					.center-left {
						height: 160rpx;

						.img {
							width: 160rpx;
							height: 160rpx;
						}
					}

					.center-right {
						width: 100%;
						height: 160rpx;
						display: flex;
						justify-content: space-between;
						margin-left: 20rpx;

						.r-l {
							display: flex;
							flex-direction: column;
							justify-content: space-around;

							.right-name {
								color: #4d5671;
								font-size: 32rpx;
								font-weight: bold;
							}

							.right-descript {
								font-size: 28rpx;
								color: #858797;
							}

							.l-box {
								display: flex;
								font-size: 24rpx;
								align-items: center;
								font-style: italic;

								.right-price {
									margin-right: 20rpx;
									font-weight: bold;
									font-size: 28rpx;
									color: #f57f32;
								}

								.right-numb {
									font-size: 24rpx;
									color: #858797;
								}
							}
						}

						.r-r {
							.r-item {
								align-items: center;
							}
						}
					}
				}

				.item-allnumb-box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-weight: bold;

					.allnumb-left {
						display: flex;
						justify-content: start;
						align-items: center;
						font-size: 32rpx;

						.img {
							display: block;
						}
					}

					.allnumb-right {
						font-size: 26rpx;
						color: #f57f32;

						.r-text {
							color: #000;
						}
					}
				}
			}
		}
	}
</style>