<template>
	<view>
		<view class=" mart10 marb20 alijus">
			<view class="font16 fcor333 paddtop5 paddbotm5  margle20  marRight40" v-for="(item,index) in orderStatus"
				@click="switchid(item)" :class="[goodtyid == item.id ? 'fcor089 borbtom fontwig6' : '']" :key="index">
				{{item.title}}
			</view>
		</view>

		<view v-if="serviceList == ''" class="mart60 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
		</view>
		<view class="width94 backcorfff border-r mart15" v-for="(item,index) in serviceList" :key="index"
			@click="jumpService(item.orderNo)">
			<view class="notes">
				<view class="width75 margle">
					<view class="font18 fcor333 fontwig6">{{item.orderNo}}</view>
					<view class="font13 fcor999 mart5">支付金额: ¥{{item.payPrice}}</view>
					<view class="font13 fcor999 mart5">支付时间: {{item.payTime | timeFormat('yyyy-mm-dd hh:mm:ss')}}
					</view>
				</view>
				<view class="otstatucs border-r" @click.stop="orderRefund(item.orderNo)" v-if="item.status == 2">
					订单退款
				</view>
				<view class="otstatucs border-r" @click.stop="replace(item.orderAssignList[0].id)"
					v-if="item.status == 3">
					更换设备
				</view>
			</view>
			
			<view class="conts" v-if="item.orderAssignList !=''">
				<view class="margle10 font13 fcor999" >设备编号: {{item.orderAssignList[0].deviceNo}}</view>
			</view>
			<view class="conts">
				<view class="margle10 font13 fcor999">设备类型: {{item.deviceType | toFilter()}}</view>
				<view class="margle10 font13 fcor999">申请数量: 1台</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	import {
		getOrderList,
		orderRefund
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				orderStatus: [{
						id: 2,
						title: '已支付'
					},
					{
						id: 3,
						title: '已完成'
					},
					{
						id: 4,
						title: '已退款'
					}
				], //状态
				pageNum: 1,
				pagesize: 15,
				goodtyid: 2, //当前状态
				serviceList: [] //设备列表˚
			}
		},
		filters: {
			// 过滤器
			toFilter: function(id) {
				let codeName;
				for (let i = 0; i < app.globalData.Dictionaries.DEVICE_TYPE.length; i++) {
					if (id == app.globalData.Dictionaries.DEVICE_TYPE[i].codeValue) {
						codeName = app.globalData.Dictionaries.DEVICE_TYPE[i].codeName;
					}
				}
				return codeName;
			}
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.pageNum += 1
				this.serviceList = [];
				this.getDeviceList();
			}
		},
		onShow() {
			this.serviceList = [];
			this.getOrderList();
		},
		methods: {
			//切换id
			switchid(item) {
				this.goodtyid = item.id;
				this.serviceList = [];
				this.getOrderList();
			},

			//查询订单设备
			getOrderList() {
				uni.showLoading({
					title: '加载中'
				})
				let datas = {
					pageNum: this.pageNum,
					pageSize: this.pagesize,
					status: this.goodtyid
				}
				getOrderList(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data.list != '') {
						this.serviceList = this.serviceList.concat(res.return_data.list);
						if (res.return_data.pages == this.pageNum) {
							this.isLoadMore = true;
						} else {
							this.isLoadMore = false
						}
					} else {
						this.serviceList = [];
					}
				})
			},
			//分配设备
			jumpService(item) {
				if (this.goodtyid == 2) {
					uni.navigateTo({
						url: '../mineService/mineService?id=2' + '&orderNo=' + item
					})
				}
				if (this.goodtyid == 3 || this.goodtyid == 4) {
					uni.navigateTo({
						url: '../serviceOrderDetails/serviceOrderDetails?orderNo=' + item
					})
				}
			},
			//更换设备
			replace(item) {
				uni.navigateTo({
					url: '../mineService/mineService?id=4' + '&assderid=' + item
				})
			},
			//订单退款
			orderRefund(item) {
				uni.showModal({
					title: '温馨提示',
					content: '是否退款当前订单',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中'
							})
							let datas = {
								"orderNo": item
							}
							orderRefund(datas).then(res => {
								uni.hideLoading();
								if (res.return_code == '000000') {
									uni.showToast({
										title: '退款成功',
										duration: 2000,
										icon: 'none'
									})
									this.serviceList = [];
									this.getOrderList();
								} else {
									uni.showToast({
										title: res.return_msg,
										duration: 2000,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.borbtom {
		border-bottom: 3px solid #089bf5;
	}

	page {
		background-color: #f6f6f6;
	}

	.notes {
		width: calc(100% - 40rpx);
		display: flex;
		align-items: center;
		padding: 30rpx 0 10rpx 20rpx;
	}

	.storestus {
		padding: 1px 5px;
		color: #91bb88;
		font-size: 14px;
		background-color: #e8fbe6;
	}

	.otstatucs {
		background-color: #fbeee4;
		color: #db8c73;
		margin-top: -20px;
		font-size: 14px;
		padding: 4px 8px;
	}

	.conts {
		width: calc(100% - 60rpx);
		display: flex;
		align-items: center;
		padding: 2px 0rpx 14rpx 14rpx;
	}

	.xfimg {
		width: 100rpx;
		bottom: 60rpx;
		position: fixed;
		right: 40rpx;
	}
</style>
