<template>
	<view style="">
		<view style="width: 100%;" v-for="(item,index) in orderlist" >
			<view class="spnodetail">
				<view style="width: 100%;" @click="gotoDetail(item.ddId)">
					<view class="actBTV" >
						<view class="textfontB4" style="margin-left: 20rpx;">{{item.ddId}}</view>
						<view v-if="item.type==0"  class="textfontB4" style="color: brown;margin-right: 30rpx;">{{$t('order.peisong')}}</view>
						<view v-if="item.type==1" class="textfontB4" style="color: brown;margin-right: 30rpx;">{{$t('order.ziqu')}}</view>
						<view v-if="item.type==2" class="textfontB4" style="color: brown;margin-right: 30rpx;">{{$t('shouye.tangshi')}}</view>
					</view>
					<view class="actBTV">
						<text v-if="item.collectPayment==1"  class="jiedanBtdf">{{$t('index.huodaofukan')}}</text>
						<text v-if="item.collectPayment!=1"  class="jiedanBtdf">線上付款</text>
						<view  class="textfontB4" style="color: blueviolet;margin-left: 20rpx;">{{$t('order.dingdanjin')}}: {{getspjr(item)}}{{$t('locale.huobidw')}}</view>
					</view>
					<!-- <view v-if="item.type==0" class="actBTV">
						<view  class="textfontB4" style="color: blueviolet;margin-left: 20rpx;">{{$t('order.dingdanjin')}}: {{getspjr(item)}}{{$t('locale.huobidw')}}</view>
						<view v-if="item.state>0" class="xiaoji textfontB4" style="color: brown;">{{$t('order.yizhifu')}}</view>
						<view v-if="item.state==0" class="xiaoji textfontB4" style="color: brown;">{{$t('order.weizhifu')}}</view>
					</view> -->
					<view v-if="item.activity" class="actBTV">
						<view class="contentInRowL" style="margin-left:20rpx;">
							<text class="textfontB4">{{$t('index.youhuiq')}}: </text>
							<text class="textfontB4" style="padding-left: 20rpx;">{{item.activity.salesName}}</text>
						</view>
						<text class="xiaoji textfontB4">{{getyhjr(item)}}</text>
					</view>
					
					<view class="actBTV" >
						<view  class="textfontB4" style="color: brown;margin-left: 20rpx;">{{$t('order.xiadanshijian')}}: {{item.cretim}}</view>
					</view>
					<view v-if="item.type==0" class="actBTV" >
						<view v-if="item.delryTime!=''" class="textfontB4" style="color: blueviolet;margin-left: 20rpx;">{{$t('order.yuyueshijian')}}: {{item.delryTime}}</view>
					</view>
					<view v-for="(itemf,index) in item.food" >
						<view class="contentInRowL bottomline">
							<!-- <myImage class="spIcon" :mysrc="itemf.image" mymode="scaleToFill" ></myImage> -->
							<netImage class="spIcon" width="90" height="90" bradius="4" :mysrc="itemf.image" mymode="scaleToFill"></netImage>
							<view class="contentColumn">
								<text class="textfontB3">{{itemf.name}}</text>
								<view class="contentInRowS">
									<view class="contentInRowL ">
										<text class="kouweisku textfontB3">{{arraytoStr(itemf.ask)}}</text>
									</view>
									<text class="textfontB3">{{itemf.number}}({{$t('order.jian')}})</text>
								</view>
								<view v-if="item.beizhu" class="">
									<text style="font-size: 30rpx;color:#00A6FF;">{{item.beizhu}}</text>
								</view>
							</view>
						</view>
					</view>
					<view v-if="item.delryTime!=''" class="actBTV">
						<text class="kouweisku textfontB3" style="margin-left: 20rpx;">{{$t('order.yuyueshijian')}}</text>
						<view>
							<text class="kouweisku textfontB3" style="margin-right: 30rpx;">{{item.delryTime}}</text>
						</view>
					</view>
				</view>
				<view v-if="item.activity" class="contentColumnC psfnote">
					<text v-if="item.activity.salesType!=0" class="textfontB5" style="color:white;padding: 6rpx;">{{$t('order.sjyhts')}}</text>
				</view>
				<view class="contentInRowC actView">
					<text v-if="item.state==1" class="acttext textfontB3" @click="dowithdingdan(2,item)">{{$t('order.shouli')}}</text>
					<text v-if="item.state==0&&item.collectPayment==1" class="acttext textfontB3" @click="dowithdingdan(2,item)">{{$t('order.shouli')}}</text>
					<text v-if="item.diningStatus==0&&(item.state==2||item.state==3)" class="acttext textfontB3" @click="dowithdingdan(-3,item)">{{$t('order.chuchan')}}</text>
					<text v-if="item.diningStatus==1&&(item.state==2||item.state==3)&&item.type!=1" class="acttextB textfontB3">{{$t('order.peisongquchan')}}</text>
					<text v-if="item.type==1&&item.diningStatus==1&&item.collectPayment==1&&(item.state==2||item.state==3)" class="acttext textfontB3" @click="dowithdingdan(-4,item)">{{$t('order.shoukuan')}}</text>
					<text v-if="item.state==4" class="acttextB textfontB3" >{{$t('order.peisongzhong')}}</text>
					<text v-if="item.state==5" class="acttextB textfontB3" >{{$t('order.yiwancheng')}}</text>
					<text v-if="item.state==6&&item.collectPayment!=1" class="acttext textfontB3" @click="dowithdingdan(7,item)">{{$t('order.shifoutyjj')}}</text>
					<text v-if="item.state==7" class="acttextB textfontB3" >{{$t('order.yituikuan')}}</text>
					<text v-if="item.state==8" class="acttextB textfontB3" >{{$t('order.jujuetuiK')}}</text>
					<text v-if="item.state==9" class="acttextB textfontB3" >{{$t('order.kefujs')}}</text>
					<text v-if="item.state==11" class="acttextB textfontB3" >{{$t('order.shouhwc')}}</text>
					<text v-if="item.state==12" class="acttextB textfontB3" >{{$t('order.songda')}}</text>
				</view>
			</view>
		</view>
		<!-- 提示窗示例 -->
		<uni-popup ref="alertDialog" type="dialog" :isMaskClick="true" @maskClick="maskClick">
			<uni-popup-dialog type="NOMLE" :cancelText="quxiao" :confirmText="queren" :title="noteMsg.title" :content="noteMsg.msg" @confirm="dialogConfirm"
				@close="dialogClose"></uni-popup-dialog>
		</uni-popup>
		<view>
			<uni-popup ref="popPay" type="center" :isMaskClick="truefalse" :safeArea="truefalse">
				<tuikanPop :refund_fee="refund_fee"  v-on:Etuikanresult="tuikanresult"></tuikanPop>
			</uni-popup>
		</view>
	</view>
</template>

<script>	
	import api from "@/pages/api/api.js"
	
	export default {
		name:"foodlistItem",
		props:{
			orderlist:''
		},
		data() {
			return {
				atcText:'',
				noteMsg:{
					title:'',
					msg:''
				},
				quxiao:'',
				queren:'',
				state:-1,
				rid:-1,
				truefalse:true,
				refundObj:'',
				refund_fee:0
			};
		},
		watch:{
			orderlist(val){
				;
			}
		},
		methods:{
			getspjr(obj){
				var jinr=0;
				var yunfei = 0;
				if(obj.type!=0){
					yunfei=obj.freight;
				}
				if(obj.activity){
					if(obj.activity.salesType=="0"){
						if(obj.discountAmount){
							if(yunfei>obj.discountAmount){
								jinr=obj.amount-(yunfei-obj.discountAmount);
							}
							else{
								jinr =obj.amount-yunfei;
							}
							
						}else{
							jinr =obj.amount-yunfei;
						}
					}
					else{
						jinr =obj.amount-yunfei;
					}
				}
				else{
					jinr =obj.amount-yunfei;
				}
				jinr=parseInt(jinr);
				return this.$formPr(jinr);
			},
			getyhjr(obj){
				var jinr=0;
				if(obj.discountAmount){
					jinr=obj.discountAmount;
				}
				jinr=parseInt(jinr);
				return '-'+this.$formPr(jinr)+this.$t('locale.huobidw');
			},
			arraytoStr(arry){
				var str='';
				if(arry.length>0){
					for(var i=0;i<arry.length;i++){
						str=str+arry[i]+'; ';
					}
					
				}
				return str;
			},
			gotoDetail(e){
				console.log(e);
				uni.navigateTo({
					url:'/pages/OrderList/OrderDetail?ddid='+e+'&isShangjia=1'
				})
			},
			getOrderType(type){
				if(type==0){
					this.ordertypename=this.$t('order.peisong');
				}
				else if(type==1){
					this.ordertypename=this.$t('order.ziqu');
				}
				else{
					this.ordertypename=this.$t('shouye.tangshi');
				}
			},
			dowithdingdan(state,obj){
					var note='';
					this.quxiao=this.$t('index.quxiao');
					this.queren=this.$t('index.queren');
					
					switch(state){
						case 2:
						note=this.$t('mend.shifoushouli')+obj.ddId+'?';
						this.noteMsg.title=this.$t('order.shouli');
						this.noteMsg.msg=note;
						break;
						case -3:
						note=this.$t('mend.shifwanch')+obj.ddId+'?';
						this.noteMsg.title=this.$t('order.chuchan');
						this.noteMsg.msg=note;
						this.refundObj=obj;
						break;
						case -4:
						note=this.$t('mend.shifwcshk')+obj.ddId+'?';
						this.noteMsg.title=this.$t('order.shoukuan');
						this.noteMsg.msg=note;
						break;
						case 7://退款
						this.refundObj=obj;
						this.refund_fee=obj.amount;
						this.$refs.popPay.open('center');
						return;
					}
					this.state=state;
					this.rid=obj.id;
					this.$refs.alertDialog.open('center');
				},
				dialogConfirm() {
					console.log('点击确认')
					if(this.state==-3){
						this.upchucanState(this.rid);
					}
					else if(this.state==-4){
						this.upstoreorderState(5,this.rid);
					}else{
						this.upstoreorderState(this.state,this.rid);
					}
				},
				dialogClose() {
					console.log('点击取消')
				},
				maskClick(){
					console.log('maskClick');
					this.$refs.alertDialog.close();
				},
				upstoreorderState(state,ddid){
					api('setorderuzt',{
						id:ddid,
						state:state
					},
					r=>{
						console.log('gengxintoken',r)
						if(r.data.code==200){
							this.$emit('ERefresh');
						}
						else{
							uni.showToast({
							    title:r.data.msg,
							    icon: 'none',
							    duration: 2500
							})
						}
					},failc=>{
						
					});
				},
				upchucanState(ddid){
					api('setorderuzt',{
						id:ddid,
						state:this.refundObj.state,
						diningStatus:1
					},
					r=>{
						console.log('gengxintoken',r)
						this.$emit('ERefresh');
					},failc=>{
						
					});
				},
				tuikanresult(refund_fee){
					this.$refs.popPay.close();
					if(refund_fee==-1){//取消
						return;
					}
					if(refund_fee==-2){//拒绝退款
						this.upstoreorderState(8,this.refundObj.id);
						return;
					}
					if(this.refundObj.collectPayment==1){
						this.upstoreorderState(10,this.refundObj.id);
						return;
					}
					
					this.quanertuikuan(refund_fee);
				},
				//部分退款
				quanertuikuan(refund_fee){
					console.log('quanertuikuan');
					api('setorderuzt',{
						'order_id':this.refundObj.ddId, //需要退款的订单号
						'amount': parseInt(refund_fee), //退款金额
						'trantype': '03', //退款类型：02全额退款，03部份退款
						'illustrate':'部分退款',
						'trans_date':'20231218114102',
						"transaction":'14248219' //交易号，不存在可为空
					},
					res=>{
						console.log('gengxintoken',r)
						if(res.data.code==200){
							if(res.data.data.vnp_ResponseCode=='00'){
								uni.showToast({
								    title:this.$t('order.tuikuanchg'),
								    icon: 'none',
								    duration: 2500
								})
								this.upstoreorderState(7,this.refundObj.id);
							}else if(res.data.data.vnp_ResponseCode=='94'){
								uni.showToast({
								    title:this.$t('order.tuikuanchg'),
								    icon: 'none',
								    duration: 2500
								})
								this.upstoreorderState(7,this.refundObj.id);
							}
							else{
								uni.showToast({
								    title: res.data.data.vnp_Message,
								    icon: 'none',
								    duration: 2500
								})
							}
						}
						else{
							uni.showToast({
							    title: res.data.msg,
							    icon: 'none',
							    duration: 2500
							})
						}
					},failc=>{
						
					});
				},
		}
		
	}
</script>

<style>
.actBTV{
	width: 100%;
	margin-top: 10rpx;
	display: flex;
	flex-direction: row;
	justify-content:space-between;
	align-items: center;
	
}
.psfnote{
	width: 92%;
	margin-left: 4%;
	margin-top: 16rpx;
	border-radius: 10rpx;
	background-color: crimson;
	margin-bottom: 16rpx;
}
.spnodetail{
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	margin-top: 16rpx;
	background-color: whitesmoke;
	border-radius: 16rpx;
}
.spIcon{
	margin: 20rpx;
	width: 90rpx;
	height: 90rpx;
}
.xiaoji{
	margin-left: auto;
	margin-right: 30rpx;
}
.kouweisku{
	color: chocolate;
	padding-right: 12rpx;
}

.actView{
	width: 100%;
	height: 76rpx;
	background-color:lavender;
	border-radius: 0 0 16rpx 16rpx;
}
.acttext{
	color: #006AFF;
	width: 100%;
	text-align: center;
}

.acttextB{
	color: #1A1A1A;
	width: 100%;
	text-align: center;
}
.jiedanBt{
	padding: 10rpx;
	color:white;
	background-color: #006AFF;
	border-radius: 8rpx;
	box-shadow: 0rpx 0rpx 10rpx 0rpx #006AFF;
}
.jiedanBtdf{
	margin-left: 20rpx;
	font-size: 26rpx;
	padding: 10rpx;
	color:white;
	background-color: #1A1A1A;
	border-radius: 8rpx;
	box-shadow: 0rpx 0rpx 2rpx 0rpx #1A1A1A;
}

.bottomline{
	border:solid darkgray;
	border-width: 0rpx 0rpx 1rpx 0rpx;
	 margin-top: 10rpx;
}
</style>