<template>
	<view>
		<view class="status_bar"></view>
		<view style="position: fixed;z-index: 100;top: 64px;">
			<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回"></uni-nav-bar>
			<view class="search_top_input">
				<input type="text" value="" placeholder="请输入设备ID"  v-model="imports" @input="searchinp"/>
				<u-icon name="search" size="40" class="icon" @click="search"></u-icon>
			</view>
		</view>
		<view class="aftersaleinfo" v-if="aftersaleinfotf">
			暂无此设备信息
		</view>
		<view class="aftersale" v-else>
			<view class="aftersale_item" v-for="(item,index) in faultdata" :key="index">
				<view class="aftersale_item_title">
					<u-icon name="calendar" color="#71D8AF" size="34"></u-icon>
					<span>设备 ID：{{item.device_id}}</span>
				</view>
				<view class="aftersale_item_con">
					<p>联系人：{{item.user}}</p>
					<p>联系电话：{{item.userphone}}</p>
					<p>位置：{{item.addr}}</p>
					<p>故障上报时间：{{item.uptime|timeFormat()}}</p>
				</view>
				<view class="aftersale_item_operate">
					<button class="fault" @click="fault(item.errordesc)">故障原因</button>
					<button :class="item.errorimg.length!=0?'imgs':'none'" :disabled="item.errorimg.length==0" @click="faultImg(item.errorimg)">图片</button>
					<button :class="item.errorvideo?'video':'none'" :disabled="!item.errorvideo" @click="faultVideo(item.errorvideo)">视频</button>
				</view>
				<view class="aftersale_item_icon">
					<image :src="'http://static.yfpyx.com/bigdata_app'+aftersale_icon[Number(item.device_type)-2].src" mode=""></image>
				</view>
			</view>
		</view>
		<u-modal v-model="show" :mask-close-able="maskcloseable" :show-confirm-button="showconfirmbutton" :title="title" class="model">
			<view class="model_box">
				<p v-if="faultinfo_tf">{{faultinfo}}</p>
				<u-swiper :list="faultimg" v-if="faultimg_tf" class="uswiper" height="400" style="width: 100%;" @click="examine(faultimg)"></u-swiper>
				<video :src="BASE_URL+faultvideo" controls v-if="faultvideo_tf" style="width: 90%;"></video>
			</view>
		</u-modal>
	</view>
</template>
<script>
	import {
		Debounce,
		Throttle
	} from "../../util/anitthro.js"
	export default {
		data() {
			return {
				imports:'',
				BASE_URL: 'http://182.92.193.64:8002',
				faultdata:[],
				aftersale_icon: [{
						src: '/image/afterSale/6.png'
					},
					{
						src: '/image/afterSale/1.png'
					},
					{
						src: '/image/afterSale/4.png'
					},
					{
						src: '/image/afterSale/3.png'
					},
					{
						src: '/image/afterSale/5.png'
					},
					{
						src: '/image/afterSale/2.png'
					}
				],
				title:"",//弹框标题
				show: false,//弹框先显示
				maskcloseable: true,
				showconfirmbutton: false,
				faultinfo: '',//故障信息
				faultinfo_tf:false,//故障信息显示
				faultvideo: '',//故障视频
				faultvideo_tf:false,//故障视频显示
				faultimg: [],//故障图片
				faultimg_tf: false,//故障图片显示
				aftersaleinfotf:'',
				page:1
			}
		},
		methods: {
			async getAftersale(num) {
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=after_sale.after_sale_manage.aftersale_info',
					data:{
						f_id:num,
						page:this.page
					}
				})
				this.faultdata =this.faultdata.concat(res.data)
				console.log(this.faultdata)
				if(this.faultdata.length==0){
					this.aftersaleinfotf = true
				}else{
					this.aftersaleinfotf = false
				}
				for (var i = 0; i < this.faultdata.length; i++) {
					this.faultdata[i].errorimg = JSON.parse(this.faultdata[i].errorimg)
					if (this.faultdata[i].errorimg == null) {
						this.faultdata[i].errorimg = []
					}
				}
			},
			search(){
				this.getAftersale(Number(this.imports))
			},
			fault(info) { //查看故障信息
				this.title="故障信息"
				this.show = true
				this.faultinfo = info
				this.faultimg_tf = false
				this.faultinfo_tf=true
				this.faultvideo_tf=false
			},
			faultImg(info) { //查看故障图片
				this.faultimg=[]
				for (var i = 0; i < info.length; i++) {
					let obj = {}
					obj.image = info[i]
					this.faultimg.push(obj)
				}
				console.log(this.faultimg)
				this.title="故障图片"
				this.show = true
				this.faultimg_tf = true
				this.faultinfo_tf=false
				this.faultvideo_tf=false
			},
			faultVideo(info) { //查看故障视频
			this.title="故障视频"
				this.faultvideo=info
				this.show = true
				this.faultimg_tf = false
				this.faultinfo_tf=false
				this.faultvideo_tf=true
			},
			clickLeft(){
				uni.navigateTo({
					url:"./index"
				})
			},
			searchinp() {
				Debounce(() => {
					this.eqlistdata = []
					this.search()
				}, 1000)()
			},
			examine(url) {
				var imgarr =[]
				for(var i=0;i<url.length;i++){
					imgarr.push(url[i].image)
				}
				console.log(imgarr)
				uni.previewImage({
					urls: imgarr
				});
			},
		},
		onReachBottom() {
			this.page++
			this.getAftersale(Number(this.imports))
		}
	}
</script>
<style lang="scss">
	.search_top_input{
		width: 80%;
		height: 54rpx;
		background-color: #E4E4E4;
		border-radius: 27rpx;
		position: absolute;
		top: 18rpx;
		right: 18rpx;
		padding-top: 8rpx;
		box-sizing: border-box;
		input {
			width: 85%;
			// text-indent: 1rem;
			font-size: 26rpx;
			padding-left: 20px;
		}
		.icon{
			position: absolute;
			top: 8rpx;
			right: 26rpx;
		}
	}
	.aftersaleinfo{
		width: 100%;
		position: relative;
		top: 98px;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
		font-size: 32rpx;
	}
	.aftersale {
		width: 100%;
		// margin-top: 20rpx;
		position: relative;
		top: 118px;
	
		.aftersale_item {
			width: 90%;
			margin: 0 auto 30rpx;
			box-shadow: 0 0 10rpx #bcb9ca;
			padding: 30rpx 20rpx 20rpx;
			position: relative;
			box-sizing: border-box;
			.aftersale_item_title {
				width: 100%;
	
				span {
					margin-left: 16rpx;
					font-weight: 700;
				}
			}
	
			.aftersale_item_con {
				width: 92%;
				margin-left: 8%;
				margin-top: 20rpx;
	
				p {
					height: 48rpx;
					font-size: 24rpx;
					color: #BEBEBE;
				}
			}
	
			.aftersale_item_operate {
				width: 70%;
				display: flex;
				margin: 18rpx 0 0 30%;
	
				button {
					width: 130rpx;
					padding: 0;
					font-size: 24rpx;
					color: #FFFFFF;
				}
	
				.fault {
					background-color: #F78E01;
				}
	
				.imgs {
					background-color: #71CD9A;
				}
	
				.video {
					background-color: #53C6E6;
				}
	
				.none {
					background-color: #F3F3F3;
					color: #B4B4B4;
				}
			}
	
			.aftersale_item_icon {
				position: absolute;
				top: 0;
				right: 36rpx;
	
				image {
					width: 68rpx;
					height: 64rpx;
				}
			}
		}
	}
	.model {
		width: 90%;
		.model_box {
			width: 90%;
			margin: 20rpx auto 48rpx;
			display: flex;
			justify-content: center;
		}
	}
</style>

