mixin.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. import {
  2. researcherList,
  3. telTypes,
  4. addActivity,
  5. editActivity,
  6. companyInfo
  7. } from '@/api/roadshow/index.js';
  8. import { getDefaultOption } from './common.js';
  9. import { validateForm } from '../utils/validate.js';
  10. import { areaList } from '../utils/area.js';
  11. const moment = require('../utils/_moment.js');
  12. moment.locale('zh-cn');
  13. export default {
  14. data() {
  15. return {
  16. edit_id: '',//编辑活动id
  17. edit_rs_id: '',//编辑人id
  18. formData: {
  19. activityType: '',
  20. activityClass: '', // 活动类别
  21. roadshowType: '', // 路演/会议 形式
  22. roadshowPlatform: '', // 路演/会议 平台
  23. roadshowCity: '', // 路演/会议城市
  24. companyId: 0, // 客户id
  25. companyName: '', // 客户名称
  26. meetingTheme: '', // 会议主题
  27. partnersName: '', // 合作方名称
  28. selectResearchers: [
  29. {
  30. researcherId: '',
  31. startTime: '',
  32. endTime: '',
  33. }
  34. ], // 选择的研究员
  35. },
  36. isActivityPicker: false, //活动类型弹窗
  37. isResearcherPicker: false, //研究员弹窗
  38. isTimePicker: false, //时间弹窗
  39. isAreaPicker: false, //地区弹窗
  40. isRoadshowTypePicker: false, //路演/会议形式弹窗
  41. isActivityClassPicker: false,//活动类别弹窗
  42. rs_picker: {
  43. firstindex:0,
  44. id:[],//选择研究员块级标识
  45. },
  46. pickerForm: {
  47. time: '',//时间默认
  48. area:'',//地区默认
  49. }, //picker的默认选中
  50. selectObj: {}, //选中的日期信息 下标
  51. selectRsIndex: '', //选中的研究员下标
  52. // weekMap: new Map([
  53. // ['1','周一'],
  54. // ['2','周二'],
  55. // ['3','周三'],
  56. // ['4','周四'],
  57. // ['5','周五'],
  58. // ['6','周六'],
  59. // ['7','周日']
  60. // ]),
  61. activiytyTypes: [],//活动类型
  62. researcherList: [],//研究员列表
  63. telTypeList: [],//电话会类别
  64. areaList,//地区数据
  65. companyInfo: null,//客户信息
  66. }
  67. },
  68. computed: {
  69. /* 动态前缀 路演/会议 */
  70. dynamic_prefix() {
  71. return this.formData.activityType === '路演' ? '路演' : this.formData.activityType === '沙龙' ? '沙龙' : '会议';
  72. },
  73. // 新增的研究员的索引数组
  74. addResearchersIdx() {
  75. return this.formData.selectResearchers.map((item, index) => index).slice(1);
  76. },
  77. isRaiRole() {
  78. return this.$store.state.userInfo.RoleTypeCode.includes('rai')
  79. },
  80. //ficc研究员列表
  81. ficcReasearcherList(){
  82. return (this.researcherList.find(i=>i.text==='ficc')||{}).children||[]
  83. },
  84. //rai研究员列表
  85. raiReasercherList(){
  86. return (this.researcherList.find(i=>i.text==='权益')||{}).children||[]
  87. }
  88. },
  89. watch: {
  90. },
  91. methods: {
  92. /* 获取研究员列表 */
  93. async getResearcherList() {
  94. const res = await researcherList();
  95. if (res.code !== 200) return
  96. /* this.researcherList = res.data.map(group => ({
  97. ...group,
  98. text: group.GroupName,
  99. children: group.ResearcherList ? group.ResearcherList.map(child => ({
  100. ...child,
  101. text: child.RealName,
  102. id: child.AdminId
  103. })) : []
  104. })); */
  105. const ficcList = this.formatResearcherList(res.data.find(i=>i.GroupName==='ficc').ResearcherList||[]);
  106. const raiList = this.formatResearcherList(res.data.find(i=>i.GroupName==='权益').ResearcherList||[]);
  107. this.researcherList = [{
  108. text:'ficc',
  109. value:-1,
  110. children:ficcList
  111. },{
  112. text:'权益',
  113. value:-2,
  114. children:raiList
  115. }]
  116. },
  117. formatResearcherList(list){
  118. list.forEach((group) => {
  119. // 对组做处理
  120. group.text = group.GroupName
  121. group.value = group.GroupId
  122. group.id = group.GroupId //非路演,公开会议的活动组件需要用到的字段
  123. // 如果有列表
  124. if (group.ResearcherList) {
  125. group.ResearcherList.forEach((item) => {
  126. // 对研究员做处理
  127. item.text = item.RealName
  128. item.value = item.AdminId
  129. item.id = item.AdminId//非路演,公开会议的活动组件需要用到的字段
  130. });
  131. }
  132. group.children = group.ResearcherList||[]
  133. });
  134. return list.filter((group) => group.GroupName !== "ficc全体");
  135. },
  136. /* 获取客户信息 */
  137. async getCompanyInfo() {
  138. const res = await companyInfo({
  139. CompanyId: this.formData.companyId,
  140. EnglishCompany:this.formData.englishCompany
  141. })
  142. if(res.code !== 200) return
  143. this.companyInfo = res.data;
  144. this.formData.companyName = res.data.CompanyName;
  145. },
  146. /* 获取电话会类别 */
  147. async getTelType() {
  148. const { code,data } = await telTypes();
  149. if (code !== 200) return
  150. this.telTypeList = data[0].ChildList.map(_ => _.ActivityTypeName);
  151. },
  152. /* ficc-新增活动成功后操作 */
  153. addActivityLink({text,content,link,query}) {
  154. uni.showModal({
  155. title:text,
  156. content,
  157. confirmText:'去查看',
  158. cancelColor: '#A9AFB8',
  159. confirmColor: '#3385FF',
  160. success: function(res) {
  161. if(res.confirm){
  162. uni.redirectTo({
  163. url:`${link}?type=${query.type}`,
  164. })
  165. }else {
  166. uni.navigateBack({
  167. delta:1
  168. })
  169. }
  170. }
  171. })
  172. },
  173. addRaiActivityLink() {
  174. uni.showModal({
  175. title:'添加活动成功,研究员日程已添加成功',
  176. content:'可前往【研究员日历】查看',
  177. confirmText:'去查看',
  178. cancelColor: '#A9AFB8',
  179. confirmColor: '#3385FF',
  180. success: function(res) {
  181. if(res.confirm){
  182. //跳转至日历页
  183. uni.navigateBack({
  184. delta:1
  185. })
  186. }else {
  187. uni.navigateBack({
  188. delta:1
  189. })
  190. }
  191. }
  192. })
  193. },
  194. /* 提交表单 */
  195. async submitHandle() {
  196. console.log(this.formData,'------')
  197. let isCheck = validateForm(this.formData.activityType,this.formData);
  198. console.log(isCheck)
  199. if(!isCheck) return
  200. if(this.isRaiRole&&this.formData.roadshowType==='线下'&&!this.formData.District) {
  201. uni.showToast({title:'请选择路演城市',icon:'none'})
  202. return
  203. }
  204. let parmas;
  205. const param_research = ['公开会议', '路演', '沙龙'].includes(
  206. this.formData.activityType
  207. ) ?
  208. this.formData.selectResearchers.map((item) => ({
  209. ResearcherId: Number(item.researcherId),
  210. ResearcherName: this.findResearcherName(item.researcherId),
  211. StartDate: moment(item.startTime).format('YYYY-MM-DD'),
  212. EndDate: moment(item.endTime).format('YYYY-MM-DD'),
  213. StartTime: moment(item.startTime).format('HH:mm:ss'),
  214. EndTime: moment(item.endTime).format('HH:mm:ss'),
  215. StartWeek: moment(item.startTime).format('ddd'),
  216. EndWeek: moment(item.endTime).format('ddd'),
  217. })) :
  218. this.formData.selectResearchers[0].researcherId.map((item) => ({
  219. ResearcherId: Number(item),
  220. ResearcherName: item === 99 ? 'ficc全体' : this.findResearcherName(item),
  221. StartDate: moment(
  222. this.formData.selectResearchers[0].startTime
  223. ).format('YYYY-MM-DD'),
  224. EndDate: moment(
  225. this.formData.selectResearchers[0].endTime
  226. ).format('YYYY-MM-DD'),
  227. StartTime: moment(
  228. this.formData.selectResearchers[0].startTime
  229. ).format('HH:mm:ss'),
  230. EndTime: moment(
  231. this.formData.selectResearchers[0].endTime
  232. ).format('HH:mm:ss'),
  233. StartWeek: moment(this.formData.selectResearchers[0].startTime).format('ddd'),
  234. EndWeek: moment(this.formData.selectResearchers[0].endTime).format('ddd'),
  235. }));
  236. parmas = {
  237. ActivityType: this.formData.activityType,
  238. ActivityCategory: this.formData.activityClass,
  239. City: this.formData.roadshowCity[1],
  240. Province: this.formData.roadshowCity[0],
  241. District:this.formData.District||'',
  242. CooperationName: this.formData.partnersName,
  243. Theme: this.formData.meetingTheme,
  244. RoadshowType: this.formData.roadshowType,
  245. RoadshowPlatform: this.formData.roadshowPlatform,
  246. CompanyId: this.formData.companyId || 0,
  247. CompanyName: this.formData.companyName || '',
  248. ResearcherList: param_research,
  249. EnglishCompany:this.formData.englishCompany
  250. };
  251. // console.log(parmas);
  252. const res = this.edit_id ?
  253. await editActivity({
  254. ...parmas,
  255. RsCalendarId: Number(this.edit_id),
  256. RsCalendarResearcherId: Number(this.edit_rs_id),
  257. EditType: ['公开会议', '路演'].includes(this.formData.activityType) ? 2 : 1
  258. }) : await addActivity(parmas);
  259. if (res.code !== 200) return;
  260. const { text,content,link,query } = this.setDynamicLink(this.formData.activityType);
  261. /* this.edit_id ? uni.showToast({
  262. title: '提交成功',
  263. icon: 'success'
  264. }) : this.addActivityLink({text,content,link,query}); */
  265. if(this.edit_id){
  266. uni.showToast({
  267. title: '提交成功',
  268. icon: 'success'
  269. })
  270. }else{
  271. if(this.formData.activityType!=='路演'){
  272. this.addActivityLink({text,content,link,query})
  273. return
  274. }
  275. //判断所选研究员是否有权益
  276. const ResearcherIds = this.formData.selectResearchers.map(i=>i.researcherId)
  277. const ResearcherTypes = ResearcherIds.map(i=>this.findType(i))
  278. console.log('types',ResearcherTypes)
  279. //既有权益研究员的路演,又有ficc研究员路演时,提示弹窗
  280. if(ResearcherTypes.includes('rai')&&ResearcherTypes.includes('ficc')){
  281. const { text, content,link, query } = this.setDynamicLink(
  282. 'ficc&rai路演'
  283. );
  284. this.addActivityLink({text,content,link,query})
  285. //只提交权益研究员的路演时,提示弹窗:
  286. }else if(ResearcherTypes.includes('rai')){
  287. this.addRaiActivityLink()
  288. //只提交ficc研究员的路演时,提示弹窗:(维持原来的不变)
  289. }else{
  290. this.addActivityLink({text,content,link,query})
  291. }
  292. }
  293. this.edit_id && setTimeout(() => {
  294. this.cancelHandle();
  295. },1500);
  296. },
  297. /* 添加研究员 */
  298. addResearcherHandle() {
  299. const {
  300. startTime,
  301. endTime
  302. } =
  303. this.formData.selectResearchers[0]; //默认添加时间同步
  304. this.formData.selectResearchers.push({
  305. researcherId: null,
  306. startTime,
  307. endTime,
  308. });
  309. },
  310. // 删除研究员
  311. delResearcherHandle(index) {
  312. this.formData.selectResearchers.splice(index, 1);
  313. },
  314. /* 取消 */
  315. cancelHandle() {
  316. uni.navigateBack({
  317. delta:1
  318. })
  319. },
  320. findName(id) {
  321. const flat_arr = JSON.parse(JSON.stringify(this.researcherList))
  322. .map((item) => item.ResearcherList || [])
  323. .flat(Infinity);
  324. return flat_arr.find((user) => user.AdminId === id)
  325. ? flat_arr.find((user) => user.AdminId === id).RealName
  326. : '';
  327. },
  328. /* 选择活动 */
  329. confirmActivityType({detail}) {
  330. this.formData.activityType = detail.value;
  331. this.initOtherForm();
  332. this.isActivityPicker = false;
  333. },
  334. /* 切换类型时重置部分表单 */
  335. initOtherForm() {
  336. const {
  337. RoleTypeCode
  338. } = JSON.parse(uni.getStorageSync('userInfo')) || null;
  339. const {
  340. defaultActivityType,
  341. activityTypeList,
  342. startTime,
  343. endTime
  344. } = getDefaultOption(RoleTypeCode, 2);
  345. this.formData.roadshowType = '';
  346. this.formData.roadshowPlatform = '';
  347. this.formData.roadshowCity = '';
  348. this.formData.companyId = 0;
  349. this.formData.companyName = '';
  350. this.formData.meetingTheme = '';
  351. this.formData.partnersName = '';
  352. this.formData.activityClass = '';
  353. this.companyInfo = '';
  354. // 选择研究员后进入的页面不重置默认研究员
  355. let pages = getCurrentPages();
  356. let route = pages[pages.length-1].route;
  357. if(route === 'pages-roadshow/addActivity/byCell') {
  358. this.formData.selectResearchers = ['内部会议','报告电话会'].includes(this.formData.activityType)
  359. ? [{
  360. researcherId: [ this.defaultResearcher[0].researcherId ],
  361. startTime: this.defaultResearcher[0].startTime,
  362. endTime: this.defaultResearcher[0].endTime
  363. }]
  364. : this.defaultResearcher;
  365. } else {
  366. this.formData.selectResearchers = [{
  367. researcherId: '',
  368. startTime: startTime,
  369. endTime: endTime,
  370. }];
  371. }
  372. },
  373. /* 选择活动类别 */
  374. confirmActivityClass({detail}) {
  375. this.formData.activityClass = detail.value;
  376. this.isActivityClassPicker = false;
  377. },
  378. /* 前往客户搜索 */
  379. goSearchCompany() {
  380. uni.navigateTo({
  381. url: `/pages-approve/search/index?type=roadshow`
  382. })
  383. },
  384. /* 选择研究员弹窗展开 */
  385. clickRsChoose(index,type='') {
  386. console.log(this.edit_id,['路演','沙龙','公开会议'].includes(this.formData.activityType),type);
  387. if((this.edit_id && ['路演','沙龙','公开会议'].includes(this.formData.activityType)) && type != 'raiEdit' || (type && type != 'raiEdit')) return;
  388. this.isResearcherPicker = true;
  389. console.log(this.formData.selectResearchers[index])
  390. // return
  391. this.selectRsIndex = index;
  392. this.rs_picker= {
  393. firstindex:0,
  394. id: this.formData.selectResearchers[index].researcherId ?
  395. (['路演','沙龙','公开会议'].includes(this.formData.activityType) ?
  396. this.formData.selectResearchers[index].researcherId :
  397. this.formData.selectResearchers[index].researcherId.map(item => item))
  398. : []//选择研究员块级标识
  399. }
  400. },
  401. /* 选择研究员分组 */
  402. clickFirstHandle({detail}) {
  403. this.rs_picker.firstindex = detail.index;
  404. },
  405. /* 选择研究员项 路演 公开会议为单选 其余多选*/
  406. clickItemHandle({detail}) {
  407. const { activityType } = this.formData;
  408. if(['内部会议', '报告电话会'].includes(activityType)) {
  409. let index = this.rs_picker.id.indexOf(detail.AdminId);
  410. index > -1 ? this.rs_picker.id.splice(index, 1) : this.rs_picker.id.push(detail.AdminId);
  411. }else {
  412. this.rs_picker.id = detail.AdminId;
  413. }
  414. },
  415. /* 取消选择研究员 */
  416. cancelResearcher() {
  417. this.rs_picker = {
  418. firstindex: 0,
  419. id: []
  420. }
  421. this.isResearcherPicker = false;
  422. },
  423. /* 选择研究员确认 */
  424. confirmResearcher() {
  425. console.log('确认选择')
  426. this.formData.selectResearchers[this.selectRsIndex].researcherId = this.rs_picker.id;
  427. this.isResearcherPicker = false;
  428. },
  429. chooseResearcher({target}){
  430. this.formData.selectResearchers[this.selectRsIndex].researcherId = target.value
  431. this.isResearcherPicker = false;
  432. },
  433. /* 研究员显示格式化为名字 */
  434. formatRsLable(arr) {
  435. if(!arr) return '';
  436. if( arr instanceof Array ) {
  437. return arr.map(item => {
  438. return this.findResearcherName(item)
  439. })
  440. }else {
  441. return this.findResearcherName(arr)
  442. }
  443. },
  444. findResearcherName(id){
  445. const isFicc = this.findResearcherById(id,'ficc')
  446. const isRai = this.findResearcherById(id,'rai')
  447. return isFicc?isFicc.RealName:isRai?isRai.RealName:''
  448. },
  449. findType(id){
  450. const isFicc = this.findResearcherById(id,'ficc')
  451. const isRai = this.findResearcherById(id,'rai')
  452. return isFicc?'ficc':isRai?'rai':''
  453. },
  454. findResearcherById(id,type='ficc'){
  455. const list = type==='ficc'?this.ficcReasearcherList:this.raiReasercherList
  456. const flatList = list.map(item=>item.ResearcherList||[]).flat(Infinity)
  457. return flatList.find(user=>user.AdminId===id)
  458. },
  459. /* 选择路演/会议形式 重置城市平台 */
  460. confirmRoadshowType({
  461. detail
  462. }) {
  463. this.formData.roadshowType = detail.value;
  464. this.formData.roadshowPlatform = '';
  465. this.formData.roadshowCity = '';
  466. this.isRoadshowTypePicker = false;
  467. },
  468. /* 选择地区弹窗 */
  469. clickAreaChoose() {
  470. const city = this.formData.roadshowCity.length ? this.formData.roadshowCity[1] : '';
  471. let cityCode = '';
  472. if(city) for(let i in this.areaList.city_list) {
  473. if(this.areaList.city_list[i] === city){
  474. cityCode = String(i);
  475. break;
  476. }
  477. }
  478. // console.log(cityCode)
  479. this.pickerForm.area = cityCode;
  480. this.isAreaPicker = true
  481. },
  482. /* 选择地区 */
  483. confirmArea({detail}) {
  484. const { values } = detail;
  485. this.formData.roadshowCity = values.map(item => item.name);
  486. this.formData.District = values.length===3?values[2].name:''
  487. this.isAreaPicker = false;
  488. },
  489. /* 点击选择时间 */
  490. clickTimeChoose(index, type) {
  491. console.log(this.formData.selectResearchers[index])
  492. this.pickerForm.time = type === 'start' ? this.formData.selectResearchers[index].startTime : this.formData.selectResearchers[index].endTime;
  493. this.selectObj = {
  494. index,
  495. type
  496. }
  497. setTimeout(() => {
  498. this.isTimePicker = true;
  499. })
  500. },
  501. /* 选择时间 */
  502. confirmTime({detail}) {
  503. // console.log(val)
  504. const {
  505. index,
  506. type
  507. } = this.selectObj;
  508. if (type === 'start') {
  509. this.formData.selectResearchers[index].startTime = detail;
  510. } else {
  511. this.formData.selectResearchers[index].endTime = detail;
  512. }
  513. this.isTimePicker = false;
  514. this.pickerForm.time = '';
  515. },
  516. /* 添加完成后 拼接动态内容 */
  517. setDynamicLink(type) {
  518. switch (type) {
  519. case '内部会议' : return {
  520. text: '添加成功,已加入研究员日历',
  521. content: `可前往【我的日历】-【${type}】查看`,
  522. link: '/pages-approve/activity/list',
  523. query: {
  524. type
  525. },
  526. }
  527. case '报告电话会' : return {
  528. text: '添加成功,已加入研究员日历',
  529. content: `可前往【我的日历】-【${type}】查看`,
  530. link: '/pages-approve/activity/list',
  531. query: {
  532. type
  533. },
  534. }
  535. case '路演' : return {
  536. text: '活动申请已提交,请等待研究员处理',
  537. content: `可前往【我的日历】-【活动申请】查看`,
  538. link: '/pages-approve/activity/list',
  539. query: {
  540. type: '活动申请'
  541. },
  542. }
  543. case '沙龙' : return {
  544. text: '添加活动成功,研究员日程已添加成功',
  545. content: `可前往【研究员日历】查看`,
  546. link: '/pages-approve/activity/list',
  547. query: {
  548. type: '活动申请'
  549. },
  550. }
  551. case 'ficc&rai路演' : return {
  552. text:'权益研究员日历已添加成功,ficc研究员日历已发送申请,请等待处理',
  553. content:'可前往【我的日历】查看',
  554. link:'/pages-approve/activity/list',
  555. query:{
  556. type: '活动申请'
  557. },
  558. }
  559. case '公开会议' : return {
  560. text: '活动申请已提交,请等待研究员处理',
  561. content: `可前往【我的日历】-【活动申请】查看`,
  562. link: '/pages-approve/activity/list',
  563. query: {
  564. type: '活动申请'
  565. },
  566. }
  567. }
  568. },
  569. /* 绑定input输入value */
  570. bindInputHandle(key,{detail}) {
  571. this.formData[key] = detail;
  572. },
  573. /* 格式化时间显示 */
  574. formatterLabelTime(val) {
  575. if(!val) return '';
  576. const date = moment(val).format('MM.DD(ddd) HH:mm');
  577. return date;
  578. },
  579. /* 格式化弹窗时间显示 */
  580. formatterPickerTime(type, val) {
  581. switch (type) {
  582. case 'year':
  583. return val + '年';
  584. case 'month':
  585. return val + '月';
  586. case 'day':
  587. return val + '日';
  588. case 'hour':
  589. return val + '时';
  590. case 'minute':
  591. return val + '分';
  592. }
  593. }
  594. }
  595. }