<template>
	<view class="processWrapper exportBody ">
		<view style="height:98rpx"></view>
		<view class="ding">
			<!-- <calendar></calendar> -->
			<view class="example-body">
				<uni-datetime-picker v-model="datetimerange" type="datetimerange" start-placeholder="请选择开始时间"
					end-placeholder="请选择结束时间" start="2000-3-20 12:00:00" end="2025-10-20 20:00:00" rangeSeparator="至" />
			</view>
		</view>

		<block>
			<view class="processList">
				<view class="cu-list menu-avatar">
					<view class="cu-item" v-for="(item,index) in getExportData" :key="index">
						<view class="cu-avatar lg">
							<image class="image-bg"
								:src="item.device_state=='离线'?'/static/device-icon.png':'/static/device-icon.png'" />
						</view>
						<view class="content">
							<view class="pro-title">
								<view class="cut" >{{item.owner_name}}</view>
							
							</view>
							<view class="pro-des  ">
								<view class="text-cut">{{item.unitinfo}}</view>
							</view>
							<view class="pro-date ">{{item.install_time}}</view>
						</view>
					<view class="nav-right num">
						<view class="text-grey">
							<!-- <span class="online">{{item.device_state}}</span> -->
							<span :class="item.device_state=='在线'?'online':'offline'">{{item.device_state}}</span>
				
							<text class="icon iconfont margin-right-xs margin-left-lg">&#xe629;</text>
						</view>
					</view>
					</view>
					<view class=" text-center margin-top" v-if="!this.getExportData.length&&this.dataRes">暂无数据...</view>
				</view>
			</view>
		</block>
		<view v-if="this.getExportData.length>0" class="padding-lr padding-bottom-lg bg-white" style="position:fixed;bottom:0;width:100%">
			<view class="btn-area">
				<button class="bg-blue  round missReport margin-top" @tap="exportButton()">导 出 </button>
			</view>
		</view>



	</view>
</template>
<script>
	export default {
		data() {
			return {
				getExportData: [],
				dataRes: 0,
				datetimerange: ['', ''],
				keyWords:'',
				dwtype:0
			};
		},
		onLoad: function(option) {
			this.dwtype=option.dwtype
			this.getData({
				"company_code": uni.getStorageSync('selectedCode'),
				"dwtype":this.dwtype,
				"start_time": '',
				"end_time": '',
			})

		},
		watch: {
			datetimerange(newval) {
				this.getData({
					"company_code": uni.getStorageSync('selectedCode'),
					"dwtype":this.dwtype,
					"start_time":newval[0],
					"end_time": newval[1],
				})
			}
		},
		
		methods: {
			async getData(params = {}) {
				const res = await this.$myRequest({
					url: 'DeviceManagement/getDeviceList', //设备管理列表渲染
					data: params,
					showLoading: true
				})
				this.getExportData = res.data.data;
				this.dataRes = 1;
			},
			exportButton() {
				// alert(this.dwtype)

				//#ifdef H5
				var start_time =this.datetimerange[0]?`start_time/${this.datetimerange[0]}/`:'';
				var end_time =this.datetimerange[1]?`end_time/${this.datetimerange[1]}/`:'';
				let exportUrl = this.$BASE_URL+
					`ExportModule/getDeviceListExpor/${start_time}${end_time}dwtype/${this.dwtype}/company_code/${uni.getStorageSync('selectedCode')}/`
				// alert(exportUrl)
				var ua = window.navigator.userAgent.toLowerCase();
				
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					uni.showModal({
						showCancel: false,
						content: '如需下载，请在默认浏览器中操作',
						success: function(res) {
							window.location.href = exportUrl;
						}
					});
				} else {
					window.location.href = exportUrl;
				}
				//#endif

			}





		}
	}
</script>

<style lang="scss">


</style>
