Index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <script setup>
  2. import { useStore } from "vuex";
  3. import { ref, reactive, onMounted } from 'vue'
  4. import { useRouter } from "vue-router";
  5. import { ElMessage,ElMessageBox } from 'element-plus'
  6. import moment from 'moment'
  7. import BaseCalendar from './components/BaseCalendar.vue'
  8. import {apiGetPermissionList,apiGetCalendarEventList,apiGetDailyEventList,apiGetPermissionNewestDate} from '@/api/forexCalendar.js'
  9. //权限控制
  10. const store = useStore();
  11. let hasAuth = ref(true)
  12. let noAuth = ref({
  13. type:'',
  14. name:'',
  15. mobile:'',
  16. customer_info:{}
  17. })
  18. //日历点击
  19. let showEventList = ref(false) //控制事项列表弹窗
  20. let currentDay = ref('') //选择的日期
  21. //日历点击事件
  22. function dateClick(info){
  23. setEventInfo(info.dateStr)
  24. }
  25. function eventClick(info){
  26. //直接打开弹窗
  27. setEventInfo(info.event.startStr)
  28. }
  29. async function setEventInfo(date){
  30. if(!permissionValue.value) return ElMessage.warning("请选择品种")
  31. currentDay.value = date||''
  32. //获取当天的日历信息,若有事项,则打开弹窗
  33. await getEventsByDay()
  34. if(eventList.value.length) showEventList.value = true
  35. }
  36. //事项列表
  37. let eventList = ref([
  38. {
  39. title:'我是自定义事项', //事件名称
  40. start:'2024-03-26',//日期,默认是全天事件
  41. textColor:'#000',//字体颜色
  42. backgroundColor:'#ffc0cb',//背景色
  43. borderColor:'#ffc0cb',//边框色
  44. isTextBold:false,
  45. matter_type:1,
  46. },
  47. {
  48. title:'我是某个关联指标', //事件名称
  49. start:'2024-03-26',//日期,默认是全天事件
  50. textColor:'#000',//字体颜色
  51. backgroundColor:'#ffc0cb',//背景色
  52. borderColor:'#ffc0cb',//边框色
  53. isTextBold:false,
  54. matter_type:2,
  55. }
  56. ])
  57. async function getEventsByDay(){
  58. await apiGetDailyEventList({
  59. chart_permission_id:Number(permissionValue.value),
  60. matter_date:currentDay.value
  61. }).then(res=>{
  62. if(res.code!==200){
  63. eventList.value=[]
  64. return
  65. }
  66. eventList.value = res.data||[]
  67. })
  68. }
  69. const router = useRouter()
  70. //跳转事项详情
  71. function handleClickEvent(event){
  72. if(event.matter_type===1) return ElMessage("该事项未关联指标")
  73. const {activeStart,activeEnd} = baseCalendarRef.value?.calendarApi.view||{}
  74. router.push({
  75. path:'/forexCalendar/detail',
  76. query:{
  77. startDate:moment(activeStart).format('YYYY-MM-DD'),
  78. endDate:moment(activeEnd).subtract(1, 'days').format('YYYY-MM-DD'),
  79. edbInfoId:event.edb_info_id,
  80. permissionId:permissionValue.value,
  81. permissionName:permissionName.value
  82. }
  83. })
  84. showEventList.value = false
  85. }
  86. let baseCalendarRef = ref(null) //日历api
  87. let monthValue = ref('') //选中的月份
  88. function changeMonth(month){
  89. const Month = month||new Date()
  90. baseCalendarRef.value?.calendarApi.gotoDate(Month)
  91. renderCalendar()
  92. }
  93. let permissionValue = ref('') //选中的品种ID
  94. let permissonList = ref([]) //品种列表
  95. let cascaderRef = ref(null) //品种cascader
  96. let permissionName = ref('') //品种名称
  97. function getPermissionList(){
  98. apiGetPermissionList().then(res=>{
  99. if(res.code===200){
  100. hasAuth.value = true
  101. permissonList.value = res.data
  102. /* permissionValue.value = permissonList.value[0]?.children[0]?.chart_permission_id
  103. changePermission() */
  104. }else{
  105. hasAuth.value = false
  106. noAuth.value = res.data
  107. }
  108. })
  109. }
  110. async function changePermission(){
  111. if(!hasAuth.value) return
  112. if(!permissionValue.value) return
  113. getPermissionName()
  114. await getPermissionNewestMonth()
  115. //renderCalendar()
  116. }
  117. async function getPermissionNewestMonth(){
  118. //获取最新月份的接口
  119. await apiGetPermissionNewestDate({
  120. chart_permission_id:Number(permissionValue.value)
  121. }).then(res=>{
  122. if(res.code!==200) return
  123. monthValue.value = res.data||moment(new Date()).format('YYYY-MM')
  124. changeMonth(monthValue.value)
  125. })
  126. }
  127. function getPermissionName(){
  128. const node = cascaderRef.value?.getCheckedNodes(true)[0]
  129. permissionName.value = node.label
  130. }
  131. //加载日历表
  132. async function renderCalendar(){
  133. //获取当前日历的起始日期+终止日期,可能会跨月
  134. const {activeStart,activeEnd} = baseCalendarRef.value?.calendarApi.view||{}
  135. const res = await apiGetCalendarEventList({
  136. chart_permission_id:Number(permissionValue.value),
  137. start_date:moment(activeStart).format('YYYY-MM-DD'),
  138. end_date:moment(activeEnd).subtract(1, 'days').format('YYYY-MM-DD'), //activeEnd到最后一天的24:00会被认为是第二天,所以取前一天
  139. })
  140. if(res.code!==200) return
  141. const allEventSource = baseCalendarRef.value?.calendarApi.getEventSources()||[]
  142. //先清空所有eventSource,再添加
  143. allEventSource.forEach(es=>es.remove())
  144. //将日历表每天的事件作为一个eventSource
  145. const eventList = (res.data?res.data:[]).map(dailyEvents=>{
  146. const eventSource = { id:dailyEvents.Date,events:[]}
  147. eventSource.events = dailyEvents.matters.map(e=>{
  148. return {
  149. ...e,
  150. start:e.matter_date,
  151. title:e.title,
  152. textColor:e.font_color||'#000',
  153. backgroundColor:e.filling_color||'#fff',
  154. borderColor:e.filling_color||'#fff',
  155. }
  156. })
  157. return eventSource
  158. })
  159. eventList.forEach(es=>{
  160. baseCalendarRef.value?.calendarApi.addEventSource(es)
  161. })
  162. }
  163. const handleApply=()=>{
  164. if(store.state.userInfo.is_bind===0){
  165. ElMessageBox({
  166. title:`温馨提示`,
  167. message:'为了优化您的用户体验,<br>请登录后查看更多信息!',
  168. dangerouslyUseHTMLString: true,
  169. center: true,
  170. confirmButtonText:'去登录',
  171. confirmButtonClass:'self-elmessage-confirm-btn',
  172. showCancelButton:true,
  173. cancelButtonText:'取消',
  174. cancelButtonClass:'self-elmessage-cancel-btn'
  175. }).then(res=>{
  176. wx.miniProgram.reLaunch({url:'/pages/login'})
  177. }).catch(()=>{})
  178. return
  179. }
  180. if(noAuth.value.customer_info.has_apply){
  181. const htmlStr=`<p>您已提交过申请,请耐心等待</p>`
  182. ElMessageBox({
  183. title:`事件日历`,
  184. message:htmlStr,
  185. center: true,
  186. dangerouslyUseHTMLString: true,
  187. confirmButtonText:'知道了',
  188. confirmButtonClass:'self-elmessage-confirm-btn'
  189. })
  190. }else{
  191. if (!noAuth.value.customer_info.status || noAuth.value.customer_info.status != '流失'|| noAuth.value.customer_info.status != '关闭') {
  192. console.log('跳转申请页');
  193. router.push({
  194. path:'/apply/permission',
  195. query:{
  196. source:11,
  197. fromPage:'事件日历'
  198. }
  199. })
  200. }else{
  201. apiApplyPermission({
  202. company_name:noAuth.value.customer_info.company_name,
  203. real_name:noAuth.value.customer_info.name,
  204. source:11,
  205. from_page:'事件日历'
  206. }).then(res=>{
  207. console.log('主动申请成功');
  208. const htmlStr=`<p>申请已提交</p><p>请等待销售人员与您联系</p>`
  209. ElMessageBox({
  210. title:`事件日历`,
  211. message:htmlStr,
  212. center: true,
  213. dangerouslyUseHTMLString: true,
  214. confirmButtonText:'知道了',
  215. confirmButtonClass:'self-elmessage-confirm-btn'
  216. })
  217. })
  218. }
  219. }
  220. }
  221. onMounted(()=>{
  222. monthValue.value = moment(new Date()).format('YYYY-MM')
  223. getPermissionList()
  224. })
  225. </script>
  226. <template>
  227. <div class="forex-calendar-wrap" v-if="hasAuth">
  228. <div class="calendar-header">
  229. <el-cascader :options="permissonList"
  230. ref="cascaderRef"
  231. placeholder="请选择品种"
  232. v-model="permissionValue"
  233. :props="{
  234. expandTrigger:'hover',
  235. emitPath:false,
  236. value:'chart_permission_id',
  237. label:'chart_permission_name'
  238. }"
  239. style="min-width:210px;"
  240. @change="changePermission"
  241. ></el-cascader>
  242. <el-date-picker v-model="monthValue" type="month" value-format="YYYY-MM" @change="changeMonth" :clearable="false" ></el-date-picker>
  243. </div>
  244. <BaseCalendar
  245. ref="baseCalendarRef"
  246. :markText="{date:monthValue,type:permissionName||'请选择品种'}"
  247. @dateClick="dateClick"
  248. @eventClick="eventClick"
  249. ></BaseCalendar>
  250. </div>
  251. <div class="no-auth" v-else>
  252. <img :src="$store.state.globalImgUrls.activityNoAuth" alt="">
  253. <p style="font-size:16px;margin-bottom: 0;">您暂无权限查看事件日历</p>
  254. <template v-if="noAuth.type=='contact'">
  255. <p style="font-size:16px;margin-top: 5px;margin-bottom: 62px;">若想查看,可以联系对口销售--{{noAuth.name}}:<span style="color:#F3A52F">{{noAuth.mobile}}</span></p>
  256. </template>
  257. <template v-else>
  258. <p style="font-size:16px;margin-top: 5px;margin-bottom: 62px;">若想参加可以申请开通</p>
  259. <div class="global-main-btn btn" @click="handleApply" style="margin-bottom: 20px;">立即申请</div>
  260. </template>
  261. </div>
  262. <!-- 事项详情弹窗 -->
  263. <el-dialog
  264. v-model="showEventList"
  265. :title="`${currentDay}${permissionName}事项`"
  266. :width="550"
  267. :close-on-click-modal="false"
  268. append-to-body
  269. class="event-list-dialog"
  270. >
  271. <div class="event-list-wrap">
  272. <ul class="event-list">
  273. <li class="event-item" v-for="(item,index) in eventList" :key="index" @click="handleClickEvent(item)">
  274. {{item.title}}
  275. </li>
  276. </ul>
  277. </div>
  278. </el-dialog>
  279. </template>
  280. <style scoped lang="scss">
  281. .forex-calendar-wrap{
  282. min-height: 700px;
  283. display: flex;
  284. flex-direction: column;
  285. .calendar-header{
  286. display: flex;
  287. justify-content: space-between;
  288. margin-bottom: 20px;
  289. }
  290. }
  291. .no-auth{
  292. text-align: center;
  293. img{
  294. width: 400px;
  295. }
  296. .btn{
  297. width: 218px;
  298. margin-left: auto;
  299. margin-right: auto;
  300. }
  301. }
  302. .event-list-dialog{
  303. .event-list-wrap{
  304. min-height: 300px;
  305. .event-list{
  306. padding:0 15px;
  307. .event-item{
  308. margin-bottom: 35px;
  309. cursor: pointer;
  310. }
  311. }
  312. }
  313. }
  314. </style>