<template>
	<view>
		<view>
			<view class="desc">
				<hs-input label="申请人" v-model="form.name" :disabled="true" />
			</view>
			<view class="desc">
				<hs-dept-select label="部门" v-model="form.department" :autofill="true" />
			</view>
			<view class="desc">
				<hs-dict-select label="使用形式" dictKey="hzl_seal_use_type" v-model="form.usA" />
			</view>
			<view class="desc">
				<hs-dict-select label="印章类型" dictKey="seal_type" v-model="form.usB" />
			</view>
			<view class="desc">
				<hs-dict-select label="使用地点" dictKey="hzl_seal_use_address" v-model="form.usE" />
			</view>
			<view class="desc" v-if="form.usA==='2'">
				<uni-row>
					<uni-col :span="7">
						<view class="desc" style="font-size: 25rpx;">
							用印开始时间
						</view>
					</uni-col>
					<uni-col :span="16">
						<view>
							<uni-datetime-picker type="date" :clear-icon="false" v-model="form.usFTime"
								@maskClick="maskClick" @change="onchange()" />
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="desc" v-if="form.usA==='2'">
				<uni-row>
					<uni-col :span=" 7">
						<view class="desc" style="font-size: 25rpx;">
							用印结束时间
						</view>
					</uni-col>
					<uni-col :span="16">
						<view>
							<uni-datetime-picker type="date" :clear-icon="false" v-model="form.usDTime"
								@maskClick="maskClick" @change="onchange()" />
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="desc" v-if="form.usA==='2'">
				<uni-row>
					<uni-col :span="5">
						<view class="desc" style="font-size: 25rpx;">
							归还时间
						</view>
					</uni-col>
					<uni-col :span="18">
						<view>
							<uni-datetime-picker type="date" :clear-icon="false" v-model="form.usJTime"
								@maskClick="maskClick" @change="onchange()" />
						</view>
					</uni-col>
				</uni-row>
			</view>
			<view class="desc">
				<hs-dict-select label="文件类型" dictKey="hzl_file_type" v-model="form.soG" />
			</view>
			<view class="desc">
				<hs-input label="文件名称" v-model="form.soH" model="textarea" />
			</view>
			<view class="desc">
				<hs-input label="文件份数" v-model="form.soI" />
			</view>
			<hs-photo label="文件预览照片" limit="10" v-model="form.photos"></hs-photo>
			<!-- 	<view class="desc">
				<uni-row>
					<uni-col :span="9">
						<view style="font-size: 25rpx;">
							纸质文件是否有签字
						</view>
					</uni-col>
					<uni-col :span="15">
						<view>
							<uni-row>
								<radio-group @change="radioChange2">
									<uni-col :span="12" v-for="(item, index) in radiolist2">
										<label :key="item.value">
											<radio color="rgb(55,186,189)" :value="item.value"
												:checked="index === current">
												{{item.value}}
											</radio>
										</label>
									</uni-col>
								</radio-group>
							</uni-row>
						</view>
					</uni-col>
				</uni-row>
			</view> -->
			<view class="desc">
				<hs-input label="申请原因" v-model="form.conclusion" model="textarea" />
			</view>
		</view>
		<u-gap height="70" bgColor="#ffffff"></u-gap>
		<view class="bottim_view">
			<view>
				<u-row>
					<u-col span="11">
						<u-button :disabled="isDisabled" class="btnDoPay" shape="circle" @click="submit"
							color="rgb(55,186,189)" text="提交"></u-button>
					</u-col>
				</u-row>
			</view>
		</view>
		<!-- 下一步选择人员弹窗 -->
		<uni-popup ref="popup" background-color="#fff">
			<view style="height: 800rpx;">
				<view class="desc">
					<uni-row>
						<uni-col :span="10">
							<view style="font-size: 40rpx;color: rgb(145, 145, 145);">
							</view>
						</uni-col>
						<uni-col :span="11">
							<view style="font-size: 40rpx;color: rgb(98, 98, 98);">
								下一步
							</view>
						</uni-col>
						<uni-col :span="3">
							<view @click="submitPass" style="font-size: 40rpx;color: rgb(55,186,189);">
								确认
							</view>
						</uni-col>
					</uni-row>
				</view>
				<view>
					<!--  -->
					<uni-row>
						<uni-col>
							<view style="padding: 15rpx 20rpx;">
								<uni-data-picker ref="picker" placeholder="请选择" :popup-title="selectTitle"
									:localdata="dataTree" v-model="hxForm.candidate" @change="nextApprovalChange">
								</uni-data-picker>
							</view>
						</uni-col>
					</uni-row>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 0,
				isDisabled: false,
				selectTitle: '',
				hxForm: {},
				pageType: '',
				searchGoodsName: '',
				dataTree: [],
				index: 0,
				sealTypes: ['公章', '合同专用章', '财务专用章', '携带外出办公', '其他'],
				deptConfig: {
					deptDatas: [],
					deptIndex: uni.getStorageSync('deptData'),
				},
				radiolist2: [{
						value: '否'
					},
					{
						value: '是'
					}
				],
				defaultDept: '',
				form: {
					isSign: '否'
				}
			}
		},
		onLoad() {
			//申请人初始化
			this.form.name = uni.getStorageSync("userInfo").nickName
		},
		methods: {
			radioChange2: function(evt) {
				this.form.isSign = evt.detail.value
			},
			async submit() {
				this.isDisabled = true
				setTimeout(() => {
					this.isDisabled = false
				}, 1000)
				//统一写入参数
				this.form.applyUserId = uni.getStorageSync('setUserName')
				this.form.applyUserName = uni.getStorageSync('userInfo').nickName
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/submitApply/useSeal',
					method: 'post',
					data: this.form,
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					this.dataTree = res.data.tree
					this.hxForm.taskId = res.data.taskId
					this.$refs.popup.open('bottom')
					this.selectTitle = "请选择" + this.dataTree[0].text
					this.isDisabled = false
				} else {
					this.$showModal(res.msg)
				}
				this.isDisabled = false
			},
			async submitPass() {
				if (!this.hxForm.candidate) {
					uni.showModal({
						content: '请选择' + this.dataTree[0].text,
						title: '提交失败',
						showCancel: false,
					})
				}
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/task/submit/candidate?taskId=' + this.hxForm.taskId +
						'&candidate=' + this.hxForm.candidate + '&applyUserName=' + this.hxForm.applyUserName,
					method: 'get',
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					uni.showModal({
						content: '已提交给审批人员',
						title: '提交成功',
						showCancel: false,
						success() {
							uni.navigateBack()
						}
					})
				} else {
					uni.showModal({
						content: res.msg,
						title: '提交失败',
						showCancel: false,
						success() {
							uni.navigateBack()
						}
					})
				}
			},
			nextApprovalChange(e) {
				// console.log('onchange:', e.detail.value[1].text);
				this.hxForm.applyUserName = e.detail.value[1].text
				this.hxForm.candidate = e.detail.value[1].value
			},
			maskClick(e) {},
			bindPickerChange: function(e) {
				this.index = e.detail.value
			},
		}
	}
</script>

<style lang="scss" scoped>
	.desc {
		padding: 10rpx 15rpx;
		color: #818181;
		font-size: 20rpx;
	}

	.pickerView {
		// align-items: flex-end;
		padding: 10rpx 20rpx;
		border: 1rpx #eeeeee solid;
	}

	.pickerText {
		font-size: 26rpx;
		color: #b1b1b1;
	}

	.bottim_view {
		padding: 5px 20px 30px;
		position: fixed;
		left: 0px;
		bottom: 0px;
		width: 100%;
		height: 40px;
		background-color: #ffffff;
	}
</style>