import { researcherList, telTypes, addActivity, editActivity, companyInfo } from '@/api/roadshow/index.js'; import { getDefaultOption } from './common.js'; import { validateForm } from '../utils/validate.js'; import { areaList } from '../utils/area.js'; const moment = require('../utils/_moment.js'); moment.locale('zh-cn'); export default { data() { return { edit_id: '',//编辑活动id edit_rs_id: '',//编辑人id formData: { activityType: '', activityClass: '', // 活动类别 roadshowType: '', // 路演/会议 形式 roadshowPlatform: '', // 路演/会议 平台 roadshowCity: '', // 路演/会议城市 companyId: 0, // 客户id companyName: '', // 客户名称 meetingTheme: '', // 会议主题 partnersName: '', // 合作方名称 selectResearchers: [ { researcherId: '', startTime: '', endTime: '', } ], // 选择的研究员 }, isActivityPicker: false, //活动类型弹窗 isResearcherPicker: false, //研究员弹窗 isTimePicker: false, //时间弹窗 isAreaPicker: false, //地区弹窗 isRoadshowTypePicker: false, //路演/会议形式弹窗 isActivityClassPicker: false,//活动类别弹窗 rs_picker: { firstindex:0, id:[],//选择研究员块级标识 }, pickerForm: { time: '',//时间默认 area:'',//地区默认 }, //picker的默认选中 selectObj: {}, //选中的日期信息 下标 selectRsIndex: '', //选中的研究员下标 // weekMap: new Map([ // ['1','周一'], // ['2','周二'], // ['3','周三'], // ['4','周四'], // ['5','周五'], // ['6','周六'], // ['7','周日'] // ]), activiytyTypes: [],//活动类型 researcherList: [],//研究员列表 telTypeList: [],//电话会类别 areaList,//地区数据 companyInfo: null,//客户信息 } }, computed: { /* 动态前缀 路演/会议 */ dynamic_prefix() { return this.formData.activityType === '路演' ? '路演' : this.formData.activityType === '沙龙' ? '沙龙' : '会议'; }, // 新增的研究员的索引数组 addResearchersIdx() { return this.formData.selectResearchers.map((item, index) => index).slice(1); }, isRaiRole() { return this.$store.state.userInfo.RoleTypeCode.includes('rai') }, //ficc研究员列表 ficcReasearcherList(){ return (this.researcherList.find(i=>i.text==='ficc')||{}).children||[] }, //rai研究员列表 raiReasercherList(){ return (this.researcherList.find(i=>i.text==='权益')||{}).children||[] } }, watch: { }, methods: { /* 获取研究员列表 */ async getResearcherList() { const res = await researcherList(); if (res.code !== 200) return /* this.researcherList = res.data.map(group => ({ ...group, text: group.GroupName, children: group.ResearcherList ? group.ResearcherList.map(child => ({ ...child, text: child.RealName, id: child.AdminId })) : [] })); */ const ficcList = this.formatResearcherList(res.data.find(i=>i.GroupName==='ficc').ResearcherList||[]); const raiList = this.formatResearcherList(res.data.find(i=>i.GroupName==='权益').ResearcherList||[]); this.researcherList = [{ text:'ficc', value:-1, children:ficcList },{ text:'权益', value:-2, children:raiList }] }, formatResearcherList(list){ list.forEach((group) => { // 对组做处理 group.text = group.GroupName group.value = group.GroupId group.id = group.GroupId //非路演,公开会议的活动组件需要用到的字段 // 如果有列表 if (group.ResearcherList) { group.ResearcherList.forEach((item) => { // 对研究员做处理 item.text = item.RealName item.value = item.AdminId item.id = item.AdminId//非路演,公开会议的活动组件需要用到的字段 }); } group.children = group.ResearcherList||[] }); return list.filter((group) => group.GroupName !== "ficc全体"); }, /* 获取客户信息 */ async getCompanyInfo() { const res = await companyInfo({ CompanyId: this.formData.companyId, EnglishCompany:this.formData.englishCompany }) if(res.code !== 200) return this.companyInfo = res.data; this.formData.companyName = res.data.CompanyName; }, /* 获取电话会类别 */ async getTelType() { const { code,data } = await telTypes(); if (code !== 200) return this.telTypeList = data[0].ChildList.map(_ => _.ActivityTypeName); }, /* ficc-新增活动成功后操作 */ addActivityLink({text,content,link,query}) { uni.showModal({ title:text, content, confirmText:'去查看', cancelColor: '#A9AFB8', confirmColor: '#3385FF', success: function(res) { if(res.confirm){ uni.redirectTo({ url:`${link}?type=${query.type}`, }) }else { uni.navigateBack({ delta:1 }) } } }) }, addRaiActivityLink() { uni.showModal({ title:'添加活动成功,研究员日程已添加成功', content:'可前往【研究员日历】查看', confirmText:'去查看', cancelColor: '#A9AFB8', confirmColor: '#3385FF', success: function(res) { if(res.confirm){ //跳转至日历页 uni.navigateBack({ delta:1 }) }else { uni.navigateBack({ delta:1 }) } } }) }, /* 提交表单 */ async submitHandle() { console.log(this.formData,'------') let isCheck = validateForm(this.formData.activityType,this.formData); console.log(isCheck) if(!isCheck) return if(this.isRaiRole&&this.formData.roadshowType==='线下'&&!this.formData.District) { uni.showToast({title:'请选择路演城市',icon:'none'}) return } let parmas; const param_research = ['公开会议', '路演', '沙龙'].includes( this.formData.activityType ) ? this.formData.selectResearchers.map((item) => ({ ResearcherId: Number(item.researcherId), ResearcherName: this.findResearcherName(item.researcherId), StartDate: moment(item.startTime).format('YYYY-MM-DD'), EndDate: moment(item.endTime).format('YYYY-MM-DD'), StartTime: moment(item.startTime).format('HH:mm:ss'), EndTime: moment(item.endTime).format('HH:mm:ss'), StartWeek: moment(item.startTime).format('ddd'), EndWeek: moment(item.endTime).format('ddd'), })) : this.formData.selectResearchers[0].researcherId.map((item) => ({ ResearcherId: Number(item), ResearcherName: item === 99 ? 'ficc全体' : this.findResearcherName(item), StartDate: moment( this.formData.selectResearchers[0].startTime ).format('YYYY-MM-DD'), EndDate: moment( this.formData.selectResearchers[0].endTime ).format('YYYY-MM-DD'), StartTime: moment( this.formData.selectResearchers[0].startTime ).format('HH:mm:ss'), EndTime: moment( this.formData.selectResearchers[0].endTime ).format('HH:mm:ss'), StartWeek: moment(this.formData.selectResearchers[0].startTime).format('ddd'), EndWeek: moment(this.formData.selectResearchers[0].endTime).format('ddd'), })); parmas = { ActivityType: this.formData.activityType, ActivityCategory: this.formData.activityClass, City: this.formData.roadshowCity[1], Province: this.formData.roadshowCity[0], District:this.formData.District||'', CooperationName: this.formData.partnersName, Theme: this.formData.meetingTheme, RoadshowType: this.formData.roadshowType, RoadshowPlatform: this.formData.roadshowPlatform, CompanyId: this.formData.companyId || 0, CompanyName: this.formData.companyName || '', ResearcherList: param_research, EnglishCompany:this.formData.englishCompany }; // console.log(parmas); const res = this.edit_id ? await editActivity({ ...parmas, RsCalendarId: Number(this.edit_id), RsCalendarResearcherId: Number(this.edit_rs_id), EditType: ['公开会议', '路演'].includes(this.formData.activityType) ? 2 : 1 }) : await addActivity(parmas); if (res.code !== 200) return; const { text,content,link,query } = this.setDynamicLink(this.formData.activityType); /* this.edit_id ? uni.showToast({ title: '提交成功', icon: 'success' }) : this.addActivityLink({text,content,link,query}); */ if(this.edit_id){ uni.showToast({ title: '提交成功', icon: 'success' }) }else{ if(this.formData.activityType!=='路演'){ this.addActivityLink({text,content,link,query}) return } //判断所选研究员是否有权益 const ResearcherIds = this.formData.selectResearchers.map(i=>i.researcherId) const ResearcherTypes = ResearcherIds.map(i=>this.findType(i)) console.log('types',ResearcherTypes) //既有权益研究员的路演,又有ficc研究员路演时,提示弹窗 if(ResearcherTypes.includes('rai')&&ResearcherTypes.includes('ficc')){ const { text, content,link, query } = this.setDynamicLink( 'ficc&rai路演' ); this.addActivityLink({text,content,link,query}) //只提交权益研究员的路演时,提示弹窗: }else if(ResearcherTypes.includes('rai')){ this.addRaiActivityLink() //只提交ficc研究员的路演时,提示弹窗:(维持原来的不变) }else{ this.addActivityLink({text,content,link,query}) } } this.edit_id && setTimeout(() => { this.cancelHandle(); },1500); }, /* 添加研究员 */ addResearcherHandle() { const { startTime, endTime } = this.formData.selectResearchers[0]; //默认添加时间同步 this.formData.selectResearchers.push({ researcherId: null, startTime, endTime, }); }, // 删除研究员 delResearcherHandle(index) { this.formData.selectResearchers.splice(index, 1); }, /* 取消 */ cancelHandle() { uni.navigateBack({ delta:1 }) }, findName(id) { const flat_arr = JSON.parse(JSON.stringify(this.researcherList)) .map((item) => item.ResearcherList || []) .flat(Infinity); return flat_arr.find((user) => user.AdminId === id) ? flat_arr.find((user) => user.AdminId === id).RealName : ''; }, /* 选择活动 */ confirmActivityType({detail}) { this.formData.activityType = detail.value; this.initOtherForm(); this.isActivityPicker = false; }, /* 切换类型时重置部分表单 */ initOtherForm() { const { RoleTypeCode } = JSON.parse(uni.getStorageSync('userInfo')) || null; const { defaultActivityType, activityTypeList, startTime, endTime } = getDefaultOption(RoleTypeCode, 2); this.formData.roadshowType = ''; this.formData.roadshowPlatform = ''; this.formData.roadshowCity = ''; this.formData.companyId = 0; this.formData.companyName = ''; this.formData.meetingTheme = ''; this.formData.partnersName = ''; this.formData.activityClass = ''; this.companyInfo = ''; // 选择研究员后进入的页面不重置默认研究员 let pages = getCurrentPages(); let route = pages[pages.length-1].route; if(route === 'pages-roadshow/addActivity/byCell') { this.formData.selectResearchers = ['内部会议','报告电话会'].includes(this.formData.activityType) ? [{ researcherId: [ this.defaultResearcher[0].researcherId ], startTime: this.defaultResearcher[0].startTime, endTime: this.defaultResearcher[0].endTime }] : this.defaultResearcher; } else { this.formData.selectResearchers = [{ researcherId: '', startTime: startTime, endTime: endTime, }]; } }, /* 选择活动类别 */ confirmActivityClass({detail}) { this.formData.activityClass = detail.value; this.isActivityClassPicker = false; }, /* 前往客户搜索 */ goSearchCompany() { uni.navigateTo({ url: `/pages-approve/search/index?type=roadshow` }) }, /* 选择研究员弹窗展开 */ clickRsChoose(index,type='') { console.log(this.edit_id,['路演','沙龙','公开会议'].includes(this.formData.activityType),type); if((this.edit_id && ['路演','沙龙','公开会议'].includes(this.formData.activityType)) && type != 'raiEdit' || (type && type != 'raiEdit')) return; this.isResearcherPicker = true; console.log(this.formData.selectResearchers[index]) // return this.selectRsIndex = index; this.rs_picker= { firstindex:0, id: this.formData.selectResearchers[index].researcherId ? (['路演','沙龙','公开会议'].includes(this.formData.activityType) ? this.formData.selectResearchers[index].researcherId : this.formData.selectResearchers[index].researcherId.map(item => item)) : []//选择研究员块级标识 } }, /* 选择研究员分组 */ clickFirstHandle({detail}) { this.rs_picker.firstindex = detail.index; }, /* 选择研究员项 路演 公开会议为单选 其余多选*/ clickItemHandle({detail}) { const { activityType } = this.formData; if(['内部会议', '报告电话会'].includes(activityType)) { let index = this.rs_picker.id.indexOf(detail.AdminId); index > -1 ? this.rs_picker.id.splice(index, 1) : this.rs_picker.id.push(detail.AdminId); }else { this.rs_picker.id = detail.AdminId; } }, /* 取消选择研究员 */ cancelResearcher() { this.rs_picker = { firstindex: 0, id: [] } this.isResearcherPicker = false; }, /* 选择研究员确认 */ confirmResearcher() { console.log('确认选择') this.formData.selectResearchers[this.selectRsIndex].researcherId = this.rs_picker.id; this.isResearcherPicker = false; }, chooseResearcher({target}){ this.formData.selectResearchers[this.selectRsIndex].researcherId = target.value this.isResearcherPicker = false; }, /* 研究员显示格式化为名字 */ formatRsLable(arr) { if(!arr) return ''; if( arr instanceof Array ) { return arr.map(item => { return this.findResearcherName(item) }) }else { return this.findResearcherName(arr) } }, findResearcherName(id){ const isFicc = this.findResearcherById(id,'ficc') const isRai = this.findResearcherById(id,'rai') return isFicc?isFicc.RealName:isRai?isRai.RealName:'' }, 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) }, /* 选择路演/会议形式 重置城市平台 */ confirmRoadshowType({ detail }) { this.formData.roadshowType = detail.value; this.formData.roadshowPlatform = ''; this.formData.roadshowCity = ''; this.isRoadshowTypePicker = false; }, /* 选择地区弹窗 */ clickAreaChoose() { const city = this.formData.roadshowCity.length ? this.formData.roadshowCity[1] : ''; let cityCode = ''; if(city) for(let i in this.areaList.city_list) { if(this.areaList.city_list[i] === city){ cityCode = String(i); break; } } // console.log(cityCode) this.pickerForm.area = cityCode; this.isAreaPicker = true }, /* 选择地区 */ confirmArea({detail}) { const { values } = detail; this.formData.roadshowCity = values.map(item => item.name); this.formData.District = values.length===3?values[2].name:'' this.isAreaPicker = false; }, /* 点击选择时间 */ clickTimeChoose(index, type) { console.log(this.formData.selectResearchers[index]) this.pickerForm.time = type === 'start' ? this.formData.selectResearchers[index].startTime : this.formData.selectResearchers[index].endTime; this.selectObj = { index, type } setTimeout(() => { this.isTimePicker = true; }) }, /* 选择时间 */ confirmTime({detail}) { // console.log(val) const { index, type } = this.selectObj; if (type === 'start') { this.formData.selectResearchers[index].startTime = detail; } else { this.formData.selectResearchers[index].endTime = detail; } this.isTimePicker = false; this.pickerForm.time = ''; }, /* 添加完成后 拼接动态内容 */ setDynamicLink(type) { switch (type) { case '内部会议' : return { text: '添加成功,已加入研究员日历', content: `可前往【我的日历】-【${type}】查看`, link: '/pages-approve/activity/list', query: { type }, } case '报告电话会' : return { text: '添加成功,已加入研究员日历', content: `可前往【我的日历】-【${type}】查看`, link: '/pages-approve/activity/list', query: { type }, } case '路演' : return { text: '活动申请已提交,请等待研究员处理', content: `可前往【我的日历】-【活动申请】查看`, link: '/pages-approve/activity/list', query: { type: '活动申请' }, } case '沙龙' : return { text: '添加活动成功,研究员日程已添加成功', content: `可前往【研究员日历】查看`, link: '/pages-approve/activity/list', query: { type: '活动申请' }, } case 'ficc&rai路演' : return { text:'权益研究员日历已添加成功,ficc研究员日历已发送申请,请等待处理', content:'可前往【我的日历】查看', link:'/pages-approve/activity/list', query:{ type: '活动申请' }, } case '公开会议' : return { text: '活动申请已提交,请等待研究员处理', content: `可前往【我的日历】-【活动申请】查看`, link: '/pages-approve/activity/list', query: { type: '活动申请' }, } } }, /* 绑定input输入value */ bindInputHandle(key,{detail}) { this.formData[key] = detail; }, /* 格式化时间显示 */ formatterLabelTime(val) { if(!val) return ''; const date = moment(val).format('MM.DD(ddd) HH:mm'); return date; }, /* 格式化弹窗时间显示 */ formatterPickerTime(type, val) { switch (type) { case 'year': return val + '年'; case 'month': return val + '月'; case 'day': return val + '日'; case 'hour': return val + '时'; case 'minute': return val + '分'; } } } }