<template>
	<view>
		
		<image class="echo-workerformpic" mode="widthFix" :src="param.workerformpic"></image>
		
		<view class="padding-xl"></view>
		<view class="cu-bar bg-white tabbar border shop foot">
			<view class="btn-group">
				<button class="cu-btn bg-red round shadow-blur" @tap="tabModal" style="width: 80%;">工厂招聘信息</button>
			</view>
		</view>
		
		<view class="cu-modal" :class="showform">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">信息内容</view>
					<view class="action" @tap="tabModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="bg-white margin-top-xs echo-workerform">
					<form>
						<view class="cu-form-group">
							<view class="title">企业名称</view>
							<input placeholder="请输入..." @input="bindInput" data-val="comname" :value="forminfo.comname"></input>
						</view>
						<view class="cu-form-group">
							<view class="title">企业住址</view>
							<input placeholder="请输入..." @input="bindInput" data-val="address" :value="forminfo.address"></input>
						</view>
						<view class="cu-form-group align-start">
							<view class="title">企业简介</view>
							<textarea maxlength="-1" placeholder="请输入..." data-val="details" name="details" :value="forminfo.details"
							 @input="bindInput"></textarea>
						</view>
						<view class="cu-form-group align-start">
							<view class="title">招聘岗位</view>
							<textarea maxlength="-1" placeholder="请输入..." data-val="comjobs" name="comjobs" :value="forminfo.comjobs"
							 @input="bindInput"></textarea>
						</view>
						<view class="cu-form-group">
							<view class="title">姓名</view>
							<input placeholder="请输入..." @input="bindInput" data-val="realname" :value="forminfo.realname"></input>
						</view>
						<view class="cu-form-group solids-bottom">
							<view class="title">手机号</view>
							<input placeholder="请输入..." @input="bindInput" data-val="mobile" :value="forminfo.mobile"></input>
						</view>
						<view class="padding-lr padding-top flex flex-direction">
							<button class="cu-btn bg-orange margin-tb-sm lg" @tap="addWorker">确认提交</button>
						</view>
					</form>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				userinfo: false,
				workerinfo: false,
				
				showform: '',
				param: {},
				isRotate: false,
				forminfo: {
					comname: "",
					address: "",
					details: "",
					realname: "",
					mobile: "",
					comjobs: ""
				}
			};
		},
		onLoad: function(){ 
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/my");
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.userinfo === false || _this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			
			_this.$req.ajax({
				path: "worker/pageform",
				data: {}
			}).then((data) => {
				_this.param = data.param;
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		methods: {
			addWorker: function() {
				if(_this.isRotate){
					return false;
				}
				_this.isRotate = true;
				_this.$req.ajax({
					path: "worker/addworker",
					data: {
						workerid: _this.workerinfo.id,
						comname: _this.forminfo.comname,
						address: _this.forminfo.address,
						details: _this.forminfo.details,
						realname: _this.forminfo.realname,
						mobile: _this.forminfo.mobile,
						comjobs: _this.forminfo.comjobs
					}
				}).then((data) => {
					uni.showModal({
						title: '信息提示',
						content: "信息提交成功。",
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								_this.forminfo = {
									comname: "",
									address: "",
									details: "",
									realname: "",
									mobile: "",
									comjobs: ""
								};
								_this.tabModal();
							}
						}
					});
					_this.isRotate = false;
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
					_this.isRotate = false;
				});
			},
			
			bindInput: function(e) {
				var dataval = e.currentTarget.dataset.val;
				_this.forminfo[dataval] = e.detail.value;
			},
			tabModal: function() {
				_this.showform = _this.showform=="show" ? "" : "show";
			}
		}
	}
</script>

<style>
	.echo-workerformpic{ width: 100%; display: block; }
	.echo-workerform view.title{ text-align: left !important; width: 25%; }
	.echo-workerform input{ text-align: left !important; width: 75%; }
	.echo-workerform textarea{ text-align: left !important; width: 75%; }
	
</style>

