/* 拓展客户列表额外需求 原页面太长 逻辑不好找 */

import { customInterence } from '@/api/api.js'
export default {
	data() {
		return {
			act_trialTag: 0,//默认的标签状态
			trialTagArr: [],
			trialTags:[ 
				{
					label: '推进',
					value: 2
				},
				{
					label: '跟踪',
					value: 3
				},
				{
					label: '预备',
					value: 4
				},
				{
					label: '未分类',
					value: 1
				},
			],// 试用的标签状态
      isTotalDayDialogShow:false,//控制累计试用天数弹窗
      customInfo:{},
            isShareRecodeDialogShow:false,//控制服务记录弹窗
            allowEdit:true,//是否允许编辑服务记录
			isCloseCustomDialogShow:false,
			closeReason:'',
			fromArea:'',
			areaArr:[{name:'国内'},{name:'海外'}],
		}
	},

	methods: {
		/* 切换标签状态 */
		changeTagStatus({ TryStage }) {
			this.act_trialTag = TryStage;
			this.$refs.userTable.clearSort();
			this.sort_type =  '';
			this.sort_param = '';
			this.SortByTodo = false;
			this.page_no = 1;
			this.getTableData()
		},
	
		/* 改变客户的试用标签 */
		changeTrialHandle({ CompanyId },trialItem) {
			const { ProductId,TryStage } = trialItem;

			customInterence.setTrialTag({
				CompanyId,
				ProductId,
				TryStage
			}).then(res => {
				if(res.Ret !== 200) return
				this.$message.success('设置成功');

				this.getTableData()
			})
		},

        /* 打开 累计试用天数弹窗 */
        handleTotalDayClick(data){
        this.isTotalDayDialogShow = true
        this.customInfo = data
        },
        //打开服务记录弹窗
        handleShowShareRecode(data,type=''){
            if(data.ServiceTimes===0&&type==='list') return
            this.allowEdit = type==='list'?false:true
            this.isShareRecodeDialogShow = true
            this.customInfo = data
        },
		/* 打开关闭理由弹窗 */
		openCloseReasonDialog(data){
			this.customInfo = data
			this.closeReason=''
			this.isCloseCustomDialogShow = true
		},
		/* 关闭客户 */
		closeCustom(){
			if(!this.closeReason){
				this.$message.warning('请填写关闭理由')
				return
			}
			customInterence.closeCustom({
				CompanyId:this.customInfo.CompanyId,
				Remark:this.closeReason
			}).then(res=>{
				if(res.Ret!==200) return 
				this.getTableData()
				this.$message.success('关闭客户成功')
				this.isCloseCustomDialogShow = false
			})
			
		},
		/* 确认将客户转流失 */
		turnLose(data){
			this.$confirm(`是否确认将【${data.CompanyName}】转为流失客户？`,'提示',{
				confirmButtonText:'确认',
				cancelButtonText:'取消',
				type: 'warning'
			}).then(()=>{
				customInterence.turnLose({
					CompanyId:data.CompanyId
				}).then(res=>{
					if(res.Ret!==200) return 
					this.getTableData()
					this.$message.success('转流失成功')
				})
				
			}).catch(()=>{})
		},
		/* 筛选所属区域 */
		changeFromArea(){
			this.page_no = 1;
			this.getTableData()
		},
	}
}