<template>
	<ciy-header title="收款银行"></ciy-header>
	<view class="ciy-card char3">
		<view class="ciy-form">
			<label class="imp">账户名称</label>
			<view>
				<ciy-input v-model="editdata.bankaccount" type="text" bb></ciy-input>
			</view>
			<view class="flexnone" style="padding-left:1em" @tap="editdata.bankaccount=me.truename">
				{{me.truename}}
			</view>
		</view>
		<view class="ciy-form">
			<label class="imp">银行账号</label>
			<view>
				<ciy-input v-model="editdata.bankno" type="text" bb></ciy-input>
			</view>
		</view>
		<view class="ciy-form">
			<label class="imp">开户银行</label>
			<view>
				<ciy-input v-model="editdata.bankname" type="text" bb></ciy-input>
			</view>
		</view>
		<view class="ciy-form">
			<label>联行号</label>
			<view>
				<ciy-input v-model="editdata.bankcode" type="text" bb></ciy-input>
			</view>
		</view>

		<view class="ciy-tip">实名认证人【{{me.truename}}】
			<br />账户名称与实名不一致，需为对公账户。
			<br />对公账户收款(含提现)，需开具发票。
			<br />个人银行账户收款，平台代缴个税。
		</view>
		<view class="ciy-form-bottom">
			<button class="btn lg cc" @tap="submit">设置收款信息</button>
		</view>
		<view style="margin:1em;">
			<ciy-checkitem sq v-model="editdata.xieyi">
				已阅读并同意
				<text @tap="gourl" :data-url="lang('login.xieyi')" style="color:#0000FF;">
					用户协议
				</text>、<text @tap="gourl" :data-url="lang('login.yinsi')" style="color:#0000FF;">
					隐私协议
				</text>
			</ciy-checkitem>
		</view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {
			this.getauth('real');
			this.editdata.bankaccount = this.me.bankaccount;
			this.editdata.bankno = this.me.bankno;
			this.editdata.bankname = this.me.bankname;
			this.editdata.bankcode = this.me.bankcode;
		},
		methods: {
			async submit(e) {
				if (!this.editdata.xieyi && await this.askmsg('是否阅读并同意协议？', '同意') != 'ok')
					return;
				if (!this.editdata.bankaccount)
					return this.toast('请输入账户名称');
				if (!this.editdata.bankno)
					return this.toast('请输入银行账号');
				if (!this.editdata.bankname)
					return this.toast('请输入开户银行');
				//对公账户，再次确认。
				if (this.me.truename != this.editdata.bankaccount) {
					if (await this.askmsg(this.editdata.bankaccount + '\n请确认该账户为对公账户？\n对公账户提现需开具发票', '是对公户') != 'ok')
						return;
				}

				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.user_bank_change',
					data: this.editdata
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.me.bankno = this.editdata.bankno;
				this.me.bankname = this.editdata.bankname;
				this.me.bankaccount = this.editdata.bankaccount;
				this.me.bankcode = this.editdata.bankcode;
				this.setstorage('me', this.me);
				await this.toast('设置成功');
				uni.navigateBack();
			}
		}
	}
</script>