<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 44px;">
			<view style="position: fixed;z-index: 100;width: 100%;">
				<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="sim卡详情"></uni-nav-bar>
			</view>
			<view class="sim_info">
				<view class="sim_info_loding" v-if="loding">
					<image src="../../static/images/cb/6286299.gif" mode="" class="img"></image>
				</view>
				<view class="sim_info_title">
					<image :src="$imageURL+ '/bigdata_app'+'/image/cb/sim1.png'" mode=""></image>
					<p>sim卡查询{{"("+simnew+")"}}</p>
				</view>
				<view class="sim_info_text">
					<p>运营商：{{siminfo.data.carrier}}</p>
					<view class="sim_info_iccid" @click="copy(siminfo.data.iccid)">
						<p>ICCID：{{siminfo.data.iccid}}</p>
						<image src="../../static/images/ba167c2774bc7a63381dc3aaf1ef95c.png" mode="" class="tishi"></image>
					</view>
					<p>状态：{{state}}</p>
					<p>套餐：{{siminfo.data.data_plan || siminfo.data.totalDataVolume}}MB</p>
					<p v-if="simnew=='旧'">已用流量：{{siminfo.data.data_usage.toFixed(2)}}MB</p>
					<p v-if="simnew=='新'">已用流量：{{siminfo.data.usedDataVolume.toFixed(2)}}MB</p>
					<p v-if="simnew=='旧'">剩余流量：{{siminfo.data.data_balance.toFixed(2)}}MB</p>
					<p v-if="simnew=='新'">剩余流量：{{(siminfo.data.totalDataVolume-siminfo.data.usedDataVolume).toFixed(2)}}MB</p>
					<p v-if="simnew=='旧'">到期时间：{{siminfo.data.expiry_date|timeFormat()}}</p>
					<p v-if="simnew=='新'">到期时间：{{siminfo.data.expireDate}}</p>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				iccid: '',
				siminfo: {
					data: {
						carrier: "--",
						account_status: "--",
						data_plan: "--",
						data_usage: "--",
						data_balance: "--",
						outbound_date: ""
					}
				},
				state:"",
				id: '',
				simnew:"",
				loding:false
			}
		},
		methods: {
			async simdata(data) { //获取sim信息
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=forecast.send_control.sim_query',
					data: {
						iccid: data
					}
				})
				if(res.code==1){//企鹏
					this.simnew = "新"
					switch (res.data.data.deviceStatus){
						case "TEST_READY_NAME":
							this.state = "可测试"
							break;
						case "INVENTORY_NAME":
							this.state = "库存"
							break;
						case "ACTIVATION_READY_NAME":
							this.state = "可激活"
							break;
						case "ACTIVATED_NAME":
							this.state = "已激活"
							break;
						case "DEACTIVATED_NAME":
							this.state = "已停卡"
							break;
						case "RETIRED_NAME":
							this.state = "已销卡"
							break;
						case "PURGED_NAME":
							this.state = "已清除"
							break;
					}
				}else if(res.code==2){//合宙
					var arr = ['未知', '测试期', '沉默期', '使用中', '停机', '停机保号', '预销号', '销号']
					this.state = arr[res.data.data.account_status]
					this.simnew = "旧"
				}
				this.siminfo = res.data
				this.loding = false
				console.log(this.siminfo.data)
			},
			clickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			copy(item){
				uni.setClipboardData({
				    data: item , 
				    success: function () {
				        console.log('success');
				    }
				});
			},
		},
		onLoad(option) {
			console.log(option.simid)
			this.simdata(option.simid)
			this.id = option.simid
			this.loding = true
		}
	}
</script>

<style lang="scss">
	.sim_info {
		width: 90%;
		position: absolute;
		top: 54px;
		left: 5%;
		box-shadow: 0 0 10rpx #bcb9ca;
		padding: 30rpx 20rpx 50rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		
		.sim_info_loding{
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			background-color: rgba(0,0,0,0.3);
			border-radius: 20rpx;
			height: 100%;
			display: flex;
			justify-content: space-around;
			align-items: center;
			.img{
				width: 200rpx;
				height: 175rpx;
				
			}
		}
		.sim_info_title {
			width: 100%;
			display: flex;

			image {
				width: 24rpx;
				height: 32rpx;
				margin: 6rpx 20rpx 0 0;
			}

			p {
				font-weight: 700;
			}
		}

		.sim_info_text {
			width: 100%;
			padding-left: 44rpx;

			p {
				height: 30rpx;
				margin-top: 20rpx;
				font-size: 26rpx;
			}
			.sim_info_iccid{
				display: flex;
				.tishi{
					width: 30rpx;
					height: 30rpx;
					margin: 26rpx 0 0 20rpx;
					color: #000;
				}
			}
		}
	}
</style>

