<template>
	<view>

		<view class="mart15 width100 backcorfff">
			<view class="notes">
				<view class="fcor666 width25">门店名称</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.storeName}}</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">订单状态</view>
				<view class="font14 fcor333 width75 fotrt" v-if="orderDetails.status == 2">已支付</view>
				<view class="font14 fcor333 width75 fotrt" v-if="orderDetails.status == 3">已完成</view>
				<view class="font14 fcor333 width75 fotrt" v-if="orderDetails.status == 4">已退款</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">订单编号</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.orderNo}}</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">支付流水号</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.paySerialNo}}</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">订单时间</view>
				<view class="font14 fcor333 width75 fotrt">
					{{orderDetails.createTime | timeFormat('yyyy-mm-dd hh:mm:ss')}}
				</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">支付时间</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.payTime | timeFormat('yyyy-mm-dd hh:mm:ss')}}
				</view>
			</view>

			<view class="notes">
				<view class="fcor666 width25">支付金额</view>
				<view class="font14 fcor333 width75 fotrt">¥{{orderDetails.payPrice}}</view>
			</view>

			<view class="notes" v-if="orderDetails.orderAssignList.length !=0">
				<view class="fcor666 width25">设备编号</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.orderAssignList[0].deviceNo}}</view>
			</view>

			<view class="notes" v-if="orderDetails.orderAssignList.length !=0">
				<view class="fcor666 width25">设备类型</view>
				<view class="font14 fcor333 width75 fotrt">{{orderDetails.orderAssignList[0].deviceType | toFilter()}}
				</view>
			</view>

			<view class="notes" v-if="orderDetails.orderAssignList.length !=0">
				<view class="fcor666 width25">购买类型</view>
				<view class="font14 fcor333 width75 fotrt">
					{{ orderDetails.orderAssignList[0].orderType | toFilterDdevic()}}
				</view>
			</view>
		</view>
		
		<button class="btns marb40" @click="deviceRefund" v-if="userInfo.secUser.objectType == 5 && orderDetails.status == 3">申请退款</button>
	</view>
</template>

<script>
	import {
		getOrderDetail,
		deviceRefund
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				userInfo: app.globalData.userInfo, //登录信息
				orderNo: '', // 订单号
				orderDetails: '' // 订单详情
			}
		},
		//过滤器
		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;
			},
			//购买方式
			toFilterDdevic: function(id) {
				let codeName;
				for (let i = 0; i < app.globalData.Dictionaries.DEVICE_ORDER_TYPE.length; i++) {
					if (id == app.globalData.Dictionaries.DEVICE_ORDER_TYPE[i].codeValue) {
						codeName = app.globalData.Dictionaries.DEVICE_ORDER_TYPE[i].codeName;
					}
				}
				return codeName;
			},
		},
		onLoad(options) {
			this.orderNo = options.orderNo;
			if (this.orderNo) {
				this.getOrderDetail();
			}
		},
		methods: {
			//查询详情
			getOrderDetail() {
				uni.showLoading({
					title: '加载中'
				})
				let datas = {
					orderNo: this.orderNo
				}
				getOrderDetail(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						this.orderDetails = res.return_data;
					}
				})
			},
			//设备申请退款
			deviceRefund(){
				let that = this;
				uni.showModal({
					title: '温馨提示',
					content: '是否申请设备退款',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中'
							})
							let datas = {
								"deviceOrderAssignId": that.orderDetails.orderAssignList[0].id
							}
							deviceRefund(datas).then(res => {
								uni.hideLoading();
								if (res.return_code == '000000') {
									uni.showToast({
										title: '退款成功',
										icon: 'none',
										success() {
											setTimeout(() => {
													that.getOrderDetail();
											}, 2000);
										}
									})
								} else {
									uni.showToast({
										title: res.return_msg,
										duration: 5000,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {}
					}
				});
			}
		}
	}
</script>

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

	.notes {
		width: calc(100% - 40rpx);
		display: flex;
		align-items: center;
		padding: 30rpx 0 30rpx 20rpx;
		border-bottom: 1px solid #f6f6f6;
	}
	
	.btns {
		margin-top: 200rpx;
		width: 80%;
		margin-left: 10%;
		height: 50px;
		line-height: 50px;
		background-color: #0083f5;
		color: #FFFFFF;
		font-weight: bold;
	}
</style>