﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="110px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24" v-if="JudgeShow('enCode')">
					<el-form-item label="报名编号" prop="enCode">
						<el-input v-model="dataForm.enCode" placeholder="系统自动生成" readonly :disabled="JudgeWrite('enCode')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('partnerId')">
					<el-form-item label="供应商信息" prop="partnerId">
						<el-select v-model="dataForm.partnerId" placeholder="请选择"  @visible-change="handlePartnerChange" clearable required :disabled="JudgeWrite('partnerId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in partnerIdOptions" :key="index" :label="item.F_Name" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('certificatesNumber')">
					<el-form-item label="统一信用代码" prop="certificatesNumber">
						<el-input v-model="dataForm.certificatesNumber" placeholder="请输入"  disabled :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('projectId')">
					<el-form-item label="招标项目" prop="projectId">
						<el-select v-model="dataForm.projectId" placeholder="请选择"  @visible-change="handleChange" clearable required :disabled="JudgeWrite('projectId')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in projectIdOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidsectionId')">
					<el-form-item label="标段(包)信息" prop="bidsectionId">
						<el-select v-model="dataForm.bidsectionId" placeholder="请选择" @visible-change="handleBidsectionChange" clearable required :disabled="JudgeWrite('bidsectionId')" :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in bidsectionIdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('inviteFileAmount')">
					<el-form-item label="招标文件售价" prop="inviteFileAmount">
						<el-input-number v-model="dataForm.inviteFileAmount" placeholder="数字文本" :precision="2"  disabled :step="1" >
						</el-input-number>
					</el-form-item>
				</el-col>
					<el-col :span="12" v-if="JudgeShow('enrollTime')">
					<el-form-item label="报名时间" prop="enrollTime">
						<el-date-picker v-model="dataForm.enrollTime" placeholder="请选择" clearable required :disabled="JudgeWrite('enrollTime')" :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="8" v-if="JudgeShow('lastHander')">
					<el-form-item label="联系人" prop="lastHander">
						<el-input v-model="dataForm.lastHander" placeholder="请输入" clearable required :disabled="JudgeWrite('lastHander')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8" v-if="JudgeShow('lastHanderPhone')">
					<el-form-item label="联系电话" prop="lastHanderPhone">
						<el-input v-model="dataForm.lastHanderPhone" placeholder="请输入" clearable required :disabled="JudgeWrite('lastHanderPhone')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8" v-if="JudgeShow('lastHanderEmail')">
					<el-form-item label="电子邮箱" prop="lastHanderEmail">
						<el-input v-model="dataForm.lastHanderEmail" placeholder="请输入" clearable required :disabled="JudgeWrite('lastHanderEmail')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('appendix')">
					<el-form-item label="报名资料" prop="appendix">
						<NCC-UploadFz v-model="dataForm.appendix" required :disabled="JudgeWrite('appendix')" :fileSize="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
					<el-col :span="12" v-if="JudgeShow('enrollAuditing')">
					<el-form-item label="报名费缴纳" prop="enrollAuditing">
						<el-radio-group v-model="dataForm.enrollAuditing" :disabled="JudgeWrite('enrollAuditing')" :style='{}' >
							<el-radio v-for="(item, index) in enrollAuditingOptions" :key="index" :label="item.id"  >{{item.fullName}}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('auditingTime')">
					<el-form-item label="缴纳时间" prop="auditingTime">
						<el-date-picker v-model="dataForm.auditingTime" placeholder="请选择" clearable :disabled="JudgeWrite('auditingTime')" :style='{"width":"100%"}' type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('remark')">
					<el-form-item label="备注" prop="remark">
						<el-input v-model="dataForm.remark" placeholder="请输入" :disabled="JudgeWrite('remark')" show-word-limit :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="创建人" prop="creatorUserId">
						<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly :disabled="JudgeWrite('creatorUserId')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="创建时间" prop="creatorTime">
						<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('creatorTime')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="修改人" prop="lastModifyUserId">
						<el-input v-model="dataForm.lastModifyUserId" placeholder="系统自动生成" readonly :disabled="JudgeWrite('lastModifyUserId')" >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<el-form-item label="修改时间" prop="lastModifyTime">
						<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly :disabled="JudgeWrite('lastModifyTime')" >
						</el-input>
					</el-form-item>
				</el-col>
            </el-form>
        </el-row>
        <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		data(){
			return {
				visible: false,
				setting:{},
				eventType: '',
				userBoxVisible:false,
				dataForm: {
					id:'',
					enCode:undefined,
					partnerId:undefined,
					certificatesNumber:undefined,
					projectId:undefined,
					enrollTime:undefined,
					inviteFileAmount:0.00,
					bidsectionId:undefined,
					lastHander:undefined,
					lastHanderPhone:undefined,
					lastHanderEmail:undefined,
					appendix:[],
					enrollAuditing:"0",
					auditingTime:undefined,
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					partnerId:[
						{
							required:true,
							message:'请输入供应商信息',
							trigger:'change'
						},
					],
					projectId:[
						{
							required:true,
							message:'请输入招标项目',
							trigger:'change'
						},
					],
					enrollTime:[
						{
							required:true,
							message:'请输入报名时间',
							trigger:'change'
						},
					],
					bidsectionId:[
						{
							required:true,
							message:'请输入标段(包)信息',
							trigger:'change'
						},
					],
					lastHander:[
						{
							required:true,
							message:'请输入联系人',
							trigger:'blur'
						},
					],
					lastHanderPhone:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					lastHanderEmail:[
						{
							required:true,
							message:'请输入电子邮箱',
							trigger:'blur'
						},
						{
							pattern:/^[a-z0-9]+([._\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/,
							message:'请输入正确的邮箱',
							trigger:'blur'
						},
					],
					appendix:[
						{
							required:true,
							message:'请上传报名资料',
							trigger:'click'
						},
					],
				},
				partnerIdOptions : [],
				projectIdOptions : [],
				bidsectionIdOptions:[],
				enrollAuditingOptions:[{"fullName":"否","id":"0"},{"fullName":"是","id":"1"}],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getpartnerIdOptions();
			this.getprojectIdOptions();
			this.getbidsectionIdOptions();
		},
		mounted() {},
		methods: {
			getpartnerIdOptions(){
				previewDataInterface('208733355913512197').then(res => {
					this.partnerIdOptions = res.data
				});
			},
			getprojectIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.projectIdOptions = res.data
				});
			},
			getbidsectionIdOptions(){
				previewDataInterface('211413979229062405').then(res => {
					this.bidsectionIdOptions = res.data
				});
			},
			goBack() {
                this.$emit('refresh')
            },
			init(data) {
				this.dataForm.id = data.id || 0;
                this.loading = true
				this.setting = data
				this.visible = true;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyZbwfBidenroll/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
							if(!this.dataForm.appendix)this.dataForm.appendix=[];
						})
					}
					else{
						this.dataForm.flowId = data.flowId
					}
					this.loading = false
					this.$emit('setPageLoad')
				})
			},
			handlePartnerChange() {
                // 项目Id
                if (this.dataForm.partnerId) {
					request({
						url: '/api/SubDev/ZyZbPartner/'+ this.dataForm.partnerId,
						method: 'get'
					}).then(res =>{
						this.dataForm.certificatesNumber = res.data.certificatesNumber;
					})
				}
            },
			handleChange() {
				  this.dataForm.bidsectionId="";
                // 项目Id
                if (this.dataForm.projectId) {
					request({
						url: '/api/SubDev/ZyZbwfProjectitem/Actions/GetProjectitem/' + this.dataForm.projectId,
						method: 'get'
					}).then(res =>{
						this.bidsectionIdOptions = res.data.zyZbBidsectionSelectorList;
					})
				}
            },
			handleBidsectionChange() {
				this.dataForm.inviteFileAmount ="";
                // 标段（包）Id
                // 标项Id
                if (this.dataForm.bidsectionId) {
					request({
						url: '/api/SubDev/ZyZbwfInvitebids/Actions/GetInvitebids/' + this.dataForm.bidsectionId,
						method: 'get'
					}).then(res =>{
						this.dataForm.inviteFileAmount = res.data.inviteFileAmount;
					})
				}
            },
			dataFormSubmit(eventType) {				
				this.$refs['elForm'].validate((valid) => {
					if (valid) {
						if (eventType === 'audit' || eventType === 'reject') {
            				this.$emit('eventReciver', this.dataForm, eventType)
            				return
          				}
						this.dataForm.flowState = eventType === 'submit' ? 0 : 1
						this.eventType = eventType
						if (this.eventType === 'submit') {
							this.$confirm('您确定要提交当前流程吗, 是否继续?', '提示', {
								type: 'warning'
							}).then(() => {
								this.request()
							}).catch(() => { });
						} else {
							this.request()
						}
					}
				})
			},
			request() {
				if (!this.dataForm.id) {
					delete (this.dataForm.id)
					request({
						url: '/api/SubDev/ZyZbwfBidenroll',
						method: 'post',
						data: this.dataForm
					}).then((res) => {
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false
								this.$emit('close', true)
							}
						})
					})
				}else{
					request({
						url: '/api/SubDev/ZyZbwfBidenroll/' + this.dataForm.id,
						method: 'PUT',
						data: this.dataForm
					}).then((res) => {
						this.$message({
							message: res.msg,
							type: 'success',
							duration: 1000,
							onClose: () => {
								this.visible = false
								this.$emit('close', true)
							}
						})
					})
				}
			},
			JudgeShow(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return true
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return item.read
			},
			JudgeWrite(id) {
				if (!this.setting.formOperates || !this.setting.formOperates.length) return false
				let arr = this.setting.formOperates.filter(o => o.id === id) || []
				if (!arr.length) return true
				let item = arr[0]
				return !item.write
			},
		}
	}
</script>

