﻿<template>
    <div>
        <el-row :gutter="15">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="medium" label-width="135px" label-position="right" :disabled="setting.readonly">
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="招标信息" :textStyle='{"color":"#767575","text-align":"center","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":32,"font-size":20}' :style='{"width":"100%"}' ></NCC-Text>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="项目信息" :textStyle='{"color":"#0395FE","text-align":"left","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":20,"font-size":16}' :style='{"width":"100%"}'></NCC-Text>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="false" >
					<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('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%"}' >
							<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('projectCode')">
					<el-form-item label="项目编号" prop="projectCode">
						<el-input v-model="dataForm.projectCode" placeholder="请输入"  disabled :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('biddingType')">
					<el-form-item label="招标方式" prop="biddingType">
						<el-input v-model="dataForm.biddingType" placeholder="请输入"  disabled :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidAmount')">
					<el-form-item label="项目金额" prop="bidAmount">
						<el-input-number v-model="dataForm.bidAmount" placeholder="数字文本" disabled  :precision="2" :style='{"width":"40%"}'>
						</el-input-number>元
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('lastHander')">
					<el-form-item label="项目负责人" prop="lastHander">
						<el-input v-model="dataForm.lastHander" placeholder="请输入"  disabled :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('desPersonName')">
					<el-form-item label="其他成员" prop="desPersonName">
						<el-input v-model="dataForm.desPersonName" placeholder="请输入"  disabled :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidsection')">
					<el-form-item label="项目标段" prop="bidsection">
						<el-select v-model="dataForm.bidsection" placeholder="请选择" clearable required @visible-change="handleBidsectionChange" :disabled="JudgeWrite('bidsection')" :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in bidsectionOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidsectionAmount')">
					<el-form-item label="预算金额" prop="bidsectionAmount">
						<el-input-number v-model="dataForm.bidsectionAmount" placeholder="数字文本"  disabled  :precision="2" :style='{"width":"40%"}'>
						</el-input-number>元
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label-width="0">
						<NCC-Text value="招标信息" :textStyle='{"color":"#0395FE","text-align":"left","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":20,"font-size":16}' :style='{"width":"100%"}' ></NCC-Text>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('inviteStartTime')">
					<el-form-item label="标书出售开始时间" prop="inviteStartTime">
						<el-date-picker v-model="dataForm.inviteStartTime" placeholder="请选择" clearable required :disabled="JudgeWrite('inviteStartTime')" :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="12" v-if="JudgeShow('inviteEndTime')">
					<el-form-item label="标书出售结束时间" prop="inviteEndTime">
						<el-date-picker v-model="dataForm.inviteEndTime" placeholder="请选择" clearable required :disabled="JudgeWrite('inviteEndTime')" :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="12" v-if="JudgeShow('inviteFileAmount')">
					<el-form-item label="标书售价" prop="inviteFileAmount">
						<el-input-number v-model="dataForm.inviteFileAmount" placeholder="数字文本" required :disabled="JudgeWrite('inviteFileAmount')" :step="100" :precision="2" :style='{"width":"40%"}'>
						</el-input-number>元
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidBond')">
					<el-form-item label="投标保证金" prop="bidBond">
						<el-input-number v-model="dataForm.bidBond" placeholder="数字文本" required :disabled="JudgeWrite('bidBond')" :step="100" :precision="2" :style='{"width":"40%"}'>
						</el-input-number>元
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('bidStartTime')">
					<el-form-item label="投标截止时间" prop="bidStartTime">
						<el-date-picker v-model="dataForm.bidStartTime" placeholder="请选择" clearable required :disabled="JudgeWrite('bidStartTime')" :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="12" v-if="JudgeShow('bidServicefee')">
					<el-form-item label="招标服务费" prop="bidServicefee">
						<el-input-number v-model="dataForm.bidServicefee" placeholder="数字文本" required :disabled="JudgeWrite('bidServicefee')" :step="100" :precision="2" :style='{"width":"40%"}'>
						</el-input-number>元
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('bidPlace')">
					<el-form-item label="开标地点" prop="bidPlace">
						<el-input v-model="dataForm.bidPlace" placeholder="请输入" clearable required :disabled="JudgeWrite('bidPlace')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('inviteHander')">
					<el-form-item label="联系人" prop="inviteHander">
						<el-input v-model="dataForm.inviteHander" placeholder="请输入" clearable required :disabled="JudgeWrite('inviteHander')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('inviteHanderPhone')">
					<el-form-item label="联系电话" prop="inviteHanderPhone">
						<el-input v-model="dataForm.inviteHanderPhone" placeholder="请输入" clearable required :disabled="JudgeWrite('inviteHanderPhone')" :style='{"width":"100%"}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('noticeAppendix')">
					<el-form-item label="公告附件" prop="noticeAppendix">
						<NCC-UploadFz v-model="dataForm.noticeAppendix" :disabled="JudgeWrite('noticeAppendix')" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('inviteFile')">
					<el-form-item label="招标文件" prop="inviteFile">
						<NCC-UploadFz v-model="dataForm.inviteFile" required :disabled="JudgeWrite('inviteFile')" :fileSize="2" sizeUnit="MB" :limit="9" buttonText="点击上传" >
						</NCC-UploadFz>
					</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="6" 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="6" 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="6" 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="6" 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,
					projectId:undefined,
					projectCode:undefined,
					biddingType:undefined,
					bidAmount:0,
					lastHander:undefined,
					desPersonName:undefined,
					bidsection:undefined,
					bidsectionAmount:0,
					inviteStartTime:undefined,
					inviteEndTime:undefined,
					inviteFileAmount:0,
					bidBond:0,
					bidStartTime:undefined,
					bidServicefee:0,
					bidPlace:undefined,
					inviteHander:undefined,
					inviteHanderPhone:undefined,
					noticeAppendix:[],
					inviteFile:[],
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					projectId:[
						{
							required:true,
							message:'请输入招标项目',
							trigger:'change'
						},
					],
					bidsection:[
						{
							required:true,
							message:'请输入项目标段',
							trigger:'change'
						},
					],
					inviteStartTime:[
						{
							required:true,
							message:'请输入标书出售开始时间',
							trigger:'change'
						},
					],
					inviteEndTime:[
						{
							required:true,
							message:'请输入标书出售结束时间',
							trigger:'change'
						},
					],
					inviteFileAmount:[
						{
							required:true,
							message:'请输入标书售价',
							trigger:["blur","change"]
						},
					],
					bidBond:[
						{
							required:true,
							message:'请输入投标保证金',
							trigger:["blur","change"]
						},
					],
					bidStartTime:[
						{
							required:true,
							message:'请输入投标截止时间',
							trigger:'change'
						},
					],
					bidServicefee:[
						{
							required:true,
							message:'请输入招标服务费',
							trigger:["blur","change"]
						},
					],
					bidPlace:[
						{
							required:true,
							message:'请输入开标地点',
							trigger:'blur'
						},
					],
					inviteHander:[
						{
							required:true,
							message:'请输入联系人',
							trigger:'blur'
						},
					],
					inviteHanderPhone:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					inviteFile:[
						{
							required:true,
							message:'请上传招标文件',
							trigger:'click'
						},
					],
				},
				projectIdOptions : [],
				bidsectionOptions:[],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getprojectIdOptions();
			this.getbidsectionOptions();
		},
		mounted() {},
		methods: {
			getprojectIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.projectIdOptions = res.data
				});
			},
			getbidsectionOptions(){
				request({
					url: '/api/SubDev/ZyZbwfProjectitem/Actions/GetBidsection/' + this.dataForm.bidsection,
					method: 'get'
				 }).then(res =>{
					this.bidsectionOptions = res.data;
				})
			},
			goBack() {
                this.$emit('refresh')
            },
			handleChange() {
				this.dataForm.bidsection="";
                // 项目Id
                if (this.dataForm.projectId) {
					request({
						url: '/api/SubDev/ZyZbwfProjectitem/Actions/GetProjectitem/' + this.dataForm.projectId,
						method: 'get'
					}).then(res =>{
						this.dataForm.biddingType = res.data.biddingType;
						this.dataForm.projectCode = res.data.enCode;
						this.dataForm.lastHander=res.data.desPerson;
						this.dataForm.approveTime = res.data.approveTime;
						this.dataForm.bidAmount = res.data.budget;
						this.dataForm.desPersonName=res.data.desPersonName;
						this.bidsectionOptions = res.data.zyZbBidsectionSelectorList;
					})
				}
            },
			handleBidsectionChange() {
                // 标段（包）Id
                if (this.dataForm.bidsection) {
					request({
						url: '/api/SubDev/ZyZbwfProjectitem/Actions/GetBidsection/' + this.dataForm.bidsection,
						method: 'get'
					}).then(res =>{
						this.dataForm.bidsectionAmount = res.data.budgetAmount;
					})
				}
            },
			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/ZyZbwfInvitebids/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						  if(!this.dataForm.noticeAppendix)this.dataForm.noticeAppendix=[];
						  if(!this.dataForm.inviteFile)this.dataForm.inviteFile=[];
						})
					}
					else{
						this.dataForm.flowId = data.flowId
					}
					this.loading = false
					this.$emit('setPageLoad')
				})
			},
			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/ZyZbwfInvitebids',
						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/ZyZbwfInvitebids/' + 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>

