<template>
	<view class="content">
		<view class="card">
			<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 class="uni-container">
			<uni-table ref="table" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<uni-th width="140" align="center">业务类型</uni-th>
					<uni-th width="150" align="center">操作时间</uni-th>
					<uni-th width="170" align="center">日志记录时间</uni-th>
				</uni-tr>
				<uni-tr v-for="(item,index) in state.listData" :key="index">
					<uni-td align="center">{{item.serviceType}}</uni-td>
					<uni-td align="center">{{item.operateTime}}</uni-td>
					<uni-td align="center">{{item.insertTime}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<!-- <view class="uni-pagination-box"><uni-pagination show-icon :page-size="state.pageSize" :current="state.pageNo"
				:total="state.total" @change="change" /></view> -->
	</view>

</template>

<script setup lang="ts">
	import { reactive } from "vue";
	import {
		businessType
	} from "@/datas/businessType.js"
	import { onLoad } from "@dcloudio/uni-app";
	import { businessApi } from "@/utils/network/api.js";
	import { stringToJson } from "@/utils/network/encryption";
	import { request } from "@/utils/network/request.js";
	import { getItem, StorageKeys } from "@/utils/storage";
	const state = reactive({
		startTime: Date.now(), //日期
		businessTypeVal: "",
		businessRange: [],
		listDataTitle: ["业务类型", "操作时间", "日志记录时间"],
		listData: [],
		range: ['', ''],
		pageSize: 10,  //每页数据量
		pageNo: 1,	// 当前页
		total: 0,	// 数据总量
	})
	onLoad((option) => {
		state.businessRange = businessType;
		search(0)
	})
	const changeBusiness = (e) => {
		state.businessTypeVal = e
		console.log(e)
	}
	//业务完成日志
	const search = (val) => {
		if (val == 1) {
			var data = {
				opId: getItem(StorageKeys.OpenId),
				serviceType: state.businessTypeVal,
				startDate: state.range[0],
				endDate: state.range[1],
				// pageNo: state.pageNo,
				// pageSize: state.pageSize,
			};
		} else {
			var data = {
				opId: getItem(StorageKeys.OpenId),
				// pageNo: state.pageNo,
				// pageSize: state.pageSize,
			};
		}
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};

		request(businessApi, options).then((res) => {
			const data = stringToJson(res.bizContent);
			state.listData = [];
			state.listData = data.data
			state.total = data.data.length
			console.log("业务完成日志", data.data)
		});
	}
	const change = (e) => {
		console.log("e", e)
		state.pageNo = e.current
		search(1)
	}
</script>

<style scoped>
	.content {
		font-size: 32rpx;
		padding: 20rpx 30rpx;
	}

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

	.title {
		margin-bottom: 20rpx;
	}

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

	/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: 30px;
		line-height: 30px;
	}

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

	/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: 76rpx !important;
	}
</style>