<template>
	<view class="content">
		<view class="list" v-for="(item,index) in form.data">
			<view class="title" :style="{'--bgimg':`url(${$imgUrl}etcbg.png)`}">
				<view class="title_left">
					<image :src="`${$imgUrl}etc.png`" mode=""></image>
					<text class="question">{{item.buyerName}}</text>
					<view v-if="item.isDefault==1" class="default">默认</view>
				</view>
				<image @click="toEdit(item)" :src="`${$imgUrl}applyCard/edit.png`" mode=""></image>
			</view>
			<view class="bot">
				<view class="details">
					<view><text>税号：</text>
						<view>{{item.buyerTaxNo}}</view>
					</view>
					<view v-if="item.companyTel"><text>电话：</text>
						<view>{{item.companyTel}}</view>
					</view>
					<view v-if="item.bankName"><text>银行：</text>
						<view>{{item.bankName}}</view>
					</view>
				</view>
			</view>

		</view>
		<!-- <view style="text-align: center;margin: 20rpx;font-size: 30rpx;" v-if="state.flags">我是有底线的~</view> -->
		<NoDataView v-if="form.data.length == 0" text="暂无发票抬头" />
	</view>
	
	<view class="bottom-box is-fixed-bottom">
		<button type="default" class="ui-btn" @click="add()">
			添加新抬头
		</button>
	</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";
	import NoDataView from "@/components/no-data-view/no-data-view.vue";
	// 表单数据
	const form = reactive({
		userMobile: "",
		data: [],
		manage: 1,//1订单管理过来的    2申请选择抬头过来的
	});
	const value = ref('-1')
	onLoad((option) => {
		form.manage = option.manage
		queryList()
	})
	onShow(() => {
		queryList()
	})
	const choose = (i, item) => {
		value.value = i
		console.log(item);
		uni.$emit('list', {
			item: item
		})
		uni.navigateBack({
			delta: 1
		})
	}
	const add = () => {
		navTo(`/subpackage/orders/invoiceApply/invoice-header-add?userMobile=${form.userMobile}`);
	}
	const queryList = () => {
		const options = {
			type: 2,
			data: {
				customerId: getItem('customerObj')['customerId']
			},
			method: "POST",
			showLoading: true,
		};
		console.log("options", options)
		requestNew(billRaiseSelect, options).then((res) => {
			console.log("data", res)
			form.data = res.result

		});
	}
	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">

	.no {
		text-align: center;
		padding-top: 300rpx;
	}
	.content {
		padding-top: 30rpx;
		box-sizing: border-box;
		padding-bottom: 200rpx;
	}

	.list {
		background: #FFFFFF;
		border-radius: 12rpx;
		border: 1px solid #FFFFFF;
		width: 90%;
		margin: 0 auto;
		font-weight: 400;
		margin-bottom: 30rpx;

		.title {
			padding: 0 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 80rpx;
			background-image: var(--bgimg);
			background-size: 100% 100%;
			background-repeat: no-repeat;

			.title_left {
				display: flex;
				align-items: center;
			}

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

			.question {
				font-size: 30rpx;
				color: #01243A;
				margin-left: 10rpx;
			}

			// 待处理
			.statusdcl {
				font-size: 24rpx;
				color: #b3b3b3;
			}
		}

		.bot {
			padding: 10rpx 20rpx 20rpx 20rpx;

			.details {
				font-size: 26rpx;
				padding: 10rpx 0 5rpx 0;

				view {
					display: flex;
					margin-bottom: 5rpx;

					text {
						color: #999999;
						width: 13%;
					}

					view {
						color: #002025;
						width: 79%;
					}
				}
			}

			.time {
				font-size: 24rpx;
				color: #999999;
				padding: 20rpx 0;
				border-top: 1rpx solid #DCDCDC;
			}
		}
	}
</style>