<template>
	<ciy-header title="我要开票"></ciy-header>
	<view v-if="init.code != 1">
		<view class="px4 py4">
			<view style="height:2em;width:60%;" class="ciy-skeleton"></view>
			<view style="height:1em;width:40%;margin-left:1em;" class="ciy-skeleton"></view>
			<view style="height:1em;width:50%;" class="ciy-skeleton"></view>
			<view style="height:6em;width:100%;" class="ciy-skeleton"></view>
		</view>
	</view>
	<view v-else>
		<form @submit="submit" class="char3">
			<view class="ciy-card">
				<view class="content">
					<view class="ciy-form">
						<label>可开票金额</label>
						<view style="text-align: left;">
							{{toint(init.user.myinvmoney/100)}}元
						</view>
					</view>
					<view class="ciy-form">
						<label>开票金额</label>
						<view>
							<ciy-inputbet name="money" :value="toint(init.user.myinvmoney/100)*100" bb unit="元" bet="100"></ciy-inputbet>
						</view>
					</view>
					<view class="ciy-form">
						<label>发票抬头</label>
						<view>
							<ciy-selpage name="invtit" page="me_invoicetitle">
								<template v-slot:default="{data}">
									<view>{{data.name}}</view>
									<view class="txt1">{{data.taxnumber}}</view>
								</template>
							</ciy-selpage>
						</view>
					</view>
					<view class="ciy-form-bottom">
						<button class="btn lg cc" form-type="submit">申请开票</button>
					</view>
					<view class="ciy-tip">
						开具增值税普通电子发票。<br />
						开票科目: 技术服务费。<br />
						联系客服签订技术服务合同。
					</view>
				</view>
			</view>
		</form>
	</view>
	<ciy-swipelist title="开票历史" @tap="gourl" data-url="$/pages/main/me_invoice_history" more></ciy-swipelist>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {
			this.getinit();
		},
		methods: {
			async getinit() {
				var retjson = await this.callajax({
					func: 'me.balance_get',
					data: {}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init = retjson;
			},
			async submit(e) {
				if (e.detail.value.money < 100)
					return;
				if (this.init.user.myinvmoney < e.detail.value.money)
					return this.toast('开票金额不足');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'me.invoicing',
					data: e.detail.value
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init.user.myinvmoney -= retjson.money;
				this.toast('申请成功');
			}
		}
	}
</script>