<template>
	<view style="background-color: #F2F3F5;" :style="{height:pageHeight+'px'}">
		<Card class="searchForm" :hideTitle="true">
			<form @submit="onSubmit">
				<FormItem :title="'合同编号'">
					<input class="uni-input" name="contractCode" />
				</FormItem>
				<button form-type="submit">Submit</button>
			</form>
		</Card>
		<Card class="table" :hideTitle="true">
			<uni-collapse>
				<uni-collapse-item v-for="i in list">
					<template v-slot:title>
						<view class="list-item-title">
							<view class="leftText">
								{{i.contractName}}
							</view>
							<view class="rightText">
								<DictTag :options="contract_category" :value="i.contractCategory" />
							</view>
						</view>
					</template>
					<view style="padding:20rpx 0 " @tap="itemOperation(i)">
						<view class="is-open-text">有无合同：{{i.contractFlag}}
						</view>
						<view class="is-open-text">合同编号：{{i.contractCode}}
						</view>
						<view class="is-open-text">业务方向：
							<DictTag :options="business_direction" :value="i.businessDirection" type="text" />
						</view>
						<view class="is-open-text">部门：{{i.deptName}}</view>
						<view class="is-open-text">合同签订日期：{{i.contractDate}}
						</view>
						<view class="is-open-text">合同总价：{{i.totalPrice}}
						</view>
						<view class="is-open-text">
							甲方公司：{{i.oneCustomerName}}
						</view>
						<view class="is-open-text">
							乙方公司：{{i.twoCustomerName}}
						</view>
						<view class="is-open-text">合同状态：
							<DictTag :options="contract_status" :value="i.contractStatus" type="text" />
						</view>
						<view class="is-open-text">流程状态：{{i.flowStatus}}
						</view>
						<view class="is-open-text">
							内部合同号：{{i.internalContractCode}}</view>
						<view class="is-open-text">
							外部合同号：{{i.externalContractCode}}</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</Card>
	</view>
</template>

<script setup>
	import {
		ref,
		toRefs,
		onMounted,
	} from 'vue';
	import {
		useDict
	} from '@/utils/dict.js'

	const {
		contract_category,
		business_direction,
		active_flag,
		contract_flag,
		contract_type,
		contract_status
	} = toRefs(
		useDict(['contract_category', 'business_direction', 'active_flag', 'contract_flag', 'contract_type',
			'contract_status'
		])
	);

	const list = ref([{
			"contractId": "2001118586166714370",
			"contractFlag": "1",
			"contractCode": "HT202512170005",
			"customerContractCode": null,
			"contractName": "13",
			"contractCategory": "1",
			"contractType": null,
			"businessDirection": "1",
			"contractDeptId": 100,
			"contractDate": null,
			"totalPrice": "0.00",
			"oneCustomerId": null,
			"oneRepresent": null,
			"oneDate": null,
			"twoCustomerId": null,
			"twoRepresent": null,
			"twoDate": null,
			"contractStatus": "1",
			"flowStatus": "draft",
			"templateId": null,
			"ossId": null,
			"paymentMethod": null,
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": null,
			"twoCustomerName": null,
			"deptName": "青岛海威物联科技有限公司"
		},
		{
			"contractId": "2000863577393192962",
			"contractFlag": "1",
			"contractCode": "HT202512160002",
			"customerContractCode": null,
			"contractName": "合同20251216",
			"contractCategory": "1",
			"contractType": null,
			"businessDirection": "5",
			"contractDeptId": 107,
			"contractDate": null,
			"totalPrice": "20.00",
			"oneCustomerId": 2,
			"oneRepresent": "甲方",
			"oneDate": "2025-12-11 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": "乙方授",
			"twoDate": "2025-12-09 00:00:00",
			"contractStatus": "1",
			"flowStatus": "draft",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": null,
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团股份有限公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "软件产品部"
		},
		{
			"contractId": "2000481472066621442",
			"contractFlag": "1",
			"contractCode": "HT202512150001",
			"customerContractCode": null,
			"contractName": "产品销售合同1215",
			"contractCategory": "2",
			"contractType": null,
			"businessDirection": "5",
			"contractDeptId": 107,
			"contractDate": "2025-12-15 00:00:00",
			"totalPrice": "80000.00",
			"oneCustomerId": 2,
			"oneRepresent": "甲方",
			"oneDate": "2025-12-18 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": "乙方",
			"twoDate": "2025-12-31 00:00:00",
			"contractStatus": "3",
			"flowStatus": "finish",
			"templateId": null,
			"ossId": "2000506818547793921",
			"paymentMethod": null,
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团股份有限公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "软件产品部"
		},
		{
			"contractId": "1997918929098559489",
			"contractFlag": "1",
			"contractCode": "HT202512080003",
			"customerContractCode": null,
			"contractName": "同名称",
			"contractCategory": "1",
			"contractType": "2",
			"businessDirection": "3",
			"contractDeptId": 100,
			"contractDate": null,
			"totalPrice": "23840.00",
			"oneCustomerId": 3,
			"oneRepresent": null,
			"oneDate": null,
			"twoCustomerId": 1,
			"twoRepresent": null,
			"twoDate": null,
			"contractStatus": "1",
			"flowStatus": "draft",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团山东分公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "青岛海威物联科技有限公司"
		},
		{
			"contractId": "1996824342348529665",
			"contractFlag": "1",
			"contractCode": "HT202512050001",
			"customerContractCode": null,
			"contractName": "测试合同001",
			"contractCategory": "1",
			"contractType": "2",
			"businessDirection": "1",
			"contractDeptId": 107,
			"contractDate": "2025-12-19 00:00:00",
			"totalPrice": "1350.00",
			"oneCustomerId": 2,
			"oneRepresent": "甲方",
			"oneDate": "2025-12-18 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": " 乙方",
			"twoDate": "2025-12-11 00:00:00",
			"contractStatus": "3",
			"flowStatus": "finish",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": "1996829163566764034",
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团股份有限公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "软件产品部"
		},
		{
			"contractId": "1996466907519762434",
			"contractFlag": "1",
			"contractCode": "HT202512040001",
			"customerContractCode": null,
			"contractName": "市场实施合同一",
			"contractCategory": "1",
			"contractType": "2",
			"businessDirection": "1",
			"contractDeptId": 107,
			"contractDate": "2025-12-12 00:00:00",
			"totalPrice": "3810.00",
			"oneCustomerId": 2,
			"oneRepresent": "甲方授",
			"oneDate": "2025-12-16 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": "乙方",
			"twoDate": "2025-12-18 00:00:00",
			"contractStatus": "3",
			"flowStatus": "finish",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": "1996470593947987969",
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团股份有限公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "软件产品部"
		},
		{
			"contractId": "1994225942858510338",
			"contractFlag": "1",
			"contractCode": "HT202511280001",
			"customerContractCode": null,
			"contractName": "合同名称1",
			"contractCategory": "1",
			"contractType": "2",
			"businessDirection": null,
			"contractDeptId": 100,
			"contractDate": null,
			"totalPrice": "27.00",
			"oneCustomerId": null,
			"oneRepresent": null,
			"oneDate": null,
			"twoCustomerId": null,
			"twoRepresent": null,
			"twoDate": null,
			"contractStatus": "1",
			"flowStatus": "draft",
			"templateId": null,
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": null,
			"twoCustomerName": null,
			"deptName": "青岛海威物联科技有限公司"
		},
		{
			"contractId": "1991418792844570626",
			"contractFlag": "1",
			"contractCode": null,
			"customerContractCode": "A",
			"contractName": "备件销售合同1120",
			"contractCategory": "2",
			"contractType": "2",
			"businessDirection": "7",
			"contractDeptId": 106,
			"contractDate": "2025-11-05 00:00:00",
			"totalPrice": "6090.00",
			"oneCustomerId": 3,
			"oneRepresent": "甲方",
			"oneDate": "2025-11-19 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": "乙方",
			"twoDate": "2025-11-13 00:00:00",
			"contractStatus": "3",
			"flowStatus": "finish",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": null,
			"internalContractCode": "E",
			"externalContractCode": "S",
			"orderContractCode": "T",
			"projectContractCode": "Y",
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团山东分公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "市场部"
		},
		{
			"contractId": "1991345844477517825",
			"contractFlag": "1",
			"contractCode": "HT202511200002",
			"customerContractCode": null,
			"contractName": "产品销售合同1120",
			"contractCategory": "2",
			"contractType": "2",
			"businessDirection": "1",
			"contractDeptId": 106,
			"contractDate": "2025-11-08 00:00:00",
			"totalPrice": "1100.00",
			"oneCustomerId": 2,
			"oneRepresent": "甲方A",
			"oneDate": "2025-11-19 00:00:00",
			"twoCustomerId": 1,
			"twoRepresent": "乙方",
			"twoDate": "2025-11-18 00:00:00",
			"contractStatus": "4",
			"flowStatus": "invalid",
			"templateId": "1976189070472728577",
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": "某一集团股份有限公司",
			"twoCustomerName": "青岛海威物联科技有限公司",
			"deptName": "市场部"
		},
		{
			"contractId": "1988899504180830209",
			"contractFlag": "2",
			"contractCode": null,
			"customerContractCode": null,
			"contractName": "合同名称AS",
			"contractCategory": null,
			"contractType": null,
			"businessDirection": null,
			"contractDeptId": null,
			"contractDate": null,
			"totalPrice": null,
			"oneCustomerId": null,
			"oneRepresent": null,
			"oneDate": null,
			"twoCustomerId": null,
			"twoRepresent": null,
			"twoDate": null,
			"contractStatus": "1",
			"flowStatus": "draft",
			"templateId": null,
			"ossId": null,
			"paymentMethod": "3-3-3-1",
			"signatureAppendix": null,
			"internalContractCode": null,
			"externalContractCode": null,
			"orderContractCode": null,
			"projectContractCode": null,
			"warrantyPeriod": null,
			"taxRate": null,
			"remark": null,
			"activeFlag": "1",
			"contractMaterialList": null,
			"oneCustomerName": null,
			"twoCustomerName": null,
			"deptName": null
		}
	])
	const itemOperation = (e) => {
		console.log(e);
		if (e.contractStatus !== '1') {
			uni.navigateTo({
				url: '/pages/contract/info?type=1&id=' + e.contractId
			})
		}
		if (e.contractStatus === '1') {
			uni.navigateTo({
				url: '/pages/contract/info?type=2&id=' + e.contractId
			})
		}
	}

	const onSubmit = (e) => {
		console.log(e.detail.value);
	}

	const pageHeight = ref(0)
	const sys = uni.getSystemInfoSync()
	onMounted(() => {
		pageHeight.value = sys.windowHeight
	})
</script>

<style lang="scss" scoped>
	.searchForm {
		margin-top: 30rpx;
		padding-top: 0 !important;

		:deep(.content) {
			margin-top: 0 !important;
		}
	}

	.table {
		margin-top: 30rpx;
		padding-top: 0 !important;

		:deep(.content) {
			margin-top: 0 !important;
		}
	}

	.list-item-title {
		padding: 30rpx 0;
		display: flex;

		.leftText {
			display: inline-block;
		}

		.rightText {
			margin-left: auto;
		}

	}

	.is-open-text {
		padding-right: 20rpx;
		display: inline-block;
		min-width: calc(45% - 20rpx);
		color: #999
	}
</style>