<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1400px"
      height="500px"
      @close="close"
      append-to-body
      v-model="visible">
<!--      <el-row>-->
<!--        <el-row>-->
			<el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
					 label-width="135px" @submit.native.prevent>

				<el-divider content-position="left"><i class="el-icon-document"></i> 项目信息</el-divider>
				<el-row  :gutter="0">
					<el-col :span="12">
						<el-form-item label="项目名称" prop="projectName"
									  :rules="[
                   ]">
							<el-input :disabled="true" v-model="inputForm.projectName" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="项目编号" prop="projectNumber"
									  :rules="[
                   ]">
							<el-input :disabled="true" v-model="inputForm.projectNumber" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="项目类别" prop="reportType"
									  :rules="[
                                 {required: true, message:'项目类别不能为空', trigger:'blur'}
                  ]">
							<el-select :disabled="true" v-model="inputForm.reportType" placeholder="请选择项目类别" clearable style="width: 100%;">
								<el-option
									v-for="item in $dictUtils.getDictList('program_engineering_consultation_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="projectManager"
									  :rules="[
                   ]">
							<el-input :disabled="true" v-model="inputForm.projectManager" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="创建人" prop="projectCreateByName"
									  :rules="[
                   ]">
							<el-input :disabled="true" v-model="inputForm.projectCreateByName" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="创建时间" prop="projectCreateTime"
									  :rules="[
                   ]">
							<el-input :disabled="true" v-model="inputForm.projectCreateTime" clearable></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-divider content-position="left"><i class="el-icon-document"></i> 质量复核信息</el-divider>
				<el-row  :gutter="0">
					<el-col :span="12">
						<el-form-item label="合同类别" prop="contractCategory" :rules="[]">
							<el-radio-group v-model="inputForm.contractCategory">
								<el-radio v-for="item in $dictUtils.getDictList('contract_amount_type')" :key="item.value" :label="item.value">{{item.label}}</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="inputForm.contractCategory === '1'">
						<el-form-item label="合同价(元)" prop="contractFee"
									  :rules="[

			   ]">
							<el-input v-model="inputForm.contractFee" placeholder="请输入合同价(元)" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="审核人员" prop="reviewBy"
									  :rules="[
										{required: true, message:'审核人员不能为空', trigger:'change'}
                   ]">
							<UserSelectSignatory style="width: 100%" ref="userSelect1"
												 :readonly="true" :limit='1' :modelValue="inputForm.reviewBy"
												 @update:modelValue='(value) => {inputForm.reviewBy = value}'></UserSelectSignatory>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="造价咨询营业收入(万元)" prop="ziXunShouRu"
									  :rules="[
									  	{ validator: ziXunShouRuRange, trigger: 'change' },
										{required: true, message: '造价咨询营业收入(万元)不能为空', trigger: 'blur'},
			   ]">
							<el-input
								v-on:input="inputForm.ziXunShouRu=inputForm.ziXunShouRu.replace(/[^\d.]/g,'')
							  .replace(/^\./g,'')
							  .replace(/\.{2,}/g,'.')
							  .replace('.','$#$').replace(/\./g,'').replace('$#$','.')
							  .replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
								v-model="inputForm.ziXunShouRu"
								controls-position="right"
								:controls="false"
								style="width:100%;"
								placeholder="请输入造价咨询营业收入(万元)"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="工作开始时间" prop="workStartDate" :rules="[
					  	{required: true, message: '工作开始时间不能为空', trigger: 'blur'},
					  	{ validator: validateDateRange, trigger: 'change' }
               ]">
							<el-date-picker
								style="width: 100%"
								v-model="inputForm.workStartDate"
								value-format="YYYY-MM-DD"
								placeholder="选择日期"
							>
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="工作结束时间" prop="workEndDate" :rules="[
					  	{required: true, message: '工作结束时间不能为空', trigger: 'blur'},
					  	{ validator: validateDateRange, trigger: 'change' }
               ]">
							<el-date-picker
								style="width: 100%"
								v-model="inputForm.workEndDate"
								value-format="YYYY-MM-DD"
								placeholder="选择日期"
							>
							</el-date-picker>
						</el-form-item>
					</el-col>
				</el-row>
				<div>
					<el-divider content-position="left"><i class="el-icon-document"></i>
						<span style="color:#f5222d;">*</span> 项目组成员(质量控制流程)
						<el-button size="default" style="margin-left: 20px" type="primary" @click="insertEvent('detail')" plain>
							新增
						</el-button>
					</el-divider>
					<el-row  :gutter="15" v-if="inputForm.projectLevel==='1'">
						<el-col :span="24">
							<vxe-table
								border
								show-footer
								show-overflow
								ref="detailTable"
								:key="detailKey"
								class="vxe-table-element"
								:data="inputForm.detailInfos"
								style="margin-left: 5em"
								highlight-current-row
								:edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
							>
								<vxe-table-column title="编号" field="index" width="80">
									<template v-slot="scope">
										{{ scope.$rowIndex + 1 }}
									</template>
								</vxe-table-column>
								<vxe-table-column field="memberName" title="成员名称" :edit-render="{}" show-overflow="title" :rules="[{required: true, message:'请选择用户', trigger:'blur'}]">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.memberName" @focus="userPullListForm(scope.$rowIndex)"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="userRole" title="角色" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.userRole" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="enrollCertNo" title="注册/资格证号" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.enrollCertNo" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="profession" title="专业" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.profession" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="content" title="本人负责内容" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.content" :disabled="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="opinion" title="审核意见" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.opinion" :disabled="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column title="操作" width="100">
									<template v-slot="scope">
										<el-button size="default" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'detail')" :disabled="true" v-if="scope.$rowIndex !== 0 ">删除</el-button>
									</template>
								</vxe-table-column>
							</vxe-table>
						</el-col>
					</el-row>
					<el-row  :gutter="15" v-else-if="inputForm.projectLevel==='2'">
						<el-col :span="24">
							<vxe-table
								border
								show-footer
								show-overflow
								ref="detailTable"
								:key="detailKey"
								class="vxe-table-element"
								:data="inputForm.detailInfos"
								style="margin-left: 5em"
								highlight-current-row
								:edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon:'_'}"
							>
								<vxe-table-column title="编号" field="index" width="80">
									<template v-slot="scope">
										{{ scope.$rowIndex + 1 }}
									</template>
								</vxe-table-column>
								<vxe-table-column field="memberName" title="成员名称" :edit-render="{}" show-overflow="title" :rules="[{required: true, message:'请选择用户', trigger:'blur'}]">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.memberName" @focus="userPullListForm(scope.$rowIndex)"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="userRole" title="角色" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.userRole" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="enrollCertNo" title="注册/资格证号" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.enrollCertNo" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="profession" title="专业" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.profession" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="content" title="本人负责内容" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.content" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column field="opinion" title="审核意见" :edit-render="{}" show-overflow="title">
									<template v-slot:edit="scope">
										<el-input v-model="scope.row.opinion" :readonly="true"></el-input>
									</template>
								</vxe-table-column>
								<vxe-table-column title="操作" width="100">
									<template v-slot="scope">
										<el-button size="default" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'detail')"  v-if="scope.$rowIndex !== 0 && scope.$rowIndex !== 1 ">删除</el-button>
									</template>
								</vxe-table-column>
							</vxe-table>
						</el-col>
					</el-row>
				</div>
				<UserPullFormNew ref="userPullFormNew" @getProgramForUser="getProgramForUser"></UserPullFormNew>
			</el-form >
			<el-divider content-position="left"><i class="el-icon-document"></i>
				<span>文件信息</span>
			</el-divider>
			<el-row  :gutter="0" >
				<el-col :span="24" >
					<vxe-table
						border
						show-overflow
						ref="clientTable"
						class="vxe-table-element"
						:row-config="{keyField: 'id'}"
						:column-config="{resizable: true}"
						:tree-config="{transform: true, expandAll: true}"
						:key="tableKey"
						:data="tableData">
						<vxe-column field="name" title="文件要求" width="240px" tree-node>
							<template #default="scope">
							<span style="font-weight: bold"
								  v-if="scope.row.parentId === '0'"
							>{{ scope.row.name }}
							</span>
								<span
									v-if="scope.row.parentId !== '0' && scope.row.mustFlag === 1"
								><span style="color: red;font-weight: bold">* </span>{{ scope.row.name }}
							</span>
								<span
									v-if="scope.row.parentId !== '0' && scope.row.mustFlag === 0"
								>{{ scope.row.name }}
							</span>
							</template>
						</vxe-column>
						<vxe-column field="attachmentName" title="文件描述/文件名称" show-overflow="false">
							<template #default="scope">
							<span
								v-if="scope.row.levelFlag === 2"
							>
								<span style="font-weight: bold">文件格式及大小：{{ scope.row.size }}</span>
								<br>
								<span>{{ scope.row.type }}</span>
							</span>
								<div v-if="ifName(scope.row) === true">
									<el-image
										style="width: 30px; height: 30px;padding-top: 4px;"
										:src="scope.row.lsUrl"
										:preview-src-list="[scope.row.lsUrl]"
										:preview-teleported="true"
									></el-image>
								</div>
								<div v-else>
									<el-link v-if="scope.row.levelFlag === 3"  type="primary" :underline="false" @click="showFile(scope.row)">{{scope.row.attachmentName}}</el-link>
								</div>
							</template>
						</vxe-column>
						<vxe-column field="workAttachmentType" width="100px" title="文件类型"></vxe-column>
						<vxe-column field="createDate" title="上传时间" width="100px"></vxe-column>
						<vxe-column field="fileSize" width="100px" title="文件大小(M)">
							<template #default="scope">
								{{getSize(scope.row.fileSize)}}
							</template>
						</vxe-column>

						<vxe-column
							title="操作"
							width="100px"
							fixed="right"
							align="center"
						>
							<template #default="scope">
								<el-button
									v-if="scope.row.levelFlag === 2"
									type="primary"
									size="small"
									:disabled="status === 'audit' ||status === 'taskFormDetail'|| method ==='view'"
									@click="openFileForm(scope.row.id,this.inputForm.id)"
								>编辑</el-button>
								<el-button
									v-if="scope.row.levelFlag === 3"
									type="info"
									size="small"
									@click="toHref(scope.row)" >下载</el-button>

							</template>
						</vxe-column>
					</vxe-table>
				</el-col>
			</el-row>
<!--        </el-row>-->
<!--      </el-row>-->
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button  v-if="method === 'edit'" type="primary" icon="el-icon-circle-check" @click="doSubmit('save')">确定</el-button>
			</span>
		</template>
		<FileForm ref="fileForm" @getFiles="getFiles"></FileForm>
    </el-dialog>
  </div>
</template>

<script>
	import OSSSerivce, {
		// eslint-disable-next-line no-unused-vars
		beforeAvatarUpload,
		// eslint-disable-next-line no-unused-vars
		openWindowOnUrl,
		// eslint-disable-next-line no-unused-vars
		toHref
	} from '@/api/sys/OSSService'
	import UserPullFormNew from '@/views/finance/invoice/UserPullFormNew'
	import UserSelectSignatory from '@/components/userSelectNew'
	import ReportReviewService from '@/api/cw/reportManagement/ReportReviewService'
	import projectReportService from '@/api/cw/reportManagement/ProjectReportService'
	import CommonApi from '@/api/cw/common/CommonApi'
  import FileForm from "./reportReview/FileForm";
  export default {
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      },
      status: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
		  detailKey: '',
        title: '',
        method: '',
        loading: false,
		  tableKey: '',
		  tableData: [],
		  validRules: {
			  memberName: [
				  {required: true, message: '成员名称不能为空'}
			  ],
			  enrollCertNo: [
				  {required: true, message: '注册/资格证号不能为空'}
			  ],
			  profession: [
				  {required: true, message: '专业不能为空'}
			  ],
			  content: [
				  {required: true, message: '本人负责内容不能为空'}
			  ],
			  opinion: [
				  {required: true, message: '审核意见不能为空'}
			  ],
		  },
		  inputForm: {
			  reviewByName: '',
			  reviewNewId: '',
			  projectLevel: '',
			  memberName: '',
			  enrollCertNo: '',
			  profession: '',
			  professionType: '',
			  projectName: '',
			  projectId: '',
			  projectNumber: '',
			  projectManager: '',
			  projectManagerId: '',
			  projectCreateByName: '',
			  projectCreateTime: '',
			  reviewFee: '',
			  approvalFee: '',
			  contractCategory: '',
			  contractFee: '',
			  contractRate: '',
			  reviewBy: '',
			  verifyFee: '',
			  verifyRate: '',
			  consultFee: '',
			  buildingFee: '',
			  installFee: '',
			  buildingRate: '',
			  installRate: '',
			  workStartDate: '',
			  workEndDate: '',
			  ziXunShouRu: '',
			  detailInfos: [],
			  createBy: {
				  id: '',
				  name: this.$store.state.user.name
			  },
		  },
        keyWatch: '',
        visible: false,
        tabName: ''
      }
    },
	  ReportReviewService: null,
	  commonApi: null,
    created () {
		this.reportReviewService = new ReportReviewService()
		this.commonApi = new CommonApi()
    },
    computed: {
      bus: {
        get () {
          return this.businessId
        },
        set (val) {
          this.businessId = val
        }
      }
    },
    watch: {
      'keyWatch': {
        handler (newVal) {
          if (this.commonJS.isNotEmpty(this.bus)) {
            this.init('', this.bus)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        }
      }
    },
    components: {
		FileForm,
		UserPullFormNew,
		UserSelectSignatory,
    },
    methods: {
      getKeyWatch (keyWatch) {
        this.keyWatch = keyWatch
      },
      init (method, id, tabName) {
        this.tabName = tabName
        this.visible = true
        if (method === 'edit') {
          this.title = '报告信息修改'
          this.method = method
        } else {
          this.title = '报告详情'
          this.method = 'view'
        }
        this.reportReviewService = new ReportReviewService()
        this.method = method
		  this.inputForm = {
			  reviewByName: '',
			  reviewNewId: '',
			  projectLevel: '',
			  memberName: '',
			  enrollCertNo: '',
			  profession: '',
			  professionType: '',
			  projectName: '',
			  projectId: '',
			  projectNumber: '',
			  projectManager: '',
			  projectManagerId: '',
			  projectCreateByName: '',
			  projectCreateTime: '',
			  reviewFee: '',
			  approvalFee: '',
			  contractCategory: '',
			  contractFee: '',
			  contractRate: '',
			  reviewBy: '',
			  verifyFee: '',
			  verifyRate: '',
			  consultFee: '',
			  buildingFee: '',
			  installFee: '',
			  buildingRate: '',
			  installRate: '',
			  workStartDate: '',
			  workEndDate: '',
			  ziXunShouRu: '',
			  detailInfos: [],
			  createBy: {
				  id: '',
				  name: this.$store.state.user.name
			  },
		  }
        this.inputForm.id = id
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.loading = true
			projectReportService.queryByIdNew(this.inputForm.id).then((data) => {
				this.inputForm = this.recover(this.inputForm, data)

				if (this.commonJS.isEmpty(this.inputForm.contractCategory)) {
					this.inputForm.contractCategory = '1'
				}

				// 根据证书类型  获取字典值
				let professionList = this.getProfessionList(this.inputForm.professionType)
				if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
					professionList.forEach(item => {
						if (item.value == this.inputForm.profession) {
							this.inputForm.profession = item.label
						}
					})
					let d = {
						memberName: this.inputForm.memberName,
						userId: this.inputForm.projectManagerId,
						userRole: '负责人',
						enrollCertNo: this.inputForm.enrollCertNo,
						profession: this.inputForm.profession,
					}
					this.inputForm.detailInfos = []
					this.inputForm.detailInfos.push(d)
					this.detailKey = Math.random()
				} else {
					this.reportReviewService.getUserInfo(this.inputForm.reviewBy).then((data) => {
						this.inputForm.detailInfos.forEach(item => {
							professionList = this.getProfessionList(item.professionType)
							professionList.forEach(item2 => {
								if (item.profession == item2.value) {
									item.profession = item2.label
								}
								if (item.userRole === '技术负责人') {
									item.memberName = data.memberName + '(' + this.inputForm.reviewByName + '代)'
								}
							})
						})
					})
				}

				projectReportService.getAttachmentList(data.projectId,this.inputForm.id,'').then((data) => {
					this.tableData = data
					this.tableKey = Math.random()
				})

				this.loading = false
			})
        })
      },
      // 表单提交
      doSubmit (status) {
		  if (status === 'save') {
			  this.$refs['inputForm'].validate((valid) => {
				  if (valid) {
					  // 暂存
					  this.loading = true

					  if (this.commonJS.isEmpty(this.inputForm.reviewBy)){
						  this.loading = false
						  this.$message.error('请选择下一节点审核人')
						  throw new Error()
					  }
					  if (this.commonJS.isEmpty(this.inputForm.workStartDate)){
						  this.loading = false
						  this.$message.error('请选择工作开始时间')
						  throw new Error()
					  }
					  if (this.commonJS.isEmpty(this.inputForm.workEndDate)){
						  this.loading = false
						  this.$message.error('请选择工作结束时间')
						  throw new Error()
					  }
					  if (this.commonJS.isEmpty(this.inputForm.detailInfos)){
						  this.loading = false
						  this.$message.error('至少选择一位项目组成员')
						  throw new Error()
					  }else {
						  let i = this.inputForm.detailInfos.length

						  if (this.inputForm.projectLevel === '1') {
							  if (i <= 1) {
								  this.loading = false
								  this.$message.error('请添加咨询员信息')
								  throw new Error('请添加咨询员信息')
							  }
						  } else if (this.inputForm.projectLevel === '2') {
							  if (i <= 1) {
								  this.loading = false
								  this.$message.error('请添加技术负责人信息')
								  throw new Error('请添加技术负责人信息')
							  } else if (i <= 2) {
								  this.loading = false
								  this.$message.error('请添加咨询员信息')
								  throw new Error('请添加咨询员信息')
							  }
						  }

						  for (let j = 0; j < i; j++) {
							  this.inputForm.detailInfos[j].detailNumber = j+1;
							  /*let k = j + 1
							  if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].memberName)){
								  this.loading = false
								  this.$message.error('项目组成员第'+k+'行成员名称为空')
								  throw new Error('项目组成员第'+k+'行成员名称为空')
							  }
							  if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].enrollCertNo)){
								  this.loading = false
								  this.$message.error('项目组成员第'+k+'行注册/资格证号为空')
								  throw new Error('项目组成员第'+k+'行注册/资格证号为空')
							  }
							  if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].profession)){
								  this.loading = false
								  this.$message.error('项目组成员第'+k+'行专业为空')
								  throw new Error('项目组成员第'+k+'行专业为空')
							  }
							  if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].content)){
								  this.loading = false
								  this.$message.error('项目组成员第'+k+'行本人负责内容为空')
								  throw new Error('项目组成员第'+k+'行本人负责内容为空')
							  }
							  if (this.commonJS.isEmpty(this.inputForm.detailInfos[j].opinion)){
								  this.loading = false
								  this.$message.error('项目组成员第'+k+'行审核意见为空')
								  throw new Error('项目组成员第'+k+'行审核意见为空')
							  }*/


						  }
					  }

					  this.tableData.forEach(item=>{
						  if (item.levelFlag === 2 && item.mustFlag === 1){
							  if (item.children.length === 0){
								  this.loading = false
								  this.$message.error(item.name + '文件未上传')
								  throw new Error(item.name + '文件未上传')
							  } else {
								  item.children.forEach(child => {
									  const fileExtension = child.attachmentName.split('.').pop(); // 获取文件后缀名
									  const supportedFileTypes = item.type.split(','); // 支持的文件类型数组
									  if (!supportedFileTypes.includes(fileExtension)) {
										  this.loading = false;
										  this.$message.error(child.attachmentName + ' 文件类型不受支持');
										  throw new Error(child.attachmentName + ' 文件类型不受支持');
									  }
								  });
							  }
						  }
					  })

					  this.reportReviewService.saveFormReviewNew(this.inputForm).then(() => {
						  this.$emit('refreshList')
						  this.close()
						  this.loading = false
					  }).catch(() => {
						  this.loading = false
					  })
				  }
			  })
			  return
		  }
      },
		close () {
			this.inputForm = {
				reviewByName: '',
				reviewNewId: '',
				projectLevel: '',
				memberName: '',
				enrollCertNo: '',
				profession: '',
				professionType: '',
				projectName: '',
				projectId: '',
				projectNumber: '',
				projectManager: '',
				projectManagerId: '',
				projectCreateByName: '',
				projectCreateTime: '',
				reviewFee: '',
				approvalFee: '',
				contractCategory: '',
				contractFee: '',
				contractRate: '',
				reviewBy: '',
				verifyFee: '',
				verifyRate: '',
				consultFee: '',
				buildingFee: '',
				installFee: '',
				buildingRate: '',
				installRate: '',
				workStartDate: '',
				workEndDate: '',
				ziXunShouRu: '',
				detailInfos: [],
				createBy: {
					id: '',
					name: this.$store.state.user.name
				},
			}
			this.$refs.inputForm.resetFields()
			this.visible = false
		},
		getProfessionList(type) {
			switch (type) {
				case '1':
				case '2':
					return this.$dictUtils.getDictList('sys_cert_profession_build');
				case '3':
				case '4':
					return this.$dictUtils.getDictList('sys_cert_profession_cost');
				case '5':
					return this.$dictUtils.getDictList('sys_cert_profession_supervision');
				case '6':
					return this.$dictUtils.getDictList('sys_cert_profession_accounting');
				default:
					return [];
			}
		},
		// 删除
		removeEvent (row, rowIndex, type) {
			if (type === 'detail') {
				this.$refs.detailTable.remove(row)
				this.inputForm.detailInfos.splice(rowIndex, 1)
			}
		},
		getFee() {
			//送审价
			var rf = this.inputForm.reviewFee
			//审定价
			var af = this.inputForm.approvalFee
			if (this.commonJS.isNotEmpty(rf) && rf !== '0.00' && this.commonJS.isNotEmpty(af) && af !== '0.00') {
				var hf = (af*100-rf*100)/100;
				var rate = parseFloat(hf) / parseFloat(rf) * 100
				this.inputForm.verifyFee = hf.toFixed(2)
				this.inputForm.verifyRate = rate.toFixed(2)
			}
			if (this.commonJS.isNotEmpty(af)) {
				this.inputForm.consultFee = af
			}

		},
		getApprovalFee() {
			//送审价
			var rf = this.inputForm.reviewFee
			//审定价
			var af = this.inputForm.approvalFee
			if(this.commonJS.isNotEmpty(rf) && rf != '0.00' && this.commonJS.isNotEmpty(af) && af !='0.00'){
				//计算审核增减额
				var hf = (af*100-rf*100)/100;
				var rate = parseFloat(hf) / parseFloat(rf) * 100
				this.inputForm.verifyFee = hf.toFixed(2)
				this.inputForm.verifyRate = rate.toFixed(2)
			}
			if(this.commonJS.isNotEmpty(af)){
				this.inputForm.consultFee = af
			}
			this.inputForm.buildingFee = ''
			this.inputForm.installFee = ''
			this.inputForm.buildingRate = ''
			this.inputForm.installRate = ''
		},
		getBuildingFee() {
			var af = this.inputForm.approvalFee
			//土建
			var bf = this.inputForm.buildingFee
			if(this.commonJS.isNotEmpty(bf) && this.commonJS.isNotEmpty(af)){
				var hf = parseInt(af)-parseInt(bf);
				var rate = Math.round(parseInt(bf) / parseInt(af) * 100) / 100 * 100
				this.inputForm.buildingRate = rate
				this.inputForm.installFee = hf
				var inRate = Math.round(parseInt(hf) / parseInt(af) * 100) / 100 * 100
				this.inputForm.installRate = inRate
			}
			if(this.commonJS.isEmpty(bf) || this.commonJS.isEmpty(af)){
				this.inputForm.buildingRate = ''
			}
		},
		getInstallFee() {
			var af = this.inputForm.approvalFee
			//安装
			var inf = this.inputForm.installFee
			if(this.commonJS.isNotEmpty(inf) && this.commonJS.isNotEmpty(af)){
				var hf = parseInt(af)-parseInt(inf);
				var rate = Math.round(parseInt(inf) / parseInt(af) * 100) / 100 * 100
				this.inputForm.installRate = rate
				this.inputForm.buildingFee = hf
				var bRate = Math.round(parseInt(hf) / parseInt(af) * 100) / 100 * 100
				this.inputForm.buildingRate = bRate
			}
			if(this.commonJS.isEmpty(inf) || this.commonJS.isEmpty(af)){
				this.inputForm.installRate = ''
			}
		},
		validateDateRange(rule, value, callback) {
			const workStartDate = this.inputForm.workStartDate;
			const workEndDate = this.inputForm.workEndDate;

			if (workStartDate && workEndDate && workStartDate > workEndDate) {
				this.inputForm.workEndDate = ''
				callback(new Error('工作开始时间不能大于工作结束时间'));
			} else {
				callback();
			}
		},
		ziXunShouRuRange(rule, value, callback) {
			if (!value || value.trim() === "") {
				callback(new Error('造价咨询营业收入不能为空！'));
			} else if (parseFloat(value) <= 0) {
				callback(new Error('造价咨询营业收入必须大于0！'));
			} else {
				callback();
			}
		},
		// 项目组成员下拉弹窗
		userPullListForm (rowIndex) {
			this.indexRow = rowIndex
			this.$refs.userPullFormNew.init()
		},
		ifName (row) {
			if (this.commonJS.isEmpty(row.attachmentName)) {
				row.attachmentName = '---'
				return false
			}
			let suffix = row.attachmentName.substring(row.attachmentName.lastIndexOf('.') + 1)
			if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
				return true
			} else {
				return false
			}
		},
		showFile (row) {
			row.name = row.attachmentName
			openWindowOnUrl(row)
		},
		getSize (value) {
			if (this.commonJS.isEmpty(value)) {
				return ''
			} else {
				let val = parseInt(value)
				let k = 1024
				let sizes = ['B', 'KB', 'MB', 'GB', 'PB', 'TB', 'EB', 'ZB', 'YB']
				let i = Math.floor(Math.log(val) / Math.log(k))
				let result = val / Math.pow(k, i);
				let kb = parseFloat(result.toPrecision(3));
				return kb + '' + sizes[i]
			}
		},
		//测试按钮
		openFileForm(id,typeId){
			this.$refs.fileForm.init("add", id,this.inputForm.projectId)
		},
		toHref (row) {
			toHref(row)
		},
		getFiles(){
			projectReportService.getAttachmentList(this.inputForm.projectId,this.inputForm.id,'').then((data) => {
				this.tableData = data
				this.tableKey = Math.random()
			})

		},
		getProgramForUser (rows) {
			this.inputForm.detailInfos[this.indexRow].userId = rows[0].id
			this.inputForm.detailInfos[this.indexRow].memberName = rows[0].name
			this.inputForm.detailInfos[this.indexRow].enrollCertNo = rows[0].enrollCertNo
			// 根据证书类型  获取字典值
			let professionList = this.getProfessionList(rows[0].type)
			professionList.forEach(item => {
				if (item.value == rows[0].profession) {
					rows[0].profession = item.label
				}
			})

			this.inputForm.detailInfos[this.indexRow].profession = rows[0].profession
			this.indexRow = ''
			this.$forceUpdate()
		},
		async insertEvent (type) {
			if (type === 'detail') {

				//根据项目等级来设置
				if (this.inputForm.projectLevel === '1') {
					let d = {
						memberName: '',
						userId: '',
						userRole: '咨询员',
						enrollCertNo: '',
						profession: '',
					}
					if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
						this.inputForm.detailInfos = []
					}
					this.inputForm.detailInfos.push(d)
					this.detailKey = Math.random()
				} else if (this.inputForm.projectLevel === '2') {

					if (this.commonJS.isEmpty(this.inputForm.reviewBy)) {
						this.$message.error('请先选择审核人员!')
						throw new Error('请先选择审核人员!')
					}

					if (this.inputForm.detailInfos.length  == 1) {
						//查询陈红星的注册/资格证号，专业信息
						this.reportReviewService.getUserInfo(this.inputForm.reviewBy).then((data) => {

							let professionList = this.getProfessionList(data.professionType)
							professionList.forEach(item => {
								if (item.value == data.profession) {
									data.profession = item.label
								}
							})

							let d = {
								memberName: data.memberName + '(' + this.inputForm.reviewByName + '代)',
								userId: data.id,
								userRole: '技术负责人',
								enrollCertNo: data.enrollCertNo,
								profession: data.profession,
							}
							if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
								this.inputForm.detailInfos = []
							}
							this.inputForm.detailInfos.push(d)
							this.detailKey = Math.random()
						}).catch(() => {

						})
					} else {
						let d = {
							memberName: '',
							userId: '',
							userRole: '咨询员',
							enrollCertNo: '',
							profession: '',
						}
						if (this.commonJS.isEmpty(this.inputForm.detailInfos)) {
							this.inputForm.detailInfos = []
						}
						this.inputForm.detailInfos.push(d)
						this.detailKey = Math.random()
					}

				}
			}
		},
    }
  }
</script>
<style scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
