<template>
	<view>
		<view style="position: fixed;z-index: 100;">
			<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="售后系统"></uni-nav-bar>
		</view>
		<view class="aftersale_search">
			<u-icon name="search" class="sp_icon" @click="search"></u-icon>
			<u-icon name="plus" class="sp_icon" @click="addf"></u-icon>
		</view>
		<image src="../../static/image/afterSale/dcd7147f4b15d00c5c90006738b8453.png" class="expertimages"></image>
		<view class="aftersale">
			<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="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" ></u-swiper>
				<video :src="BASE_URL+faultvideo" controls v-if="faultvideo_tf" style="width: 540rpx;"></video>
			</view>
		</u-modal>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				BASE_URL: 'http://182.92.193.64:8002',
				faultdata: [],
				aftersale_icon: [{
						src: '../../static/image/afterSale/6.png'
					},
					{
						src: '../../static/image/afterSale/1.png'
					},
					{
						src: '../../static/image/afterSale/4.png'
					},
					{
						src: '../../static/image/afterSale/3.png'
					},
					{
						src: '../../static/image/afterSale/5.png'
					},
					{
						src: '../../static/image/afterSale/2.png'
					}
				],
				title:"",//弹框标题
				show: false,//弹框先显示
				maskcloseable: true,
				showconfirmbutton: false,
				faultinfo: '',//故障信息
				faultinfo_tf:false,//故障信息显示
				faultvideo: '',//故障视频
				faultvideo_tf:false,//故障视频显示
				faultimg: [],//故障图片
				faultimg_tf: false//故障图片显示
			}
		},
		methods: {
			async getAftersale() {
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=after_sale.after_sale_manage.aftersale_info',
				})
				this.faultdata = res.data
				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 = []
					}
				}
				console.log(res.data)
			},
			fault(info) { //查看故障信息
				this.title="故障信息"
				this.show = true
				this.faultinfo = info
				this.faultimg_tf = false
				this.faultinfo_tf=true
				this.faultvideo_tf=false
			},
			faultImg(info) { //查看故障图片
				console.log(info)
				this.faultimg=[]
				// for (var i = 0; i < info.length; i++) {
				// 	let obj = {}
				// 	obj.image = info[i]
				// 	console.log(obj.image )
				// 	this.faultimg.push(obj)
				// }
				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
			},
			search() { //搜索
				uni.navigateTo({
					url:"./search"
				})
			},
			addf() { //添加
				uni.navigateTo({
					url:"./addafter"
				})
			}
		},
		onLoad() {
			this.getAftersale()
		}
	}
</script>

<style lang="scss">
	.expertimages {
		width: 100%;
		height: 154rpx;
		position: fixed;
		top: 88rpx;
		z-index: 100;
	}

	.aftersale_search {
		position: fixed;
		z-index: 100;
		top: 24rpx;
		right: 20rpx;

		.sp_icon {
			font-size: 36rpx;
			margin-left: 16rpx;
		}
	}

	.aftersale {
		width: 100%;
		// margin-top: 20rpx;
		position: relative;
		top: 264rpx;

		.aftersale_item {
			width: 90%;
			margin: 0 auto 30rpx;
			box-shadow: 0 0 10rpx #bcb9ca;
			padding: 30rpx 20rpx 20rpx;
			position: relative;

			.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;
		}
	}
</style>
