<template>
	<view class="content">
		<view class="theform">
			<u--form labelPosition="left" :model="dataForm" :rules="rules" ref="uForm">
				<u-form-item v-if="ifupYy || dataForm.approveStatus == 4" required label-width="180rpx"
					:label="'审核状态'" prop="licenseName" ref="item1">
					<u--input :disabled="true" :placeholder="'请输入'" v-model="dataForm.approveStatusVal"
						disabledColor="#F5F5F5;"></u--input>
				</u-form-item>
				<u-form-item v-if="ifupYy || dataForm.approveStatus == 4" required label-width="180rpx"
					:label="'驳回原因'" prop="rejectMsg" ref="item1">
					<u--textarea :disabled="true" :placeholder="'请输入'" v-model="dataForm.rejectMsg"
						disabledColor="#F5F5F5;"></u--textarea>
				</u-form-item>
				<u-form-item required label-width="180rpx" :label="'营业执照名称'" prop="licenseName" ref="item1">
					<u--input :disabled="ifupYy"
          maxlength="100"
          :placeholder="'请输入'" v-model="dataForm.licenseName"
						disabledColor="#F5F5F5;"></u--input>
				</u-form-item>


				<u-form-item required label-width="180rpx" :label="'统一社会信用代码'" prop="creditCode" ref="item1">
					<u--input :disabled="ifupYy" 
          maxlength="100"
          :placeholder="'请输入'" v-model="dataForm.creditCode"
						disabledColor="#F5F5F5;"></u--input>
				</u-form-item>

				<u-form-item required label-width="180rpx" :label="'法人姓名'" prop="legalName" ref="item1">
					<u--input :disabled="ifupYy" :placeholder="'请输入'" v-model="dataForm.legalName"
						disabledColor="#F5F5F5;"></u--input>
				</u-form-item>

				<u-form-item required @click="getDiqu" :label="'所在地区'" label-width="180rpx" prop="theaddress">
					<u--input :disabled="ifupYy" v-model="dataForm.theaddress" readonly suffixIcon="arrow-right"
						disabledColor="#ffffff" :placeholder="'请选择'">
					</u--input>
				</u-form-item>

				<view class="view-class">
					<u-form-item required :label="'详细地址'" class="label-style" label-width="180rpx"
						prop="licenseAddress">
						<u-textarea :disabled="ifupYy" v-model="dataForm.licenseAddress" placeholder-class="place-class"
							class="border-color" :placeholder="'请输入'" />

					</u-form-item>
				</view>


				<u-form-item required label-width="180rpx" :label="'营业执照'">
					<uploadImg :ifdisabled="ifupYy" :ifsfz='true' @imageUploaded='imageUploaded' prop="licenseImage"
						style="margin-right: 30rpx;"
						:twidth="twidth"
						:theight="theight"
						:bgimg="`${dataForm.licenseImage||'../../../static/images/upload.png'}`"
						v-model="dataForm.licenseImage"></uploadImg>

				</u-form-item>

			</u--form>

		</view>
		<view class="btnbox">
			<u-button :disabled="ifupYy" class="subbtn" @click="submit">{{'确定'}}</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
		<v-address ref="address" @getAddressData="AddressData" :defaultCode="defaultCode"
			@addressData="addressData"></v-address>
	</view>
</template>

<script>
	import * as bal from "@/config/balance.js"
	import address from '@/components/address.vue'
	import uploadImg from '@/components/uploadImg.vue'
	export default {
		components: {
			'v-address': address,
			uploadImg
		},
		data() {
			return {
				showAmount: false,
				showCtype: false,
				theight:"288rpx",
				twidth:"520rpx",
				dataForm: {
					licenseName: "",
					creditCode: "",
					legalName: "",
					theaddress: "",
					licenseAddress: "",
					licenseImage: "",

					licenseProvince: "",
					licenseCity: "",
					licenseCounty: "",

				},
				defaultCode: [],
				rules: {
					licenseName: [{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}],

					creditCode: [{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}],
					legalName: [{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}],
					licenseAddress: [{
						type: 'string',
						required: true,
						message: '请输入',
						trigger: ['blur', 'change']
					}],


					theaddress: [{
						type: 'string',
						required: true,
						message: '请选择',
						trigger: ['change']
					}],
					licenseImage: [{

						required: true,
						message: '请上传',

					}],
				},
				ifupYy: false
			}
		},
		onLoad() {
			this.getDetail()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},

		methods: {
			getDetail() {
				bal.getLicenseDetail().then(res => {
					if (res.code == 200) {
						if (res.data.approveStatus) {
							this.dataForm = res.data;
							this.dataForm.theaddress = res.data.province + '-' + res.data.city + (('-' + res.data
								.county) || "")
							if (this.dataForm.approveStatus == 4) {
								uni.$u.toast("请重新上传营业执照")
								this.ifupYy = false;
							} else {
								//上传后未被驳回 不可修改 只能查看
								this.ifupYy = true;
							}
						} else {
							//未上传
							this.ifupYy = false;
						}
					}
				})
			},
			imageUploaded(url) {
				this.dataForm.licenseImage = url
			},

			AddressData(name) {
				this.dataForm.theaddress = name
			},
			getDiqu() {
				this.$refs.address.setShow()
			},
			addressData(diqu, obj) {
				this.dataForm.theaddress = diqu
				this.dataForm.licenseProvince = obj.province
				this.dataForm.licenseCity = obj.city
				this.dataForm.licenseCounty = obj.county
				this.$forceUpdate()
			},
			submit() {
				this.$refs.uForm.validate().then(res => {
					if (this.dataForm.approveStatus == 4) {
						bal.updateLicense(this.dataForm).then(res => {
							if (res.code == 200) {
								uni.$u.toast(res.msg)
								setTimeout(() => {
									uni.navigateBack()
								}, 1500);

							} else {
								uni.$u.toast(res.msg)
							}
						})
					} else {
						bal.addLicense(this.dataForm).then(res => {
							if (res.code == 200) {
								uni.$u.toast(res.msg)
								setTimeout(() => {
									uni.navigateBack()
								}, 1500);

							} else {
								uni.$u.toast(res.msg)
							}
						})
					}
				}).catch(errors => {
					uni.$u.toast('校验失败')
					return false
				})
			},


		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-input--radius,
	.u-input--square {
		border-radius: 12rpx;
		// border:2rpx solid #cccccc;
	}

	.content {
		background: #F2F2F2;

		.uni-textarea {
			height: 100rpx;
		}

		.theform {
			margin-top: 6rpx;
			background: #FFFFFF;
			padding: 20rpx 23rpx 48rpx 23rpx;

			.contentye {
				font-size: 28rpx;
				margin-left: 200rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
			}

		}

		.btnbox {
			margin-top: 38rpx;
			padding: 0 20rpx;

			.subbtn {
				background: #005BAC;
				border-radius: 46rpx;
				font-size: 30rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		.getcodes {

			background: #2FBC42;
			border-radius: 38rpx;
			color: #fff;
		}


	}
</style>