<template>
	<view>
		<view class="box">
			<view class="top">
				<text class="title">企业注册</text>
			</view>
			<view class="item">
				<view class="l">企业名称：</view>
				<view class="r">
					<u-input v-model="form.name" placeholder="输入企业名称"/>
				</view>
			</view>
			<view class="item">
				<view class="l">联系人：</view>
				<view class="r">
					<u-input v-model="form.dutyPeople" placeholder="输入联系人"/>
				</view>
			</view>
			<view class="item">
				<view class="l">联系电话：</view>
				<view class="r">
					<u-input maxlength="11" v-model="form.phone" placeholder="输入电话号码"/>
				</view>
			</view>
			<view class="item">
				<view class="l">结算方式：</view>
				<view class="r">
					 <radio-group  @change="payChange">
						 <label class="radio"><radio value="2" checked/>月结</label>
						 <label class="radio" style="margin-left: 20rpx;"><radio value="1" />现结</label>
					 </radio-group>
				</view>
			</view>
		<!-- 	<view class="item">
				<view class="l">验证码：</view>
				<view class="r">
					<u-input placeholder="输入验证码"/>
					<view class="btn">发送</view>
				</view>
			</view> -->
			<view class="item">
				<view class="l">营业执照：</view>
				<view class="r">
					<view class="img">
						<u-upload max-count="1" ref="license" :file-list="imgList" :action="uploadImageUrl" width="300" height="200"></u-upload>
					</view>
				</view>
			</view>
		</view>
		<view class="common-btn" @click="confirm">确认注册</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				imgList:[],
				uploadImageUrl: request.server + '/upload/image',
				form:{
					name:'',
					dutyPeople:'',
					phone:'',
					payType:'2',
					businessLicence:''
				}
			}
		},
		methods: {
			payChange(e){
				this.form.payType=e.detail.value
			},
			check(){
				if(!this.form.name){
					this.$common.toast('请录入名称');
					return false;
				}
				if(!this.form.dutyPeople){
					this.$common.toast('请录入负责人');
					return false;
				}
				if(!this.form.phone){
					this.$common.toast('请录入联系号码');
					return false;
				}
				let licenseFiles = this.$refs.license.lists.filter(val => {
					return val.progress == 100;
				})
				if(licenseFiles.length==0){
					this.$common.toast('请上传营业执照');
					return false;
				}
				this.form.businessLicence= licenseFiles.map(obj => {
					if (obj.response) {
						return obj.response.data;
					} else if (obj.url) {
						return obj.url;
					}
				}).join(',');
				return true;
			},
			confirm(){
				if(this.check()){
					this.$api.register(this.form).then(resp=>{
						if(resp.code==200){
							this.$common.to('/pages/ok/registerSuccess')
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
	}
	@import '@/common/common.scss'
</style>
