<template>
	<view class="havedone-container">
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="我的已办" @clickLeft="back"  background-color="#157A2C" color="#fff"></uni-nav-bar>
		<view class="search-box">
			<view class="inp-wrapper">
				<u-input placeholder="搜索流程名称" prefixIcon="search" v-model="searchData.name" @blur="doSearch"
					prefixIconStyle="font-size: 22px;color: #909399"></u-input>
			</view>

		</view>
		<view class="list-wrapper">
			<u-list @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in list" :key="index" @click.native="handleDetail(item)">

					<view class="kd-card">
						<view class="card-title">
							<text>{{ item.name }}</text>
							<text
								:class="item.result == 0 ? 'text-danger' : 'text-primary'">{{ getResult(item.result) }}</text>
						</view>
						<view>
							<view class="card-body">
								
								<view class="card-col">
									<text class="label">流程名称</text>
									<text class="content">{{ item.processInstance.name }}</text>
								</view>
								<view class="card-col">
									<text class="label">审批意见</text>
									<text class="content">{{ item.reason }}</text>
								</view>
								<view class="card-col">
									<text class="label">处理时间</text>
									<text class="content">{{ item.endTime }}</text>
								</view>

							</view>
							<view class="card-footer">
								
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	import {
		getDoneTaskPage,
		getDoneTaskList
	} from '@/api/wt/index.js'
	import {
		getByCode
	} from '@/api/pda/common.js'

	// let [page, isEnd] = [1, false]
	export default {
		components: {},
		data() {
			return {
				bpm_process_instance_result: [],
				page:1,
				size:10,
				isEnd:false,
				list: [],
				handleResult: {
					0: '驳回',
					1: '待审核',
					2: '通过'
				},
				moreSearch: false,
				searchData: {
					name: ''
				},
				doneRange: [{
						value: '',
						text: '所有已办'
					},
					{
						value: 0,
						text: '维修计划审批',
						devOpsType: 3,
						handleType: 0
					},
					{
						value: 1,
						text: '维修报工验收',
						devOpsType: 3,
						handleType: 1
					},
					{
						value: 2,
						text: '巡点检计划审批',
						devOpsType: 1,
						handleType: 0
					},
					{
						value: 3,
						text: '保养计划审批',
						devOpsType: 2,
						handleType: 0
					}
					// { value: 1, text: "申领单审批" },
					// { value: 1, text: "出库单审批" },
					// { value: 1, text: "入库单审批" },
					// { value: 1, text: "盘点审批" },
					// { value: 1, text: "调拔审批" },
					// { value: 1, text: "报损报溢审批" },
				],
				resultRange: [{
						value: '',
						text: '所有结果'
					},
					{
						value: 0,
						text: '驳回'
					},
					{
						value: 2,
						text: '通过'
					}
				]
			}
		},
		onShow() {
			this.page = 1
			this.getList()
			this.getByCode()
		},
		methods: {
			getByCode() {
				const codeS = ['bpm_process_instance_result']
				codeS.forEach(async (code) => {
					const codeValue = await getByCode(code);
					this[code] = codeValue.map(item => {
						const key = Object.keys(item)[0]
						return {
							value: key,
							text: item[key]
						}
					})
					console.log(code, this[code])
				})
				console.log('1111~~~~~~~~~', this.purchase_origin)
			},
			getResult(result) {
				const item = this.bpm_process_instance_result.find(item => item.value == result)
				return item?.text || ''
			},
			handleDetail(item) {
				console.log(item)
				uni.navigateTo({
					url: `/pages/home/wt/components/detail?processInstanceId=${item.processInstance.id}`
				})
			
			},
			doSearch() {
				this.page = 1
				this.list = []
				this.getList()
			},
			reset() {
				this.searchData = {
					name: '',
				}
				this.page = 1
				this.list = []
				this.getList()
			},
			scrolltolower() {
				if (this.isEnd) return
				this.page++
				this.getList()
			},
			calendarConfirm(...rest) {
				console.log(rest)
			},
			async getList() {
				const params = {
					pageNo:this.page,
					size: this.size,
					status:'',
					...this.searchData
				}
				this.isEnd = false
				const data = await getDoneTaskList(params)
				this.list.push(...data.list)
				this.isEnd = this.list.length >= data.count
			}
		}
	}
</script>

<style lang="scss" scoped>
	.havedone-container {
		display: flex;
		height: 100vh;
		overflow: hidden;
		flex-direction: column;
		background-color: $page-bg;
		padding-bottom: 24rpx;
	}

	.list-wrapper {
		padding: 20rpx;
		flex: 1;
		overflow: hidden;

		/deep/.u-list {
			height: 100% !important;
		}
	}

	.kd-card {
		font-size: 34rpx;
		color: #333;
		background-color: #fff;
		border-radius: 10rpx;
		word-break: break-all;
		margin-bottom: 2rpx;

		.status {
			font-weight: normal;
		}

		.card-title {
			font-size: 1rem;
			font-weight: bold;

			.card-time {
				font-weight: normal;
				color: #bfbfbf;
				font-size: 0.9rem;
				align-self: center;
			}
		}

		.card-footer,
		.card-title {
			display: flex;
			justify-content: space-between;
			padding: 30rpx 30rpx;

		}


		.card-footer {
			padding: 10rpx 30rpx 18rpx 30rpx;
			font-size: 0.8rem;

		}

		.card-body {
			padding: 0 28rpx;
			position: relative;
			min-height: 150rpx;


		}

		// .card-body:after {
		// 	content: '';
		// 	position: absolute;
		// 	left: auto;
		// 	top: auto;
		// 	bottom: 5rpx;
		// 	right: auto;
		// 	height: 1rpx;
		// 	width: 91%;
		// 	background-color: #f1f1f1;
		// }



		.card-col {
			padding: 8rpx 0;
			display: flex;
			// line-height: ;


			.content {
				flex: 1;
				overflow: hidden;
				font-size: 0.9rem;
			}

			.label {
				font-size: 0.9rem;
				color: #999;
				width: 25%;
			}
		}
	}

	.search-box {
		display: flex;
		align-items: center;
		padding: 10rpx;
		background-color: #fff;
		position: relative;

		.slide-search {
			position: absolute;
			top: 100%;
			left: 0;
			right: 0;
			z-index: 10;
			background-color: #fff;

			.timerange {
				width: 90%;
				margin: 0 auto 10rpx;
			}

			.select-box {
				display: flex;
				padding: 0 10rpx;

				.uni-stat__select+.uni-stat__select {
					margin-left: 10rpx;
				}
			}

			.more-search {
				padding-bottom: 20rpx;

				/deep/.uni-date__x-input {
					height: 66rpx !important;
				}

				.btn-search {
					text-align: right;
					padding: 10rpx 10rpx 0;

					button {
						display: inline-block;
						width: 200rpx;
						height: 60rpx;
						line-height: 58rpx;
						font-size: 28rpx;
						margin-left: 20rpx;

						&.primary {
							background-color: $j-primary-border-green;
							color: #fff;
						}
					}
				}
			}
		}

		.inp-wrapper {
			flex: 1;
		}

		/deep/.u-input {
			border: 1rpx solid #ccc;

			.u-input__content__field-wrapper__field {
				height: 40rpx !important;
			}
		}

		image {
			width: 52rpx;
			height: 52rpx;
			margin-left: 10rpx;
		}
	}
</style>