<template>
	<view>
		<view style="padding: 30rpx;">
			<view style="font-size: 28rpx;color: #fff;border-bottom: #fff solid 1rpx;line-height: 300%;">兑换商品：{{data.cpmc}}</view>
			<view style="font-size: 28rpx;color: #fff;border-bottom: #fff solid 1rpx;line-height: 300%;">兑换价格：{{data.price}}</view>
			<view style="font-size: 28rpx;color: #fff;line-height: 200%;">付款方式：
			<text v-if="data.lzc==1">拍拍宝付款</text>
			</view>
			<view  v-for="(item, index) in goodlist" :key="index" style="margin-bottom:20rpx;" v-if="data.lzc==0">
				<view class="b1" style="border-radius: 10rpx 10rpx 0 0;font-size: 30rpx;">
					<text style="float: left;color:#f1a325;">{{item.type}}</text>					
				</view>
				<view style="background: #fff;padding: 20rpx;font-size: 30rpx;line-height: 200%;">
					<view v-if="item.type=='银行卡支付'">开户行：{{item.khh}}<text class="copy" @click="copy(item.khh)">复制</text></view>
					<view>账户名称：{{item.zhmc}}<text class="copy" @click="copy(item.zhmc)">复制</text></view>
					<view v-if="item.type=='USDT支付'">手机账号：{{item.sjh}}<text class="copy" @click="copy(item.sjh)">复制</text></view>
					<view v-if="item.type=='银行卡支付' || item.type=='支付宝支付'">账号：{{item.skzh}}<text class="copy" @click="copy(item.skzh)">复制</text></view>
					<view v-if="item.type=='银行卡支付'">开户行地址：{{item.fhh}}<text class="copy" @click="copy(item.fhh)">复制</text></view>
					<view v-if="item.type=='微信支付'">收款码：
					<view>
						<image :src="item.skm" style="width: 150rpx;height: 150rpx;" @click="viewimg(item.skm)">
					</view>
					</view>
				</view>
			</view>		
			<view class="tit">收件人</view>
			<input class="srk" placeholder="请输入收件人" v-model="data.xm" />
			
			<view class="tit">联系电话</view>
			<input class="srk" placeholder="请输入联系电话" v-model="data.sjh" />
			
			<view class="tit">收件地址</view>
			<input class="srk" placeholder="请输入收件地址" v-model="data.dz" />	
			<view class="tit"  v-if="data.lzc==0">付款凭证：</view>
			<view  v-if="data.lzc==0">
				<image v-if="data.dkpz"  style="width:150rpx;height: 150rpx;"   referrerpolicy="no-referrer"
					:src="data.dkpz"
					 @click="viewimg(data.dkpz)"
				/>
				<image v-else style="width: 150rpx;height: 150rpx;" referrerpolicy="no-referrer" src="/static/xj.png"  @click="shangchuanpingzheng()"/>
			</view>		
			<button type="warn" style="margin-top: 40rpx;" @click="add">确认兑换</button>	
		</view>		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:{
					dkpz:'',
					cpmc:'',
					id:'',
					price:'',
					lx:'',
					xm:'',
					sjh:'',
					dz:'',
					uid:0,
					lzc:0
				},
				skr:'',
				goodlist:[],
				userinfo:[]
			}
		},
		methods: {
			add() {
				var data = this.data;
				if(!data.xm || !data.sjh || !data.dz){
					uni.showToast({
						title:"请输入完整信息后兑换",
						icon:"none"
					})
					return;
				}
				if(!data.dkpz && data.lzc==0){
					uni.showToast({
						title:"请输入完整信息后兑换",
						icon:"none"
					})
					return;
				}
				this.$api
					.MhGetModel(data, 'shop/duihuan')
					.then(res => {
						if(res.data.code==1){
							uni.redirectTo({
								url: 'cg?tel='+this.skr
							});
						}else{
							uni.showModal({
								title: '提示',
								content: res.data.msg,
								showCancel:false,
								success: function (res) {
									if (res.confirm) {
										
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
						
					})
					.catch(err => {
						// console.log('request fail', JSON.stringify(err));
					});
				// console.log(333)
			},
			shangchuanpingzheng() {
				var that = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						// console.log(JSON.stringify(res.tempFilePaths));
						uni.uploadFile({
							url: that.$api.getUploadurl2,
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: function(res) {								
								var path = res.data;
								path = JSON.parse(path).data.url;
								that.data.dkpz=path;
								//console.log(that.data)
								//that.saveShangchuanpingzheng(item, path);
							}
						});
					}
				});
			},
			copy(text){
				uni.setClipboardData({
					data:text,
					success: function () {
						console.log('success');
					}
				});
			},
			viewimg(path) {
				uni.previewImage({
					urls: [path],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							// console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							// console.log(err.errMsg);
						}
					}
				});
			},
			sklist(){
				var data = this.data;
				this.$api
					.MhGetModel(data, 'shop/sklist')
					.then(res => {		
						this.goodlist = res.data.data;
						this.skr=res.data.skr;
						if(res.data.ppb==1){
							console.log(22)
							this.data.lzc=-1;
						}
					})
					.catch(err => {
						// console.log('request fail', JSON.stringify(err));
					});
			},
			skm(skm){
				uni.navigateTo({
					url: '/pages/shoukuan/cktp?src='+skm
				});
			},
			getMhUserinfo() {
				var data = new Object();
				//data.uid = this.data.id;
				data.uid = this.userinfo.id;
				data.src='my';
				this.$api
					.MhPostModel(data, 'user/info')
					.then(res => {						
						if (res.data.code != 1) {
							uni.showModal({
								title: '提示',
								content: '账号异常！',
								showCancel:false,
								success: function (res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/lanhu_login/index'
										});
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else {
							this.userinfo = res.data.data;
							this.data.lzc=this.userinfo.lzc1
							console.log(this.data.lzc)
							this.$api.setUserinfo(res.data.data);
						}
					})
					.catch(err => {
						// console.log('request fail', JSON.stringify(err));
					});
					
			}
		},
		onLoad(o) {
			this.data.cpmc = o.cpmc;
			this.data.price = o.price;
			this.data.id = o.id;
			this.data.lx = o.lx;			
			
			var user = this.$api.getUserinfo();
			if (user) {
				this.userinfo = user;
				this.data.uid = user.id;
				this.getMhUserinfo();
			} else {
				this.userinfo = null;
				uni.showToast({
					title:"请先登录",
					icon:"none"
				})
				setTimeout(function(){
					uni.navigateTo({
						url:"/pages/lanhu_login/index"
					})
				},1000)
			}
			this.sklist()
		}
	}
</script>

<style>
page{padding: 15rpx;background:   #98a737;background-attachment: fixed !important;
    background-repeat: no-repeat !important;}
.b1 {
    overflow: hidden;
    padding: 10rpx 15rpx;
    color: #f1a325;
    background: #fff0d5;
    border: 1rpx solid #ffdcbc;
}
.copy{background: #98a737;font-size: 26rpx;color: #fff;padding: 5rpx 10rpx;margin-left: 30rpx;border-radius: 10rpx;}
.srk {
		color: #000;
		height: 60rpx;
		line-height: 60rpx;
		background: #fff;
		border-radius: 10rpx;
		padding-left: 20rpx;
		font-size: 30rpx;
	}

	.tit {
		font-size: 28rpx;color: #fff;line-height: 300%;
	}
</style>
