<template>
	<view style="height: 100vh;">
		<image src="http://equiphappy.shs.broing.cn/assets/miniprogram/bg0.png" style="width: 100%; height:100vh;"
			mode=""></image>
		<view class="box" style="position: absolute;top:740rpx; padding: 32rpx;">
			<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">
				<u-form-item label="公司名称" labelWidth="200rpx" prop="userInfo.name" borderBottom ref="item1">


					<view>
						<u--input v-model="model1.userInfo.name1" @input="inputCorpName" placeholder="请输入公司名称"
							border="none"></u--input>
					</view>
					<!-- -->
					<view class="select_box" v-if="select">
						<view v-for="item in filterArr" >
							<view class="select_one" @click="mySelect">
								<rich-text ></rich-text>
							</view>
						</view>
					</view>
				</u-form-item>
				<u-form-item label="主营产品" labelWidth="200rpx" prop="userInfo.product_ids" borderBottom @click="goChoose"
					ref="item1">
					<u--input v-model="model1.userInfo.name" disabled placeholder="请选择主营产品" disabledColor="#ffffffeb"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="联系人" labelWidth="200rpx" prop="userInfo.contract_name" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.contract_name" placeholder="请输入联系人姓名" border="none"></u--input>
				</u-form-item>
				<u-form-item label="联系电话" labelWidth="200rpx" prop="userInfo.contract_mobile" borderBottom ref="item1">
					<u--input v-model="model1.userInfo.contract_mobile" placeholder="请输入联系人电话" border="none"></u--input>
				</u-form-item>
			</u--form>
			<view style="margin-top: 40rpx;">
				<u-button text="提交" type="primary" @click="submit"></u-button>
			</view>
		</view>
		<view class="font">
			合作加盟: {{kfPhone}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isSelect: '',
				select: false,
				kfPhone:'',
				filterArr: [],
				model1: {
					userInfo: {
						name: '',
						contract_mobile: ''
					}
				}
			}
		},
		onShow() {
			let pagearr = getCurrentPages(); //获取应用页面栈
			let currentPage = pagearr[pagearr.length - 1]; //获取当前页面信息
			console.log('option:', currentPage) //获取页面传递的信息
			this.model1.userInfo.product_ids = currentPage.$vm.category_id || ''
			this.model1.userInfo.name = currentPage.$vm.name || ''
			this.model1.userInfo.contract_mobile = uni.getStorageSync('phone')
			this.kfPhone = uni.getStorageSync('kfphone')
		},
		methods: {
			 // 修改企业名称
			    inputCorpName(e) {
					console.log(e);
			        this.isSelect= false
			            this.select= true
			        let value = e;
			        this.model1.userInfo.name1 = value
			            this.filterArr= []
			           
			        if (value == '') {
						this.filterArr = []
					}
			        // 获取企业
			        this.getCom(value)
			    },
			    getCom(value) {
			        // 调取企业接口
			        wx.showLoading({
			            title: '加载中',
			        })
			        uni.$u.http.post('/manager/common/tianyanchaSearch', {
			            word: value
			        }).then(r => {
			            wx.hideLoading()
			            if (r.code == 1) {
			                r.data.forEach((item, index) => {
			                    if (item.name.includes(value)) {
			                        this.filterArr =  [...this.data.filterArr, {
			                                filter_text: this.join(item.name, value),
			                                filter_name: item.name,
			                                filter_id: item.id,
			                                creditCode: item.creditCode
			                            }]
			                    }
			                });
			
			            }
			        })
			    },
			mySelect(e) {
				console.log(e);
				// 当前选中的值值
				console.log(e.currentTarget.dataset.name, "9999999999999");
				this.select=false
					this.isSelect= true //选择了公司
					this.model1.userInfo.name1 = e.currentTarget.dataset.name
				this.recordCom(e.currentTarget.dataset.name)
			},
			recordCom(value) {
				uni.$u.http.post('/manager/common/tianyanchaBaseinfo', {
					company_name: value
				}).then(r => {
					if (r.code == 1) {
						console.log('记录成功', r)
					}
				})
			},
			goChoose() {
				uni.navigateTo({
					url: '/pages/subPages/more?val=2'
				})
			},
			submit() {
				delete this.model1.userInfo.name1
				uni.$u.http.post('/api/user/company_join', this.model1.userInfo).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}

				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.select_box {
		background-color: #fff;
		padding: 0 20rpx;
		width: 100%;
		position: absolute;
		right: 0;
		top: 101%;
		z-index: 1;
		overflow: hidden;
		text-align: left;
		animation: myfirst 0.5s;
		font-size: 30rpx;
	}

	.select_one {
		padding-left: 20rpx;
		text-align: right;
		width: 100%;
		height: 60rpx;
		position: relative;
		line-height: 60rpx;
		border-bottom: 1px solid #efebeb;
	}

	.box {
		width: 82vw;
		border-radius: 16rpx;
		background: #ffffffeb;
		margin-left: 5%;
	}

	.font {
		position: absolute;
		bottom: 66rpx;
		
		width: 100%;
		text-align: center;
		color: #ffffffff;
		font-size: 40rpx;
		font-weight: 700;
		font-family: "Alibaba PuHuiTi";
		text-align: center;
		line-height: 44rpx;
		letter-spacing: 0.6rpx;
	}

	/deep/ .u-input {
		background: rgb(236, 238, 241) !important;
	}
</style>