export default {
	data() {
		return {
			rules: {
				// 表单校验规则
				activityType: [
					{ required: true, message: "请选择活动类型", trigger: "change" },
				],
				// roadshowType: [
				// 	{ required: true, message: "请选择路演形式", trigger: "change" },
				// ],
				// roadshowPlatform: [
				// 	{ required: true, message: "请选择路演平台", trigger: "blur" },
				// ],
				// roadshowCity: [
				// 	{ required: true, message: "请选择路演城市", trigger: "blur" },
				// ],
				companyName: [
					{ required: true, message: "请选择客户", trigger: "blur" },
				],
				meetingType: [
					{ required: true, message: "请选择会议形式", trigger: "blur" },
				],
				meetingPlatform: [
					{ required: true, message: "请选择会议平台", trigger: "blur" },
				],
				meetingCity: [
					{ required: true, message: "请选择会议城市", trigger: "blur" },
				],
				meetingTheme: [
					{ required: true, message: "请输入会议主题", trigger: "blur" },
				],
				partnersName: [
					{ required: true, message: "请输入合作方名称", trigger: "blur" },
				],
				activityClass: [
					{ required: true, message: "请选择活动类别", trigger: "blur" },
				],
			},
			activityClassProps:{
				value:"ActivityTypeName",
				label:"ActivityTypeName",
				children:"ChildList"
			}
		}
	},
	methods: {

		/* 添加完成后 拼接动态内容 */
		setDynamicLink(type) {
      switch (type) {
        case '内部会议' : return {
          text: '添加成功，已加入研究员日历',
          content: `可前往【我的日历】-【${type}】查看`,
          query: {
            act_tab: 3
          },
        }
        case '报告电话会' : return {
          text: '添加成功，已加入研究员日历',
          content: `可前往【我的日历】-【${type}】查看`,
          query: {
            act_tab: 4
          },
        }
        case '路演' : return {
          text: '活动申请已提交，请等待研究员处理',
          content: `可前往【我的日历】-【待处理申请】查看`,
          query: {
            act_tab: 1
          },
        }
		case '沙龙' : return {
			text: '研究员日程已添加成功',
			content: `可前往【研究员日历】查看`,
			query: {
			  act_tab: 1
			},
		  }
        case 'ficc&rai路演' : return {
            text: '权益研究员日历已添加成功，ficc研究员日历已发送申请，请等待处理',
            content: `可前往【我的日历】`,
            query: {
              act_tab: 1
            },
        }
        case '公开会议' : return {
          text: '活动申请已提交，请等待研究员处理',
          content: `可前往【我的日历】-【待处理申请】查看`,
          query: {
            act_tab: 1
          },
        }
      }
    },

		// // 清除客户信息
		companyClear() {
			this.formData.companyId = '';
			this.formData.companyName = "";
			this.companyInfo = null;
		},

		//添加多个研究员选择时 校验是否重复
		addUserCheckHandler(val) {
      let arr = this.formData.selectResearchers.filter(item => item.researcherId === val);
      if(arr.length > 1) return this.$message.warning('研究员已重复添加');
    },

		// 改变路演城市 重置城市校验
		onChangeCity(val, type) {
			console.log(val)
			if (type === "roadshow") {
				this.formData.roadshowCity = [val.province.value,val.city.value];
				this.formData.District = val.area.value
				this.$refs.form.clearValidate(['roadshowCity'])
			} else if (type === "meeting") {
				this.formData.meetingCity = [val.province.value, val.city.value];
				this.$refs.form.clearValidate(['meetingCity'])
			}
		},
		findType(id){
			const isFicc = this.findResearcherById(id,'ficc')
			const isRai = this.findResearcherById(id,'rai')
			return isFicc?'ficc':isRai?'rai':''

		},
		findResearcherById(id,type='ficc'){
			const list = type==='ficc'?this.ficcReasearcherList:this.raiReasercherList
			const flatList = list.map(item=>item.ResearcherList||[]).flat(Infinity)
			return flatList.find(user=>user.AdminId===id)
		},
		findResearcherName(id){
			const isFicc = this.findResearcherById(id,'ficc')
			const isRai = this.findResearcherById(id,'rai')
			return isFicc?isFicc.RealName:isRai?isRai.RealName:''
		}
	},
	watch: {
    'formData.companyName'(val) {
      if(!val) {
        this.companyClear();
      }
    },
		'formData.roadshowType': {
			handler() {
				this.$refs.form && this.$refs.form.clearValidate(['roadshowPlatform','roadshowCity'])
			}
		},
		'formData.meetingType': {
			handler() {
				this.$refs.form && this.$refs.form.clearValidate(['meetingPlatform','meetingCity'])
			}
		}
	},
	computed:{
		isRaiRole(){//是否为权益角色
			return localStorage.getItem('Role').includes('rai')
		},
		//ficc研究员列表
		ficcReasearcherList(){
			return (this.researcherList.find(i=>i.label==='ficc')||{}).ResearcherList||[]
		},
		//rai研究员列表
		raiReasercherList(){
			return (this.researcherList.find(i=>i.label==='权益')||{}).ResearcherList||[]
		}
	}
}