<template>
	<view>
		<form>
			
			<view class="padding-sm bg-white"></view>
			<view class="echo-article-title bg-white">
				普通公司升级为派遣公司
			</view>
			<view class="echo-article-meta bg-white">
				<view class="echo-article-meta-left">
					<text>提交升级信息后，需审核，请耐心等待。</text>
				</view>
			</view>
			<view class="padding-sm bg-white"></view>
			
			<view class="cu-form-group margin-top-sm">
				<view class="title">公司类型</view>
				<input class="text-gray" placeholder="请输入..." data-field="wtype" name="wtype" :value="workerinfo.wtype==1?'普通公司':'派遣公司'"
				 disabled="true"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">姓名</view>
				<input placeholder="请输入..." data-field="realname" name="realname" :value="workerinfo.realname" disabled="true"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">手机号</view>
				<input placeholder="请输入..." data-field="mobile" name="mobile" :value="workerinfo.mobile" disabled="true"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">公司名称</view>
				<input placeholder="请输入..." data-field="title" name="title" :value="workerinfo.title" disabled="true"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">微店名称</view>
				<input placeholder="请输入..." data-field="ftitle" name="ftitle" :value="workerinfo.ftitle" disabled="true"></input>
			</view>
			
			<view class="cu-bar bg-white margin-top">
				<view class="action">
					相关资质
				</view>
			</view>
			<view class="cu-form-group">
				<view class="grid col-3 grid-square flex-sub">
					<view class="bg-img solids" style="margin-bottom: 0rpx !important;" data-fieldimage="picone" @tap="chooseImage">
						<text v-if="workerinfo.picone==''" class='cuIcon-cameraadd'></text>
						<image v-else :src="workerinfo.picone" mode="aspectFill"></image>
					</view> 
					<view class="bg-img solids" style="margin-bottom: 0rpx !important;" data-fieldimage="pictwo" @tap="chooseImage">
						<text v-if="workerinfo.pictwo==''" class='cuIcon-cameraadd'></text>
						<image v-else :src="workerinfo.pictwo" mode="aspectFill"></image>
					</view> 
					<view class="bg-img solids" style="margin-bottom: 0rpx !important;" data-fieldimage="picthr" @tap="chooseImage">
						<text v-if="workerinfo.picthr==''" class='cuIcon-cameraadd'></text>
						<image v-else :src="workerinfo.picthr" mode="aspectFill"></image>
					</view> 
				</view>
			</view>
			<view class="cu-form-group" style="border-top: 0rpx; text-align: center;">
				<view class="grid col-3 flex-sub">
					<view>营业执照</view>
					<view>派遣许可证</view>
					<view>人力资源许可证</view>
				</view>
			</view>
			
			<view class="padding flex flex-direction">
				<button v-if="workerinfo.status==4" class="cu-btn bg-green margin-tb-sm lg" @tap="updateWorker">升级申请已提交，请耐心等待</button>
				<button v-if="workerinfo.status==5" class="cu-btn bg-green margin-tb-sm lg" @tap="updateWorker">立即提交升级</button>
			</view>
			<view class="padding"></view>
		</form>

	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				isRotate: false,
				workerinfo: false
			}
		},
		onLoad: function() {
			_this = this;
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
		},
		methods: {
			// 图片上传
			chooseImage: function(e) {
				var fieldimage = e.currentTarget.dataset.fieldimage;
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album'],
					success: (res) => {
						_this.$req.ajaxFile({
							path: "attachment/tplfieldimage",
							title: '正在上传',
							filePath: res.tempFilePaths[0],
							fileName: 'file',
						}).then((filedata) => {
							var data = JSON.parse(filedata.data);
							_this.workerinfo[fieldimage] = data.data.src;
						}).catch((err) => {
							uni.showModal({
								title: '信息提示',
								content: err,
								showCancel: false
							});
						});
					}
				});
			},

			// 提交修改
			updateWorker: function() {
				if (_this.isRotate) {
					return false;
				}
				_this.isRotate = true;
				_this.$req.ajax({
					path: "worker/updateworker",
					title: "正在提交修改",
					data: {
						id: _this.workerinfo.id,
						userid: _this.workerinfo.userid,
						picone: _this.workerinfo.picone,
						pictwo: _this.workerinfo.pictwo,
						picthr: _this.workerinfo.picthr
					}
				}).then((data) => {
					uni.setStorageSync('workerinfo', data.worker);
					uni.showModal({
						title: '信息提示',
						content: '升级信息提交成功，请耐心等待审核。',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								uni.redirectTo({
									url: "/pages/worker/worker"
								});
							}
						}
					});
					_this.isRotate = false;
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
					_this.isRotate = false;
				});
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(5em + 15px);
	}
	
	.cu-form-group input {
		text-align: right;
	}

	.fieldpic {
		width: 150rpx;
		height: 150rpx;
	}

	.fieldpictil {
		width: 230rpx;
		text-align: center;
	}
</style>
