<template>
	<view class="contentAll">
		<view class="cardbox" v-if="form.data.length>0">
			<view class="card" v-for="(item,i) in form.data" :key="i">
				<view v-if="form.manage==2">
					<view class="icon-active" v-if="i==value" @click="choose(i,item)">
						<u-icon name="checkbox-mark" color="#fff" size="28"></u-icon>
					</view>
					<view class="icon-no-active" v-else @click="choose(i,item)">
					</view>
				</view>

				<view class="content">
					<view class="title">抬头类型：{{item.titleType==1?'单位':'个人'}}<text v-if="item.titleType==1"
							class="default">默认</text>
					</view>
					<view class="title">抬头名称：{{item.buyerName}}</view>
					<view class="title">纳税人识别号：{{item.buyerTaxNo}}</view>
					<view class="title" v-if="item.companyAddress">单位地址：{{item.companyAddress}}</view>
					<view class="title" v-if="item.companyTel">公司电话号码：{{item.companyTel}}</view>
					<view class="title" v-if="item.bankName">开户银行：{{item.bankName}}</view>
					<view class="title" v-if="item.bankAccount">银行账户：{{item.bankAccount}}</view>
				</view>
				<view class="edit" @click="toEdit(item)">
					<image :src="`${$imgUrl}applyCard/edit.png`" mode=""></image>
					<view>
						编辑
					</view>
				</view>
			</view>
		</view>
		<view v-else class="no">暂无发票抬头</view>
		<view class="add" @click="add">添加新抬头</view>
	</view>
</template>

<script lang="ts" setup>
	import {
		reactive, ref
	} from "vue";
	import {
		onLoad, onShow
	} from "@dcloudio/uni-app";
	import {
		navTo,
	} from "@/utils/utils";
	import { billRaiseSelect, getUserMsg } from "@/utils/network/api.js";
	import { requestNew } from "@/utils/network/request.js";
	import {
		getItem
	} from "@/utils/storage";
	// 表单数据
	const form = reactive({
		userMobile: "",
		data: [],
		manage: 1,//1订单管理过来的    2申请选择抬头过来的
	});
	const value = ref('-1')
	onLoad((option) => {
		form.manage = option.manage
		getUserinfo()
	})
	onShow(() => {
		if (form.userMobile) {
			queryList()
		}
	})
	const choose = (i, item) => {
		value.value = i
		console.log(item);
		uni.$emit('list', {
			item: item
		})
		uni.navigateBack({
			delta: 1
		})
	}
	const getUserinfo = () => {
		const options = {
			type: 2,
			data: { openId: getItem('openId') },
			method: "POST",
			showLoading: true,
		};
		requestNew(getUserMsg, options).then((res) => {
			const data = res;
			console.log(data, "用户信息");
			form.userMobile = data.customerTel
			queryList()
		});
	}
	const add = () => {
		navTo(`/subpackage/orders/invoiceApply/invoice-header-add?userMobile=${form.userMobile}`);
	}
	const queryList = () => {

		var data = {
			userMobile: form.userMobile,
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};
		console.log("options", options)
		requestNew(billRaiseSelect, options).then((res) => {
			console.log("data", res)
			const data = res;
			form.data = data.titles

		});
	}
	const toEdit = (item) => {
		const params = encodeURIComponent(JSON.stringify(item))
		navTo(`/subpackage/orders/invoiceApply/invoice-header-edit?params=${params}&&userMobile=${form.userMobile}`)
	}
</script>

<style scoped lang="scss">
	.contentAll {
		background-color: #EEF7F7;
		width: 100%;
		min-height: 100vh;
		overflow: hidden;
		padding-bottom: 70rpx;
	}

	.add {
		width: 100%;
		height: 80rpx;
		background-color: white;
		text-align: center;
		line-height: 80rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		font-size: 32rpx;
	}

	.no {
		text-align: center;
		padding-top: 300rpx;
	}

	.cardbox {
		width: 95%;
		margin: 0 auto;
		margin-top: 20rpx;

		.card {
			background: #FFFFFF;
			box-shadow: 0rpx 2rpx 6rpx 0rpx rgba(223, 223, 223, 0.8);
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx;
			margin-bottom: 30rpx;

			.content {
				.title {
					font-size: 30rpx;
					font-family: Noto Sans S Chinese;
					font-weight: 400;
					color: #333333;
					margin-bottom: 15rpx;
				}

				text {
					font-size: 26rpx;
					font-family: Noto Sans S Chinese;
					font-weight: 400;
					color: #666666;
				}
			}

			.icon-active {
				width: 43rpx;
				height: 43rpx;
				background: #00B38B;
				border-radius: 50%;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.icon-no-active {
				width: 44rpx;
				height: 44rpx;
				background: #FFFFFF;
				border: 1px solid #00B38B;
				border-radius: 50%;
			}

			.edit {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;


				image {
					width: 40rpx;
					height: 40rpx;
				}

				view {
					font-size: 26rpx;
					font-family: Noto Sans S Chinese;
					font-weight: 400;
					color: #999999;
				}
			}
		}
	}

	.default {
		border: 1rpx solid #00b38b;
		border-radius: 5rpx;
		padding: 2rpx 4rpx;
		color: #00b38b;
		margin-left: 10rpx;
	}
</style>