
import { ref,reactive,computed } from "vue";
import { router } from "@/router";
import {ElMessage,ElMessageBox} from "element-plus"
import { customInterence } from '@/api/api.js'


export function customListHook(){
	const customInfo=ref({})
	const isShareRecodeDialogShow=ref(false)//控制服务记录弹窗
	const allowEdit=ref(true)//是否允许编辑服务记录

	//打开服务记录弹窗
	const handleShowShareRecode=(data,type='')=>{
		if(data.ServiceTimes===0&&type==='list') return
		allowEdit.value = type==='list'?false:true
		isShareRecodeDialogShow.value = true
		customInfo.value = data
	}
	return {
		isShareRecodeDialogShow,
		customInfo,
		handleShowShareRecode
	}
}


export function useList() {
	const btnCommandList = {// 按钮命令列表
		BtnView: '查看权限',
		BtnModifySeller: '分配销售',
		BtnUpdate: '续约申请',
		BtnAddAgreement: '补充协议',
		BtnTryOut: '增开试用',
		BtnServiceRecord:'沟通记录',
		BtnRemarkView:'备注',
		BtnShare:'设置共享',
	}

	const statusList = [{label:'未共享',value:3},{label:'已分配',value:1},{label:'待分配',value:2}]

	const defaultSalesProps = {
		multiple: true,
		label:'RealName',
		children:'ChildrenList',
		value:'AdminId'
	}//销售级联配置

	// 用于返回按钮名称
	function btnName(btnItem,row){
		if(btnItem.code=='BtnShare') return row.IsShare===1?'取消共享':'设置共享'
		if(btnItem.code=='BtnModifySeller') return row.ShareSellerId?'修改销售':'分配销售'
		return btnItem.type
	}


	/* 前往详情页 */
	function goDetail(item) {
		router.push({
			path:'/customDetail',
			query:{
				id:item.CompanyId
			}
		})
	}

	/* 启用/暂停 */
	function suspendHandle(item) {
		customInterence.Suspend({
			CompanyId:item.CompanyId
		}).then(res => {
			if(res.Ret === 200) {
				ElMessage.success(res.Msg);
				item.IsSuspend = item.IsSuspend === 1 ? 0 : 1;
			}
		})
	}


	/* 编辑客户 */
	function editHandle(item) {
		router.push({
			path:'/editCustom',
			query:{
				id:item.CompanyId
			}
		})
	}

	const Role = computed(() => {
		let role = localStorage.getItem('Role') || '';
		return role;
	})
	const RaiSellerRole = computed(() => {
		return ['rai_seller','rai_admin','admin'].includes(Role.value)
	})
	const RoleType = computed(() => {
		let type = localStorage.getItem('RoleType') || '';
		return type;
	})
	const RoleIdentity = computed(() => {
		let role = localStorage.getItem('RoleIdentity') || '';
		return role;
	})
	const SellerAdminId = computed(() => {
		let type = localStorage.getItem('AdminId') || '';
		return type;
	})
	//管理权限
	const ManageType = computed(() => {
		return localStorage.getItem('ManageType') || '';
	})

	return {
		btnCommandList,
		defaultSalesProps,
		statusList,
		btnName,
		goDetail,
		suspendHandle,
		editHandle,

		Role,
		RaiSellerRole,
		RoleType,
		RoleIdentity,
		SellerAdminId,
		ManageType
	}
}


/* 阅读记录弹窗 */
export function useReadia() {

	const readId = ref(0);
	const isRead = ref(false);
	const readTit = ref('阅读报告列表');
	
	//取消弹窗
	function cancelRead() {
		isRead.value = false
		readTit.value = "阅读报告列表";
	}


	//查看阅读报告列表弹窗
	function lookReport(item) {
		console.log(item);
		readId.value = item.UserId;
		readTit.value = item.RealName + "阅读报告列表";
		isRead.value = true;
	}


	return {
		readId,
		isRead,
		readTit,
		cancelRead,
		lookReport
	}
}


/* 累计点击量弹窗 */
export function useClickNumDia() {
	const showClickTimesDia = ref(false)
	const clickTimesDetailItem = ref({
		contactsName:"",
		contactsId:0
	})


	//累计点击量详情
	function clickTimesDetail(row){
		clickTimesDetailItem.value.contactsName = row.Name
		clickTimesDetailItem.value.contactsId = row.Id
		showClickTimesDia.value=true
	}

	function closeNumDia() {
		showClickTimesDia.value=false
	}

	return {
		showClickTimesDia,
		clickTimesDetailItem,
		clickTimesDetail,
		closeNumDia
	}
}


/* 沟通记录弹窗 */
export function useCommunicaRecordDia() {
	const customInfo = ref({})
	const isShareRecodeDialogShow = ref(false)//控制服务记录弹窗
	const allowEdit = ref(true)//是否允许编辑服务记录

	 //打开服务记录弹窗
	function handleShowShareRecode(data,type=''){
			if(data.ServiceTimes===0&&type==='list') return
			allowEdit.value = type==='list'?false:true
			isShareRecodeDialogShow.value = true
			customInfo.value = data
	}

	return {
		shareCustomInfo: customInfo,
		isShareRecodeDialogShow,
		allowEdit,
		handleShowShareRecode
	}
}


/* 查看权限弹窗 */
export function useViewPermissionDia() {
		const isLook = ref(false)//权限弹窗
		const	lookTitle = ref('')//权限弹窗标题
		const	lookAuthList = ref([])//查看的权限
		const	lookAuthListEquity = ref([])//权益

		// 打开弹窗
		function lookHandle(item) {
			lookTitle.value = item.CompanyName;
			customInterence.lookauth({
				CompanyId:item.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
					isLook.value = true;
					let auth = [];			
					res.Data.List ?	res.Data.List.forEach(item=> { 
						auth.push(item.Items)
					}):''
					lookAuthList.value = auth.flat(Infinity);

					let authEquity =[] //权益
					res.Data.ListRai ?	res.Data.ListRai.forEach(item=> {//权益
						// 过滤没有权限的套餐
						let check_Auth = item.Items.filter(it => item.CheckList.includes(it.ChartPermissionId))
						check_Auth.map(item =>{
						// 排序 以防合并问题
							if(item.PermissionType==1){
								//主观 找客观
								authEquity.push(item)
								let ob = check_Auth.find(it => it.PermissionName == item.PermissionName && it.PermissionType!==1)
								ob && authEquity.push(ob)
							}else if(item.PermissionType==0){
								authEquity.push(item)
							}else{
								// 客观
								if(!authEquity.find(t => t.ChartPermissionId == item.ChartPermissionId)){
									authEquity.push(item)
								}
							}
						})
					}):''
					lookAuthListEquity.value = authEquity.flat(Infinity) //权益
				}
			})
		}

		/* 关闭查看权限弹窗 */
		function closeDia() {
			lookTitle.value = '';
			lookAuthList.value = [];
			lookAuthListEquity.value = []
			isLook.value = false;
		}

		return {
			isLook,
			lookTitle,
			lookAuthList,
			lookAuthListEquity,
			lookHandle,
			closeDia
		}
}

/* 备注弹窗 */
export function useViewRemarkDia() {
	const customInfo = ref({})
	const isRemarkLook = ref(false)

	function handleShowRemark(item){
		customInfo.value = item
		isRemarkLook.value = true
	}

	function closeRemarkDia() {
		isRemarkLook.value = false
		customInfo.value = {}
	}

	return {
		customInfo,
		isRemarkLook,
		handleShowRemark,
		closeRemarkDia
	}
}

/* 生成合同弹窗 */
export function useCreateContractDia() {

}

/* 增开试用弹窗 */
export function useAddTrialDia() {
	/* 增加试用 */
	const isAddTrial = ref(false)//增加试用弹窗
	const addTryId = ref('')//增开试用的id
	const authList = ref([])

	function addTrialHandle(item) {
		authList.value = [];
		customInterence.lookauth({
			CompanyId:item.CompanyId,
			LookType:1
		}).then(res => {
			if(res.Ret === 200) {
				let auth = [];
				// res.Data.List 有值为 ficc
				// res.Data.ListRai 有值为 权益
				if(res.Data.List) {
					res.Data.List.forEach(item=> {
						let obj = {
							checkAll:item.CheckList&&item.CheckList.length===item.Items.length?true:false,
							isIndeterminate:item.CheckList&&item.CheckList.length>0 && item.CheckList.length<item.Items.length,
							defaultAuth:item.CheckList,
							customType:'ficc',
							...item,
						}
						auth.push(obj)
					})
				}else if(res.Data.ListRai) {
					auth = filterRaiAuth(res.Data.ListRai,auth)

				}
			
				authList.value = auth;
			}
		})
		addTryId.value = item.CompanyId;
		isAddTrial.value = true;
	}

	function filterRaiAuth(data,auth) {
			// 权益 RaiMerge 0不管 1合并 2拆分 所传入的数据结构不一样
			data[0].RaiMerge==1
				? data.forEach(item=> { // 合并
						let obj = {
							checkAll:item.CheckList&&item.CheckList.length===item.Items.length?true:false,
							isIndeterminate:item.CheckList&&item.CheckList.length>0 && item.CheckList.length<item.Items.length,
							defaultAuth:item.CheckList,
							...item,
						}
						auth.push(obj)
					})
				: data.forEach(item=> { // 拆分
						let obj = {
							defaultAuth:item.CheckList,
							customType:'权益',
							...item,
						}	
						// 组合所需的数据格式
						obj.dataList=[
							{
								PermissionTypeName:'',
								medicine:{
									value:'医药',
									isIndeterminate:item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[1].ChartPermissionId].includes(id)).length ==1,
									isCheckAll:item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[1].ChartPermissionId].includes(id)).length == 2,
									isDisabled:item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[1].ChartPermissionId].includes(id)).length ==2
								},
								consumption:{
									value:'消费',
									isIndeterminate:item.CheckList.filter(id => [obj.Items[2].ChartPermissionId,obj.Items[3].ChartPermissionId].includes(id)).length ==1,
									isCheckAll:item.CheckList.filter(id => [obj.Items[2].ChartPermissionId,obj.Items[3].ChartPermissionId].includes(id)).length == 2,
									isDisabled:item.CheckList.filter(id => [obj.Items[2].ChartPermissionId,obj.Items[3].ChartPermissionId].includes(id)).length ==2
								},
								technology:{
									value:'科技',
									isIndeterminate:item.CheckList.filter(id => [obj.Items[4].ChartPermissionId,obj.Items[5].ChartPermissionId].includes(id)).length ==1,
									isCheckAll:item.CheckList.filter(id => [obj.Items[4].ChartPermissionId,obj.Items[5].ChartPermissionId].includes(id)).length == 2,
									isDisabled:item.CheckList.filter(id => [obj.Items[4].ChartPermissionId,obj.Items[5].ChartPermissionId].includes(id)).length ==2
								},
								smart:{
									value:'智造',
									isIndeterminate:item.CheckList.filter(id => [obj.Items[6].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length ==1,
									isCheckAll:item.CheckList.filter(id => [obj.Items[6].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length == 2,
									isDisabled:item.CheckList.filter(id => [obj.Items[6].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length ==2
								},
								strategy:{
									value:'策略'
								},
								experts:{
									value:'专家'
								},
								roadshow:{
									value:'路演服务'
								},
								choose:{
									value:'研选订阅'
								},
								points:{
									value:'研选扣点包'
								},
							},
							{
								PermissionTypeName:{
									value:'主观',
									isIndeterminate:[1,2,3].includes(item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[2].ChartPermissionId,
										obj.Items[4].ChartPermissionId,obj.Items[6].ChartPermissionId].includes(id)).length),
									isCheckAll:item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[2].ChartPermissionId,
										obj.Items[4].ChartPermissionId,obj.Items[6].ChartPermissionId].includes(id)).length == 4,
									isDisabled:item.CheckList.filter(id => [obj.Items[0].ChartPermissionId,obj.Items[2].ChartPermissionId,
										obj.Items[4].ChartPermissionId,obj.Items[6].ChartPermissionId].includes(id)).length ==4
								},
								medicine:{
									value:obj.Items[0].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[0].ChartPermissionId)
								},
								consumption:{
									value:obj.Items[2].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[2].ChartPermissionId)
								},
								technology:{
									value:obj.Items[4].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[4].ChartPermissionId)
								},
								smart:{
									value:obj.Items[6].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[6].ChartPermissionId)
								},
								strategy:{
									value:obj.Items[8].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[8].ChartPermissionId)
								},
								experts:{
									value:obj.Items[9].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[9].ChartPermissionId)
								},
								roadshow:{
									value:obj.Items[10].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[10].ChartPermissionId)
								},
								choose:{
									value:obj.Items[11].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[11].ChartPermissionId)
								},
								points:{
									value:obj.Items[12].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[12].ChartPermissionId)
								}
							},
							{
								PermissionTypeName:{
									value:'客观',
									isIndeterminate:[1,2,3].includes(item.CheckList.filter(id => [obj.Items[1].ChartPermissionId,obj.Items[3].ChartPermissionId,
										obj.Items[5].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length),
									isCheckAll:item.CheckList.filter(id => [obj.Items[1].ChartPermissionId,obj.Items[3].ChartPermissionId,
										obj.Items[5].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length == 4,
									isDisabled:item.CheckList.filter(id => [obj.Items[1].ChartPermissionId,obj.Items[3].ChartPermissionId,
										obj.Items[5].ChartPermissionId,obj.Items[7].ChartPermissionId].includes(id)).length ==4
								},
								medicine:{
									value:obj.Items[1].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[1].ChartPermissionId)
								},
								consumption:{
									value:obj.Items[3].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[3].ChartPermissionId)
								},
								technology:{
									value:obj.Items[5].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[5].ChartPermissionId)
								},
								smart:{
									value:obj.Items[7].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[7].ChartPermissionId)
								},
								strategy:{
									value:obj.Items[8].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[8].ChartPermissionId)
								},
								experts:{
									value:obj.Items[9].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[9].ChartPermissionId)
								},
								roadshow:{
									value:obj.Items[10].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[10].ChartPermissionId)
								},
								choose:{
									value:obj.Items[11].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[11].ChartPermissionId)
								},
								points:{
									value:obj.Items[12].ChartPermissionId,
									isDisabled:item.CheckList.includes(obj.Items[12].ChartPermissionId)
								}
							}
						]

						auth.push(obj)
					})
					
			return auth
	}

	function closeAddTrial() {
		isAddTrial.value = false
	}

	return {
		isAddTrial,
		addTryId,
		addTrialHandle,
		closeAddTrial,
		authList
	}
}

/* 查看路演详情弹窗 */
export function useViewRoadShowDia() {
	const accumulativeFrequencyItem = ref({})
	const accumulativeFrequencyDlg = ref(false)

	function accumulativeFrequencyClick(item){
	 	accumulativeFrequencyDlg.value = true
		accumulativeFrequencyItem.value = item.row
	}

	function closeAccumulativeDlg() {
		accumulativeFrequencyDlg.value = false
	}
	
	return {
		accumulativeFrequencyClick,
		accumulativeFrequencyDlg,
		accumulativeFrequencyItem,
		closeAccumulativeDlg
	}
}


/* 查看累计试用天数弹窗 */
export function useLookTrialDia() {
	const isTotalDayDialogShow = ref(false)
	const customItem = ref({})

	function handleTotalDayClick(data){
		isTotalDayDialogShow.value = true
		customItem.value = data
	}

	function closeLookTrial() {
		isTotalDayDialogShow.value = false
		customItem.value = {}
	}

	return {
		isTotalDayDialogShow,
		customItem,
		handleTotalDayClick,
		closeLookTrial
	}
}


export function useMoveSaleDia() {
	const isMove = ref(false)//修改销售
	const moveform = ref({
		companyType:'',
		companyId:'',//客户id
		companyName:'',
		sale:'',//修改的销售
	})
	const moveRule = {
		sale:[
			{ required: true, message: '所属销售不能为空', trigger: 'blur' },
		]
	}

	function updateSale(item) {
		moveform.value = {
			companyType:item.CompanyType,
			companyName:item.CompanyName,
			companyId:item.CompanyId,
			sale:''
		}
		handleModifysalesArr(item.SellerId)
		isMove.value = true;
	}

	/* 取消移动客户 */
	function cancelMove() {
		moveformRef.value.resetFields();
		isMove.value = false;
	} 

	return {
		isMove,
		moveRule,
		moveform,
		updateSale,
		cancelMove
	}
}


/* 申请转正，续约申请，补充协议 */
export function useChooseContractDia() {

	const contractModel = reactive({
		show:false,
		data:null,//客户信息（列表用户数据）
		type:'',//类型 申请转正、续约申请、补充协议
	})
	const { getCustomerDetail } = useCompleteInfoDia();

	async function applyTurn(item) {
		//判断是否需要补全信息
		let flag=await getCustomerDetail(item.CompanyId,0) 
		if(flag) return
		contractModel.show=true
		contractModel.data=item
		contractModel.type='申请转正'
	}

	/* 续约申请操作 */
	async function updateHandle(item) {
		//判断是否需要补全信息
		let flag = await getCustomerDetail(item.CompanyId)
		if(flag) return
		contractModel.show=true
		contractModel.data=item
		contractModel.type='续约申请'
	}

	// 补充协议
	async function addAgreement(item) {
		//判断是否需要补全信息
		let flag = await getCustomerDetail(item.CompanyId)
		if(flag) return
		contractModel.show=true
		contractModel.data=item
		contractModel.type='补充协议'
	}


	const contractDialog = reactive({
		show:false,
		type:'',//类型 申请转正、续约申请、补充协议
		cusdata:null,//客户信息（列表用户数据）
	})//申请转正、续约申请、补充协议 合同信息弹窗

	// 申请转正、续约申请、补充协议点击合同类型
	function handleContractModel(e){
		contractModel.show=false
		if(e==='非标准'){
			if(contractModel.type==='申请转正'){
				sessionStorage.setItem('companyInfo',JSON.stringify(contractModel.data))
				router.push({
					path:'/turnCustom',
				})
			}else if(contractModel.type==='续约申请'){
				sessionStorage.setItem('companyInfo',JSON.stringify(contractModel.data))
				router.push({
					path:'/updateCustom',
				})
			}else if(contractModel.type==='补充协议'){
				sessionStorage.setItem('companyInfo',JSON.stringify(contractModel.data))
				router.push({
					path:'/addAgreement',
				})
			}
			return
		}
		// 标准合同
		contractDialog.show=true
		contractDialog.type=contractModel.type
		contractDialog.cusdata=contractModel.data
	}

	function closeContractInfoDia() {
			contractDialog.show = false;
			contractDialog.type = '';//类型 申请转正、续约申请、补充协议
			contractDialog.cusdata = null;//客户信息（列表用户数据）
	}

	return {
		contractModel,
		applyTurn,
		updateHandle,
		addAgreement,
		handleContractModel,
		contractDialog,
		closeContractInfoDia
	}
}


/* 查看备注弹窗 客户列表 */
export function useViewRemarkCustomDia() {
	/* 查看备注 */
	const lookRemarkTitle = ref('')//查看备注标题
	const	lookRemarkList = ref([])//查看备注列表
	const	lookRemarkTextarea = ref('')//备注的文本框
	const	isRemarkLook = ref(false)////查看备注弹窗
	const	lookRemarkItem = ref({})////查看备注的item项


	function lookRemarkHandle(item) {
		/*
		lookRemarkTitle:'',//查看备注标题
		lookRemarkList:[],//查看备注列表
		*/
		lookRemarkTitle.value = "备注";
		// lookAuthList.value = [];
		lookRemarkItem.value = item;
		customInterence.lookRemarkAuth({
			CompanyId:item.CompanyId
		}).then(res => {
			if(res.Ret === 200) {
				lookRemarkList.value=res.Data;
			}
		})
		isRemarkLook.value = true;
	}

	//新增备注
	async function lookRemarkAdd(){
		if(!lookRemarkTextarea.value) return ElMessage.error("请输入文本内容")
		const res = await customInterence.lookRemarkAuthAdd({
			CompanyId:lookRemarkItem.value.CompanyId,
			Remark:lookRemarkTextarea.value
		})
		if(res.Ret===200) {
			ElMessage.success('保存成功')
			lookRemarkList.value = []
			lookRemarkTextarea.value =''
			customInterence.lookRemarkAuth({
				CompanyId:lookRemarkItem.value.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
					lookRemarkList.value=res.Data;
				}
			})
		}
	}

	//删除备注
	async function lookRemarkDelete(data){
		ElMessage('备注删除后不可恢复，确认删除吗？','提示',{
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			type:'warning',
			appendToBody:false
		}).then(async()=>{
			const res = await customInterence.deleteRemark({
				RemarkId:data.RemarkId
			})
			if(res.Ret!==200) return 
			ElMessage.success("删除成功")
			customInterence.lookRemarkAuth({
				CompanyId:lookRemarkItem.value.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
					lookRemarkList.value=res.Data;
				}
			})
		})
	}

	function closeRemark() {
		isRemarkLook.value = false
	}

	return {
		lookRemarkTitle,
		lookRemarkList,
		lookRemarkTextarea,
		isRemarkLook,
		lookRemarkItem,
		lookRemarkDelete,
		lookRemarkAdd,
		closeRemark,
		lookRemarkHandle
	}
}


/* 补全客户信息弹窗 */
export function useCompleteInfoDia() {
	const completeForm = ref({
		show:false,
	})//补全信息弹窗

	const RoleType = computed(() => {
		let type = localStorage.getItem('RoleType') || '';
		return type;
	})
	
	//获取客户详情判断基本信息是否完整 id 客户id type 1 跨部门 0 不是跨部门
	async function getCustomerDetail(id,type){
		
		let res=await customInterence.customDetail({
			CompanyId:id
		})
		if(res.Ret!=200) return
	
		// 跨部门领取
		if(type===1){
			if((res.Data.Item.RegionType!='海外'&&!res.Data.Item.Province&&!res.Data.Item.City)||!res.Data.Item.CreditCode){
	
				completeForm.value={
					CompanyId:id,
					name:res.Data.Item.CompanyName,
					nameDisable:res.Data.Item.CompanyName!='',
					Province:res.Data.Item.Province,
					City:res.Data.Item.City,
					CityDisable:res.Data.Item.City!='',
					CreditCode:res.Data.Item.CreditCode,
					CreditCodeDisable:res.Data.Item.CreditCode!='',
					RegionType:res.Data.Item.RegionType,
					
					flag:true,//是否为跨部门
					show:true
				}
			}else{
				completeForm.value.show=false
			}
		}else{
			let IndustryId='',Source=';'
			if(RoleType.value=='ficc'){
				IndustryId=res.Data.FiccItem.IndustryId
				Source=res.Data.FiccItem.Source
			}else if(RoleType.value=='权益'){
				IndustryId=res.Data.RaiItem.IndustryId
				Source=res.Data.RaiItem.Source
			}
			// let IndustryId=res.Data.CreateAuth == 1?res.Data.FiccItem.IndustryId:res.Data.RaiItem.IndustryId
			// let Source=res.Data.CreateAuth == 1?res.Data.FiccItem.Source:res.Data.RaiItem.Source
			if((res.Data.Item.RegionType!='海外'&&!res.Data.Item.Province&&!res.Data.Item.City)||!res.Data.Item.CreditCode||!IndustryId||!Source){
				completeForm.value={
					nameDisable:res.Data.Item.CompanyName!='',
					CityDisable:res.Data.Item.City!='',
					CreditCodeDisable:res.Data.Item.CreditCode!='',
					IndustryIdDisable:IndustryId!=' ',
					SourceDisable:Source!='',
					CompanyId:id,
					name:res.Data.Item.CompanyName,
					Province:res.Data.Item.Province,
					City:res.Data.Item.City,
					CreditCode:res.Data.Item.CreditCode,
					IndustryId:IndustryId?IndustryId:'',
					Source:Source,
					RegionType:res.Data.Item.RegionType,
					flag:false,//是否为跨部门
					show:true
				}
			}else{
				completeForm.value.show=false
			}
		}
	
		return new Promise((resolve,reject)=>{
			resolve(completeForm.value.show)
		})
			
	}

	function closeCompleteInfo() {
		completeForm.value.show = false
	}

	return {
		completeForm,
		getCustomerDetail,
		closeCompleteInfo
	}
}

/* 冻结客户理由弹窗 */
export function useFreezeReasonDia() {
	const isFreezeReason = ref(false)//冻结理由弹窗
	const freezeData = ref({
		reason:"",//冻结理由
		CompanyId:'',
		CompanyType:""
	})


	function freezHandle(item) {
		isFreezeReason.value = true
		freezeData.value.CompanyId=item.CompanyId
		let RoleType=localStorage.getItem('RoleType')
		freezeData.value.CompanyType=RoleType
	}

	//关闭冻结理由弹窗
	function closeFreezeReason(){
		isFreezeReason.value=false
		freezeData.value={
			reason:"",
			CompanyId:'',
			CompanyType:""
		}
	}

	return {
		isFreezeReason,
		freezeData,
		freezHandle,
		closeFreezeReason
	}

}
