<template>
	<!--
    swiper中的transfrom会使fixed失效,此时用height固定高度;
    swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
    -->
	<!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
	<!-- top的高度等于悬浮菜单tabs的高度 -->
	<mescroll-uni :ref="'mescrollRef' + i" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
		:up="upOption" @up="upCallback" @emptyclick="emptyClick">
		<view>
			<view class="service-order " v-for="(item,index) in list" >
				<!-- 门店列表 -->
				<view class="store-wrap" >
					<view :class="{ 'grayscale': item.forstStatus === '1' }">
						<view @click="orderDetail(item)" class="">
							<view class="store-list">
								<view class="store-content">
									<view class="content">
										<view class="desc flex-row justify-start ">
											<view  :class="item.serviceAttribute == 1? 'service-type':'service-mode'">
												{{item.serviceAttrDesc}}
											</view>
										</view>
									</view>
								</view>
                <view class="order-state-name">
                  <text class="h-text1">{{ item.forstStatus === '1' ? '已冻结' : item.orderStatusDesc }}</text>
                </view>
							</view>
							<view class="order-state">
								<view class="order-num">
									<view class="h-order-num">
										<image src="/static/index/u217.png" mode=""></image>订单编号：{{ item.orderNo }}
									</view>
									<view class="h-order-text">
										<text> {{item.serviceType }} </text>
									</view>
								</view>


							</view>
							<view class="flex-row justify-between ">
								<view class="flex-col detail11 ">
									<view class="d-item-row ">
										<view class="item-icon">
											<image src="/static/order/ud1.png" mode=""></image>
										</view>
										<view class="item-text">
											服务对象：<text class="item-v">{{ item.serviceObjectName }}</text>
										</view>
									</view>
									<view class="d-item-row ">
										<view class="item-icon">
											<image src="/static/order/ud2.png" mode=""></image>
										</view>
										<view class="item-text">
											服务门店：<text class="item-v">{{ item.storeName }}</text>
										</view>
									</view>
									<view class="d-item-row ">
										<view class="item-icon">
											<image src="/static/order/ud14.png" mode=""></image>
										</view>
										<view class="item-text">
											下单时间：<text class="item-v">{{ item.createTime }}</text>
										</view>
									</view>
								</view>


								<view class="flex-col justify-center" v-if="item.serviceAttribute == 1">
									<view class="planNumber flex-row justify-center">
										<text>{{ item.planNumber || '未排号' }}</text>
									</view>

									<view class="planNumber1 flex-row justify-center">
										<text>排号</text>
									</view>

								</view>



							</view>
							<view class="detail flex-row justify-between" v-if="item.serviceAttribute == '2' " >
								<view class="flexLR">
									<view>
										<view class="d-item-row ">
											<view class="item-icon">
												<image src="/static/order/ud3.png" mode=""></image>
											</view>
											<view class="item-text">
												服务日期：<text class="item-v">{{item.serviceDate.substring(0,10) || ''}}</text>
											</view>
										</view>
										<view class="d-item-row ">
											<view class="item-icon">
												<image src="/static/order/ud3.png" mode=""></image>
											</view>
											<view class="item-text">
												服务时段：<text>{{item.serviceStartTime || ''}}</text>
											</view>
										</view>
										<view class="d-item-row ">
											<view class="item-icon">
												<image src="/static/order/ud3.png" mode=""></image>
											</view>
											<view class="item-text">
												服务技师：<text class="item-v">{{item.servicePersonName || '签到成功自动分配'}}</text>
											</view>
										</view>
									</view>
									<view class=" flex-col justify-center">
										<view class="planNumber flex-row justify-center">
											<text>{{ item.planNumber || '未排号' }}</text>
										</view>

										<view class="planNumber1 flex-row justify-center">
											<text>预约号</text>
										</view>
									</view>
								</view>
							</view>
							<view class="price">
								订单总金额：<text class="fontColor"> ￥{{ item.totalAmount || 0}}</text>
							</view>
						</view>
						<view class="nav-bar">
							<view class="btn" v-if="item.orderStatus != 2"  @click="scanCodeOrder(item)">
								<u-icon name="scan" size="18" />
								<text>扫码</text>
							</view>
							<view class="btn" v-if="item.orderStatus == 6"  @click="oneClickPay(item)">
								<text>一键付款</text>
							</view>
<!--							<view class="btn" v-else-if="item.orderStatus == 2">-->
<!--								<text>已取消</text>-->
<!--							</view>-->
<!--							<view @click="orderSign(item)" v-else-if="item.orderStatus == 4" class="btn">-->
<!--								立即排队-->
<!--								&lt;!&ndash; <text class="text1">点击开始排号</text> &ndash;&gt;-->
<!--							</view>-->
<!--							<view @click="getOrderSign(item)" class="btn" v-else-if="item.orderStatus == 5">-->
<!--								<text>点击查看排号</text>-->
<!--							</view>-->
<!--							<view class="btn" v-else-if="item.orderStatus == 6">-->
<!--								<text>服务中</text>-->
<!--							</view>-->
<!--							<view class="btn" v-else-if="item.orderStatus == 7">-->
<!--								<text>排号过期</text>-->
<!--							</view>-->
<!--							<view @click="gotoEvaluate(item)" class="btn" v-else-if="item.orderStatus == 8">-->
<!--								<text>待评价</text>-->
<!--							</view>-->
<!--							<view @click="gotoPayOrder(item)" class="btn" v-else-if="item.orderStatus == 9">-->
<!--								<text>去支付预约费用</text>-->
<!--							</view>-->
						</view>
					</view>
				</view>
			</view>



		</view>

	</mescroll-uni>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		components: {},

		data() {
			return {
				downOption: {
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						icon: '/static/imageIcon/empty.png',
						tip: '暂无内容', // 提示
						// btnText: '去看看'
					},
					textNoMore: '没有更多了'
				},
				list: [],

			}
		},
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			dataTime: {
				type: String,
				default () {
					return ''
				}
			},

			tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
				type: Array,
				default () {
					return []
				}
			},
			height: [Number, String], // mescroll的高度

		},
		watch: {

		},

		created() {
			this.userInfo = uni.getStorageSync('userInfo')
		},


		methods: {



			oneClickPay(order){
				this.$emit('openPay',order)
			},


      scanCodeOrder(item){
      	let that = this
        uni.scanCode({
			scanType: ['qrCode'],
          success: function (res) {
			uni.navigateTo({
				 url:'/orderPages/serviceItems/index?serviceStationId='+ res.result + '&orderId='+item.orderId
			})
          }
        })
      },
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {

				let status = this.index
				if (this.index === 3){
					status = 4
				}

				//联网加载数据
				let httpData = {
					pageNum: page.num,
					pageSize: 10,
					orderType:'SERVICE',
					status:status
				}

				this.$api.getOrderList(httpData).then((res) => {
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					this.mescroll.endSuccess(res.data.rows.length, res.data.rows.length === 10);
					//设置列表数据
					if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res.data.rows); //追加新数据
					console.log(this.list)
				}).catch((err) => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})


			},

			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			},
			// 搜索
			doSearch() {
				this.list = []; // 先清空列表,显示加载进度
				this.mescroll.resetUpScroll();
			},

			orderDetail(item) {
				uni.navigateTo({
					url:'/orderPages/orderDetail/index?id='+ item.orderId
				})
			}

		}
	}
</script>
<style>
	@import '/common/css/common.css';
	@import './index.rpx.css';
</style>
