<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
	<div>
		<el-form size="large" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="status === 'audit' || status === 'taskFormDetail'"
				 label-width="170px" @submit.native.prevent>

			<el-row  :gutter="15">
				<el-col :span="24">
					<el-form-item label="合同情况:" prop="contractStatus"
								  :rules="[
							   {required: true, message:'请选择合同情况', trigger:'blur'}
                 ]">
						<el-radio-group v-model="inputForm.contractStatus" @change="changeStatus" class="ml-4">
							<el-radio label="1" size="large">有合同</el-radio> <el-radio label="0" size="large">无合同</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>

				<div style="width: 100%;"  v-show="inputForm.contractStatus === '1'">
					<el-divider content-position="left"><i class="el-icon-document"></i>
						<span style="color: red;border-top: 20px">*</span>选择合同
					</el-divider>
					<el-row  :gutter="15">
					<el-col :span="12" >
						<el-form-item label="选择合同" prop="contractName"
									  :rules="[
                 ]">
							<el-input :readonly="true" @focus="openContractForm()" v-model="inputForm.contractName" placeholder="请选择合同">
								<el-button slot="append" icon="el-icon-search" @click="openContractForm()"></el-button>
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="合同编号" prop="contractNo"
									  :rules="[
                 ]">
							              <el-input :disabled="true" v-model="inputForm.contractNo" placeholder="请填写合同编号"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="委托方" prop="primaryLinkman"
									  :rules="[
                 ]">
							<el-input :disabled="true" v-model="inputForm.primaryLinkman" placeholder="请填写委托方"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="合同类型(大类)" prop="contractTypeFirst"
									  :rules="[
                 ]">
							<el-input :disabled="true" v-model="inputForm.contractTypeFirst" placeholder="请填写合同类型(大类)"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="合同类型(小类)" prop="contractType"
									  :rules="[
                 ]">
							<el-input :disabled="true" v-model="inputForm.contractType" placeholder="请填写合同类型(小类)"></el-input>
						</el-form-item>
					</el-col>
					</el-row>
				</div>

			</el-row>
			<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" v-model="inputForm.name" placeholder="请输入项目名称" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="项目所在地" prop="projectPlace"
								  :rules="[
                          {required: true, message:'项目所在地不能为空', trigger:'change'}
                 ]">
						<SelectTree
							ref="areaTree"
							:props="{
                      value: 'id',             // ID字段名
                      label: 'name',         // 显示名称
                      children: 'children'    // 子级字段名
                    }"
							url="/system-server/sys/area/treeData"
							:value="computedProjectPlace"
							:clearable="true"
							size="large"
							:accordion="true"
							@getValue="(value) => {inputForm.projectPlace=value}"
						/>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所在省份" prop="provience"
								  :rules="[
                 ]">
						<el-input :disabled="true" v-model="provience" placeholder="请输入所在省份" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所在地级市" prop="city"
								  :rules="[
                 ]">
						<el-input :disabled="true" v-model="city" placeholder="请输入所在地级市" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所在区县" prop="con"
								  :rules="[
                 ]">
						<el-input :disabled="true" v-model="con" placeholder="请输入所在区县" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="建设地点" prop="buildPlace"
								  :rules="[
                 ]">
						<el-input  v-model="inputForm.buildPlace" placeholder="请输入建设地点" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" :disabled="status === 'audit' || status === 'taskFormDetail'|| method ==='view'">
					<el-form-item label="项目负责人" prop="projectLeader"
								  :rules="[
                          {required: true, message:'项目负责人不能为空', trigger:'change'}
                 ]">
						<SelectUserTree
							ref="companyTree"
							size="large"
							:props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"
							:url="`/system-server/sys/user/treeUserDataJyOffice?type=2`"
							:value="inputForm.projectLeader"
							:clearable="true"
							:accordion="true"
							@getValue="(value) => {inputForm.projectLeader=value}"/>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="创建人" prop="createByName"
								  :rules="[
                   ]">
						<el-input :disabled="true" v-model="inputForm.createByName" placeholder="请填写创建人" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="创建时间" prop="createDate"
								  :rules="[
                   ]">
						<el-input :disabled="true" v-model="inputForm.createDate" placeholder="请填写创建时间" clearable></el-input>
					</el-form-item>
				</el-col>

				<el-col :span="24">
					<el-form-item label="工程概况" prop="projectOverview"
								  :rules="[
                 ]">
						<el-input type="textarea" v-model="inputForm.projectOverview" maxlength="500" placeholder="请输入工程概况" show-word-limit></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="特殊要求" prop="special"
								  :rules="[
                 ]">
						<el-input type="textarea" v-model="inputForm.special" maxlength="500" placeholder="请输入特殊要求" show-word-limit></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-divider content-position="left"><i class="el-icon-document"></i>
				<span><span style="color: red;border-top: 20px">*</span>委托方联系人信息</span>
				<el-button style="margin-left: 20px" type="primary" :disabled="this.inputForm.contractStatus === '1'" size="default" @click="openContactForm()" plain>
					新增
				</el-button>
			</el-divider>
			<el-row  :gutter="15" >
				<el-col :span="24">
					<vxe-table
						border
						show-overflow
						ref="clientTable"
						class="vxe-table-element"
						:data="inputForm.clientList"
						style="margin-left: 5em"
						:key="clientTableKey"
						:edit-rules="validRulesClient"
						highlight-current-row
						:edit-config="{trigger: 'click', mode: 'row', showStatus: true, autoClear: true, icon: '#'}"
					>
						<vxe-table-column field="clientName" title="联系人" :edit-render="{}"  align="center">
							<template v-slot:edit="scope">
								<el-input :disabled="true" v-model="scope.row.clientName" ></el-input>
							</template>
						</vxe-table-column>
						<!--					<vxe-table-column  align="center" field="clientType" title="人员类型" :edit-render="{name: '$select', options: clientTypes}">-->
						<!--						<template v-slot:edit="scope">-->
						<!--							<vxe-select :disabled="status === 'audit' || status === 'taskFormDetail'" v-model="scope.row.clientType"  transfer>-->
						<!--								<vxe-option-->
						<!--									v-for="item in clientTypes"-->
						<!--									:key="item.value"-->
						<!--									:value="item.value"-->
						<!--									:label="item.label">-->
						<!--								</vxe-option>-->
						<!--							</vxe-select>-->
						<!--						</template>-->
						<!--					</vxe-table-column>-->
						<vxe-table-column  align="center" field="linkPhone" title="联系方式1" :edit-render="{}">
							<template v-slot:edit="scope">
								<el-input :disabled="true" v-model="scope.row.linkPhone" ></el-input>
							</template>
						</vxe-table-column>
						<vxe-table-column  align="center" field="linkMobile" title="联系方式2" :edit-render="{}">
							<template v-slot:edit="scope">
								<el-input :disabled="true" v-model="scope.row.linkMobile" ></el-input>
							</template>
						</vxe-table-column>
						<vxe-table-column  align="center" field="position" title="职位" :edit-render="{}">
							<template v-slot:edit="scope">
								<el-input :disabled="true" v-model="scope.row.position" ></el-input>
							</template>
						</vxe-table-column>
						<vxe-table-column  align="center" title="操作" width="100">
							<template v-slot="scope">
								<el-button size="large" type="danger" @click="removeEvent(scope.row,scope.$rowIndex,'client')">删除</el-button>
							</template>
						</vxe-table-column>
					</vxe-table>
				</el-col>
			</el-row>
			<el-row  :gutter="15" v-show=" method==='view' || status ==='audit' ">
				<el-col :span="24">
					<el-divider content-position="left"><i class="el-icon-document"></i>
						项目组成员
					</el-divider>
					<el-row  :gutter="15">
						<el-col :span="24">
							<vxe-table
								border
								show-footer
								show-overflow
								:footer-method="footerMethod"
								ref="memberTable"
								class="vxe-table-element"
								:key="memberKey"
								:data="inputForm.members"
								style="margin-left: 5em"
								@cell-click=""
								:edit-rules="validRulesMember"
								@edit-closed=""
								highlight-current-row
								:edit-config="{trigger: 'click', mode: 'row', showStatus: false, autoClear:  status === 'audit' || status === 'taskFormDetail' ? true : false, icon: '#'}"
							>
								<vxe-table-column min-width="218" align="center" field="name" title="姓名"></vxe-table-column>
								<vxe-table-column min-width="218" align="center" field="officeName" title="部门"></vxe-table-column>
								<vxe-table-column min-width="218" align="center" field="roleName" title="角色"></vxe-table-column>
								<vxe-table-column min-width="218" align="center" field="mobile" title="手机号"></vxe-table-column>
								<vxe-table-column min-width="218" align="center" field="status" title="状态">
									<template #default="scope">
										<span v-if="scope.row.status === '0'" style="color: #67C23A">正常</span>
										<span v-else>移除</span>
									</template>
								</vxe-table-column>
							</vxe-table>
						</el-col>
					</el-row>
				</el-col>
			</el-row>
<!--			<el-row  :gutter="15" v-show=" method==='view' || status ==='audit' ">-->
<!--				<el-col :span="24">-->
<!--					<el-divider content-position="left"><i class="el-icon-document"></i>-->
<!--						<span>附件信息</span>-->
<!--					</el-divider>-->
<!--				</el-col>-->
<!--			</el-row>-->


		</el-form>
		<!--		&lt;!&ndash;        附件&ndash;&gt;-->
		<UpLoadComponent ref="uploadComponent"></UpLoadComponent>
		<ContractForm  ref="contractForm" @getContract="getContract"></ContractForm>
		<ContactForm  ref="contactForm" @getContract="getContact"></ContactForm>
		<WorkClientChooseRadio ref="workClientChooseRadio" @getWorkClientRadioChoose="getWorkClientChoose2"></WorkClientChooseRadio>

	</div>
</template>

<script>
	import ContractForm from './ContractForm'
	import ContactForm from './ContractForm'
	import SelectTree from '@/components/treeSelect/treeSelect.vue'
	import areaService from "@/api/sys/areaService";
	import SelectUserTree from '@/views/utils/treeUserSelect'
	import ProjectInfoService from "@/api/jy/ProjectInfoService";
	import UpLoadComponent from '@/views/common/UpLoadComponent'
	import WorkClientChooseRadio from '../workClientInfo/WorkClientChooseRadio'
	import userService from '@/api/sys/UserService'

	export default {
		props: {
			businessId: {
				type: String,
				default: ''
			},
			formReadOnly: {
				type: Boolean,
				default: false
			},
			status: {
				type: String,
				default: ''
			}
		},
		data () {
			return {
				title: '',
				method: '',
				loading: false,
				typeDictList: [],
				inputForm: {
					id: '', // 主键值（新增不传，修改必传）
					no: '', // 编号（新增不传，修改必传）
					contractId: '', // 合同id
					contractName: '', // 合同名称
					client: '', // 委托方
					primaryLinkman: '', // 委托方名称
					contractNo: '', // 合同金额
					contractType: '', // 合同类别
					name: '', // 项目名称
					projectPlace: '', // 项目所在地
					status: '', // 状态
					procInsId: '', // 流程id
					processDefinitionId: '', // 流程信息
					members: [], // 成员列表
					files: [], // 附件信息
					contractStatus: '1',//合同情况
					contractType:'',//合同类型(小类)
					contractTypeFirst:'', //合同类型(大类)
					buildPlace:'', // 建设地点
					createByName:this.$store.state.user.name, //创建人
					createDate: this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), //创建时间
					projectOverview:'', //工程概况
					special:'', //特殊要求
					projectLeader:this.$store.state.user.id, //项目负责人
					clientList:[], //委托方联系人
					files: [], // 附件信息
				},
				clientTypes: [
					{value: '1', label: '委托人'},
					{value: '2', label: '项目对接人'}
				],
				keyWatch: '',
				clientTableKey: 'default',
				tableIndex: '',
				memberKey: '',
				validRulesMember: {
					name: [
						{required: true, message: '姓名不能为空'}
					]
				},
				validRulesClient: {
					clientType: [
						{required: true, message: '人员类型不能为空'}
					]
				},
				provience:'',
				city:'',
				con:'',
				formReadOnly:''
			}
		},
		ProjectInfoService:null,
		created () {
			this.projectInfoService=new ProjectInfoService()
		},
		computed: {
			bus: {
				get () {
					this.$refs.uploadComponent.setDividerName('附件')
					return this.businessId
				},
				set (val) {
					this.businessId = val
				}
			},
			computedProjectPlace() {
				if (this.commonJS.isNotEmpty(this.inputForm.projectPlace)){
					this.getLocation()
					return this.inputForm.projectPlace
				}else {
					this.getLocation()
				}
			}
		},
		watch: {
			'keyWatch': {
				handler (newVal) {
					if (this.bus) {
						if (this.bus !== 'false') {
							this.init('', this.bus)
						}
					} else {
						this.$nextTick(() => {
							this.$refs.inputForm.resetFields()
						})
					}
				}
			},
			'loading': {
				handler (newVal) {
					this.$emit('changeLoading', newVal)
					this.$refs.uploadComponent.changeLoading(newVal)
				}
			}
		},
		components: {
			ContractForm,
			ContactForm,
			SelectTree,
			SelectUserTree,
			UpLoadComponent,
			WorkClientChooseRadio,
		},
		methods: {
			getKeyWatch (keyWatch) {
				this.keyWatch = keyWatch
			},
			init (method, id) {
				this.method = method
				console.log('method', method)
				this.inputForm = {
					id: '', // 主键值（新增不传，修改必传）
					no: '', // 编号（新增不传，修改必传）
					contractId: '', // 合同id
					contractName: '', // 合同名称
					client: '', // 委托方
					primaryLinkman: '', // 委托方名称
					contractNo: '', // 合同金额
					contractType: '', // 合同类别
					name: '', // 项目名称
					projectPlace: '', // 项目所在地
					status: '', // 状态
					procInsId: '', // 流程id
					processDefinitionId: '', // 流程信息
					members: [], // 成员列表
					files: [], // 附件信息
					contractStatus: '',//合同情况
					contractType:'',//合同类型(小类)
					contractTypeFirst:'', //合同类型(大类)
					buildPlace:'', // 建设地点
					createByName:this.$store.state.user.name, //创建人
					createDate: this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), //创建时间
					projectOverview:'', //工程概况
					special:'', //特殊要求
					projectLeader:this.$store.state.user.id, //项目负责人
					clientList:[], //委托方联系人
					files: [], // 附件信息
					formReadOnly:''
				}
				this.inputForm.id = id
				if (method === 'add') {
					// this.inputForm.id = 'add'
					this.title = `新建项目`
				} else if (method === 'edit') {
					this.title = '修改项目'
				} else if (method === 'view') {
					this.title = '查看项目详情'
				}
				console.log("进入init方法")
				this.loading = false
				this.$nextTick(() => {
					this.$refs.inputForm.resetFields()
					this.loading = true
					this.$refs.uploadComponent.clearUpload()
					// this.$refs.archiveFile.clearUpload()
					if (this.commonJS.isNotEmpty(this.inputForm.id)) {
						this.projectInfoService.findById(this.inputForm.id).then((data) => {
							console.log(data)
							this.inputForm = this.recover(this.inputForm, data)
							if(data.projectLeader){
								this.inputForm.projectLeader = data.projectLeader
							}else{
								this.inputForm.projectLeader = this.$store.state.user.id
							}
							this.inputForm.members=data.projectMembers
							this.inputForm.clientList=data.clientList
							this.inputForm.createByName=data.createById
							this.inputForm.createDate=data.createTime
							this.inputForm.members=data.projectMembers
							this.inputForm.contractNo=data.no
							if (this.commonJS.isEmpty(this.inputForm.members)) {
								this.inputForm.cwProjectMembersDTOList = []
							} else {
								this.inputForm.members.forEach((member, index) => {
									userService.queryDetailById(member.userId).then((data) => {
										member.name = this.commonJS.isEmpty(data.name) ? '' : data.name
										member.mobile = this.commonJS.isEmpty(data.mobile) ? '' : data.mobile
										member.officeName = this.commonJS.isEmpty(data.officeDTO) ? '' : this.commonJS.isEmpty(data.officeDTO.name) ? '' : data.officeDTO.name
										member.roleName = this.commonJS.isEmpty(data.roleList) ? '' : data.roleList.map(role => { return this.commonJS.isEmpty(role.name) ? '' : role.name }).join(',')
										this.tableKeyMembers = Math.random()
									})
								})
							}
							this.getLocation()
							// this.inputForm.cwWorkClientContactDTOList=data.cwWorkClientContactDTOList
							console.log('data', data)
							if (this.commonJS.isEmpty(this.inputForm.createDate)) {
								this.inputForm.createDate = this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
							}
							if (this.formReadOnly) {
								method = 'view'
							}
							if (this.status === 'audit' || this.status === 'taskFormDetail') {
								method = 'view'
							}
							console.log('me',this.method)
							this.$refs.uploadComponent.newUpload(method, this.inputForm.files, 'jyProject', null, null, null, null, null)
							// this.$refs.archiveFile.newUpload('view', [], 'cwWorkContract', null, null, null, null, false)
							this.loading = false
						})
					}
				})
			},
			openContractForm () {
				if (!this.commonJS.isEmpty(this.inputForm.contractId)) {
					this.$refs.contractForm.init(this.inputForm.contractId)
				} else {
					this.$refs.contractForm.init()
				}
			},
			getContract (row) {
				console.log('row',row)
				let _this = this
				// eslint-disable-next-line no-unused-vars
				let _list = row
				let _num = 0
				if (this.commonJS.isEmpty(this.inputForm.clientList)) {
					this.inputForm.clientList = []
				}
				const waitForEach = function () {
					return new Promise(function (resolve, reject) {
						if (_this.commonJS.isEmpty(_this.inputForm.clientList)) {
							resolve()
						} else {
							_this.inputForm.clientList.forEach((client, index) => {
								if (_this.inputForm.customerNo === client.no) {
									_this.$refs.clientTable.remove(client)
									_this.inputForm.clientList.splice(index, 1)
								}
							})
							setTimeout(() => {
								resolve()
							}, 400)
						}
					})
				}
				waitForEach().then(() => {
					this.inputForm.contractId = row.id // 合同id
					this.inputForm.contractName = row.name // 合同名称
					this.inputForm.primaryLinkman = row.primaryLinkman // 委托方名称
					this.inputForm.contractNo = row.no // 合同金额
					this.inputForm.contractType = row.contractType // 合同类型(小类)
					this.inputForm.contractTypeFirst = row.contractTypeFirst // 合同类型(大类)
					const wait = function () {
						return new Promise(function (resolve, reject) {
							_this.inputForm.clientList.forEach(client => {
								if (_list.no === client.no) {
									_num = 1
								}
							})
							setTimeout(() => {
								resolve()
							}, 100)
						})
					}
					wait().then(() => {
						if (_num === 0) {
							this.inputForm.clientList.push({ clientName: row.linkmanList[0].name,id: row.linkmanList[0].id,linkPhone:row.linkmanList[0].linkPhone,linkMobile:row.linkmanList[0].linkMobile,position:row.linkmanList[0].position})
							this.$refs.clientTable.insertAt({name: row.linkmanList[0].name,id: row.linkmanList[0].id,linkPhone:row.linkmanList[0].linkPhone,linkMobile:row.linkmanList[0].linkMobile,position:row.linkmanList[0].position})
							this.clientTableKey = Math.random()
						}
					})
				})
				this.$forceUpdate()
				console.log('list',this.inputForm.clientList)
			},
			//获取省市县
			getLocation(){
				var locationId=this.inputForm.projectPlace
				console.log('id',this.inputForm.projectPlace)
				areaService.getParent(locationId).then((data)=>{
					if (!data){
						return
					}
					console.log('da',data)
					this.provience=data[2]
					this.city=data[3]
					this.con=data[4]

				})
			},
			//委托方联系人
			openContactForm(){
				if (this.commonJS.isEmpty(this.inputForm.clientList)) {
					this.$refs.workClientChooseRadio.init()
				}
			},
			//添加委托方联系人
			getContact(row){
				console.log('o',row)
				this.inputForm.clientList.push({clientName: row.clientName,id: row.client,linkPhone:row.linkPhone,linkMobile:row.linkMobile,position:row.position})
				this.$refs.clientTable.insertAt({clientName: row.clientName,id: row.client,linkPhone:row.linkPhone,linkMobile:row.linkMobile,position:row.position})
				this.clientTableKey = Math.random()
			},
			// 删除
			removeEvent (row, rowIndex, type) {
				if (type === 'member') {
					this.$refs.memberTable.remove(row)
					this.inputForm.members.splice(rowIndex, 1)
				}
				if (type === 'client') {
					this.$refs.clientTable.remove(row)
					this.inputForm.clientList.splice(rowIndex, 1)
				}
			},
			reapplyForm (callback) {
				this.loading = true
				this.projectInfoService.findById(this.inputForm.id).then((data) => {
					if (data.status !== '4') { // 审核状态不是“驳回”，就弹出提示
						this.loading = false
						this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
					} else {
						this.startFormTrue(callback)
					}
				})
			},
			saveForm (callback) {
				this.doSubmit('save', callback)
			},
			startForm (callback) {
				this.loading = true
				if (this.commonJS.isNotEmpty(this.inputForm.id)) {
					this.projectInfoService.findById(this.inputForm.id).then((data) => {
						if (this.commonJS.isNotEmpty(data.status) && data.status !== '0' && data.status !== '1' && data.status !== '3') { // 审核状态不是“未发起”或“暂存”或“撤回”，就弹出提示
							this.loading = false
							this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
							throw new Error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
						} else {
							this.startFormTrue(callback)
						}
					})
				} else {
					this.startFormTrue(callback)
				}
			},
			startFormTrue (callback) {
				this.doSubmit('startAndHold', callback)
			},
			// 通过
			agreeForm (callback) {
				this.loading = true
				this.$refs['inputForm'].validate(async (valid) => {
					if (valid) {
						await this.projectInfoService.findById(this.inputForm.id).then((data) => {
							if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
								this.loading = false
								this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
								throw new Error()
							} else {
								this.loading = true
								this.inputForm.files = this.$refs.uploadComponent.getDataList()
								if (this.$store.state.user.office.name ==='总经办'){
									this.inputForm.status = '5'
								}else {
									this.inputForm.status = '2'
								}
								let param = {status: this.inputForm.status, id: this.inputForm.id}
								this.projectInfoService.updateStatusById(param).then((data) => {
									callback(data.businessTable, data.businessId, this.inputForm)
									this.$refs.inputForm.resetFields()
									this.loading = false
								}).catch(() => {
									this.$refs.inputForm.resetFields()
									this.loading = false
								})
							}
						})
					} else {
						this.loading = false
					}
				})
			},
			// 表单提交
			doSubmit (status, callback) {
				this.loading = true
				if (status === 'save') {
					// 暂存
					this.inputForm.status = '1'
					this.loading = true
					if (this.$refs.uploadComponent.checkProgress()) {
						this.loading = false
						return
					}
					this.inputForm.files = this.$refs.uploadComponent.getDataList()
					this.projectInfoService.saveForm(this.inputForm).then((data) => {
						callback(data.businessTable, data.businessId, this.inputForm)
						this.loading = false
					}).catch(() => {
						this.loading = false
					})
					return
				} else if (status === 'startAndHold') {
					if (this.commonJS.isEmpty(this.inputForm.clientList)) {
						this.loading = false
						this.$message.error('填写一条委托方联系人信息')
						return
					}
					if (this.commonJS.isEmpty(this.inputForm.contractStatus)) {
						this.loading = false
						this.$message.error('请选择合同情况')
						return
					}
					if (this.inputForm.contractStatus === '1' && this.commonJS.isEmpty(this.inputForm.contractName)) {
						this.loading = false
						this.$message.error('请选择合同')
						return
					}
					if (this.commonJS.isEmpty(this.inputForm.projectPlace)) {
						this.loading = false
						this.$message.error('请选择项目所在地')
						return
					}
					if (this.commonJS.isEmpty(this.inputForm.projectLeader)) {
						this.loading = false
						this.$message.error('请选择项目负责人')
						return
					}
					// 送审  待审核
					this.inputForm.status = '2'
				} else if (status === 'agree') {
					// 审核同意
					this.inputForm.status = '5'
				}
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.loading = true
						if (this.$refs.uploadComponent.checkProgress()) {
							this.loading = false
							return
						}
						console.log('this.inputForm', this.inputForm)
						this.inputForm.files = this.$refs.uploadComponent.getDataList()
						console.log('3',this.inputForm)
						this.projectInfoService.saveForm(this.inputForm).then((data) => {
							this.inputForm.id = data.businessId
							let processTitle = `${this.$store.state.user.name} 发起了 ${this.inputForm.name} - ${data.no} ` + `[嘉溢-项目登记]`
							this.inputForm.title = processTitle
							callback(data.businessTable, data.businessId, this.inputForm)
							this.loading = false
						}).catch(() => {
							this.loading = false
						})
					} else {
						this.loading = false
					}
				})
			},
			async updateStatusById (type, callback) {
				this.loading = true
				if (await this.$refs.uploadComponent.checkProgress()) {
					this.loading = false
					throw new Error()
				} else {
					if (type === 'reject' || type === 'reback') {
						this.projectInfoService.findById(this.inputForm.id).then((data) => {
							if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
								this.loading = false
								this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
								throw new Error()
							} else {
								// if (type === 'agree') {
								//   // 同意
								//   this.inputForm.status = '5'
								// }
								if (type === 'reject') {
									// 驳回
									this.inputForm.status = '4'
								}
								if (type === 'reback') {
									// 撤回
									this.inputForm.status = '3'
								}
								if (type === 'reject' || type === 'reback') {
									let param = {status: this.inputForm.status, id: this.inputForm.id}
									this.projectInfoService.updateStatusById(param).then(() => {
										this.loading = false
										callback()
									})
								}
							}
						})
					} else if (type === 'hold') {
						this.projectInfoService.findById(this.inputForm.id).then((data) => {
							if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
								this.loading = false
								this.$message.error('任务数据已发生改变或不存在，请在待办任务中确认此任务是否存在')
								throw new Error()
							} else {
								// 终止
								let param = {status: '1', id: this.inputForm.id}
								this.projectInfoService.updateStatusById(param).then(() => {
									this.loading = false
									callback()
								})
							}
						})
					}
				}
			},
			close () {
				this.inputForm = {
					id: '', // 主键值（新增不传，修改必传）
					no: '', // 编号（新增不传，修改必传）
					contractId: '', // 合同id
					contractName: '', // 合同名称
					client: '', // 委托方
					primaryLinkman: '', // 委托方名称
					contractNo: '', // 合同金额
					contractType: '', // 合同类别
					name: '', // 项目名称
					projectPlace: '', // 项目所在地
					status: '', // 状态
					procInsId: '', // 流程id
					processDefinitionId: '', // 流程信息
					members: [], // 成员列表
					files: [], // 附件信息
					contractStatus: '1',//合同情况
					contractType:'',//合同类型(小类)
					contractTypeFirst:'', //合同类型(大类)
					buildPlace:'', // 建设地点
					createByName:this.$store.state.user.name, //创建人
					createDate: this.moment(new Date()).format('YYYY-MM-DD HH:mm:ss'), //创建时间
					projectOverview:'', //工程概况
					special:'', //特殊要求
					projectLeader:this.$store.state.user.id, //项目负责人
					clientList:[], //委托方联系人
					files: [], // 附件信息
				}
				this.$refs.uploadComponent.clearUpload()
				this.$refs.inputForm.resetFields()
			},
			uploadVideoProcess (event, file, fileList) {
				this.progressFlag = true // 显示进度条
				this.loadProgress = parseInt(event.percent) // 动态获取文件上传进度
				if (this.loadProgress >= 100) {
					this.loadProgress = 100
					setTimeout(() => { this.progressFlag = false }, 1000) // 一秒后关闭进度条
				}
			},
			getWorkClientChoose2 (list) {
				console.log('list',list)
				if (this.commonJS.isNotEmpty(list.linkId)){
					if (this.commonJS.isEmpty(this.inputForm.clientList)) {
						this.inputForm.clientList = []
					}
					this.inputForm.clientList.push({id: list.linkId, clientName: list.clientName,linkPhone:list.phone,linkMobile:list.mobile,position:list.position})
					this.$refs.clientTable.insertAt({ clientName: list.name,linkPhone:list.phone,linkMobile:list.mobile,position:list.position})
					this.clientTableKey = Math.random()
				}


				console.log('1231312',this.inputForm.clientList)
			},
			changeStatus(){
				if (this.inputForm.contractStatus ==='0'){
					this.inputForm.contractId = ''
					this.inputForm.contractName = ''
					this.inputForm.clientName = ''
					this.inputForm.contractNo = ''
					this.inputForm.contractType = ''
					this.inputForm.contractTypeFirst = ''
					this.inputForm.clientList=[]
				}
			}
		}
	}
</script>
<style lang="scss">
	.el-input-number .el-input__inner {
		text-align: left;
	}
	.el-divider__text {
		font-size: 16px;
		font-weight: bold;
	}

</style>
