<template>
	<view class="main bg-white">
		<u-dropdown>
			<u-dropdown-item v-model="value1" :title="options1[value1].label" @change="typechange" :options="options1"></u-dropdown-item>
			<u-dropdown-item v-model="value2" :title="options2[value2].label" @change="paychange" :options="options2"></u-dropdown-item>
			<u-dropdown-item v-model="value3" :title="options3[value3].label" @change="timechange" :options="options3"></u-dropdown-item>
		</u-dropdown>
		<view class="margin-lr-sm bg-white">
			<view class="margin-top-sm" v-for="(item,index) in ordersList" @click="goinfoorder" :data-id="item.id" :key="index"
			 style="border-radius: 16rpx;box-shadow: 0 0 50rpx 0 rgba(0, 0, 0, 0.1);">
				<view class="flex justify-between align-center bg-white" style="padding: 28rpx;border-radius: 16rpx;">
					<view class="jinxing">
						<text style="display: inline-block;width: 12rpx;height: 12rpx;border-radius: 50%;background-color:#EEAA3F;margin-right: 8rpx;"></text>
						<text v-if="item.order_status==3">进行中</text>
						<text v-else-if="item.order_status==1">未支付</text>
						<text v-else-if="item.order_status==2">待接单</text>
						<text v-else-if="item.order_status==4">已完成</text>
						<text v-else>已取消</text>
					</view>
					<text class="phonezi" v-if="item.product_type==1">电话咨询</text>
					<text class="phonezi" v-else>图文咨询</text>
				</view>
				<view class="" style="background: #FBFBFB;padding: 28rpx; border-radius: 16rpx;">
					<view class="nametaile flex align-center">
						<u-avatar :src="item.docter.avatar" mode="circle"></u-avatar>
						<text class="margin-left-sm">{{item.docter.name}}</text>
						<text class="text_style" v-for="(itm,idx) in item.docter.label" :key="index">{{itm}}</text>
					</view>
					<view class="textstyle margin-top-xs flex align-center justify-between">
						<text style="color: #333333;">科室：{{item.docter.office.name}} {{item.docter.qualification.name}}</text>
						<text v-if="item.order_status==4&&item.product_type==2" class="text-blue">意见单</text>
						<text v-else-if="item.order_status==1" class="text-blue">去支付</text>
						<text v-else class="text-blue">查看详情</text>
					</view>
					<view class="textstyle margin-top-xs flex align-center justify-between">
						<text style="color: #333333;">编号：{{item.order_sn}}</text>
						<text v-if="item.order_status==4" @click.stop="pinjia" style="width: 130rpx; text-align: right;" class="text-blue">评价</text>
						<text v-else-if="item.order_status==1" class="text-blue">取消</text>
					</view>
					<view class="textstyle margin-top-xs">
						<text style="color: #333333;">下单时间：{{item.created_at}}</text>
					</view>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" mode="order" :show="show" margin-top="250"></u-empty>
		<view class="cu-tabbar-height"></view>
		<view class="cu-tabbar-height"></view>
	</view>
</template>

<script>
	export default {
		onLoad(options) {

		},
		mounted() {
			this.getordersList()
		},
		data() {
			return {
				value1: 0, //全部类型
				value2: 0, //全部状态
				value3: 0, //时间正序
				options1: [{
						value: 0,
						label: "全部类型"
					},
					{
						value: 1,
						label: "电话咨询"
					},
					{
						value: 2,
						label: "图文咨询"
					},
				],
				options2: [{
						value: 0,
						label: "全部状态"
					},
					{
						value: 1,
						label: "未支付"
					},
					{
						value: 2,
						label: "待接单"
					},
					{
						value: 3,
						label: "进行中"
					},
					{
						value: 4,
						label: "已完成"
					},
					{
						value: 5,
						label: "已取消"
					},
				],
				options3: [{
						value: 0,
						label: "时间正序"
					},
					{
						value: 1,
						label: "时间倒序"
					},
				],
				ordersList: [],
				pageindex: 1,
				show: false
			}
		},
		onReachBottom() {
			this.getordersList()
		},
		methods: {
			typechange(value) {
				this.value1 = value
				this.pageindex = 1
				this.ordersList = []
				this.getordersList()
			},
			paychange(value) {
				this.value2 = value
				this.pageindex = 1
				this.ordersList = []
				this.getordersList()
			},
			timechange(value) {
				this.value3 = value
				this.pageindex = 1
				this.ordersList = []
				this.getordersList()
			},
			getordersList: async function() {
				let res = await this.$request.post("/api/v1/order/orderList", {
					page: this.pageindex,
					list_type: this.value1,
					product_type: this.value1,
					order_status: this.value2,
					time_sort: this.value3
				})
				if (res.status == 0) {
					if (this.pageindex > res.data.last_page) {
						uni.showToast({
							title: "没有更多了",
							icon: "none"
						})
					} else {
						this.ordersList = this.ordersList.concat(res.data.data)
						this.ordersList.forEach((item, index) => {
							if (item.docter == null) {
								this.ordersList.splice(index, 1)
							}
						})
						console.log(this.ordersList)
						this.pageindex++
					}
				}
				if (this.ordersList.length == 0) {
					this.show = true
				} else {
					this.show = false
				}
			},
			pinjia(){
				console.log("ssss")
			},
			goinfoorder(e) {
				uni.navigateTo({
					url: "consultingInfo?id=" + e.currentTarget.dataset.id
				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.main {}

	.text_style {
		font-weight: 400;
		margin-left: 15rpx;
		background-color: #E5F5FF;
		color: #0B73B9;
		width: 100rpx;
		height: 28rpx;
		font-size: 20rpx;
		border-radius: 10rpx;
		text-align: center;
		align-items: center;
	}

	.nametaile {
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
	}

	.textstyle {
		font-size: 26rpx;
		color: #666666;
		font-weight: 400;
	}

	.phonezi {
		width: 160rpx;
		height: 54rpx;
		background: #F6F6F6;
		border-radius: 27rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.jinxing {
		height: 30rpx;
		font-size: 30rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #EEAA3F;
		display: flex;
		align-items: center;
	}
</style>
