<template>
	<view v-if="isShowView">
		<view class="info">
			<view class="info-c">
				<view class="status ddflex">
					<image src="../static/images/dai_sy.png"></image>
					{{ detail.state > 3 && detail.state <= 7 ? '待核销' : '已核销' }}
				</view>
				
				<view class="infos">
					<view class="shop ddflex" v-if="detail.merchantName">
						<image src="../static/images/dpico.png"></image>
						{{ detail.merchantName }}
					</view>
					<view v-for="(items, index) in deliverListss" :key="index">
						<view class="product ddflex" v-for="(item, index1) in items.extendDTOList" :key="index1">
							<image :src="item.pic" mode="aspectFill"></image>
							<view class="fflex">
								<view class="pro-tit">{{ item.productName }}</view>
								<view class="specs" v-if="item.specsList && item.specsList.length > 0">
									规格
									<text v-for="(itemGuige, index2) in item.specsList" :key="index2">{{ itemGuige.value }}</text>
								</view>
								<view class="pro-opt ddflex">
									<view class="price">
										<text>￥</text>
										{{ item.money }}
									</view>
									<view class="count">×{{ item.deliverQuantity }}</view>
								</view>
							</view>
						</view>
					</view>
					<view v-if="detail.state > 3 && detail.state <= 7" class="code ddflex">
						<u-qrcode ref="qrcode" canvas-id="qrcode" :value="'HX'+detail.code" size="170"></u-qrcode>
					</view>
					<!-- <view class="code-info ddflex">
						<view class="fflex">
							<view class="code-sta">
								<text>{{ detail.state > 3 && detail.state < 7 ? '待核销' : '已核销' }}</text>
							</view>
							<view class="code-ma">{{ detail.code }}</view>
						</view>
						<block v-if="detail.state != 1 && detail.state != 8 && detail.state != 9 && detail.state != 10">
							<block v-if="detail.state >= 30 && detail.state <= 43"></block>
							<view v-else class="tk-btn" @tap="detail.isRefundStock == 1 ? refundmod() : refundmods()">申请售后</view>
						</block>
					</view> -->
				</view>
			</view>
		</view>
		<view class="det">
			<view class="li ddflex">
				<view class="label">订单编号</view>
				<view class="item fflex">{{ detail.id }}</view>
			</view>
			<view class="li ddflex">
				<view class="label">创建时间</view>
				<view class="item fflex">{{ detail.createDate }}</view>
			</view>
			<view class="li ddflex" v-if="detail.deliverTime">
				<view class="label">核销时间</view>
				<view class="item fflex">{{ detail.deliverTime }}</view>
			</view>
			<view class="li ddflex">
				<view class="label">订单金额</view>
				<view class="priceitem fflex">￥{{ detail.money }}</view>
			</view>
			<view class="li ddflex" v-if="detail.discountMoney && detail.orderType != 11">
				<view class="label">优惠券</view>
				<view class="priceitem fflex">-￥{{ detail.discountMoney }}</view>
			</view>
			<view class="li ddflex" v-if="detail.balancePayMoney">
				<view class="label">余额扣除</view>
				<view class="priceitem fflex">-￥{{ detail.balancePayMoney }}</view>
			</view>
			<view class="li ddflex">
				<view class="label">{{ detail.state == 1 || detail.state == 8 ? '应付' : '实付' }}金额</view>
				<view class="priceitem fflex">￥{{ detail.payMoney }}</view>
			</view>
		</view>
		<view style="height: 130rpx;"></view>
		<view class="bot">
			<block v-if="detail.state != 1 && detail.state != 8 && detail.state != 9 && detail.state != 10">
				<block v-if="detail.state >= 30 && detail.state <= 43"></block>
				<view v-else class="sta-btn" @tap="detail.isRefundStock == 1 ? refundmod() : refundmods()">申请售后</view>
			</block>
		</view>

		<!-- 申请售后弹窗 -->
		<view class="ceng" v-if="popShow" @click="cancel()"></view>
		<view class="popup" v-if="popShow">
			<view class="pop-tit">提示</view>
			<view class="pop-tip">当前{{ detail.stateName }}，如有售后问题，请咨询客服</view>
			<view class="pop-btn dflex">
				<view class="pop-cancel" @click="cancel()">取消</view>
				<button open-type="contact" class="pop-contact">咨询客服</button>
			</view>
		</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const app = getApp();

export default {
	data() {
		return {
			isShowView:false,
			bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
			picUrlss: req.public.picUrls,
			id: '',
			params: {},
			code: '',
			deliverListss: '',
			detail: '',
			popShow: false
		};
	},
	onLoad(options) {
		this.id = options.id;
		this.getDetail();
	},
	onReachBottom() {},
	methods: {
		getDetail() {
			req.getRequest(
				'/api/order/detail',
				{
					id: this.id
				},
				data => {
					this.deliverListss = data.deliverList;
					data.refund = data.products.filter(it => it.quantity - (it.refundStock ? it.refundStock : 0) > 0).length;
					this.detail = data;
					this.isShowView=true;
				}
			);
		},

		getStateText() {
			if (this.detail.state > 1) {
			}

			// <view :class="'li ' + (state > 1 && state < 20 ? 'ing' : '')">
			// 	<text></text>
			// 	{{ mode != 1 ? stateName : '待自提' }}
			// </view>
			// <view :class="'li ' + (state > 3 && state < 20 ? 'ing' : '')" v-if="mode != 1">
			// 	<text></text>
			// 	待收货
			// </view>
			// <view :class="'li ' + ((mode != 1 && state == 7) || (mode == 1 && state == 6) ? 'ing' : '')">
			// 	<text></text>
			// 	{{ mode != 1 ? '已完成' : '已自提' }}
			// </view>
		},

		refundmod(event) {
			//申请退款
			uni.navigateTo({
				url: '/mine/refund/refundType/refundType?id=' + this.id
			});
		},

		refundmods() {
			this.popShow = true;
		},
		cancel() {
			this.popShow = false;
		},

		getData() {
			req.getRequest(api.card_detail, { id: this.id }, data => {
				if (data.showProduct.specs && data.showProduct.specs !== 'DEFAULT_SKU') {
					data.showProduct.specs = JSON.parse(data.showProduct.specs);
				} else {
					data.showProduct.specs = '';
				}
				this.params = data;
			});
		},

		checks(item, index) {
			let pageList = this.pageList;
			if (pageList[index].isShow) {
				pageList[index].isShow = false;
				this.pageList = JSON.parse(JSON.stringify(pageList));
			} else {
				pageList.map((it, dx) => {
					if (dx == index) it.isShow = true;
					else it.isShow = false;
					return it;
				});
				this.pageList = JSON.parse(JSON.stringify(pageList));
			}
		},
		createCode(item) {
			this.currentCard = item;
			this.isShowCard = true;
		},
		hideCardPop() {
			this.isShowCard = false;
		},
		copyCode() {
			uni.setClipboardData({
				data: this.currentCard.code,
				success() {
					req.msg('复制成功');
				}
			});
		},
		jumpUrl(url) {
			uni.navigateTo({
				url: url
			});
		},
		scanCode() {
			uni.scanCode({
				success: function(res) {
					console.log('条码类型：' + res.scanType);
					console.log('条码内容：' + res.result);
					uni.navigateTo({
						url: '/mine/secondCard/secondCard?code=' + res.result
					});
				}
			});
		}
	}
};
</script>

<style>
@import './index.css';
</style>
