<template>
	<view class="center">
		<view>
			<image @click='consent' style='width:14px;height:14px;position:relative;top:2px;margin-right:5px;' :src="consentStatus==true?'../../static/img/login/select@2x.png':'../../static/img/login/selected2.png'" alt=""></image>
			<text>公司</text>
			<image @click='consent' style='width:14px;height:14px;position:relative;top:2px;margin-right:5px;' :src="consentStatus1==true?'../../static/img/login/select@2x.png':'../../static/img/login/selected2.png'" alt=""></image>
			<text>个人</text>

		</view>
		<view v-if="consentStatus == true">
			<view>
				<button type="default" @click="license">营业执照</button>
				<view style="width: 100px;margin: 0 auto;" v-if="license1 != ''">
					<image v-bind:src = "license1" style="width: 100px;height: 100px;"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">公司名称</text>
				<view class="con-list">
					<input placeholder="请填写公司名称" name="input" v-model="deptList.compName"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">纳税人识别号</text>
				<view class="con-list">
				<input placeholder="请填写纳税人识别号" name="input" v-model="deptList.payTaxesCard"></input>
				</view>
			</view>
			<view>
				<button type="default" @click="idUp">身份证正面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="idup != ''">
					<image v-bind:src = "idup" style="width: 100px;height: 100px;"></image>
				</view>
				<button type="default"  @click="idLow">身份证反面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="idlow != ''">
					<image v-bind:src = "idlow" style="width: 100px;height: 100px;"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">姓名</text>
				<view class="con-list">
					<input placeholder="请填写姓名" name="input" v-model="deptList.customerName"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">身份证号</text>
				<view class="con-list">
					<input placeholder="请填写身份证号" name="input"
						v-model="deptList.customerNumberCard"></input>
				</view>
			</view>
			<view>
				<button type="default"  @click="bankUp()">银行卡正面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="bank1 != ''">
					<image v-bind:src = "bank1" style="width: 100px;height: 100px;"></image>
				</view>
				<button type="default" @click="bankLow()">银行卡反面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="bank2 != ''">
					<image v-bind:src = "bank2" style="width: 100px;height: 100px;"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">银行卡号</text>
				<view class="con-list">
					<input placeholder="请填写银行卡号" name="input" v-model="deptList.bankCard"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">开户行</text>
				<view class="con-list">
				<input placeholder="请填写开户行" name="input" v-model="deptList.bankDeposit"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">开户支行</text>
				<view class="con-list">
				<input placeholder="请填写开户支行" name="input"
					v-model="deptList.bankDepositBranch"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">手机号</text>
				<view class="con-list">
						<input placeholder="请填写手机号" @input='phoneinput' v-model="deptList.customerPhone"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">公司地址</text>
				<view class="con-list">
					<input placeholder="请填写公司地址" name="input" v-model="deptList.compAddress"></input>
				</view>
			</view>
		</view>
		<view v-else>
			<view>
				<button type="default" @click="idUp">上传身份证正面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="idup != ''">
					<image v-bind:src = "idup" style="width: 100px;height: 100px;"></image>
				</view>
				<button type="default" @click="idLow">上传身份证反面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="idlow != ''">
					<image v-bind:src = "idlow" style="width: 100px;height: 100px;"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">姓名</text>
				<view class="con-list">
					<input placeholder="请填写姓名" name="input" v-model="deptList.customerName"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">身份证号</text>
				<view class="con-list">
					<input placeholder="请填写身份证号" name="input"
						v-model="deptList.customerNumberCard"></input>
				</view>
			</view>
			<view>
				<button type="default" @click="bankUp()">上传银行卡正面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="bank1 != ''">
					<image v-bind:src = "bank1" style="width: 100px;height: 100px;"></image>
				</view>
				<button type="default" @click="bankLow()">上传银行卡反面</button>
				<view style="width: 100px;margin: 0 auto;" v-if="bank2 != ''">
					<image v-bind:src = "bank2" style="width: 100px;height: 100px;"></image>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">银行卡号</text>
				<view class="con-list">
					<input placeholder="请填写银行卡号" name="input" v-model="deptList.bankCard"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">开户行</text>
				<view class="con-list">
					<input placeholder="请填写开户行" name="input" v-model="deptList.bankDeposit"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">开户支行</text>
				<view class="con-list">
					<input placeholder="请填写开户支行" name="input"
						v-model="deptList.bankDepositBranch"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">收款人姓名</text>
				<view class="con-list">
					<input placeholder="请填写收款人姓名" name="input" v-model="deptList.payeeName"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">收款人身份证号</text>
				<view class="con-list">
					<input placeholder="请填写收款身份证号" name="input"
						v-model="deptList.payeeNumberCard"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">手机号</text>
				<view class="con-list">
				<input placeholder="请填写手机号" @input='phoneinput' v-model="deptList.customerPhone"></input>
				</view>
			</view>
			<view class="c-row b-b">
				<text class="tit">联系地址</text>
				<view class="con-list">
					<input placeholder="请填写联系地址" name="input" v-model="deptList.compAddress"></input>
				</view>
			</view>
		
		</view>
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-red margin-tb-sm lg" @click="commitEdit">修改</button>
		</view>
	</view>
</template>

<script>
	import {
	    mapState 
	} from 'vuex';
	export default {
		name: "buy",
		data() {
			return {
				radios: 2,
				deptList:{
					compName:"",
					payTaxesCard:"",
				},
				consentStatus:true,
				consentStatus1:false,
				parameter:{},
				businessman:{},
				id:[],
				idup:"",
				idlow:"",
				license1:"",
				bank1:"",
				bank2:"",
				bankid:[],
				payeeAddress:[],
				commitEdits:{}
			};
		},
		onLoad(option) {
			this.parameter.id = option.id,
			this.getList()
		},
		computed: {
			...mapState(['hasLogin','userInfo'])
		},
		methods: {
			commitEdit(item){
				console.log(this.deptList.compName,"公司名称")
				this.deptList.commonId = this.userInfo.id
				this.deptList.cardAddressUrl = this.id.toString()
				this.deptList.payeeAddressUrl = this.bankid.toString()
				if(this.consentStatus1 == true){
					this.deptList.customerTypeFlag = "个人"
				}else if(this.consentStatus == true){
					this.deptList.customerTypeFlag = "企业"
				}
				// console.log(this.deptList,"编辑对象")
				this.$api.doRequest('post', '/identityAuthenticationInfo/api/editIdentityAuthenticationInfo', this.deptList, 'application/json;charset=UTF-8').then(res => {
						console.log("成功连接")
						if (!this.deptList.goodsName) {
							this.$api.msg('修改成功！')
							
							return
						}
						uni.navigateTo({
							url: `/pages/attestation/index`
						})
					
					})
					.catch(res => {
						uni.showToast({
							title: res.errmsg,
							icon: 'none',
							duration: 2000
						})
					});
				
				
				},
				license() {
					var that = this
					wx.chooseImage({
						success: function(res) {
							wx.uploadFile({
								url: 'https://www.zthymaoyi.com/upload/admin',
								filePath: res.tempFilePaths[0],
								name: 'file',
								success(res) {
									var data = res.data
									var strToObj = JSON.parse(data)			
									that.deptList.businessLicenseAddressUrl = strToObj.url
									that.license1 = strToObj.url
								}
							})
						}
					})
				},
				idUp(){
					var that = this
					wx.chooseImage({
						success: function(res) {
							wx.uploadFile({
								url: 'https://www.zthymaoyi.com/upload/admin',
								filePath: res.tempFilePaths[0],
								name: 'file',
								success(res) {
									var data = res.data
									var strToObj = JSON.parse(data)			
									that.id[0] = strToObj.url
									that.idup = strToObj.url
								}
							})
						}
					})
				},
				idLow(){
					var that = this
					wx.chooseImage({
						success: function(res) {
							wx.uploadFile({
								url: 'https://www.zthymaoyi.com/upload/admin',
								filePath: res.tempFilePaths[0],
								name: 'file',
								success(res) {
									var data = res.data
									var strToObj = JSON.parse(data)			
									that.id[1] = strToObj.url
									that.idlow = strToObj.url
								}
							})
						}
					})
				},
				bankUp(){
					var that = this
					wx.chooseImage({
						success: function(res) {
							wx.uploadFile({
								url: 'https://www.zthymaoyi.com/upload/admin',
								filePath: res.tempFilePaths[0],
								name: 'file',
								success(res) {
									var data = res.data
									var strToObj = JSON.parse(data)			
									that.bankid[0] = strToObj.url
									that.bank1 = strToObj.url
								}
							})
						}
					})
				},
				bankLow(){
					var that = this
					wx.chooseImage({
						success: function(res) {
							wx.uploadFile({
								url: 'https://www.zthymaoyi.com/upload/admin',
								filePath: res.tempFilePaths[0],
								name: 'file',
								success(res) {
									var data = res.data
									var strToObj = JSON.parse(data)			
									that.bankid[1] = strToObj.url
									that.bank2 = strToObj.url
								}
							})
						}
					})
				},
			getList(ids) {		
					this.$api.doRequest('get', '/identityAuthenticationInfo/api/getIdentityAuthenticationInfo', this.parameter, 'application/json;charset=UTF-8').then(res => {
							console.log("成功连接")
				
							this.deptList = res.data.data
					console.log(this.deptList)
							if(this.deptList.businessLicenseAddressUrl != ""){
								this.license1 = this.deptList.businessLicenseAddressUrl
							}
							if(this.deptList.cardAddressUrl != ""){
								this.id = this.deptList.cardAddressUrl.split(",")
								this.idup = this.id[0]
								this.idlow = this.id[1]
							}
							if(this.deptList.payeeAddressUrl != ""){
								this.payeeAddress = this.deptList.payeeAddressUrl.split(","),
							this.bank1 = this.payeeAddress[0]
							this.bank2 = this.payeeAddress[1]
							}
		
						})
						.catch(res => {
							uni.showToast({
								title: res.errmsg,
								icon: 'none',
								duration: 2000
							})
						});
			},
			consent(){
				if(this.consentStatus == false && this.consentStatus1 == true){
					this.consentStatus = true
					this.consentStatus1 = false
				}else if(this.consentStatus == true && this.consentStatus1 == false){
					this.consentStatus = false
					this.consentStatus1 = true
				}
				
			},
			
		}
	}
</script>

<style>
	.center {
		padding: 10px 20px;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
	}

	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
		text-align: right;
		padding-right: 20rpx;
		font-size: 14px;
	}
</style>
