<template>
	<view class="content">
		<view class="top-content">
			<view class="item">
				<text>车牌号：</text><input placeholder="请输入车牌号" v-model="state.vehiclePlate" />
			</view>
			<view class="item">
				<text>车牌颜色：</text>
				<view>
					<uni-data-select v-model="state.vehiclePlateColor" :localdata="state.vehiclePlateColorArr"
						@change="changeColor" :clear="false"></uni-data-select>
				</view>
				<text style="margin-left: 20rpx;">审核状态：</text>
				<view>
					<uni-data-select v-model="state.status" :localdata="state.statusArr" @change="changeStatus"
						:clear="false"></uni-data-select>
				</view>
			</view>
			<view class="item last">
				<text>业务类型：</text>
				<uni-data-select v-model="state.businessTypeVal" :localdata="state.businessRange"
					@change="changeBusiness" :clear="false"></uni-data-select>
			</view>
			<view class="example-body">
				<uni-datetime-picker v-model="state.range" type="daterange" />
				<button size="mini" style="color: #ffffff;
				backgroundColor: rgb(118, 200, 77);
				borderColor: rgb(118, 200, 77);
				font-size: 26rpx;
				flex-shrink: 0;margin-left: 20rpx;" @click="search(1)">搜索</button>
			</view>
		</view>


		<view class="uni-container">
			<view class="list-item" v-for="(item,index) in state.listData" @click="go(item)">
				<view>
					<view><text>车牌号：</text><text>{{item.vehiclePlate}}</text></view>
					<view><text>车牌颜色：</text><text>{{item.vehiclePlateColorC}}</text></view>
					<view><text>状态：</text><text>{{item.statusC}}</text></view>
					<view><text>业务类型：</text><text>{{item.businessTypeC}}</text></view>
					<view><text>时间：</text><text>{{item.insertTime}}</text></view>
				</view>
				<image class="right" src="../../../static/image/icon-back.png" mode=""></image>
			</view>
		</view>
		<view class="bottom-line" v-if="state.flags">我是有底线的~~~</view>
	</view>

</template>

<script setup lang="ts">
	import { reactive } from "vue";
	import {
		businessType
	} from "@/datas/businessType.js"
	import { onLoad, onReachBottom } from "@dcloudio/uni-app";
	import { auditQueryApi } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption";
	import { request } from "@/utils/network/request.js";
	import { getItem, StorageKeys } from "@/utils/storage";
	import { vehiclePlateColor, getVehiclePlateColorPai } from "@/datas/vehiclePlateColor";
	const state = reactive({
		startTime: Date.now(), //日期
		businessTypeVal: "",
		businessRange: [],
		listData: [],
		range: ['', ''],
		pageSize: 10,  //每页数据量
		pageNo: 1,	// 当前页
		total: 0,	// 数据总量
		flags: false,
		vehiclePlate: "",//车牌号
		vehiclePlateColor: "",
		status: "",
		statusArr: [], //AUDIT_STATUS
		vehiclePlateColorArr: []

	})
	onLoad((option) => {
		// 车牌颜色 
		let getVehiclePlateColorArr = getItem('key')['VEHICLE_COLOR_TYPE']
		for (var k = 0; k < getVehiclePlateColorArr.length; k++) {
			let obj2 = {};
			obj2['value'] = getVehiclePlateColorArr[k]['code']
			obj2['text'] = getVehiclePlateColorArr[k]['name']
			state.vehiclePlateColorArr.push(obj2)
		}
		// 审核状态
		let getStatusArr = getItem('key')['AUDIT_STATUS'];
		for (var k = 0; k < getStatusArr.length; k++) {
			let obj1 = {};
			obj1['value'] = getStatusArr[k]['code']
			obj1['text'] = getStatusArr[k]['name']
			state.statusArr.push(obj1)
		}
		// 业务类型
		let getBusiness = getItem('key')['BUSINESS_TYPE'];
		for (var k = 0; k < getBusiness.length; k++) {
			let obj = {};
			obj['value'] = getBusiness[k]['code']
			obj['text'] = getBusiness[k]['name']
			state.businessRange.push(obj)
		}

		search(1)
	})

	const changeColor = (e) => {
		console.log("changeColor", e)
		state.vehiclePlateColor = e
	}
	const changeStatus = (e) => {
		console.log("changeColor", e)
		state.status = e
	}
	const changeBusiness = (e) => {
		state.businessTypeVal = e
		console.log(e)
	}
	//业务完成日志
	const search = (val) => {
		if (val == 1) {
			state.pageNo = 1
		}
		if (state.pageNo == 1 && state.listData.length > 0) {
			state.listData = []
		}
		var data = {
			vehiclePlate: state.vehiclePlate,
			vehiclePlateColor: state.vehiclePlateColor,
			status: state.status,
			businessType: state.businessTypeVal,
			startTime: state.range[0] ? state.range[0] + 'T00:00:00' : state.range[0],
			endTime: state.range[1] ? state.range[1] + 'T00:00:00' : state.range[1],
			pageNo: state.pageNo,
			pageSize: state.pageSize,
			// opId: getItem(StorageKeys.OpenId),
		};
		for (var index in data) {
			console.log(index, data[index], data[index] == "")
			if (data[index].toString() == "") {
				delete data[index]
			}
		}
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		request(auditQueryApi, options).then((res) => {
			const data = stringToJson(res.bizContent);
			var getData = [...stringToJson(res.bizContent).data, ...state.listData]
			for (var i = 0; i < getData.length; i++) {
				getData[i]['vehiclePlateColorC'] = getVehiclePlateColorPai(getData[i]['vehiclePlateColor'])
				if (getData[i]['status'] == 'AUDIT') {
					getData[i]['statusC'] = "审核中"
				} else if (getData[i]['status'] == 'FAIL') {
					getData[i]['statusC'] = "未通过"
				} else if (getData[i]['status'] == 'COMPLETE') {
					getData[i]['statusC'] = "已完成"
				}
				for (var m = 0; m < state.businessRange.length; m++) {
					if (getData[i]['businessType'] == state.businessRange[m]['value']) {
						getData[i]['businessTypeC'] = state.businessRange[m]['text']
						break;
					}
				}
			}
			state.listData = getData
			state.total = data.data.length
			console.log("业务完成日志", state.listData, state.pageNo,)
		});
	}
	const change = (e) => {
		console.log("e", e)
		state.pageNo = e.current
		search(2)
	}
	// 触底加载
	onReachBottom(() => {
		if (state.listData.length < state.pageNo * 10) return state.flags = true
		console.log("触底了")
		state.pageNo++
		search(2)
	})
	const go = (item) => {
		const params = encodeURIComponent(JSON.stringify(item))
		uni.navigateTo({
			url: `/subpackage/after-sale/progress-query/progress-query-business-details?params=${params}`
		})
	}
</script>

<style scoped>
	.top-content {
		position: fixed;
		left: 0;
		top: 0;
		background-color: white;
		width: 100%;
		padding: 0 20rpx 20rpx 20rpx;
		box-sizing: border-box;
		z-index: 999999;
	}

	.content {
		font-size: 32rpx;
		padding: 20rpx 30rpx;
		background-color: #EEF7F7;
		min-height: 100vh;
	}

	.card {
		display: flex;
		margin: 0 20rpx;
		align-items: center;
	}

	.title {
		margin-bottom: 20rpx;
	}

	.uni-container {
		margin: 50rpx 0;
		margin-top: 330rpx;
	}

	/deep/.uni-table-th,
	/deep/.uni-table-td {
		padding: 0 !important;
		font-size: 12px !important;
	}

	/deep/.uni-date__x-input,
	/deep/.uni-select {
		font-size: 13px;
		height: 24px;
		line-height: 24px;
	}

	/deep/.last .uni-stat__select {
		width: 320rpx;
	}

	/deep/.uni-select__selector-empty,
	/deep/.uni-select__selector-item {
		font-size: 13px !important;
	}

	/deep/.uni-date {
		width: 73% !important;
	}

	.example-body {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}

	/deep/.uni-date-x {
		height: 56rpx !important;
	}

	.list-item {
		width: 95%;
		border-radius: 10rpx;
		margin: 30rpx auto;
		font-size: 28rpx;
		border: 1rpx solid #ccc;
		padding: 12rpx;
		box-sizing: border-box;
		background-color: white;
		display: flex;
		align-items: center;
	}

	.list-item>view {
		margin-bottom: 10rpx;
		width: 90%;
	}

	.bottom-line {
		text-align: center;
		margin: 30rpx 0;
	}

	.item {
		display: flex;
		font-size: 30rpx;
		margin: 20rpx 0 0 20rpx;
		align-items: center;
	}

	input,
	.uni-input {
		border: 1rpx solid #ccc;
		padding: 0 10rpx;
		height: 28rpx;
		line-height: 28rpx;
	}

	.right {
		width: 40rpx;
		height: 40rpx;
		transform: rotateY(180deg);
	}
</style>