<template>
	<div class="customSearch_container">
		<div class="customSearch_top">
			<el-input
				placeholder="客户名称/社会信用码/手机号码/邮箱"
				v-model="search_txt"
				style="maxWidth:520px"
				@keyup.enter.native="getTableData"
				clearable>
				<i slot="prefix" class="el-input__icon el-icon-search"></i>
			</el-input>
			<el-button type="primary" @click="pageinfo.page_no=1;getTableData()" style="marginLeft:20px;">客户检索</el-button>
		</div>
		<div class="customSearch_cont">
			<el-table
			ref="table"
			:data="tableData"
			v-loading="isShowloadding"
			element-loading-text="客户检索中..."
			border>
				<el-table-column
				prop="CompanyName"
				label="客户名称"
				align="center">
					<template slot-scope="scope">
						<span class="mouse-enter" :style="scope.row.Status=='潜在'?'':'color:#bbb;cursor:pointer;'" 
						 @click="goDetail(scope.row)"
						v-if="scope.row.IsSuspend===1|| scope.row.Status=='潜在'">
							{{scope.row.CompanyName}}
						</span>
						<span v-else :class="scope.row.BtnItem.BtnView?'customName':''" :style="{color:scope.row.BtnItem.BtnView?'#409EFF':'#606266',cursor:scope.row.BtnItem.BtnView?'pointer':'text'}" @click="goDetail(scope.row)">{{scope.row.CompanyName}}</span>
						<el-tooltip content="此客户存在长期且反复申请试用，但从未签约的情况，请谨慎领取" placement="top" :open-delay="500" 
						v-if="RaiSellerRole && scope.row.IsScrounge == 1">
							<img width="16" style="cursor: pointer;" src="../../assets/img/icons/warning_triangle_yellow.png" />
						</el-tooltip>
					</template>
				</el-table-column>
				<el-table-column
				prop="CreditCode"
				label="社会信用码"
				align="center">
					<template slot-scope="scope"> <span :style="scope.row.IsSuspend===1?'color:#bbb':''">{{scope.row.CreditCode}}</span> </template>
				</el-table-column>
				<el-table-column
				prop="Status"
				label="客户状态"
				align="center">
					<template slot-scope="scope"> 
						<p :style="scope.row.IsSuspend === 1 ? 'color:#bbb;margin:3px 0' : 'margin:3px 0'" v-for="item in transformedArray(scope.row)" :key="item">
							<template v-if="item.Status">
							{{ item.Status }}
							<br v-if="item.SigningStatus"/>
							<el-tag v-if="item.SigningStatus" :type="item.SigningStatus === '已签约过' ? '' : 'warning'" size="mini">{{ item.SigningStatus }}</el-tag>
							</template>
						</p>
					</template>
				</el-table-column>
				<el-table-column
				prop="CompanyType"
				label="客户类型"
				align="center">
					<template slot-scope="scope"> <span :style="scope.row.IsSuspend===1?'color:#bbb':''">{{scope.row.CompanyType}}</span> </template>
				</el-table-column>
				<el-table-column
				prop="SellerName"
				label="销售"
				align="center">
					<template slot-scope="scope"> <span :style="scope.row.IsSuspend===1?'color:#bbb':''">{{scope.row.SellerName||'--'}}</span> </template>
				</el-table-column>
				<el-table-column
				prop="Duration"
				label="时长（天）"
				align="center">
					<!-- <template slot-scope="scope"> <span :style="(scope.row.BtnItem.BtnSuspend && scope.row.IsSuspend===1)?'color:#bbb':''">{{scope.row.Duration?((scope.row.Status=='流失'?'流失天数：':'剩余天数：')+scope.row.Duration):'--'}}</span> </template> -->
					<template slot-scope="scope"> <span :style="scope.row.IsSuspend===1?'color:#bbb':''">{{scope.row.Duration|formateDuration(scope.row.Status)}}</span> </template>
				</el-table-column>
				<el-table-column label="操作" align="center" min-width="120">
					<template slot-scope="scope" v-if="!scope.row.ApproveStatus||scope.row.ApproveStatus==='待审批'">
						<!-- 新操作栏 -->
							<div style="color:#4099ef; font-size:24px;">
								<span :class="item==='BtnDelete'?'deletesty':'editsty'" style="margin: 0 5px;" @click.stop="itemclickHandle({type:btnName(item,scope.row.IsSuspend),data:scope.row})"
								v-for="item,index in btnList(scope.row.BtnItem,'front')" :key="index">{{btnName(item,scope.row.IsSuspend)}}</span>
								<el-dropdown size="medium" placement="bottom-start" @command="itemclickHandle"
								v-if="btnList(scope.row.BtnItem,'back').length">
									<span class="el-dropdown-link">
										<i class="el-icon-more el-icon--right"></i>
										<el-dropdown-menu slot="dropdown">
											<el-dropdown-item :command="{type:btnName(item,scope.row.IsSuspend),data:scope.row}" 
											v-for="item,index in btnList(scope.row.BtnItem,'back')" :key="index">
												<span>{{btnName(item,scope.row.IsSuspend)}}</span>
											</el-dropdown-item>
										</el-dropdown-menu>
									</span>
								</el-dropdown>
							</div>
						<!-- <div style="color:#4099ef; font-size:24px;">
							<span class="editsty" style="marginRight:10px;" @click="editHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnEdit">编辑</span>
							<span class="editsty" style="marginRight:10px;" 
							v-if="scope.row.BtnItem.BtnFreeze"
							@click="freezHandle(scope.row)">冻结</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnSuspend && scope.row.IsSuspend ===1" @click="suspendHandle(scope.row)">启用</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnSuspend && scope.row.IsSuspend ===0" @click="suspendHandle(scope.row)">暂停</span>
							<span class="editsty" style="marginRight:10px;" @click="receiveOtherHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnReceiveOther">领取</span>
							<span class="editsty" style="marginRight:10px;" @click="lookHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnView">查看权限</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnModifySeller" @click="updateSale(scope.row)">修改销售</span>
							<span class="editsty" style="marginRight:10px;" @click="updateHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnUpdate">服务更新</span>
							<span class="editsty" style="marginRight:10px;" @click="receiveHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnReceive">领取客户</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnDelay" @click="applyHandle('申请延期',scope.row)">申请延期</span>
							<span class="editsty" style="marginRight:10px;" @click="applyTurn(scope.row)"
							v-if="scope.row.BtnItem.BtnTurnPositive">申请转正</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnThaw" @click="applyHandle('申请解冻',scope.row)">申请解冻</span>
							<span class="editsty" style="marginRight:10px;"
							v-if="scope.row.BtnItem.BtnApplyReceive" @click="applyHandle('申请领取',scope.row)">申请领取</span>
							<span class="deletesty" @click.stop="delHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnDelete">删除</span>
						</div> -->
						<!-- 试用操作栏显示样式 -->
						<!-- <div style="color:#4099ef; font-size:24px;" v-if="scope.row.Status=='试用'">
							<span class="editsty" style="marginRight:10px;" @click="lookHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnView">查看权限</span>
							<span class="editsty" style="marginRight:10px;" @click="itemclickHandle({type:'申请转正',data:scope.row})" 
							v-if="scope.row.BtnItem.BtnTurnPositive">申请转正</span>
							<span class="editsty" @click.stop="itemclickHandle({type:'申请延期',data:scope.row})"
							v-if="scope.row.BtnItem.BtnDelay">申请延期</span>
							<el-dropdown size="medium" placement="bottom-start" @command="itemclickHandle"
							v-if="(scope.row.BtnItem.BtnSuspend)
							||(scope.row.BtnItem.BtnDelete)
							||(scope.row.BtnItem.BtnModifySeller)
							||(scope.row.BtnItem.BtnEdit)
							||(scope.row.BtnItem.BtnFreeze)
							||(scope.row.BtnItem.BtnReceiveOther)
							||(scope.row.BtnItem.BtnTryOut)">
								<span class="el-dropdown-link">
									<i class="el-icon-more el-icon--right"></i>
								</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item :command="{type:'启用',data:scope.row}" 
									v-if="scope.row.BtnItem.BtnSuspend && scope.row.IsSuspend ===1">
										<span>启用</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'暂停',data:scope.row}" 
									v-if="scope.row.BtnItem.BtnSuspend && scope.row.IsSuspend ===0">
										<span>暂停</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'冻结',data:scope.row}" 
									v-if="scope.row.BtnItem.BtnFreeze">
										<span>冻结</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'领取',data:scope.row}" 
									v-if="scope.row.BtnItem.BtnReceiveOther">
										<span>领取</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'增开试用',data:scope.row}"
									v-if="scope.row.BtnItem.BtnTryOut">
										<span>增开试用</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'修改销售',data:scope.row}"
									v-if="scope.row.BtnItem.BtnModifySeller">
										<span>修改销售</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'编辑',data:scope.row}"
									v-if="scope.row.BtnItem.BtnEdit">
										<span>编辑</span>
									</el-dropdown-item>
									<el-dropdown-item :command="{type:'删除',data:scope.row}"
									v-if="scope.row.BtnItem.BtnDelete">
										<span>删除</span>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</div> -->
						<!-- 其他状态操作栏显示 -->
						<!-- <div style="color:#4099ef;font-size:24px;" v-else>
							<span class="editsty" style="marginRight:5px;" @click="editHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnEdit">编辑</span>
							<span class="editsty" style="marginRight:5px;" @click="receiveOtherHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnReceiveOther">领取</span>
							<span class="editsty" style="marginRight:5px;" @click="lookHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnView">查看权限</span>
							<span class="editsty" style="marginRight:5px;"
							v-if="scope.row.BtnItem.BtnModifySeller" @click="updateSale(scope.row)">修改销售</span>
							<span class="editsty" style="marginRight:5px;" 
							v-if="scope.row.BtnItem.BtnTryOut" @click="addTrialHandle(scope.row)">增开试用</span>
							<span class="editsty" style="marginRight:5px;" @click="updateHandle(scope.row)" 
							v-if="scope.row.BtnItem.BtnUpdate">续约申请</span>
							<span class="editsty" style="marginRight:5px;" @click="addAgreement(scope.row)" 
							v-if="scope.row.BtnItem.BtnAddAgreement">补充协议</span>
							<span class="editsty" style="marginRight:5px;" @click="receiveHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnReceive">领取客户</span>
							<span class="editsty" style="marginRight:5px;"
							v-if="scope.row.BtnItem.BtnThaw" @click="applyHandle('申请解冻',scope.row)">申请解冻</span>
							<span class="editsty" style="marginRight:5px;"
							v-if="scope.row.BtnItem.BtnApplyReceive" @click="applyHandle('申请领取',scope.row)">申请领取</span>
							<span class="deletesty" @click.stop="delHandle(scope.row)"
							v-if="scope.row.BtnItem.BtnDelete">删除</span>
						</div> -->
					</template>
				</el-table-column>
				<div slot="empty" style="lineHeight:44px;margin:60px 0;color:#999;" v-if="noResult">
					<img src="~@/assets/img/cus_m/nodata.png" alt="" style="display:block;width:160px;height:128px;margin: auto;">
					<span>暂无信息</span>
				</div>
				<div slot="empty" style="lineHeight:44px;margin:200px 0;color:#999;" v-else>
				</div>
			</el-table>
			<!-- 分页 -->
      		<el-col :span="24" class="toolbar">
        		<m-page :total="pageinfo.total" :page_no="pageinfo.page_no" :pageSize="pageinfo.page_size" @handleCurrentChange="handleCurrentChange"/>
      		</el-col>
		</div>
		<!-- 申请弹窗 -->
		<Capplydia 
		:isApply="isApply"
		:title="applyTit"
		:formdata="applyForm"
		:contactFormData="contactFormData"
		@cancelHandle="cancelHandle">
		</Capplydia>
		<!-- 查看权限弹窗 -->
		<el-dialog
		:visible.sync="isLook"
		:close-on-click-modal="false"
		:modal-append-to-body='false'
		@close="closeDia"
		width="800px"
		center>
			<div slot="title" style="display:flex;alignItems:center;">
				<img :src="$icons.auth" style="color:#fff;width:16px;height:16px;marginRight:5px;">
				<span style="fontSize:16px;">查看权限</span>
			</div>
			<template v-if="lookAuthList && lookAuthList.length > 0">
				<div>
					FICC权限
				</div>
				<el-table
			:data="lookAuthList"
			:span-method="objectSpanMethod"
			border
			max-height="300"
			style="width: 100%; margin-top: 20px;margin-bottom: 20px">
				<el-table-column label="所属类目" align="center">
					<template slot-scope="scope">{{scope.row.ClassifyName}}</template>
				</el-table-column>
				<el-table-column label="品种" align="center">
					<template slot-scope="scope">{{scope.row.PermissionName}}</template>
				</el-table-column>
				<el-table-column label="状态" align="center">
					<template slot-scope="scope">{{scope.row.Status}}</template>
				</el-table-column>
				<el-table-column label="服务期限" align="center" min-width="200">
					<template slot-scope="scope">{{scope.row.StartDate+'~'+scope.row.EndDate|formatTime}}</template>
				</el-table-column>
				<el-table-column label="剩余天数" align="center">
					<template slot-scope="scope">{{scope.row.ExpireDay}}</template>
				</el-table-column>
			</el-table>
			</template>
			<template v-if="lookAuthListEquity && lookAuthListEquity.length > 0">
				<div>
					权益权限
				</div>
				<el-table
			:data="lookAuthListEquity"
			:span-method="objectSpanMethodEquity"
			border
			max-height="300"
			style="width: 100%; margin-top: 20px">
				<el-table-column label="行业" align="center">
					<template slot-scope="scope">{{scope.row.PermissionName}}</template>
				</el-table-column>
				<el-table-column label="产品类型" v-if="isPermissionTypeShow" align="center">
					<template slot-scope="scope">{{scope.row.PermissionTypeName}}</template>
				</el-table-column>
				<el-table-column label="状态" align="center">
					<template slot-scope="scope">{{scope.row.Status}}</template>
				</el-table-column>
				<el-table-column label="服务期限" align="center" min-width="200">
					<template slot-scope="scope">{{scope.row.StartDate+'~'+scope.row.EndDate|formatTime}}</template>
				</el-table-column>
				<el-table-column label="剩余天数" align="center">
					<template slot-scope="scope">{{scope.row.ExpireDay}}</template>
				</el-table-column>
			</el-table>
			</template>
			<div style="padding:20px 0;"></div>
		</el-dialog>
		<!-- 增开试用弹窗 -->
		<el-dialog
		:visible.sync="isAddTrial"
		:close-on-click-modal="false"
		:modal-append-to-body='false'
		@close="isAddTrial=false"
		width="800px"
		center>
			<div slot="title" style="display:flex;alignItems:center;">
				<span style="fontSize:16px;">增开试用</span>
			</div>
			<Cauthlist
			:autharr="authList"
			:id="addTryId"
			@addOver="addTryOver"
			@close="isAddTrial=false"/>
		</el-dialog>
		<!-- 移动客户弹窗 -->
		<el-dialog
		:visible.sync="isMove"
		:close-on-click-modal="false"
		:modal-append-to-body='false'
		@close="cancelMove"
		center
		width="30%">
			<div slot="title" style="display:flex;alignItems:center;">
				<img :src="$icons.edit" style="color:#fff;width:16px;height:16px;marginRight:5px;">
				<span style="fontSize:16px;">修改销售</span>
			</div>
			<el-form :model="moveform" :rules="moveRule" ref="moveform" label-width="100px" style="marginTop:15px;">
				<el-form-item label="客户名称" prop="name">
					<span style="fontSize:16px;">{{moveform.companyName}}</span>
				</el-form-item>
				<el-form-item label="所属销售" prop="sale">
					<!-- <el-select 
					v-model="moveform.sale"
					filterable
					placeholder="请选择修改的销售"
					style="width: 70%">
						<el-option
							v-for="item in salesArr"
							:key="item.AdminId"
							:label="item.RealName"
							:value="item.AdminId">
						</el-option>
					</el-select> -->
					<el-cascader
						v-model="moveform.sale"
						placeholder="请选择修改的销售"
						style="width: 70%"
						:options="salesArr"
						:props="{multiple: false,label:'RealName',children:'ChildrenList',value:'AdminId'}"
						:show-all-levels="false"
						clearable
						filterable>
					</el-cascader>
				</el-form-item>
			</el-form>	
			<div style="display:flex;justify-content:center;margin:75px 0 26px;">
				<el-button type="primary" style="width:80px;marginRight:24px;" @click="saveMove">保存</el-button>
				<el-button  style="width:80px;" @click="cancelMove">取消</el-button>
			</div>
		</el-dialog>
		<!-- 添加联系人弹窗 -->
		<Contactdia
		:id="addCompanyId"
		:title="'新增联系人'"
		:userForm="diaform"
		:needCard="true"
		:isShowclose="isShowclose"
		:isPickLoss="isPickLoss"
		:isPickSelf="isPickSelf"
		:regionType="regionType"
		:isAddContact="isAddContact"
		@cancel="cancelConcatdia"
		@addContactNext="addContactNext">
		</Contactdia>

		<!-- 冻结理由弹窗 -->
		<el-dialog
		:visible.sync="isFreezeReason"
		:close-on-click-modal="false"
		:modal-append-to-body='false'
		@close="closeFreezeReason"
		width="800px"
		center>
			<div slot="title" style="display:flex;alignItems:center;">
				<img src="../../assets/img/freeze-icon.png" alt="" width="16" style="margin-right:10px">
				<span style="fontSize:16px;">冻结</span>
			</div>
			<el-input
				type="textarea"
				:rows="6"
				placeholder="请输入冻结理由"
				v-model="freezeData.reason">
			</el-input>
			<div style="text-align:center;margin:30px 0;">
				<el-button type="primary" @click="handleConfirmFreeze">确定</el-button>
				<el-button type="primary" plain @click="closeFreezeReason">取消</el-button>
			</div>
		</el-dialog>

		<!-- 补全信息弹窗 -->
		<CompleteInfo
			:form="completeForm"
			@cancel="cancelCompleteInfo($event)"
		></CompleteInfo>

		<!-- 申请转正、续约申请、补充协议选择申请合同模式弹窗 -->
		<el-dialog
			:visible.sync="contractModel.show"
			:modal-append-to-body='false'
			width="800px"
			class="self-dialog"
		>
			<div style="text-align:center;margin:30px 0 100px 0">
				<img width="191" src="../../assets/img/cus_m/bzht.png" @click="handleContractModel('标准')" style="margin-right:80px;cursor: pointer;">
				<img width="191" src="../../assets/img/cus_m/fbzht.png" @click="handleContractModel('非标准')" style="cursor: pointer;">
				<p style="font-size:15px;color:#333;text-align:left;padding-left:100px;margin-top:30px">
					注：<br>
					系统生成合同请选择标准合同入口<br>
					非系统生成合同请选择非标准合同入口(包含已走完邮件流程的标准合同)</p>
			</div>
		</el-dialog>
		<!-- 申请转正、续约申请、补充协议标准合同模式下 合同信息弹窗 -->
		<ContractInfo 
			:initData="contractDialog" 
			@contractInfoDialogClose="contractInfoDialogClose"
		></ContractInfo>
		<!-- 查看备注弹窗 -->
		<el-dialog
		:visible.sync="isRemarkLook"
		:close-on-click-modal="false"
		:modal-append-to-body="true"
		:append-to-body="true"
		@close="closeDia"
		width="800px"
		v-dialogDrag
		center>
			<div slot="title" style="display:flex;alignItems:center;">
				<img :src="$icons.auth" style="color:#fff;width:16px;height:16px;marginRight:5px;">
				<span style="fontSize:16px;">{{lookRemarkTitle}}</span>
			</div>
			<template>
				<div v-if="(RoleIdentity == 'rai_seller' || RoleIdentity == 'ficc_seller') || (SellerAdminId == lookRemarkItem.SellerId)">
					<el-input
						type="textarea"
						:rows="3"
						placeholder="请输入文字"
						v-model="lookRemarkTextarea">
					</el-input>
					<div class="look-remark-commit" @click="lookRemarkAdd">保存</div>
				</div>
				<el-table
			:data="lookRemarkList"
			border
			max-height="300"
			style="width: 100%; margin-top: 20px;margin-bottom: 20px">
				<el-table-column label="备注内容"  key="Remark"  align="center">
					<template slot-scope="scope">{{scope.row.Remark}}</template>
				</el-table-column>
				<el-table-column label="客户类型" align="center" key="ProductName" v-if="lookRemarkItem.IsShared && (RoleIdentity != 'rai_seller' && RoleIdentity != 'ficc_seller')">
					<template slot-scope="scope">{{scope.row.ProductName}}</template>
				</el-table-column>
				<el-table-column label="创建时间"  key="CreateTime" align="center">
					<template slot-scope="scope">{{scope.row.CreateTime}}</template>
				</el-table-column>
				<el-table-column label="操作" align="center">
					<template slot-scope="{row}">
						<el-button type="text" size="small" style="color:red;" v-if="row.ButtonDel"
							@click="lookRemarkDelete(row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			</template>
			<div style="padding:20px 0;"></div>
		</el-dialog>
		<!-- 查看备注弹窗 -->
		<!-- 权限详情弹框 -->
		<permission-detail :isPermissionDetailShow.sync="isPermissionDetailShow" :researchDetailId.sync="researchDetailId"/>
	</div>
</template>

<script>
import { customInterence } from '@/api/api.js'
import Capplydia from './compontents/Capplydialog.vue'
import Contactdia from './compontents/Contactdialog'
import Cauthlist from './compontents/CauthList.vue'
import CompleteInfo from './compontents/CompleteInfo.vue'
import ContractInfo from './compontents/ContractInfo.vue'
import mPage from '@/components/mPage.vue'
import PermissionDetail from './compontents/permissionDetail.vue'
export default {
	name:'',
	components: {Capplydia,Contactdia,Cauthlist,CompleteInfo,ContractInfo,mPage, PermissionDetail},
	computed:{
		Role() {
			let role = localStorage.getItem('Role') || '';
			return role;
		},
		RaiSellerRole(){
			return ['rai_seller','rai_admin','admin'].includes(this.Role)
		},
		RoleType() {
			let type = localStorage.getItem('RoleType') || '';
			return type;
		},
		RoleIdentity(){
			let role = localStorage.getItem('RoleIdentity') || '';
			return role;
		},
		SellerAdminId() {
			let type = localStorage.getItem('AdminId') || '';
			return type;
		},
	},	
	filters: {
		formateDuration(time,status){
			// let str
			// let arr=status.split('/').map(item=>{
			// 	if(item=='冻结'){
			// 		return '解冻天数'
			// 	}else if(item=='流失'){
			// 		return '流失天数'
			// 	}else{
			// 		return '剩余天数'
			// 	}
			// })

			// str=`${arr.join('/')}：${time}`
			
			// if(!time){
			// 	str='--'
			// }
			let timearr=time.split('/')
			let statusarr=status.split('/').map((item,index)=>{
				if(item=='冻结'){
					return `解冻天数:${timearr[index]?timearr[index]:'--'}`
				}else if(item=='流失'){
					return `流失天数:${timearr[index]?timearr[index]:'--'}`
				}else if(item=='永续'){
					return '永续'
				}else{
					return `剩余天数:${timearr[index]?timearr[index]:'--'}`
				}
			})

			return statusarr.join('/')
		}	
	},
	data () {
		return {
			contractModel:{
				show:false,
				data:null,//客户信息（列表用户数据）
				type:'',//类型 申请转正、续约申请、补充协议
			},// 申请转正、续约申请、补充协议 选择合同类型弹窗 
			contractDialog:{
				show:false,
				type:'',//类型 申请转正、续约申请、补充协议
				cusdata:null,//客户信息（列表用户数据）
			},//申请转正、续约申请、补充协议 合同信息弹窗

			noResult:false,
			search_txt:'',
			isShowloadding:false,//
			tableData:[],
			isApply:false,//申请弹窗
			applyForm:{},//客户信息
			applyTit:'',
			isLook:false,//权限弹窗
			lookAuthList:[],//查看的权限
			authList:[],
			indexArrEquity: [],//权益
			spanArrEquity: [],//权益
			posEquity: 0,//权益
			citiesListEquity:[],//权益//现有权限列表
			citiesListpitchOn:[],//权益//现有权限列表
			isPermissionTypeShow:false,
			citiesEquity:[],//权益//现有权限列表
			lookAuthListEquity:[],
			isMove:false,//修改销售
			type: '',//权益//还是ficc
			salesArr:[],//修改销售时可选择的数据
			modifysalesArrtem:[],//从后台获取的修改销售的所有数据
			moveform:{
				companyType:'',
				companyId:'',//客户id
				companyName:'',
				sale:'',//修改的销售
			},
			moveRule:{
				sale:[
					{ required: true, message: '所属销售不能为空', trigger: 'blur' },
				]
			},
			addCompanyId:'',//新增联系人的公司id
			diaform:{
				name:'',
				sex:1,
				telCode:'86',
				tel1:'',
				tel2:'',
				mail:'',
				post:'',
				desiger:'',
				depart:'',
				carte:'',
				Source:'pick_custom'
			},
			isRoleType:localStorage.getItem('RoleType'),
			isAddContact:false,//是否添加联系人
			isShowclose:false,//是否显示取消
			isPickLoss:false,//联系人弹窗时记录是否是领取流失客户
			isPickSelf:false,//是否为领取自己的流失客户
			regionType:"",
			isAddTrial:false,//增加试用弹窗
			addTryId:'',//增开试用的id
			position: 0,
			rowSpanArr: [],//处理合并行数组结构

			completeForm:{
				show:false,
			},//补全信息弹窗

			isFreezeReason:false,//冻结理由弹窗
			freezeData:{
				reason:"",//冻结理由
				CompanyId:'',
				CompanyType:""
			},

			contactFormData:{},//领取自己的流失客户新增联系人填写的表单数据

			pageinfo:{	// 分页信息
				total: 0,
				page_no: 1,
				page_size: 10
			},
			btnCommandList:{
				BtnAddAgreement: '补充协议',
				BtnApplyReceive: '申请领取',
				BtnDelay: '申请延期',
				BtnDelete: '删除',
				BtnDetail: '',
				BtnEdit: '编辑',
				BtnFreeze: '冻结',
				BtnModifySeller: '修改销售',
				BtnReceive: '领取客户',
				BtnReceiveOther: '领取',
				BtnSuspend: '启用/暂停',
				BtnThaw: '申请解冻',
				BtnTryOut: '增开试用',
				BtnTurnPositive: '申请转正',
				BtnUpdate: '续约申请',
				BtnView: '查看权限',
				BtnRemarkView: '备注',
				IsResearchShow:'研选详情'
			},	// 按钮命令列表
			lookRemarkTitle:'',//查看备注标题
			lookRemarkList:[],//查看备注列表
			lookRemarkTextarea:'',//备注的文本框
			isRemarkLook:false ,////查看备注弹窗
			lookRemarkItem:{},////查看备注的item项
			isPermissionDetailShow:false ,// 权限详情 弹框
			researchDetailId:0,
		};
	},
	/* 页面跳转前记录参数 */
	beforeRouteLeave(to, form, next) {
		let backData = {
			keyword:this.search_txt,
			page:this.pageinfo.page_no
		}
		sessionStorage.setItem('customSearchBack',JSON.stringify(backData))
		next()
	},
	/* 页面进入前是否清除参数 */
	beforeRouteEnter(to,from,next) {
		if(from.path!='/editCustom'&&from.path!='/turnCustom'&&from.path!='/updateCustom'&&from.path!='/pickCustom'&&from.path!='/customDetail') {
			sessionStorage.removeItem('customSearchBack')
		}
		next()
	},
	methods: {
		contractInfoDialogClose(e){
			this.contractDialog={
				show:false,
				type:'',//类型 申请转正、续约申请、补充协议
				cusdata:null,//客户信息（列表用户数据）
			}
			if(e==='updateList'){
				this.getTableData();
			}
		},

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

		// 领取自己的流失客户下一步申请操作
		addContactNext({formData}){
			this.contactFormData=formData
			this.isAddContact=false
			this.isApply=true
		},

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

		//确认冻结
		async handleConfirmFreeze(){
			if(!this.freezeData.reason){
				this.$message.error('请填写冻结理由')
				return
			}
			let res=await customInterence.Freez({
				CompanyId:Number(this.freezeData.CompanyId),
				CompanyType:this.freezeData.CompanyType,
				Remark:this.freezeData.reason
			})
			if(res.Ret===200){
				this.$message.success('冻结成功');
				this.closeFreezeReason()
				this.getTableData();
			}
		},

		/* 获取表格数据 */
		getTableData() {
			this.isShowloadding = true;
			customInterence.searchList({
				KeyWord:this.search_txt,
				PageSize:this.pageinfo.page_size,
				CurrentIndex:this.pageinfo.page_no
			}).then(res => {
				if(res.Ret === 200) {
					this.tableData = res.Data?res.Data.List:[];
					this.pageinfo.total=res.Data && res.Data.Paging ? res.Data.Paging.Totals : 0
					this.tableData.forEach(item => {
						item.ApproveStatus = item.ApproveStatus=='待审批'?'待审批':''
					})
					this.noResult = res.Data.List.length ? false : true;
					setTimeout(()=> {
						this.isShowloadding = false;
					},100)
				}else {
					this.tableData = [];
					this.noResult = true;
					setTimeout(()=> {
						this.isShowloadding = false;
					},100)
				}
			})	
		},
		/* 获取销售 */
		getSale() {
			customInterence.getSale({AllSeller:true}).then(res => {
				if(res.Ret === 200) {
					this.modifysalesArrtem = res.Data.List;
				}
			})
		},
		/* 查看详情 */
		goDetail(item) {
			console.log(item.BtnItem.BtnView);
			if(!item.BtnItem.BtnView) return
			this.$router.push({
				path:'/customDetail',
				query: {
					id:item.CompanyId
				}
			})
		},
		/* 试用状态下拉菜单操作 */
		itemclickHandle(query) {
			if(query.type == '申请转正') {
				this.applyTurn(query.data)
			}else if(query.type == '申请延期' || query.type == '申请解冻') {
				this.applyHandle(query.type,query.data)
			}else if(query.type == '申请领取') {
				if(this.RaiSellerRole && query.data.IsScrounge == 1){
					this.$confirm('此客户存在长期且反复申请试用，但从未签约的情况，确定要领取吗？','申请领取',{
						type:'warning'
					}).then(() => {
						this.applyHandle('申请领取',query.data)
					}).catch(() => {});
				}else{
					this.applyHandle('申请领取',query.data)
				}
			}else if(query.type == '修改销售') {
				this.updateSale(query.data);
			}else if(query.type == '启用' || query.type == '暂停') {
				this.suspendHandle(query.data)
			}else if(query.type == '冻结') {
				this.freezHandle(query.data);
			}else if(query.type == '领取') {
				this.receiveOtherHandle(query.data);
			}else if(query.type == '增开试用') {
				this.addTrialHandle(query.data)
			}else if(query.type=='编辑'){
				this.editHandle(query.data)
			}else if(query.type=='删除'){
				this.delHandle(query.data)
			}else if(query.type=='查看权限'){
				this.lookHandle(query.data)
			}else if(query.type=='续约申请'){
				this.updateHandle(query.data)
			}else if(query.type=='补充协议'){
				this.addAgreement(query.data)
				this.addAgreement(query.data)
			}else if(query.type=='领取客户'){
				if(this.RaiSellerRole && query.data.IsScrounge == 1){
					this.$confirm('此客户存在长期且反复申请试用，但从未签约的情况，确定要领取吗？','领取客户',{
						type:'warning'
					}).then(() => {
						this.receiveHandle(query.data)
					}).catch(() => {})
				}else{
					this.receiveHandle(query.data)
				}
			}else if(query.type=='备注'){
				this.lookRemarkHandle(query.data)
			}else if(query.type=='研选详情'){
				this.researchDetailHandle(query.data)
			}
		},
		/* 查看权限 */
		lookHandle(item) {
			this.authList = [];
			this.lookAuthList = [];
			customInterence.lookauth({
				CompanyId:item.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
				let auth = [];			
					res.Data.List ?	res.Data.List.forEach(item=> { 
						auth.push(item.Items)
					}):''
					this.lookAuthList = auth.flat(Infinity);
					this.getRowSpan();
					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)
								}
							}
						})
					}):''
					this.lookAuthListEquity = authEquity.flat(Infinity) //权益
					this.isPermissionTypeShow = this.lookAuthListEquity.some(item => !item.IsMerge)
					this.$nextTick(()=>{
						this.isPermissionTypeShow = this.lookAuthListEquity.some(item => !item.IsMerge)
					})
					this.getSpanArr(this.lookAuthListEquity) //权益
				}
			})
			this.isLook = true;
		},
		/* 关闭弹框后重置 */
		resetEquity(){
			this.lookAuthListEquity = []
			this.indexArrEquity = []//权益
			this.spanArrEquity = []//权益
			this.posEquity = 0//权益
		},
		/* 权益处理数据 */
		getSpanArr(data) {
			data.map((v, i, s) => {
				if (!v.PermissionTypeName) {
				this.indexArrEquity.push(i);
				}
			});
				for (var i = 0; i < data.length; i++) {
					let element = data[i]
					if (i === 0) {
						this.spanArrEquity.push(1);
						this.posEquity = 0;
					} else {
						// 判断当前元素与上一个元素是否相同（line为标记）
						if (element.PermissionName === data[i - 1].PermissionName) {
							if(element.IsMerge){
								// 主客观都有，需要合并
								this.spanArrEquity[this.posEquity] += 1;
								this.spanArrEquity.push(0);
							}else{
								// 主客观都有 不需要合并，说明是服务期限或者状态不一样
								this.spanArrEquity[this.posEquity] += 0.5;
								this.spanArrEquity.push(0.5);
							}
						} else {
							this.spanArrEquity.push(1);
							this.posEquity = i;
						}
					}
				}
				// console.log(this.indexArrEquity,this.spanArrEquity);
    	},
		/* 关闭查看权限弹窗 */
		closeDia() {
			this.lookTitle = '';
			this.lookRemarkTextarea = '';
			this.lookRemarkList = []
			this.resetEquity()
			this.isLook = false;
		},
		/* 权益处理数组合并 */
		objectSpanMethodEquity({ row, column, rowIndex, columnIndex}){
			if(!this.isPermissionTypeShow){
				console.log(this.isPermissionTypeShow);
				// 产品类型不显示
				const _row = this.spanArrEquity[rowIndex];
				if(_row == 0){
					return {
						rowspan: _row,
						colspan: 0,
					};
				}
			}else{
				//处理行的合并
				if (this.indexArrEquity.includes(rowIndex)) {
					if (columnIndex === 0) {
						return {
							rowspan: 1,
							colspan: 2,
						};
					} else if (columnIndex === 1) {
						return {
							rowspan: 0,
							colspan: 0,
						};
					}
				}
				// 权益行业主客观合并
				const _row = this.spanArrEquity[rowIndex];
				if(_row == 2){
					// 为2 是主客观都有，合并，这时合并行业和产品类型
					if(columnIndex === 0){
						return {
							rowspan: 1,
							colspan: 2,
						};
					}else if(columnIndex === 1){
						return {
							rowspan: 0,
							colspan: 0,
						};
					}
				}else if(_row == 0){
					// 为0 表示不需要这行，被合并掉了
					return {
						rowspan: _row,
						colspan: 0,
					};
				}else if(_row == 1.5){
					// 为1.5 是主客观都有，但不合并，这时合并行业
					if(columnIndex === 0){
						return {
							rowspan: 2,
							colspan: 1,
						};
					}
				}else if(_row == 0.5){
					if(columnIndex === 0){
						return {
							rowspan: 0,
							colspan: 0,
						};
					}
				}
			}
		},
		/* 修改销售操作 */
		updateSale(item) {
			this.moveform = {
				companyType:item.CompanyType,
				companyName:item.CompanyName,
				companyId:item.CompanyId,
				sale:''
			}
			this.handleModifysalesArr(item.SellerId)
			this.isMove = true;
		},
		/* 移动客户所属销售 */
		saveMove() {
			this.$refs.moveform.validate((valid) => {
				if (valid) {
					customInterence.moveSale({
						CompanyType:this.moveform.companyType,
						CompanyId:this.moveform.companyId,
						SellsId:Number(this.moveform.sale[1])||Number(this.moveform.sale[2])
					}).then(res => {
						if(res.Ret === 200) {
							this.$message.success(res.Msg);
							this.getTableData();
							this.isMove = false;
						}
					})
				}
			})		
		},
		/* 取消移动客户 */
		cancelMove() {
			this.$refs.moveform.resetFields();
			this.isMove = false;
		},
		// 服务更新拆分为 续约申请和补充协议
		/* 续约申请操作 */
		async updateHandle(item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId)
			if(flag) return
			this.contractModel={
				show:true,
				data:item,
				type:'续约申请'
			}
			// sessionStorage.setItem('companyInfo',JSON.stringify(item))
			// this.$router.push({
			// 	path:'/updateCustom',
			// })
		},
		// 补充协议
		async addAgreement(item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId)
			if(flag) return
			this.contractModel={
				show:true,
				data:item,
				type:'补充协议'
			}
			// sessionStorage.setItem('companyInfo',JSON.stringify(item))
			// this.$router.push({
			// 	path:'/addAgreement',
			// })
		},
		/* 申请转正 */
		async applyTurn(item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId,0) 
			if(flag) return
			this.contractModel={
				show:true,
				data:item,
				type:'申请转正'
			}
			// sessionStorage.setItem('companyInfo',JSON.stringify(item))
			// this.$router.push({
			// 	path:'/turnCustom'
			// })
		},
		/* 启用/暂停 */
		suspendHandle(item) {
			customInterence.Suspend({
				CompanyId:item.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
					this.$message.success(res.Msg);
					item.IsSuspend = item.IsSuspend === 1 ? 0 : 1;
				}
			})
		},
		/* 冻结客户 */
		freezHandle(item) {
			this.isFreezeReason=true 
			console.log(item.CompanyId);
			this.freezeData.CompanyId=item.CompanyId
			// this.freezeData.CompanyType=item.CompanyType
			let RoleType=localStorage.getItem('RoleType')
			this.freezeData.CompanyType=RoleType
			// this.$confirm('确认冻结该客户?','提示',{
			// 	type:'warning'
			// }).then(() => {
			// 	customInterence.Freez({
			// 		CompanyId:item.CompanyId,
			// 		CompanyType:item.CompanyType
			// 	}).then(res => {
			// 		if(res.Ret === 200) {
			// 			this.$message.success('冻结成功');
			// 			this.getTableData();
			// 		}
			// 	})
			// }).catch(() => {});
		},
		/* 领取流失客户 */
		async receiveHandle(item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId,0)
			if(flag) return

			if(this.RaiSellerRole && item.IsScrounge == 1){
				// 已经弹过二次确认弹窗 避免再一次的弹窗
				this.isPickLoss = true;
				this.regionType = item.RegionType;
				this.addCompanyId = item.CompanyId;
				this.diaform.telCode='86'
				this.isAddContact = true;
				return 
			}
			
			this.$confirm('是否确认领取该客户?','提示',{
				type:'warning'
			}).then(() => {
				/* 如果是权益领取，需要添加联系人 */
				// if(this.RoleType == '权益') {
					this.isPickLoss = true;
					this.addCompanyId = item.CompanyId;
					this.regionType=item.RegionType
					this.diaform.telCode='86'
					this.isAddContact = true;
				// }else {
				// 	customInterence.Pick({
				// 		CompanyId:item.CompanyId,
				// 	}).then(res => {
				// 		if(res.Ret === 200) {
				// 			this.$message.success(res.Msg);
				// 			this.getTableData();
				// 		}
				// 	})
				// }
			}).catch(() => {});
		},
		/* 领取权益/ficc客户 */
		async receiveOtherHandle(item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId,1)
			if(flag) return


			this.$router.push({
				path:'/pickCustom',
				query:{
					id:item.CompanyId
				}
			})
		},

		//获取客户详情判断基本信息是否完整 id 客户id type 1 跨部门 0 不是跨部门
		async 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){

					this.completeForm={
						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{
					this.completeForm.show=false
				}
			}else{
				let RoleType=localStorage.getItem('RoleType')
				let IndustryId='',Source=';'
				if(RoleType=='ficc'){
					IndustryId=res.Data.FiccItem.IndustryId
					Source=res.Data.FiccItem.Source
				}else if(RoleType=='权益'){
					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){
					this.completeForm={
						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{
					this.completeForm.show=false
				}
			}

			return new Promise((resolve,reject)=>{
				resolve(this.completeForm.show)
			})
				
		},
		
		//关闭补全信息弹窗
		cancelCompleteInfo(refresh){
			// 刷新列表
			if(refresh){
				this.getTableData()
			}
			this.completeForm={
				show:false
			}
		},

		/* 申请延期 解冻 领取小弹窗 */
		async applyHandle(tit,item) {
			//判断是否需要补全信息
			let flag=await this.getCustomerDetail(item.CompanyId,0)
			if(flag) return
			this.applyTit = tit;
			this.applyForm = item;
			console.log(this.applyTit ,item);
			// 如果是申请领取（即领取自己流失客户）先添加联系人再进行申请操作
			if(tit=='申请领取'&& (item.SellerId != localStorage.getItem("AdminId"))){
				this.isPickLoss = true;
				this.isPickSelf=true
				this.regionType = item.RegionType;
				this.addCompanyId = item.CompanyId;
				this.diaform={
					name:'',
					sex:1,
					telCode:'86',
					tel1:'',
					tel2:'',
					mail:'',
					post:'',
					desiger:'',
					depart:'',
					carte:'',
					Source:'pick_custom'
				},
				this.isAddContact = true;
			}else{
				this.isApply = true;
			}

			
		},
		/* 取消弹窗 */
		cancelHandle(type) {
			this.isApply = false;
			this.resetEquity()
			this.applyForm = {}
			if(type == 1) {
				this.getTableData();
			}
		},
		/* 编辑客户 */
		editHandle(item) {
			this.$router.push({
				path:'/editCustom',
				query:{
					id:item.CompanyId
				}
			})
		},
		/* 删除 */
		delHandle(item) {
			this.$confirm('删除后客户将不能查阅报告，确定删除吗?','提示',{
				type:'warning'
			}).then(() => {
				customInterence.customDel({
					CompanyId:item.CompanyId
				}).then(res => {
					if(res.Ret === 200) {
						this.$message.success(res.Msg)
						// let index = this.tableData.indexOf(item);
						// this.tableData.splice(index,1)
						this.getTableData();
					}
				})
			}).catch(() => {});
		},
		/* 领取流失客户添加联系人后再领取 */
		cancelConcatdia(type) {
			this.isAddContact = false;
			this.isPickSelf=false
			if(type == 1) {
				customInterence.Pick({
					CompanyId:this.addCompanyId,
				}).then(res => {
					if(res.Ret === 200) {
						this.$message.success(res.Msg);
						this.getTableData();
					}
				})
			}else {
				this.$message.warning('领取失败')
			}
		},
		/* 增加试用 */
		addTrialHandle(item) {
			this.authList = [];
			customInterence.lookauth({
				CompanyId:item.CompanyId,
				LookType:1
			}).then(res => {
				if(res.Ret === 200) {
					let auth = [];
					// res.Data.List 有值为 ficc
					// res.Data.ListRai 有值为 权益
					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)
					}):
					// 权益 RaiMerge 0不管 1合并 2拆分 所传入的数据结构不一样
						/**权益权限ID
						 * 科技-主观(20)-客观(37)
						 * 消费-主观(21)-客观(38)
						 * 医药-主观(22)-客观(39)
						 * 智造-主观(19)-客观(36)
						 * 策略(23)
						 * 专家(29)
						 * 固收(53)
						 * 调研(54)
						 * 路演服务(30)
						 * 研选订阅(31)
						 * 研选扣点包(52)
						*/
					 	res.Data.ListRai[0].RaiMerge==1?res.Data.ListRai.forEach(item=> { // 合并
						let checkedLen = item.Items.filter(it => item.CheckList && item.CheckList.includes(it.ChartPermissionId)).length
						let obj = {
							checkAll:checkedLen === item.Items.length,
							isIndeterminate:checkedLen > 0 && checkedLen < item.Items.length,
							defaultAuth:item.CheckList,
							...item,
						}
						auth.push(obj)
					}): res.Data.ListRai.forEach(item=> { // 拆分
						let obj = {
							defaultAuth:item.CheckList,
							customType:item.ClassifyName,
							...item,
						}	
						// 组合所需的数据格式
						let subjectivityIds=item.Items.filter(it => it.PermissionType==1).map(it => it.ChartPermissionId)//主观的ids
						let subjectivityLength=subjectivityIds.length//有几个主观的id
						let subjectivityCheckedLen = item.CheckList.filter(id => subjectivityIds.includes(id)).length//选中的有几个主观的id
						let objectivityIds=item.Items.filter(it => it.PermissionType==2).map(it => it.ChartPermissionId)//客观的ids
						let objectivityCheckedLen = item.CheckList.filter(id => objectivityIds.includes(id)).length//有几个客观的id
						let objectivityLength=objectivityIds.length//选中的有几个客观的id
						let arr = [{PermissionTypeName:''},
											{PermissionTypeName:{
												value:'主观',
												isIndeterminate:subjectivityCheckedLen>0 && subjectivityCheckedLen<subjectivityLength,
												isCheckAll:subjectivityCheckedLen == subjectivityLength,
												isDisabled:subjectivityCheckedLen == subjectivityLength,
												ids:subjectivityIds
											}},
											{PermissionTypeName:{
												value:'客观',
												isIndeterminate:objectivityCheckedLen > 0 && objectivityCheckedLen < objectivityLength,
												isCheckAll:objectivityCheckedLen == objectivityLength,
												isDisabled:objectivityCheckedLen == objectivityLength,
												ids:objectivityIds
											}}]
						item.Items.map(cp =>{
							if(cp.PermissionType==0){
								// 没有主客观的权限
								arr[0][cp.PermissionName]={
									value:cp.PermissionName,
									width:cp.PermissionName=='研选扣点包'?'100px':'',
									merge:true
								}
								arr[1][cp.PermissionName]={
									value:cp.ChartPermissionId,
									isDisabled:item.CheckList.includes(cp.ChartPermissionId),
									merge:true
								}
								arr[2][cp.PermissionName]={
									value:cp.ChartPermissionId,
									isDisabled:item.CheckList.includes(cp.ChartPermissionId),
									merge:true
								}
							}else if(cp.PermissionType==1){
								// 找出对应的客观Id
								let objectivity = item.Items.find(it => it.PermissionName == cp.PermissionName && it.PermissionType==2)
								arr[0][cp.PermissionName]={
									value:cp.PermissionName,
									isIndeterminate:item.CheckList.filter(id => [cp.ChartPermissionId,objectivity?objectivity.ChartPermissionId:0].includes(id)).length ==1,
									isCheckAll:item.CheckList.filter(id => [cp.ChartPermissionId,objectivity?objectivity.ChartPermissionId:0].includes(id)).length == 2,
									isDisabled:item.CheckList.filter(id => [cp.ChartPermissionId,objectivity?objectivity.ChartPermissionId:0].includes(id)).length ==2,
									bothIds:[cp.ChartPermissionId,objectivity?objectivity.ChartPermissionId:0]
								}
								arr[1][cp.PermissionName]={
									value:cp.ChartPermissionId,
									isDisabled:item.CheckList.includes(cp.ChartPermissionId)
								}
							}else{
								// 分主客观的客观
								arr[2][cp.PermissionName]={
									value:cp.ChartPermissionId,
									isDisabled:item.CheckList.includes(cp.ChartPermissionId)
								}
							}
						})
						obj.dataList=arr
						auth.push(obj)
					})
					this.authList = auth;
				}
			})
			this.addTryId = item.CompanyId;
			this.isAddTrial = true;
		},
		/* 增加试用完成 */
		addTryOver() {
			this.isAddTrial = false;
			this.getTableData();
		},
		/* 处理合并数组 */
		getRowSpan() {
			this.rowSpanArr = [];
			/* [2,0,1] */
			this.lookAuthList.forEach((item, index) => {
				if (index === 0) {
					this.rowSpanArr.push(1);
					this.position = 0;
				} else {
					if (this.lookAuthList[index].ClassifyName === this.lookAuthList[index - 1].ClassifyName) {
						this.rowSpanArr[this.position] += 1; //项目名称相同，合并到同一个数组中
						this.rowSpanArr.push(0);
						this.lookAuthList[index].ClassifyName = this.lookAuthList[index - 1].ClassifyName;
					} else {
						this.rowSpanArr.push(1);
						this.position = index;
					}
				}
			});
		},
		/* 合并行规则 */
		objectSpanMethod({ row, column, rowIndex, columnIndex }) {
			if (columnIndex === 0) {
				const _row = this.rowSpanArr[rowIndex];
					return {
						rowspan: _row,
						colspan: 1
					};
			}
		},

		// 处理修改销售数据 不可以修改到已存在销售
		handleModifysalesArr(id){
      const AllSalesArr = _.cloneDeep(this.modifysalesArrtem)
			this.salesArr=AllSalesArr.map(item=>{
				if(item.ChildrenList){
					item.ChildrenList=item.ChildrenList.filter(e=>{
            if(e.ChildrenList){
              e.ChildrenList = e.ChildrenList.filter(i=>{return i.AdminId!=id})
            }
						return  e.AdminId!=id
					})
				}
				return item
			})
		},

		// 页码改变事件
		handleCurrentChange(page){
			this.pageinfo.page_no=page
			this.getTableData()
		},
		// 按钮列表
		btnList(btnItem,part){
			const allBtnList=[]
			for (const key in btnItem) {
				btnItem[key]&&key!=='BtnClose'&&key!=='BtnShare' && allBtnList.push(key)
			}
			if(part==='front'){
				// 返回前三个按钮
				return allBtnList.slice(0,3)
			}else{
				// 返回三个后按钮
				return allBtnList.slice(3)
			}
		},
		// 用于返回按钮名称
		btnName(btnItem,isSuspend){
			if(btnItem!=='BtnSuspend') return this.btnCommandList[btnItem]
			return isSuspend===1?'启用':'暂停'
		},
		// 页码改变事件
		handleCurrentChange(page){
			this.pageinfo.page_no=page
			this.getTableData()
		},
				/* 查看备注 */
		lookRemarkHandle(item) {
			/*
			lookRemarkTitle:'',//查看备注标题
			lookRemarkList:[],//查看备注列表
			*/
			this.lookRemarkTitle = "备注";
			this.lookAuthList = [];
			this.lookRemarkItem = item;
			customInterence.lookRemarkAuth({
				CompanyId:item.CompanyId
			}).then(res => {
				if(res.Ret === 200) {
					this.lookRemarkList=res.Data;
				}
			})
			this.isRemarkLook = true;
		},
		//新增备注
		async lookRemarkAdd(){
			if(!this.lookRemarkTextarea) return this.$message.error("请输入文本内容")
			const res = await customInterence.lookRemarkAuthAdd({
				CompanyId:this.lookRemarkItem.CompanyId,
				Remark:this.lookRemarkTextarea
			})
			if(res.Ret===200) {
				this.$message.success('保存成功')
				this.lookRemarkList = []
				this.lookRemarkTextarea =''
				customInterence.lookRemarkAuth({
				CompanyId:this.lookRemarkItem.CompanyId
				}).then(res => {
				if(res.Ret === 200) {
					this.lookRemarkList=res.Data;
				}
				})
			}
		},
		//删除备注
		async lookRemarkDelete(data){
			this.$confirm('备注删除后不可恢复，确认删除吗？','提示',{
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type:'warning',
				appendToBody:false
			}).then(async()=>{
				const res = await customInterence.deleteRemark({
					RemarkId:data.RemarkId
				})
				if(res.Ret!==200) return 
				this.$message.success("删除成功")
				customInterence.lookRemarkAuth({
					CompanyId:this.lookRemarkItem.CompanyId
				}).then(res => {
					if(res.Ret === 200) {
						this.lookRemarkList=res.Data;
					}
				})
			})
		},
	researchDetailHandle(item) {
		this.isPermissionDetailShow = true
		this.researchDetailId = item.CompanyId
	},
	//  处理状态的数据
	transformedArray(row){
		return [
			{
				SigningStatus: row.CompanyStatusButton.FiccSigningStatus,
				Status: row.CompanyStatusButton.FiccStatus
			},
			{
				SigningStatus: row.CompanyStatusButton.RaiSigningStatus,
				Status: row.CompanyStatusButton.RaiStatus,
			}
     	];
	},
	},
	created() {
		/* 返回保持上次的状态 */
		if(sessionStorage.getItem('customSearchBack')) {
			let backData = JSON.parse(sessionStorage.getItem('customSearchBack'));
			this.search_txt = backData.keyword;
			this.pageinfo.page_no=backData.page
			this.getTableData()
		}
		this.getSale();
	},
	mounted() {
		this.search_txt = this.$route.query.name ? this.$route.query.name:  this.$route.query.code?this.$route.query.code : ''
		if(this.search_txt){
			this.getTableData()
		}
		// /* 返回保持上次的状态 */ 放在mounted中会导致elementUI分页组件页码样式不正确
		// if(sessionStorage.getItem('customSearchBack')) {
		// 	let backData = JSON.parse(sessionStorage.getItem('customSearchBack'));
		// 	this.search_txt = backData.keyword;
		// 	this.pageinfo.page_no=backData.page
		// 	this.getTableData()
		// }
		// this.getSale();
	},
}
</script>
<style lang='scss'>
.customSearch_container {
	.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
		background-color: #409EFF !important;
		border-color: #409EFF;
	}
	.el-checkbox__input.is-disabled.is-indeterminate .el-checkbox__inner {
		background-color: #409EFF !important;
		border-color: #409EFF;
	}
	.customSearch_top {
		display: flex;
		// justify-content:flex-end;
		align-items: center;
		border: 1px solid #ECECEC;
		padding: 20px 30px;
		background: #fff;
		border-radius: 4px;
		box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
	}
	.customSearch_cont {
		min-height: calc(100vh - 320px);
		padding: 20px 30px 80px;
		background: #fff;
		margin-top: 20px;
		position: relative;
		border: 1px solid #ECECEC;
		border-radius: 4px;
		box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
	}
	.menu_lists {
		padding: 40px 18px;
		border-radius: 4px;
		.menu_item {
			display: flex;
			// align-items: center;
			margin-bottom: 30px;
			&:last-child {
				margin-bottom: 0;
			}
			.list_item {
				margin-right: 20px;
				margin-bottom: 10px;
				&:last-child {
					margin-right: 0;
				}
			}
		}
	}
	.look-remark-commit {
		width: 426px;
		height: 41px;
		background: #409EFF;
		margin:  30px auto;
		text-align: center;
		line-height: 41px;
		color: #fff;
		box-shadow: 0px 2px 6px 1px rgba(64, 158, 255, 0.05);
		border-radius: 4px 4px 4px 4px;
		cursor: pointer;
	
	}
	.mouse-enter {
		&:hover {
			text-decoration:underline;
		}
	}
}
</style>
<style lang="scss">
	.look-remark-commit {
		width: 426px;
		height: 41px;
		background: #409EFF;
		margin:  30px auto;
		text-align: center;
		line-height: 41px;
		color: #fff;
		box-shadow: 0px 2px 6px 1px rgba(64, 158, 255, 0.05);
		border-radius: 4px 4px 4px 4px;
		cursor: pointer;
	
	}
</style>