<template>
	<view class="bg">
		<view class="t-select">
			<view @click="radioChange(1)" class="item-select l-item" :class="{active:form.titleType==1}">
				单位
			</view>
			<view @click="radioChange(2)" class="item-select r-item" 
				:class="{active:form.titleType==2}">
				个人
			</view>
		</view>
		<u-form label-width="230" :model="form" ref="uForm" :label-style='labelStyle'>
			<u-form-item label="抬头名称" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<u-input placeholder='请输入抬头名称' v-model="form.buyerName" inputAlign="right" />
			</u-form-item>
			<u-form-item label="纳税人识别号" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<u-input placeholder='请输入纳税人识别号'  v-model="form.buyerTaxNo" 
					inputAlign="right" />
			</u-form-item>
			<u-form-item v-if="form.titleType==1" label="单位地址" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon' 
				borderBottom>
				<u-input placeholder='请输入单位地址' v-model="form.companyAddress" 
					inputAlign="right" />
			</u-form-item>
			<u-form-item v-if="form.titleType==1" label="公司电话号码" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<u-input placeholder='请输入公司电话号码' type="number" v-model="form.companyTel" maxlength="11"
					inputAlign="right" />
			</u-form-item>
			<u-form-item v-if="form.titleType==1" label="开户银行" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<u-input placeholder='请输入开户银行' v-model="form.bankName" 
					inputAlign="right" />
			</u-form-item>
			<u-form-item v-if="form.titleType==1" label="银行账户" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<u-input placeholder='请输入银行账户' type="number" v-model="form.bankAccount" 
					inputAlign="right" />
			</u-form-item>
			<u-form-item label="设置默认抬头" :left-icon='`${$imgUrl}issuance/point-form.png`' :left-icon-style='leftIcon'
				borderBottom>
				<view style="display: flex;justify-content: flex-end;">
					<u-switch v-model="checked" active-color="#00B38B" inactive-color="#DCDCDC"
						@change='change'></u-switch>
				</view>
			</u-form-item>
		</u-form>
	</view>
<view class="action">
		<button type="default" class="ui-btn" @click="submit()">
			新增
		</button>
	</view>
</template>

<script setup lang="ts">
	import {
		ref,
		reactive
	} from "vue";
	import { billRaiseInsert } from "@/utils/network/api.js";
	import {requestNew } from "@/utils/network/request.js";
	import { msg } from "@/utils/utils";
	import { onLoad } from "@dcloudio/uni-app";
import { getItem } from "../../../utils/storage";
	const form = reactive({
		titleType: 1, //抬头类型 1-单位抬头 2个人抬头
		buyerName: '',
		isDefault: 0, //1：默认抬头；0：非默认抬头	
		buyerTaxNo: "",//纳税人识别号
		companyAddress: "", //单位地址
		companyTel: "",//公司电话号码
		bankName: "",//开户银行
		bankAccount: "",//银行账号
		userMobile: "",//客户手机号
	})
	const labelStyle = {
		color: "#004576",
		fontSize: "28rpx",
	}
	const leftIcon = {
		height: '100%',
		width: '8rpx',
		display: 'flex',
		'align-items': 'center',
		'margin-right': '4rpx',
	}
	// 单选数据列表
	const radiolist1 = reactive([{
		name: '单位',
		disabled: false
	},
	{
		name: '个人',
		disabled: false
	},
	])
	onLoad((options) => {
		
	})
	const checked = ref(false)
	const change = (status) => {
		if (status) {
			form.isDefault = 1
		} else {
			form.isDefault = 0
		}
		console.log(status, form.isDefault);
	}
	// 单选默认数据
	const radiovalue1 = ref('单位')
	// 单选
	const radioChange = (n) => {
		console.log('radioChange', n);
		form.titleType=n
		empty()
	}
	const empty = () => {
		form.buyerName = "";
		form.isDefault = 0;
		form.buyerTaxNo = "";
		form.companyAddress = "";
		form.companyTel = "";
		form.bankName = "";
		form.bankAccount = "";
		checked.value = false
	}
	const submit = () => {
		if (!form.buyerName) {
			msg("请输入抬头名称！");
			return;
		}
		// 抬头类型为单位时必填 纳税人识别号
		if (!form.buyerTaxNo) {
			msg("请输入纳税人识别号！");
			return;
		}
		var data = {
			titleType: form.titleType,
			buyerName: form.buyerName,
			isDefault: form.isDefault,
			buyerTaxNo: form.buyerTaxNo,
			companyAddress: form.companyAddress,
			companyTel: form.companyTel,
			bankName: form.bankName,
			bankAccount: form.bankAccount,
			userMobile: getItem('mobile'),
			customerId: getItem('customerObj')['customerId'],
		};
		const options = {
			type: 2,
			data: data,
			method: "POST",
			showLoading: true,
		};

		requestNew(billRaiseInsert, options).then((res) => {
			const data =res;
			console.log("data", data)
			uni.navigateBack({
				delta: 1
			})
		});
	}
</script>


<style>
	page {
		width: 100%;
		height: 100%;
	}
</style>

<style lang="scss" scoped>
	.bg {
		background-color: white;
		width: 88%;
		margin: 0 auto;
		margin-top: 20rpx;
		border-radius: 12px;
		border: 1px solid #FFFFFF;
		padding: 20rpx;
		overflow: hidden;
	
		
	
		.des {
			font-weight: 400;
			font-size: 28rpx;
			color: #01243A;
			line-height: 56rpx;
			margin-top: 10rpx;
			text-indent: 1rem;
		}
	}
	.action {
		position: fixed;
		left: 0;
		bottom: 0;
		height: 188rpx;
		background-color: #fff;
		border-radius: 30rpx 30rpx 0 0;
		width: 100vw;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
	}
	.t-select {
		display: flex;
		padding-bottom: 30rpx;
		justify-content: center;
		align-items: center;
	
		.item-select {
			width: 200rpx;
			height: 68rpx;
			font-family: SourceHanSansSC, SourceHanSansSC;
			font-weight: 400;
			font-size: 28rpx;
			color: #CCB375;
			text-align: center;
			line-height: 68rpx;
			border: 1rpx solid #CCB375;
	
			&.l-item {
				border-radius: 34rpx 0 0 34rpx;
			}
	
			&.r-item {
				border-radius: 0 34rpx 34rpx 0;
			}
	
			&.active {
				color: #fff;
				background: #CCB375;
			}
		}
	}
</style>