<template>
	<view class="content">
	   <navigation>
		  Red Envelope
	<view class="bread" slot="bread">
		<image src="../../../../static/bankCard/nav_icon_add@3x.png" mode="aspectFit"
			@click="goAdd()"></image>
	</view>
	   </navigation>
    <view class="record_body" >
       <view class="item" v-for="item,index in record_list" :key:="index">
		   <view class="top">
       	 <view class="flex">
       	 	<view class="money">
       	 	{{currencySymbol}}	{{item.amount}}
       	 	</view>
			<view class="status" :class="item.status=='unreceive'?'green':'red'">
				{{item.status}}
			</view>
       	 </view>
		 <view class="time">
		 {{item.addTime}}
		 </view>
		 <view class="flex">
		 	<view class="link">
		 		https://apitest.luck-work.com/#/pages/redenvelopes?code={{item.no}}
		 	<!-- https://localhost:8080/#/pages/redenvelopes?code={{item.no}} -->
			</view>
		 			<view class="copy" @click="copyTextMethod(item)">
		 			Copy
		 			</view>
					   </view>
		 </view>
		 <view class="bottom flex" :class="item.status=='unreceive'?'no':''">
		 	<view class="time">
		 		{{item.operatorName}}
		 	</view>
			<view class="time">
			 {{item.addTime}}
			</view>
		 </view>
		 <view class="bottom bg"  :class="item.status!='unreceive'?'no':''" @click="showModel(item)">
		 Cancel
		 </view>
		 
       </view>
	   <u-modal v-model="show" confirm-color="#954DE3"  @confirm="cancel()" confirm-text='confirm' cancel-text="cancel" :show-cancel-button="true" :show-title="false" :content="content"></u-modal>
	 </view>
	 <tab-bar :selectActive="5"></tab-bar>
	</view>
	
</template>

<script>
	import api from '@/utils/api'
	import utils from '@/utils'
	import cont from "@/components/navigation/navigation.vue"
	import index from '@/utils/index.js'
	export default{
		data(){
			return{
				content:'Are you sure to cancel',
				show:false,
			pageNumber:1,
			pageSize:10,
			record_list:[],
			totalPage:0,
			currencySymbol:'',
			copyText:'',
			lingshi:{},
				}
			},
		
		onLoad() {
			this.currencySymbol=uni.getStorageSync('siteInfo').currencySymbol;
			
			
			this.currencySymbol=uni.getStorageSync('siteInfo').currencySymbol;
			this.getRechardRecord()
},
		onReachBottom() {
	this.pageSize += 8;
	if(this.pageSize>this.totalPage){
		return;
	}
			this.getRechardRecord();
			},
		
		methods:{
			showModel(i){
				this.show=true;
				this.lingshi=i
			},
			cancel(){
				const post2 = api.cancelRedEnvelop({
					"ticket": uni.getStorageSync('logInfo').data,
					"code":this.lingshi.no,
				})
				post2.then(res => {
						uni.showToast({
							title: 'Successfully',
							icon: 'success',
							duration: 2500
						})
						  window.location.reload()
					})
					.catch(e => {
						uni.showToast({
							title: e,
							icon: 'none',
							duration: 2500
						})
						// #ifdef APP-PLUS
						setTimeout(()=>{
						uni.navigateTo({
								url:"/pages/menu/re/list/index"
							})
						},2000)
					
						// #endif
						// #ifdef H5
						setTimeout(()=>{
							window.location.reload();
						},2000)
						// #endif
					
					
					})
			},
			copyTextMethod(i) {
			   
		// https://apitest.luck-work.com
			// #ifdef H5
				this.copyText="https:localhost:8080/#/pages/redenvelopes?code="+i.no;
			    this.$copyText(this.copyText).then(res => {
			     uni.showToast({
			      title: 'Copy Success',
			      icon: 'success'
			     })
			    })
			    // #endif
			    // #ifdef APP-PLUS
				this.copyText="https://apitest.luck-work.com/#/pages/redenvelopes?code="+i.no;
			    uni.setClipboardData({
			     data: this.copyText,
			     success() {
					 uni.showToast({
					  title: 'Copy Success',
					  icon: 'success'
					 })
			     }
			    })
			    // #endif
			},
			goAdd(){
				 uni.navigateTo({
				 	url:'../add/index'
				 })
			},
			getRechardRecord(){
				
				const post2 = api.redEnvelopList({
					"ticket": uni.getStorageSync('logInfo').data,
					"pageNumber":this.pageNumber,
					"pageSize":this.pageSize,
				})
				post2.then(res => {
					if(res.data.content!=undefined){
					this.record_list=res.data.content;
					for(var i=0;i<this.record_list.length;i++){
						this.record_list[i].addTime=index.formatyymmddhhmmss(this.record_list[i].addTime);
						this.record_list[i].amount=this.record_list[i].amount.toFixed(2);
					}	
					this.totalPage=res.data.totalElements;
					}

		
					})
					.catch(e => {
						uni.showToast({
							title: e,
							icon: 'none',
							duration: 2500
						})
					})
				
				
				},
			},
			onReachBottom(){
				this.pageSize+=10;
				this.getRechardRecord()
			}
				
	}
</script>

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