﻿<template>
	<transition name="el-zoom-in-center">
		<div class="NCC-preview-main">
			<div class="NCC-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="120px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24">
						<el-form-item label-width="0">
							<NCC-Text value="投标信息" :textStyle='{"color":"#000000","text-align":"center","font-weight":"bold","font-style":"normal","text-decoration":"none","line-height":34,"font-size":19}' :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" >
						<el-form-item label="信息编号" prop="enCode">
							<el-input v-model="dataForm.enCode" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="14" >
						<el-form-item label="招标项目" prop="projectId">
							<el-select v-model="dataForm.projectId" placeholder="请选择"  @visible-change="handleChange" clearable required :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="10" >
						<el-form-item label="标段（包号）" prop="bidsectionId">
							<el-select v-model="dataForm.bidsectionId" placeholder="请选择"  @visible-change="handleBidsectionChange" clearable required :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="24" >
						<el-form-item label="招标内容" prop="bidContent">
							{{dataForm.bidContent}}
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="投标截止时间" prop="bidTime">
							{{dataForm.bidTime| toDate("yyyy-MM-dd HH:mm")}}
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="预算金额(元)" prop="bidAmount">
							{{dataForm.bidAmount| currency('¥')}}
						</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" >
						<el-form-item label="供应商信息" prop="partnerId">
							<el-select v-model="dataForm.partnerId" placeholder="请选择" clearable required @visible-change="handlePartnerChange" :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" >
						<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" >
						<el-form-item label="投标联系人" prop="lastHander">
							<el-input v-model="dataForm.lastHander" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="联系电话" prop="lastHanderPhone">
							<el-input v-model="dataForm.lastHanderPhone" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="保证金缴纳日期" prop="bidBondTime">
							<el-date-picker v-model="dataForm.bidBondTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="保证金金额" prop="bidBond">
							<el-input-number v-model="dataForm.bidBond" placeholder="数字文本" :precision="2"  disabled >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="投标时间" prop="tenderingTime">
							<el-date-picker v-model="dataForm.tenderingTime" placeholder="请选择" clearable required :style='{"width":"100%"}' type='date' format="yyyy-MM-dd" value-format="timestamp" >
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12" >
						<el-form-item label="投标金额" prop="tenderingAmount">
							<el-input-number v-model="dataForm.tenderingAmount" placeholder="数字文本" :precision="2"  required :step="1000" >
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="投标标书" prop="appendix">
							<NCC-UploadFz v-model="dataForm.appendix" required showTip :fileSize="1" sizeUnit="GB" :limit="9" buttonText="点击上传" >
							</NCC-UploadFz>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" 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 >
							</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 >
							</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 >
							</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 >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					id:'',
					enCode:undefined,
					projectId:undefined,
					bidsectionId:undefined,
					bidContent:undefined,
					bidTime:undefined,
					bidAmount:undefined,
					partnerId:undefined,
					certificatesNumber:undefined,
					lastHander:undefined,
					lastHanderPhone:undefined,
					bidBondTime:undefined,
					bidBond:undefined,
					tenderingTime:undefined,
					tenderingAmount:0,
					appendix:[],
					remark:undefined,
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyUserId:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					projectId:[
						{
							required:true,
							message:'请输入招标项目',
							trigger:'change'
						},
					],
					bidsectionId:[
						{
							required:true,
							message:'请输入标段（包号）',
							trigger:'change'
						},
					],
					bidContent:[
						{
							required:true,
							message:'请输入招标内容',
							trigger:'blur'
						},
					],
					bidTime:[
						{
							required:true,
							message:'请输入投标截止时间',
							trigger:'change'
						},
					],
					partnerId:[
						{
							required:true,
							message:'请输入供应商信息',
							trigger:'change'
						},
					],
					lastHander:[
						{
							required:true,
							message:'请输入投标联系人',
							trigger:'blur'
						},
					],
					lastHanderPhone:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$/,
							message:'请输入正确的手机号码',
							trigger:'blur'
						},
					],
					bidBondTime:[
						{
							required:true,
							message:'请输入保证金缴纳日期',
							trigger:'change'
						},
					],
					tenderingTime:[
						{
							required:true,
							message:'请输入投标时间',
							trigger:'change'
						},
					],
					tenderingAmount:[
						{
							required:true,
							message:'请输入投标金额',
							trigger:["blur","change"]
						},
					],
					appendix:[
						{
							required:true,
							message:'请上传投标标书',
							trigger:'click'
						},
					],
				},
				projectIdOptions : [],
				bidsectionIdOptions:[],
				partnerIdOptions : [],
			}
		},
		computed: {},
        watch: {},
        created() {
			this.getprojectIdOptions();
			this.getpartnerIdOptions();
		},
		mounted() {
        },
		methods: {
			getprojectIdOptions(){
				previewDataInterface('210191934059185413').then(res => {
					this.projectIdOptions = res.data
				});
			},
			getpartnerIdOptions(){
				previewDataInterface('208733355913512197').then(res => {
					this.partnerIdOptions = res.data
				});
			},
			goBack() {
                this.$emit('refresh')
            },
		    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.bidContent ="";
				this.dataForm.bidTime="";
				this.dataForm.bidAmount="";
				this.dataForm.bidBond="";
                // 标段（包）Id
                if (this.dataForm.bidsectionId) {
					request({
						url: '/api/SubDev/ZyZbwfInvitebids/Actions/GetInvitebids/' + this.dataForm.bidsectionId,
						method: 'get'
					}).then(res =>{
						this.dataForm.bidContent = res.data.bidContent;
						this.dataForm.bidTime=res.data.bidTime;
						this.dataForm.bidAmount=res.data.bidAmount;
						this.dataForm.bidBond=res.data.bidBond;
					})
				}
            },
			handlePartnerChange() {
                // 项目Id
                if (this.dataForm.partnerId) {
					request({
						url: '/api/SubDev/ZyZbPartner/'+ this.dataForm.partnerId,
						method: 'get'
					}).then(res =>{
						this.dataForm.certificatesNumber = res.data.certificatesNumber;
					})
				}
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyZbwfTendering/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
								if(!this.dataForm.appendix)this.dataForm.appendix=[];
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyZbwfTendering`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyZbwfTendering/' + 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('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
