<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1300px"
      @close="close"
      @keyup.enter.native=""
	  v-model="visible">
      <el-row>
        <el-col :span="24">
          <el-tabs>
              <el-form size="large" :model="inputForm" ref="inputForm" v-loading="loading"
                       label-width="180px" @submit.native.prevent>
                <el-divider content-position="left"><i class="el-icon-document"></i> 项目基本情况信息</el-divider>
                <el-row  :gutter="15">
                  <el-col :span="12">
                    <el-form-item label="项目名称" prop="name"
                                  :rules="[
                          {required: true, message:'项目名称不能为空', trigger:'blur'}
                 ]">
                      <el-input maxlength="64" :disabled="true" v-model="inputForm.name" placeholder="请输入项目名称" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="项目编号" prop="no"
                                  :rules="[
                          {required: true, message:'项目编号不能为空', trigger:'blur'}
                 ]">
                      <el-input :disabled="true" :desabled="true" v-model="inputForm.no" placeholder="请输入项目编号" clearable></el-input>
                    </el-form-item>
                  </el-col>

					<el-col :span="12">
						<el-form-item label="年份" prop="year"
									  :rules="[
                          {required: true, message:'年份不能为空', trigger:'blur'}
                 ]">
							<el-input size="large" :disabled="yearFlag" v-model="inputForm.year" placeholder="请输入年份" clearable></el-input>

						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="项目类型" prop="projectMould"
									  :rules="[
                          {required: true, message:'项目类型不能为空', trigger:'blur'}
                 ]">
							<el-select v-model="inputForm.projectMould" placeholder="请选择项目类型" clearable style="width: 100%;"  :disabled="projectMouldFlag">
								<el-option
									v-for="item in $dictUtils.getDictList('program_registered_type')"
									:key="item.value"
									:label="item.label"
									:value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>

                  <el-col :span="12">
                    <el-form-item label="评估目的" prop="assessmentObjective"
                                  :rules="[
                                  {required: true, message:'评估目的不能为空', trigger:'change'}
                 ]">
                      <el-input v-model="inputForm.assessmentObjective" :disabled="assessmentObjectiveFlag" placeholder="请输入评估目的" clearable></el-input>
                    </el-form-item>
                  </el-col>

                  <el-col :span="12">
                    <el-form-item label="评估基准日" prop="assessmentDate"
                                  :rules="[
                          {required: true, message:'评估基准日不能为空', trigger:'blur'}
                 ]">
                      <el-date-picker
						  disabled="assessmentDateFlag"
                        v-model="inputForm.assessmentDate"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="选择评估基准日"
                        style="width:100%"
                        placement="bottom-start"
                        clearable>
                      </el-date-picker>
                    </el-form-item>
                  </el-col>


                  <el-col :span="12">
                    <el-form-item label="评估对象" prop="assessmentObject"
                                  :rules="[
                          {required: true, message:'评估对象不能为空', trigger:'blur'}
                 ]">
                      <el-input v-model="inputForm.assessmentObject" :disabled="assessmentObjectFlag" placeholder="请输入评估对象" clearable></el-input>
                    </el-form-item>
                  </el-col>


                  <el-col :span="12">
                    <el-form-item label="评估范围" prop="assessmentRange"
                                  :rules="[
                          {required: true, message:'评估范围不能为空', trigger:'blur'}
                 ]">
                      <el-input v-model="inputForm.assessmentRange" :disabled="assessmentRangeFlag" placeholder="请输入评估范围" clearable></el-input>
                    </el-form-item>
                  </el-col>

				<el-col :span="12">
					<el-form-item label="项目负责人" prop="projectManager"
								  :rules="[
									  {required: true, message:'项目负责人不能为空', trigger:'blur'}
									]">
						<SelectUserTree
							ref="companyTree"
							size="large"
							:props="{
							  value: 'id',             // ID字段名
							  label: 'name',         // 显示名称
							  children: 'children'    // 子级字段名
							}"
							:url="`/system-server/sys/user/treeUserDataAllOffice?type=2`"
							:value="inputForm.projectManager"
							:clearable="true"
							:disabled="projectManagerFlag"
							:accordion="true"
							@getValue="(value) => {inputForm.projectManager=value}"/>
					</el-form-item>
				</el-col>

					<el-col :span="12">
						<el-form-item label="评估报告日" prop="evaluationReportDate"
									  :rules="[
                        {required: true, message:'评估报告日不能为空', trigger:'blur'}
                 ]">
							<el-date-picker
								style="width:100%;"
								v-model="inputForm.evaluationReportDate"
								disabled="evaluationReportDateFlag"
								type="date"
								placement="bottom-start"
								value-format="YYYY-MM-DD"
								placeholder="选择日期" clearable>
							</el-date-picker>
						</el-form-item>
					</el-col>

					<el-col :span="12" v-if="this.inputForm.reportType != 2">
						<el-form-item label="签字评估师1" prop="signatureEvaluatorFirst"
									  :rules=" [
                        {required: true, message:'签字评估师1不能为空', trigger:'blur'}
                        ]" >
							<UserSelect
								:readonly="true"
								:limit='1'
								:modelValue="inputForm.signatureEvaluatorFirst"
								:disabled="signatureEvaluatorFirstFlag"
								@update:modelValue='(value) => {inputForm.signatureEvaluatorFirst = value}'></UserSelect>
						</el-form-item>
					</el-col>


					<el-col :span="12" v-if="this.inputForm.reportType != 2">
						<el-form-item label="签字评估师2" prop="signatureEvaluatorSecond"
									  :rules=" [
                        {required: true, message:'签字评估师2不能为空', trigger:'blur'}
                        ]" >
							<UserSelect
								:readonly="true"
								:limit='1'
								:modelValue="inputForm.signatureEvaluatorSecond"
								:disabled="signatureEvaluatorSecondFlag"
								@update:modelValue='(value) => {inputForm.signatureEvaluatorSecond = value}'></UserSelect>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="废旧物资评估值(万元)" prop="waystEvaluation"
									  :rules="[
                 ]">
							<el-input-number
								v-model="inputForm.waystEvaluation"
								:disabled="feeFlag"
								controls-position="right"
								:controls="false"
								:max="999999999999999"
								style="width:100%;"
								:precision="2"
								placeholder="请填写废旧物资评估"
								:step="0.01"
								:min="0"
								clearable>
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="固定资产评估值(万元)" prop="fixedAssetsEvaluation"
									  :rules="[
                 ]">
							<el-input-number
								v-model="inputForm.fixedAssetsEvaluation"
								:disabled="feeFlag"
								controls-position="right"
								:controls="false"
								:max="999999999999999"
								style="width:100%;"
								:precision="2"
								placeholder="请填写固定资产评估"
								:step="0.01"
								:min="0"
								clearable>
							</el-input-number>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="净资产评估值(万元)" prop="netAssetsEvaluation"
									  :rules="[
                 ]">
							<el-input-number
								v-model="inputForm.netAssetsEvaluation"
								:disabled="feeFlag"
								controls-position="right"
								:controls="false"
								:max="999999999999999"
								style="width:100%;"
								:precision="2"
								placeholder="请填写净资产评估"
								:step="0.01"
								:min="0"
								clearable>
							</el-input-number>
							<!--                <el-input v-model="inputForm.netAssetsEvaluation" maxlength="64" placeholder="请填写净资产评估" @keyup.native="inputForm.netAssetsEvaluation = twoDecimalPlaces(inputForm.netAssetsEvaluation)"clearable></el-input>-->
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="租金评估(万元)" prop="rentEvaluation"
									  :rules="[
                 ]">
							<el-input-number
								v-model="inputForm.rentEvaluation"
								:disabled="feeFlag"
								controls-position="right"
								:controls="false"
								:max="999999999999999"
								style="width:100%;"
								:precision="2"
								placeholder="请填写租金评估"
								:step="0.01"
								:min="0"
								clearable>
							</el-input-number>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="报告收费(元)" prop="reportCharges"
									  :rules="[
                        {required: true, message:'报告收费不能为空', trigger:'blur'}
                 ]">
							<el-input-number
								v-model="inputForm.reportCharges"
								:disabled="reportChargesFlag"
								controls-position="right"
								:controls="false"
								:max="999999999999999"
								style="width:100%;"
								:precision="2"
								placeholder="请填写报告收费"
								:step="0.01"
								:min="0"
								clearable>
							</el-input-number>
						</el-form-item>
					</el-col>


					<el-col :span="12">
						<el-form-item label="是否开票" prop="isInvoice"
									  :rules="[
                        {required: true, message:'是否开票不能为空', trigger:'blur'}
                 ]">
							<el-radio-group v-model="inputForm.isInvoice">
								<el-radio v-for="item in $dictUtils.getDictList('yes_no')" :disabled="isInvoiceFlag" :label="item.value" :key="item.id">{{item.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="合同是否存档" prop="isContractArchive"
									  :rules="[
                        {required: true, message:'合同是否存档不能为空', trigger:'blur'}
                 ]">
							<el-radio-group v-model="inputForm.isContractArchive">
								<el-radio v-for="item in $dictUtils.getDictList('yes_no')" :label="item.value" :disabled="isContractArchiveFlag" :key="item.id">{{item.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="底稿是否归档" prop="isPapersArchive"
									  :rules="[
                        {required: true, message:'底稿是否归档不能为空', trigger:'blur'}
                 ]">
							<el-radio-group v-model="inputForm.isPapersArchive">
								<el-radio v-for="item in $dictUtils.getDictList('yes_no')" :label="item.value" :disabled="isPapersArchiveFlag" :key="item.id">{{item.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>



				</el-row>

              </el-form>

          </el-tabs>
        </el-col>
      </el-row>
		<template #footer>
			<span class="dialog-footer">
			  <el-button  @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>

    </el-dialog>
  </div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import SelectUserTree from '@/views/utils/treeUserSelect'
  import ProgramProjectListInfoService from '@/api/program/ProgramProjectListInfoService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        typeDictList: [],

		  yearFlag: false,
		  projectMouldFlag: false,
		  assessmentObjectiveFlag: false,
		  assessmentDateFlag: false,
		  assessmentObjectFlag: false,
		  assessmentRangeFlag: false,
		  projectManagerFlag: false,
		  evaluationReportDateFlag: false,
		  signatureEvaluatorFirstFlag: false,
		  signatureEvaluatorSecondFlag: false,

		  feeFlag: false,

		  reportChargesFlag: false,
		  isInvoiceFlag: false,
		  isContractArchiveFlag: false,
		  isPapersArchiveFlag: false,

        inputForm: {
          id: '', // 主键值（新增不传，修改必传）
          no: '', // 编号（新增不传，修改必传）
          projectMould: '', // 项目类型
          name: '', // 项目名称
          projectManager: '', // 项目经理
          assessmentObjective: '', // 评估目的
          assessmentDate: '', // 评估基准日
          assessmentObject: '', // 评估对象
          assessmentRange: '', // 评估范围

		  evaluationReportDate:'',	//评估报告日
			signatureEvaluatorFirst:'',	//签字评估师1
			signatureEvaluatorSecond:'',	//签字评估师2
			waystEvaluation:'',	//废旧物资评估值
			fixedAssetsEvaluation:'',	//固定资产评估值
			netAssetsEvaluation:'',	//净资产评估值
			rentEvaluation:'',	//租金评估
			reportCharges:'',	//报告收费
			isInvoice:'',	//是否开票
			isContractArchive:'',	//合同是否存档
			isPapersArchive:'',	//底稿是否存档
			year:'',	//年份,
			reportType: ''
        }
      }
    },
    programProjectListInfoService: null,
    created () {
      this.programProjectListInfoService = new ProgramProjectListInfoService()
    },
    components: {
      SelectUserTree,
		UserSelect
    },
    computed: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm = {
          id: '', // 主键值（新增不传，修改必传）
          no: '', // 编号（新增不传，修改必传）
          name: '', // 项目名称
          projectMould: '', // 项目类型
          projectManager: '', // 项目经理
          assessmentObjective: '', // 评估目的
          assessmentDate: '', // 评估基准日
          assessmentObject: '', // 评估对象
          assessmentRange: '', // 评估范围

			evaluationReportDate:'',	//评估报告日
			signatureEvaluatorFirst:'',	//签字评估师1
			signatureEvaluatorSecond:'',	//签字评估师2
			waystEvaluation:'',	//废旧物资评估值
			fixedAssetsEvaluation:'',	//固定资产评估值
		  netAssetsEvaluation:'',	//净资产评估值
		  rentEvaluation:'',	//租金评估
			reportCharges:'',	//报告收费
			isInvoice:'',	//是否开票
			isContractArchive:'',	//合同是否存档
			isPapersArchive:'',	//底稿是否存档
			year:'',	//年份
        }
        if (method === 'edit') {
          this.inputForm.id = id
          this.title = '补充项目数据'
        } else if (method === 'view') {
          this.inputForm.id = id
          this.title = '查看项目数据'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.programProjectListInfoService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
				if(data.reportType){
					this.inputForm.reportType = data.reportType
				}
              this.inputForm = JSON.parse(JSON.stringify(this.inputForm))

				if(data.year){
					this.yearFlag = true
				}
				if(data.projectMould){
					this.projectMouldFlag = true
				}
				if(data.assessmentObjective){
					this.assessmentObjectiveFlag = true
				}
				if(data.assessmentDate){
					this.assessmentDateFlag = true
				}
				if(data.assessmentObject){
					this.assessmentObjectFlag = true
				}
				if(data.assessmentRange){
					this.assessmentRangeFlag = true
				}
				if(data.projectManager){
					this.projectManagerFlag = true
				}
				if(data.evaluationReportDate){
					this.evaluationReportDateFlag = true
				}
				if(data.signatureEvaluatorFirst){
					this.signatureEvaluatorFirstFlag = true
				}
				if(data.signatureEvaluatorSecond){
					this.signatureEvaluatorSecondFlag = true
				}

				if(data.waystEvaluation){
					this.feeFlag = true
				}
				if(data.fixedAssetsEvaluation){
					this.feeFlag = true
				}
				if(data.netAssetsEvaluation){
					this.feeFlag = true
				}
				if(data.rentEvaluation){
					this.feeFlag = true
				}

				if(data.reportCharges){
					this.reportChargesFlag = true
				}
				if(data.isInvoice){
					this.isInvoiceFlag = true
				}
				if(data.isContractArchive){
					this.isContractArchiveFlag = true
				}
				if(data.isPapersArchive){
					this.isPapersArchiveFlag = true
				}

              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.programProjectListInfoService.supplementSave(this.inputForm).then((data) => {
              this.close()
              this.$message.success(data)
				this.$parent.refreshList()
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      close () {
        this.$refs.inputForm.resetFields()
        this.visible = false
        this.yearFlag = false
        this.projectMouldFlag = false
        this.assessmentObjectiveFlag = false
        this.assessmentDateFlag = false
        this.assessmentObjectFlag = false
        this.assessmentRangeFlag = false
        this.projectManagerFlag = false
        this.evaluationReportDateFlag = false
        this.signatureEvaluatorFirstFlag = false
        this.signatureEvaluatorSecondFlag = false
        this.feeFlag = false
        this.reportChargesFlag = false
        this.isInvoiceFlag = false
        this.isContractArchiveFlag = false
        this.isPapersArchiveFlag = false
      },

  }
  }
</script>
<style scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
  .el-divider__text {
    font-size: 16px;
    font-weight: bold;
  }
</style>
