<template>
	<view class="maboxbg" v-if="isshow" @click="checkbox(0)">
		<view class="modtips" @click.stop.prevent v-if="tipstate==1">
			<view class="title">
				{{title||'提示'}}
			</view>
			<!-- <view class="contents">
				{{content||'提示内容模板'}}
			</view> -->
			<view class="inputbx">
				<input v-model="inputtext" :placeholder="placeholder" />
			</view>
			<view class="buts">
				<view @click="checkbox(1)" v-if="isshowcancel" class="cancel">{{cancelTxt||'取消'}}</view>
				<view @click="checkbox(2)" class="confirm">{{confirmTxt||'确认'}}</view>
			</view>
		</view>
		<view class="modtips" @click.stop.prevent v-if="tipstate==2">
			<view class="title">
				{{title||'提示'}}
			</view>
			<!-- <view class="contents">
				{{content||'提示内容模板'}}
			</view> -->
			<view class="listcheck">
				<view @click="checkitem(index)" v-for="(item,index) in list">
					<image :src="checklist.indexOf(index)==-1?'/static/nocheck.png':'/static/check.png'"></image>
					<view>{{item}}</view>
				</view>
			</view>
			<view class="buts">
				<view @click="checkbox(1)" v-if="isshowcancel" class="cancel">{{cancelTxt||'取消'}}</view>
				<view @click="checkbox(2)" class="confirm">{{confirmTxt||'确认'}}</view>
			</view>
		</view>
		<view class="modtips" @click.stop.prevent v-if="tipstate==3">
			<view class="title">
				{{title||'提示'}}
			</view>
			<!-- <view class="contents">
				{{content||'提示内容模板'}}
			</view> -->
			<view class="tpstitl">请上传照片(上门照，货物堆放照，签收照，易碎品贵重物品，家配照):</view>
			<view class="imgbx">
				<view v-for="(item,index) in details.imglist">
					<image :src="item"></image>
					<image @click="remove(index)" src="/compoment/cus-selects-fan/cha.png"></image>
				</view>
				<view @click="updateimg" v-if="details.imglist.length!=details.maximglength">
					<image src="/static/add.png"></image>
				</view>
			</view>
<!-- 			<view class="tpstitl">货物堆放照:</view>
			<view class="imgbx">
				<view v-for="(item,index) in details.imglist">
					<image :src="item"></image>
					<image @click="remove(index)" src="/compoment/cus-selects-fan/cha.png"></image>
				</view>
				<view @click="updateimg" v-if="details.imglist.length!=details.maximglength">
					<image src="/static/add.png"></image>
				</view>
			</view>
			<view class="tpstitl">易碎品贵重物品:</view>
			<view class="imgbx">
				<view v-for="(item,index) in details.imglist">
					<image :src="item"></image>
					<image @click="remove(index)" src="/compoment/cus-selects-fan/cha.png"></image>
				</view>
				<view @click="updateimg" v-if="details.imglist.length!=details.maximglength">
					<image src="/static/add.png"></image>
				</view>
			</view> -->
			<view class="inputbx">
				<input v-model="inputtext" :placeholder="placeholder" />
			</view>
			<view class="buts">
				<view @click="checkbox(1)" v-if="isshowcancel" class="cancel">{{cancelTxt||'取消'}}</view>
				<view @click="checkbox(2)" class="confirm">{{confirmTxt||'确认'}}</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import functions from '@/utils/functions.js'
	import { tiplistType } from '@/interfaces/compoment/tiplist'
	import { reactive,ref,toRefs } from "vue";
	let details=reactive<tiplistType>({
		tipstate:2,
		title:'',
		placeholder:'',
		isshowcancel:true,
		confirmTxt:'',
		cancelTxt:'',
		success:null,
		cancel:null,
		close:null,
		isshow:false,
		list:['12341131212'],
		checklist:[],
		inputtext:'',
		isonecheck:false,
		imglist:[],
		maximglength:3
	})
	function setdetails(objs:any){
		for(let key in objs){
			details[key]=objs[key]
		}
	}
	function checkitem(index:number){
		if(details.isonecheck){
			if(details.checklist.indexOf(index)==-1){
				details.checklist=[index]
			}else{
				details.checklist.splice(details.checklist.indexOf(index),1)
			}
			return
		}
		if(details.checklist.indexOf(index)==-1){
			details.checklist.push(index)
		}else{
			details.checklist.splice(details.checklist.indexOf(index),1)
		}
	}
	function checkbox(type:number){
		switch (type){
			case 0:
				if(details.close){
					details.close(details)
				}
				break;
			case 1:
				if(details.cancel){
					details.cancel(details)
				}
				break;
			case 2:
				if(details.success){
					details.success(details)
				}
				break;
		}
	}
	function remove(index){
		details.imglist.splice(index,1)
	}
	function updateimg(){
		uni.chooseImage({
			count:details.maximglength,
			success:async (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFilePaths as any;
				// let url=await functions.upfile(tempFilePaths[0])
				tempFilePaths.map(async (item)=>{
					let url=await functions.upfile(item)
					details.imglist.push(url.link)
				})
				// uni.uploadFile({
				// 	url: 'https://www.example.com/upload', //仅为示例，非真实的接口地址
				// 	filePath: tempFilePaths[0],
				// 	name: 'file',
				// 	success: (uploadFileRes) => {
				// 		console.log(uploadFileRes.data);
				// 	}
				// });
			}
		});
	}
	defineExpose({setdetails})
	const { imglist,inputtext,checklist,list,isshow,tipstate,title,isshowcancel,placeholder,confirmTxt,cancelTxt }=toRefs(details)
</script>

<style lang="scss">
	.tpstitl{
		font-size: 26upx;
		width: 550upx;
	}
	.maboxbg{
		width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		top: 0;
		background-color: #00000050;
		z-index: 9999;
	}
	.modtips{
		width: 630upx;
		// height: 63upx;
		background: #FFFFFF;
		border-radius: 7upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding:40upx 20upx;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translateX(-50%) translateY(-50%);
		box-sizing: border-box;
		.title{
			font-size: 34upx;
			color: #092C4D;
		}
		.contents{
			max-width: 480upx;
			font-size: 29upx;
			color:#90A0AF;
			margin-top: 30upx;
		}
		.imgbx{
			width: 550upx;
			display: grid;
			grid-template-columns: 33% 33% 33%;
			margin-top: 20upx;
			>view{
				width: 130upx;
				height: 130upx;
				padding: 10upx;
				box-sizing: border-box;
				border: 1upx solid #e6e6e6;
				margin-bottom: 15upx;
				border-radius: 8upx;
				position: relative;
				>image:nth-of-type(1){
					width: 100%;
					height: 100%;
				}
				>image:nth-of-type(2){
					width: 28upx;
					height: 28upx;
					position: absolute;
					right: 10upx;
					top: 10upx;
				}
			}
		}
		.buts{
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 40upx;
			>view{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 260upx;
				height: 88upx;
				border-radius: 8upx;
				font-size: 32upx;
			}
			>.cancel{
				background-color: #F5F5F6;
				color: #5A6875;
				margin-right: 20upx;
			}
			>.confirm{
				background-color: #D3832A;
				color: #FFFFFF;
			}
		}
		.inputbx{
			margin-top: 30upx;
			margin-bottom: 10upx;
			border: 1upx solid #092C4D20;
			padding: 15upx 30upx;
			padding-left: 20upx;
			display: flex;
			align-items: center;
			justify-content: center;
			box-sizing: border-box;
			border-radius: 10upx;
			font-size: 27upx;
			color: #092C4D;
			>input{
				width: 480upx;
				flex: 1;
			}
		}
		.listcheck{
			display: flex;
			flex-direction: column;
			margin-top: 30upx;
			>view{
				width: 420upx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				font-size: 28upx;
				padding: 10upx 0;
				>image{
					width: 30upx;
					height: 30upx;
					margin-right: 15upx;
				}
			}
		}
	}
</style>