<template>
	<!--pages/pay/pay.wxml-->
	<view>
		<view class="pay">
			<view class="payt">
				<image src="/static/pages/images/wcico.png" v-if="isSuccess=='true'"></image>
				<image src="/static/pages/images/sbico.png" v-else></image>
				<view v-if="isSuccess=='true'">支付成功</view>
				<block v-else>
					<view class="fail">支付失败，请重新支付</view>
					<view class="price">￥<text>{{money}}</text></view>
				</block>
			</view>
			<view class="btn">
				<block v-if="isSuccess=='true'">
					<block v-if="isRx=='1'">
						<navigator :url="'/prescription/Consultation/index?orderId=' + orderId" class="order"
							hover-class="none">去开处方</navigator>
					</block>
					<block v-else>
						<view v-if="vip=='true'||balance=='true'">
							<navigator url="/wallet/index/index" class="order" hover-class="none"
								v-if="balance=='true'">查看余额</navigator>
							<navigator url="/mine/vip/vip" class="order" hover-class="none" v-if="vip=='true'">会员中心
							</navigator>
						</view>
						<navigator url="/mine/order/order" open-type="redirect" class="order" hover-class="none" v-else>
							查看订单</navigator>
						<!-- <navigator url="/pages/shop/shop" open-type="reLaunch" hover-class="none" class="back" wx:if="{{isSuccess}}">返回首页</navigator> -->
						<navigator
							:url="header.appId=='ZQ1VK5oc17I387E'?'/pages/timelyDelivery/index':'/pages/index/index'"
							open-type="reLaunch" hover-class="none" class="back" v-if="isSuccess=='true'">返回首页
						</navigator>
					</block>
				</block>
				<view @tap="payOrder" class="back" v-else>重新支付</view>

			</view>
		</view>
		<view class="tip" v-if="isRx=='1'">您的订单中包含处方药，需要医生开处方后才能发货，请及时完成开处方流程！</view>
		<view class="cai pdlr20" v-if="likeList.length>0">
			<view class="cai-tit dflex">
				<image src="/static/pages/images/cai_bg1.png"></image>猜您喜欢<image src="/static/pages/images/cai_bg2.png">
				</image>
			</view>
			<view class="tabcon dflex">
				<block v-for="(item, index) in likeList" :key="index">
					<view class="li" @tap="toDetail" :data-id="item.id">
						<view class="jsdimgs" @tap="toDetail" :data-id="item.id">
							<image :src="item.pic + '?x-oss-process=style/w210'" mode="aspectFit" class="jsdpro">
							</image>
							<image src="/static/pages/images/jishida.png" v-if="item.isJs" class="jsdimg"></image>
						</view>
						<view class="jsdinfo">
							<view class="proname" @tap="toDetail" :data-id="item.id">{{item.title}}</view>
							<view class="list-tag ddflex">
								<block v-if="item.label">
								<view v-for="(it,idx) in item.label.split(',')" :key="idx" v-if="idx < 2">{{it}}</view>
								</block>
							</view>
							<view class="xiaol ddflex">
								<view class="vip-news ddflex" v-if="about.show_membership_price==1&&item.actualPrice < item.salePrice"><text class="vip-sale">会员价</text><text class="vip-members">￥{{item.actualPrice}}</text></view>
								<view class="vip-news ddflex" v-if="about.show_membership_price==1&&item.membersPrice<item.salePrice"><text class="vip-sale">会员价</text><text class="vip-members">￥{{item.membersPrice}}</text></view>
								<view class="yishou">{{item.sellStock}}件已售</view>
							</view>
							<view class="operate dflex">
								<view class="price proprice">
									￥<text>{{item.salePrice}}</text>
									<!-- <text class="vip"
										v-if="about.show_membership_price==1&&item.actualPrice < item.salePrice"><text
											class="sale">VIP</text><text
											class="members">{{item.actualPrice}}</text></text>
									<text class="vip"
										v-if="about.show_membership_price==1&&item.membersPrice<item.salePrice"><text
											class="sale">VIP</text><text
											class="members">{{item.membersPrice}}</text></text> -->
									<text class="del"><!-- v-if="about.show_membership_price!=1" -->
										<block v-if="item.marketPrice!=0&&item.marketPrice>item.salePrice">
											￥{{item.marketPrice}}
										</block>
									</text>
								</view>
								<view class="add-cart">
									<view class="nums dflex" v-if="item.count > 0">
										<image src="/static/pages/images/jian.png"></image>
										<view class="num">{{item.count}}</view>
										<image src="/static/pages/images/jia1.png"></image>
									</view>
									<image src="/static/pages/images/jia.png" v-else>
									</image>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	const req = require("../../utils/request.js");
	const app = getApp();
	export default {
		data() {
			return {
				isSuccess: true,
				header: req.header,
				likeList: [],
				isLikeLoad: true,
				page: 1,
				show_membership_price: '',
				about: {}
			};
		},

		components: {},
		props: {},

		onLoad(options) {
			this.setData(options);
			this.getLikeList();
			this.getConfig()
			// console.log(options);
		},

		methods: {
			getConfig() {
				var _this = this;
			
				return new Promise((resolve, reject) => {
					req.getRequest('/api/config', {}, function(res) {
						if (res && res.show_membership_price == 1) {
							_this.setData({
								show_membership_price: 1
							});
						}
						if (res) {
							_this.setData({
								about: res
							});
						}
			
						resolve();
					});
				});
			},
			payOrder() {
				let _ts = this;

				req.payOrder(this.id, success => {
					_ts.setData({
						isSuccess: success
					});
				});
			},
			getLikeList() {
				//Recommend
				if (!this.isLikeLoad) return false;
				this.isLikeLoad = false;
				let that = this;
				req.getRequest('/api/product/list', {
					page: that.page,
					limit: 10,
					attr: 'sell_well'
				}, res => {
					if (res && res.length >= 10) that.isLikeLoad = true;
					if (that.page > 1) res = that.likeList.concat(res);
					res = res.map(it => {
						if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
						return it;
					});
					that.setData({
						likeList: res
					});
				});
			},
			toDetail(e) {
				let id = e.currentTarget.dataset.id;
				let url = 'product/detail/detail?id=' + id
				app.globalData.redirectTab('product/detail/detail?id=' + id);
			},

		}
	};
</script>
<style>
	@import "./pay.css";
</style>
